fix(misc): nx init should add .nx/cache to gitignore (#19961)
This commit is contained in:
parent
eed2cc5810
commit
18f71d25e0
@ -13,6 +13,7 @@ import {
|
||||
initCloud,
|
||||
printFinalMessage,
|
||||
runInstall,
|
||||
updateGitIgnore,
|
||||
} from './utils';
|
||||
|
||||
type Options = Pick<InitArgs, 'nxCloud' | 'interactive' | 'cacheable'>;
|
||||
@ -88,6 +89,7 @@ export async function addNxToMonorepo(options: Options) {
|
||||
scriptOutputs
|
||||
);
|
||||
|
||||
updateGitIgnore(repoRoot);
|
||||
addDepsToPackageJson(repoRoot);
|
||||
|
||||
output.log({ title: '📦 Installing dependencies' });
|
||||
|
||||
@ -23,6 +23,7 @@ import {
|
||||
markRootPackageJsonAsNxProject,
|
||||
printFinalMessage,
|
||||
runInstall,
|
||||
updateGitIgnore,
|
||||
} from './utils';
|
||||
import { nxVersion } from '../../../utils/versions';
|
||||
|
||||
@ -117,6 +118,7 @@ export async function addNxToNest(options: Options, packageJson: PackageJson) {
|
||||
|
||||
const pmc = getPackageManagerCommand();
|
||||
|
||||
updateGitIgnore(repoRoot);
|
||||
addDepsToPackageJson(repoRoot);
|
||||
addNestPluginToPackageJson(repoRoot);
|
||||
markRootPackageJsonAsNxProject(
|
||||
|
||||
@ -11,6 +11,7 @@ import {
|
||||
markRootPackageJsonAsNxProject,
|
||||
printFinalMessage,
|
||||
runInstall,
|
||||
updateGitIgnore,
|
||||
} from './utils';
|
||||
|
||||
type Options = Pick<InitArgs, 'nxCloud' | 'interactive' | 'cacheable'>;
|
||||
@ -72,6 +73,7 @@ export async function addNxToNpmRepo(options: Options) {
|
||||
|
||||
const pmc = getPackageManagerCommand();
|
||||
|
||||
updateGitIgnore(repoRoot);
|
||||
addDepsToPackageJson(repoRoot);
|
||||
markRootPackageJsonAsNxProject(
|
||||
repoRoot,
|
||||
|
||||
@ -17,6 +17,7 @@ import {
|
||||
} from '../../../utils/package-manager';
|
||||
import { joinPathFragments } from '../../../utils/path';
|
||||
import { nxVersion } from '../../../utils/versions';
|
||||
import { readFileSync, writeFileSync } from 'fs';
|
||||
|
||||
export async function askAboutNxCloud(): Promise<boolean> {
|
||||
return await enquirer
|
||||
@ -121,6 +122,17 @@ export function addDepsToPackageJson(repoRoot: string) {
|
||||
writeJsonFile(path, json);
|
||||
}
|
||||
|
||||
export function updateGitIgnore(root: string) {
|
||||
const ignorePath = join(root, '.gitignore');
|
||||
try {
|
||||
let contents = readFileSync(ignorePath, 'utf-8');
|
||||
if (!contents.includes('.nx/cache')) {
|
||||
contents = [contents, '', '.nx/cache'].join('\n');
|
||||
writeFileSync(ignorePath, contents, 'utf-8');
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
export function runInstall(
|
||||
repoRoot: string,
|
||||
pmc: PackageManagerCommands = getPackageManagerCommand()
|
||||
|
||||
@ -2,7 +2,6 @@ import { execSync } from 'child_process';
|
||||
import { prompt } from 'enquirer';
|
||||
import { existsSync } from 'fs';
|
||||
import { prerelease } from 'semver';
|
||||
import * as parser from 'yargs-parser';
|
||||
import { addNxToMonorepo } from './implementation/add-nx-to-monorepo';
|
||||
import { addNxToNest } from './implementation/add-nx-to-nest';
|
||||
import { addNxToNpmRepo } from './implementation/add-nx-to-npm-repo';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user