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,
|
initCloud,
|
||||||
printFinalMessage,
|
printFinalMessage,
|
||||||
runInstall,
|
runInstall,
|
||||||
|
updateGitIgnore,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
type Options = Pick<InitArgs, 'nxCloud' | 'interactive' | 'cacheable'>;
|
type Options = Pick<InitArgs, 'nxCloud' | 'interactive' | 'cacheable'>;
|
||||||
@ -88,6 +89,7 @@ export async function addNxToMonorepo(options: Options) {
|
|||||||
scriptOutputs
|
scriptOutputs
|
||||||
);
|
);
|
||||||
|
|
||||||
|
updateGitIgnore(repoRoot);
|
||||||
addDepsToPackageJson(repoRoot);
|
addDepsToPackageJson(repoRoot);
|
||||||
|
|
||||||
output.log({ title: '📦 Installing dependencies' });
|
output.log({ title: '📦 Installing dependencies' });
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import {
|
|||||||
markRootPackageJsonAsNxProject,
|
markRootPackageJsonAsNxProject,
|
||||||
printFinalMessage,
|
printFinalMessage,
|
||||||
runInstall,
|
runInstall,
|
||||||
|
updateGitIgnore,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import { nxVersion } from '../../../utils/versions';
|
import { nxVersion } from '../../../utils/versions';
|
||||||
|
|
||||||
@ -117,6 +118,7 @@ export async function addNxToNest(options: Options, packageJson: PackageJson) {
|
|||||||
|
|
||||||
const pmc = getPackageManagerCommand();
|
const pmc = getPackageManagerCommand();
|
||||||
|
|
||||||
|
updateGitIgnore(repoRoot);
|
||||||
addDepsToPackageJson(repoRoot);
|
addDepsToPackageJson(repoRoot);
|
||||||
addNestPluginToPackageJson(repoRoot);
|
addNestPluginToPackageJson(repoRoot);
|
||||||
markRootPackageJsonAsNxProject(
|
markRootPackageJsonAsNxProject(
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import {
|
|||||||
markRootPackageJsonAsNxProject,
|
markRootPackageJsonAsNxProject,
|
||||||
printFinalMessage,
|
printFinalMessage,
|
||||||
runInstall,
|
runInstall,
|
||||||
|
updateGitIgnore,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
type Options = Pick<InitArgs, 'nxCloud' | 'interactive' | 'cacheable'>;
|
type Options = Pick<InitArgs, 'nxCloud' | 'interactive' | 'cacheable'>;
|
||||||
@ -72,6 +73,7 @@ export async function addNxToNpmRepo(options: Options) {
|
|||||||
|
|
||||||
const pmc = getPackageManagerCommand();
|
const pmc = getPackageManagerCommand();
|
||||||
|
|
||||||
|
updateGitIgnore(repoRoot);
|
||||||
addDepsToPackageJson(repoRoot);
|
addDepsToPackageJson(repoRoot);
|
||||||
markRootPackageJsonAsNxProject(
|
markRootPackageJsonAsNxProject(
|
||||||
repoRoot,
|
repoRoot,
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import {
|
|||||||
} from '../../../utils/package-manager';
|
} from '../../../utils/package-manager';
|
||||||
import { joinPathFragments } from '../../../utils/path';
|
import { joinPathFragments } from '../../../utils/path';
|
||||||
import { nxVersion } from '../../../utils/versions';
|
import { nxVersion } from '../../../utils/versions';
|
||||||
|
import { readFileSync, writeFileSync } from 'fs';
|
||||||
|
|
||||||
export async function askAboutNxCloud(): Promise<boolean> {
|
export async function askAboutNxCloud(): Promise<boolean> {
|
||||||
return await enquirer
|
return await enquirer
|
||||||
@ -121,6 +122,17 @@ export function addDepsToPackageJson(repoRoot: string) {
|
|||||||
writeJsonFile(path, json);
|
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(
|
export function runInstall(
|
||||||
repoRoot: string,
|
repoRoot: string,
|
||||||
pmc: PackageManagerCommands = getPackageManagerCommand()
|
pmc: PackageManagerCommands = getPackageManagerCommand()
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import { execSync } from 'child_process';
|
|||||||
import { prompt } from 'enquirer';
|
import { prompt } from 'enquirer';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { prerelease } from 'semver';
|
import { prerelease } from 'semver';
|
||||||
import * as parser from 'yargs-parser';
|
|
||||||
import { addNxToMonorepo } from './implementation/add-nx-to-monorepo';
|
import { addNxToMonorepo } from './implementation/add-nx-to-monorepo';
|
||||||
import { addNxToNest } from './implementation/add-nx-to-nest';
|
import { addNxToNest } from './implementation/add-nx-to-nest';
|
||||||
import { addNxToNpmRepo } from './implementation/add-nx-to-npm-repo';
|
import { addNxToNpmRepo } from './implementation/add-nx-to-npm-repo';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user