feat(core): move prettier init logic from @nrwl/workspace to @nrwl/js (#15501)
This commit is contained in:
parent
a0e00c85fc
commit
24b82edbed
@ -52,3 +52,7 @@ export function expectNoTsJestInJestConfig(appName: string) {
|
||||
);
|
||||
expect(jestConfig).not.toContain('ts-jest');
|
||||
}
|
||||
|
||||
export function expectCodeIsFormatted() {
|
||||
expect(() => runCLI(`format:check`)).not.toThrow();
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ import {
|
||||
checkFilesExist,
|
||||
cleanupProject,
|
||||
e2eCwd,
|
||||
expectCodeIsFormatted,
|
||||
expectNoAngularDevkit,
|
||||
expectNoTsJestInJestConfig,
|
||||
getSelectedPackageManager,
|
||||
@ -34,6 +35,7 @@ describe('create-nx-workspace', () => {
|
||||
checkFilesExist('src/app/app.routes.ts');
|
||||
checkFilesDoNotExist('tsconfig.base.json');
|
||||
checkFilesExist('project.json');
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should create a workspace with a single angular app at the root without routing', () => {
|
||||
@ -51,6 +53,7 @@ describe('create-nx-workspace', () => {
|
||||
checkFilesExist('project.json');
|
||||
checkFilesExist('src/app/app.module.ts');
|
||||
checkFilesDoNotExist('src/app/app.routes.ts');
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should create a workspace with a single angular app at the root using standalone APIs', () => {
|
||||
@ -68,6 +71,7 @@ describe('create-nx-workspace', () => {
|
||||
checkFilesExist('package.json');
|
||||
checkFilesExist('project.json');
|
||||
checkFilesDoNotExist('src/app/app.module.ts');
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should create a workspace with a single react app with vite at the root', () => {
|
||||
@ -85,6 +89,7 @@ describe('create-nx-workspace', () => {
|
||||
checkFilesExist('project.json');
|
||||
checkFilesExist('vite.config.ts');
|
||||
checkFilesDoNotExist('tsconfig.base.json');
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should create a workspace with a single react app with webpack at the root', () => {
|
||||
@ -102,6 +107,7 @@ describe('create-nx-workspace', () => {
|
||||
checkFilesExist('project.json');
|
||||
checkFilesExist('webpack.config.js');
|
||||
checkFilesDoNotExist('tsconfig.base.json');
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should be able to create an empty workspace built for apps', () => {
|
||||
@ -138,11 +144,12 @@ describe('create-nx-workspace', () => {
|
||||
it('should be able to create an empty workspace with ts/js capabilities', () => {
|
||||
const wsName = uniq('ts');
|
||||
runCreateWorkspace(wsName, {
|
||||
preset: 'npm',
|
||||
preset: 'ts',
|
||||
packageManager,
|
||||
});
|
||||
|
||||
expectNoAngularDevkit();
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should be able to create an angular workspace', () => {
|
||||
@ -156,6 +163,7 @@ describe('create-nx-workspace', () => {
|
||||
standaloneApi: false,
|
||||
routing: true,
|
||||
});
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should fail correctly when preset errors', () => {
|
||||
@ -164,7 +172,7 @@ describe('create-nx-workspace', () => {
|
||||
// Due to a validation error Angular will throw.
|
||||
const wsName = uniq('angular-1-test');
|
||||
const appName = uniq('app');
|
||||
try {
|
||||
expect(() =>
|
||||
runCreateWorkspace(wsName, {
|
||||
preset: 'angular-monorepo',
|
||||
style: 'css',
|
||||
@ -172,10 +180,8 @@ describe('create-nx-workspace', () => {
|
||||
packageManager,
|
||||
standaloneApi: false,
|
||||
routing: true,
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeTruthy();
|
||||
}
|
||||
})
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it('should be able to create a react workspace with webpack', () => {
|
||||
@ -194,6 +200,7 @@ describe('create-nx-workspace', () => {
|
||||
expectNoTsJestInJestConfig(appName);
|
||||
const packageJson = readJson('package.json');
|
||||
expect(packageJson.devDependencies['@nrwl/webpack']).toBeDefined();
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should be able to create a react workspace with vite', () => {
|
||||
@ -212,6 +219,7 @@ describe('create-nx-workspace', () => {
|
||||
const packageJson = readJson('package.json');
|
||||
expect(packageJson.devDependencies['@nrwl/webpack']).not.toBeDefined();
|
||||
expect(packageJson.devDependencies['@nrwl/vite']).toBeDefined();
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should be able to create an next workspace', () => {
|
||||
@ -225,6 +233,7 @@ describe('create-nx-workspace', () => {
|
||||
});
|
||||
|
||||
expectNoAngularDevkit();
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should be able to create an web-components workspace', () => {
|
||||
@ -238,6 +247,7 @@ describe('create-nx-workspace', () => {
|
||||
});
|
||||
|
||||
expectNoAngularDevkit();
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should be able to create an express workspace', () => {
|
||||
@ -251,6 +261,7 @@ describe('create-nx-workspace', () => {
|
||||
});
|
||||
|
||||
expectNoAngularDevkit();
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should be able to create react-native workspace', () => {
|
||||
@ -263,6 +274,7 @@ describe('create-nx-workspace', () => {
|
||||
});
|
||||
|
||||
expectNoAngularDevkit();
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should be able to create an expo workspace', () => {
|
||||
@ -275,6 +287,7 @@ describe('create-nx-workspace', () => {
|
||||
});
|
||||
|
||||
expectNoAngularDevkit();
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should be able to create a workspace with a custom base branch and HEAD', () => {
|
||||
@ -304,6 +317,7 @@ describe('create-nx-workspace', () => {
|
||||
appName,
|
||||
packageManager,
|
||||
});
|
||||
expectCodeIsFormatted();
|
||||
});
|
||||
|
||||
it('should respect package manager preference', () => {
|
||||
@ -323,6 +337,7 @@ describe('create-nx-workspace', () => {
|
||||
|
||||
checkFilesDoNotExist('yarn.lock');
|
||||
checkFilesExist('package-lock.json');
|
||||
expectCodeIsFormatted();
|
||||
process.env.SELECTED_PM = packageManager;
|
||||
});
|
||||
|
||||
@ -344,6 +359,7 @@ describe('create-nx-workspace', () => {
|
||||
|
||||
checkFilesDoNotExist('yarn.lock');
|
||||
checkFilesExist('package-lock.json');
|
||||
expectCodeIsFormatted();
|
||||
process.env.SELECTED_PM = packageManager;
|
||||
});
|
||||
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
# Add files here to ignore them from prettier formatting
|
||||
|
||||
/dist
|
||||
/coverage
|
||||
@ -6,7 +6,7 @@ import {
|
||||
writeJson,
|
||||
} from '@nrwl/devkit';
|
||||
import { createTree } from '@nrwl/devkit/testing';
|
||||
import * as prettierUtils from '@nrwl/workspace/src/utilities/prettier';
|
||||
import * as prettierUtils from '@nrwl/js/src/utils/prettier';
|
||||
import { migrateFromAngularCli } from './migrate-from-angular-cli';
|
||||
|
||||
describe('workspace', () => {
|
||||
|
||||
@ -5,7 +5,8 @@ import {
|
||||
readJson,
|
||||
updateJson,
|
||||
} from '@nrwl/devkit';
|
||||
import { prettierVersion } from '@nrwl/workspace/src/utils/versions';
|
||||
import { prettierVersion } from '@nrwl/js/src/utils/versions';
|
||||
import { initGenerator as jsInitGenerator } from '@nrwl/js';
|
||||
import { nxVersion } from '../../utils/versions';
|
||||
import type { ProjectMigrator } from './migrators';
|
||||
import { AppMigrator, LibMigrator } from './migrators';
|
||||
@ -24,7 +25,6 @@ import {
|
||||
getWorkspaceRootFileTypesInfo,
|
||||
normalizeOptions,
|
||||
updatePackageJson,
|
||||
updatePrettierConfig,
|
||||
updateRootEsLintConfig,
|
||||
updateRootTsConfig,
|
||||
updateVsCodeRecommendedExtensions,
|
||||
@ -55,7 +55,7 @@ export async function migrateFromAngularCli(
|
||||
);
|
||||
createNxJson(tree, options, angularJson.defaultProject);
|
||||
updateVsCodeRecommendedExtensions(tree);
|
||||
await updatePrettierConfig(tree);
|
||||
await jsInitGenerator(tree, {});
|
||||
|
||||
// convert workspace config format to standalone project configs
|
||||
updateJson(tree, 'angular.json', (json) => ({
|
||||
|
||||
@ -10,11 +10,12 @@ import {
|
||||
writeJson,
|
||||
} from '@nrwl/devkit';
|
||||
import { Linter, lintInitGenerator } from '@nrwl/linter';
|
||||
import { DEFAULT_NRWL_PRETTIER_CONFIG } from '@nrwl/workspace/src/generators/new/generate-workspace-files';
|
||||
import {
|
||||
getRootTsConfigPathInTree,
|
||||
initGenerator as jsInitGenerator,
|
||||
} from '@nrwl/js';
|
||||
import { deduceDefaultBase } from 'nx/src/utils/default-base';
|
||||
import { resolveUserExistingPrettierConfig } from '@nrwl/workspace/src/utilities/prettier';
|
||||
import { getRootTsConfigPathInTree } from '@nrwl/js';
|
||||
import { prettierVersion } from '@nrwl/workspace/src/utils/versions';
|
||||
import { prettierVersion } from '@nrwl/js/src/utils/versions';
|
||||
import { toNewFormat } from 'nx/src/adapter/angular-json';
|
||||
import { angularDevkitVersion, nxVersion } from '../../../utils/versions';
|
||||
import type { ProjectMigrator } from '../migrators';
|
||||
@ -262,7 +263,8 @@ export function cleanupEsLintPackages(tree: Tree): void {
|
||||
|
||||
export async function createWorkspaceFiles(tree: Tree): Promise<void> {
|
||||
updateVsCodeRecommendedExtensions(tree);
|
||||
await updatePrettierConfig(tree);
|
||||
|
||||
await jsInitGenerator(tree, {});
|
||||
|
||||
generateFiles(tree, joinPathFragments(__dirname, '../files/root'), '.', {
|
||||
tmpl: '',
|
||||
@ -346,22 +348,6 @@ export function updateVsCodeRecommendedExtensions(tree: Tree): void {
|
||||
}
|
||||
}
|
||||
|
||||
export async function updatePrettierConfig(tree: Tree): Promise<void> {
|
||||
const existingPrettierConfig = await resolveUserExistingPrettierConfig();
|
||||
if (!existingPrettierConfig) {
|
||||
writeJson(tree, '.prettierrc', DEFAULT_NRWL_PRETTIER_CONFIG);
|
||||
}
|
||||
|
||||
if (!tree.exists('.prettierignore')) {
|
||||
generateFiles(
|
||||
tree,
|
||||
joinPathFragments(__dirname, '../files/prettier'),
|
||||
'.',
|
||||
{ tmpl: '', dot: '.' }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function deleteAngularJson(tree: Tree): void {
|
||||
const projects = toNewFormat(readJson(tree, 'angular.json')).projects;
|
||||
if (!Object.keys(projects).length) {
|
||||
|
||||
@ -30,6 +30,7 @@ exports[`StorybookConfiguration generator should generate in the correct folder
|
||||
Array [
|
||||
".eslintignore",
|
||||
".eslintrc.json",
|
||||
".prettierignore",
|
||||
".prettierrc",
|
||||
"apps/.gitignore",
|
||||
"apps/one/two/test-ui-lib-e2e/.eslintrc.json",
|
||||
@ -160,6 +161,7 @@ exports[`StorybookConfiguration generator should generate the right files 1`] =
|
||||
Array [
|
||||
".eslintignore",
|
||||
".eslintrc.json",
|
||||
".prettierignore",
|
||||
".prettierrc",
|
||||
"apps/.gitignore",
|
||||
"apps/test-ui-lib-e2e/.eslintrc.json",
|
||||
|
||||
@ -24,6 +24,7 @@ export async function formatFiles(tree: Tree): Promise<void> {
|
||||
const files = new Set(
|
||||
tree.listChanges().filter((file) => file.type !== 'DELETE')
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
Array.from(files).map(async (file) => {
|
||||
const systemPath = path.join(tree.root, file.path);
|
||||
|
||||
70
packages/js/src/generators/init/init.spec.ts
Normal file
70
packages/js/src/generators/init/init.spec.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import { writeJson, readJson, Tree } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import init from './init';
|
||||
|
||||
describe('js init generator', () => {
|
||||
let tree: Tree;
|
||||
|
||||
beforeEach(() => {
|
||||
tree = createTreeWithEmptyWorkspace();
|
||||
});
|
||||
|
||||
it('should install prettier package', async () => {
|
||||
await init(tree, {});
|
||||
|
||||
const packageJson = readJson(tree, 'package.json');
|
||||
expect(packageJson.devDependencies['prettier']).toBeDefined();
|
||||
});
|
||||
|
||||
it('should create .prettierrc and .prettierignore files', async () => {
|
||||
await init(tree, {});
|
||||
|
||||
const prettierrc = readJson(tree, '.prettierrc');
|
||||
expect(prettierrc).toEqual({ singleQuote: true });
|
||||
|
||||
const prettierignore = tree.read('.prettierignore', 'utf-8');
|
||||
expect(prettierignore).toMatch(/\n\/coverage/);
|
||||
expect(prettierignore).toMatch(/\n\/dist/);
|
||||
});
|
||||
|
||||
it('should not overwrite existing .prettierrc and .prettierignore files', async () => {
|
||||
writeJson(tree, '.prettierrc', { singleQuote: false });
|
||||
tree.write('.prettierignore', `# custom ignore file`);
|
||||
|
||||
await init(tree, {});
|
||||
|
||||
const prettierrc = readJson(tree, '.prettierrc');
|
||||
expect(prettierrc).toEqual({ singleQuote: false });
|
||||
|
||||
const prettierignore = tree.read('.prettierignore', 'utf-8');
|
||||
expect(prettierignore).toContain('# custom ignore file');
|
||||
});
|
||||
|
||||
it('should add prettier vscode extension if .vscode/extensions.json file exists', async () => {
|
||||
// No existing recommendations
|
||||
writeJson(tree, '.vscode/extensions.json', {});
|
||||
|
||||
await init(tree, {});
|
||||
|
||||
let json = readJson(tree, '.vscode/extensions.json');
|
||||
expect(json).toEqual({
|
||||
recommendations: ['esbenp.prettier-vscode'],
|
||||
});
|
||||
|
||||
// Existing recommendations
|
||||
writeJson(tree, '.vscode/extensions.json', { recommendations: ['foo'] });
|
||||
|
||||
await init(tree, {});
|
||||
|
||||
json = readJson(tree, '.vscode/extensions.json');
|
||||
expect(json).toEqual({
|
||||
recommendations: ['foo', 'esbenp.prettier-vscode'],
|
||||
});
|
||||
});
|
||||
|
||||
it('should skip adding prettier extension if .vscode/extensions.json file does not exist', async () => {
|
||||
await init(tree, {});
|
||||
|
||||
expect(tree.exists('.vscode/extensions.json')).toBeFalsy();
|
||||
});
|
||||
});
|
||||
@ -1,16 +1,24 @@
|
||||
import {
|
||||
addDependenciesToPackageJson,
|
||||
convertNxGenerator,
|
||||
formatFiles,
|
||||
generateFiles,
|
||||
GeneratorCallback,
|
||||
joinPathFragments,
|
||||
stripIndents,
|
||||
Tree,
|
||||
updateJson,
|
||||
writeJson,
|
||||
} from '@nrwl/devkit';
|
||||
import { getRootTsConfigFileName } from '../../utils/typescript/ts-config';
|
||||
import { typescriptVersion, nxVersion } from '../../utils/versions';
|
||||
import {
|
||||
nxVersion,
|
||||
prettierVersion,
|
||||
typescriptVersion,
|
||||
} from '../../utils/versions';
|
||||
import { InitSchema } from './schema';
|
||||
|
||||
let formatTaskAdded = false;
|
||||
|
||||
export async function initGenerator(
|
||||
tree: Tree,
|
||||
schema: InitSchema
|
||||
@ -23,21 +31,59 @@ export async function initGenerator(
|
||||
}
|
||||
const devDependencies = {
|
||||
'@nrwl/js': nxVersion,
|
||||
prettier: prettierVersion,
|
||||
};
|
||||
|
||||
if (!schema.js) {
|
||||
devDependencies['typescript'] = typescriptVersion;
|
||||
}
|
||||
|
||||
if (!tree.exists(`.prettierrc`)) {
|
||||
writeJson(tree, '.prettierrc', {
|
||||
singleQuote: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (!tree.exists(`.prettierignore`)) {
|
||||
tree.write(
|
||||
'.prettierignore',
|
||||
stripIndents`
|
||||
# Add files here to ignore them from prettier formatting
|
||||
/dist
|
||||
/coverage
|
||||
`
|
||||
);
|
||||
}
|
||||
if (tree.exists('.vscode/extensions.json')) {
|
||||
updateJson(tree, '.vscode/extensions.json', (json) => {
|
||||
json.recommendations ??= [];
|
||||
const extension = 'esbenp.prettier-vscode';
|
||||
if (!json.recommendations.includes(extension)) {
|
||||
json.recommendations.push(extension);
|
||||
}
|
||||
return json;
|
||||
});
|
||||
}
|
||||
|
||||
const installTask = !schema.skipPackageJson
|
||||
? addDependenciesToPackageJson(tree, {}, devDependencies)
|
||||
: () => {};
|
||||
|
||||
if (!schema.skipFormat) {
|
||||
await formatFiles(tree);
|
||||
}
|
||||
return async () => {
|
||||
await installTask();
|
||||
|
||||
return installTask;
|
||||
// Run Prettier once on all non-ignored files because some files may not be changed in the tree. e.g. nx.json
|
||||
// TODO(jack): Once we create @nrwl/prettier:init we can move this logic there with --formatExistingFiles option.
|
||||
if (!formatTaskAdded) {
|
||||
formatTaskAdded = true;
|
||||
try {
|
||||
const prettierCli = await import('prettier/cli');
|
||||
await prettierCli.run(['.', '--write']);
|
||||
} catch {
|
||||
// If --skipPackageJson is passed then prettier is not installed.
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default initGenerator;
|
||||
|
||||
@ -28,7 +28,7 @@ export default async function update(host: Tree) {
|
||||
|
||||
// check swcExclude build options
|
||||
const exclude =
|
||||
config?.targets?.build?.options['swcExclude'] || defaultExclude;
|
||||
config?.targets?.build?.options?.['swcExclude'] || defaultExclude;
|
||||
updateJson(host, libSwcrcPath, (swcrc) => {
|
||||
swcrc['exclude'] = exclude;
|
||||
return swcrc;
|
||||
|
||||
@ -3,6 +3,7 @@ export { swcCoreVersion } from 'nx/src/utils/versions';
|
||||
export const nxVersion = require('../../package.json').version;
|
||||
|
||||
export const esbuildVersion = '^0.17.5';
|
||||
export const prettierVersion = '^2.6.2';
|
||||
export const swcCliVersion = '~0.1.55';
|
||||
export const swcHelpersVersion = '~0.4.11';
|
||||
export const typesNodeVersion = '18.7.1';
|
||||
|
||||
@ -16,6 +16,7 @@ Object {
|
||||
"@storybook/manager-webpack5": "^6.5.15",
|
||||
"existing": "1.0.0",
|
||||
"html-webpack-plugin": "^5.5.0",
|
||||
"prettier": "^2.6.2",
|
||||
"typescript": "~4.9.5",
|
||||
"webpack": "^5.64.0",
|
||||
},
|
||||
|
||||
@ -329,7 +329,7 @@ function normalizeOptions(host: Tree, options: Schema): NormalizedSchema {
|
||||
|
||||
return {
|
||||
...options,
|
||||
prefix: options.prefix ?? npmScope,
|
||||
prefix: options.prefix ?? npmScope ?? 'app',
|
||||
name: names(options.name).fileName,
|
||||
compiler: options.compiler ?? 'babel',
|
||||
bundler: options.bundler ?? 'webpack',
|
||||
|
||||
@ -39,10 +39,12 @@ function updateDependencies(tree: Tree, schema: Schema) {
|
||||
}
|
||||
|
||||
export async function webInitGenerator(tree: Tree, schema: Schema) {
|
||||
await jsInitGenerator(tree, {
|
||||
const tasks: GeneratorCallback[] = [];
|
||||
|
||||
const jsInitTask = await jsInitGenerator(tree, {
|
||||
js: false,
|
||||
});
|
||||
let tasks: GeneratorCallback[] = [];
|
||||
tasks.push(jsInitTask);
|
||||
|
||||
if (!schema.unitTestRunner || schema.unitTestRunner === 'jest') {
|
||||
const jestTask = await jestInitGenerator(tree, {
|
||||
@ -60,7 +62,7 @@ export async function webInitGenerator(tree: Tree, schema: Schema) {
|
||||
const installTask = updateDependencies(tree, schema);
|
||||
tasks.push(installTask);
|
||||
}
|
||||
addBabelInputs(tree);
|
||||
await addBabelInputs(tree);
|
||||
|
||||
if (!schema.skipFormat) {
|
||||
await formatFiles(tree);
|
||||
|
||||
@ -9,11 +9,6 @@ export {
|
||||
|
||||
export { names } from '@nrwl/devkit';
|
||||
|
||||
export {
|
||||
ExistingPrettierConfig,
|
||||
resolveUserExistingPrettierConfig,
|
||||
} from './src/utilities/prettier';
|
||||
|
||||
export { output } from './src/utilities/output';
|
||||
|
||||
export {
|
||||
|
||||
@ -61,14 +61,6 @@
|
||||
"nx": "*"
|
||||
}
|
||||
},
|
||||
"peerDependencies": {
|
||||
"prettier": "^2.6.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"prettier": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@nrwl/devkit": "file:../devkit",
|
||||
"@parcel/watcher": "2.0.4",
|
||||
|
||||
@ -393,13 +393,6 @@ Visit the [Nx Documentation](https://nx.dev) to learn more.
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`@nrwl/workspace:generateWorkspaceFiles should create a prettierrc file 1`] = `
|
||||
"{
|
||||
\\"singleQuote\\": true
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`@nrwl/workspace:generateWorkspaceFiles should recommend vscode extensions (angular) 1`] = `
|
||||
Array [
|
||||
"nrwl.angular-console",
|
||||
|
||||
@ -8,7 +8,6 @@ Object {
|
||||
"devDependencies": Object {
|
||||
"@nrwl/workspace": "0.0.1",
|
||||
"nx": "0.0.1",
|
||||
"prettier": "^2.6.2",
|
||||
},
|
||||
"license": "MIT",
|
||||
"name": "my-workspace",
|
||||
@ -24,7 +23,6 @@ Object {
|
||||
"devDependencies": Object {
|
||||
"@nrwl/workspace": "0.0.1",
|
||||
"nx": "0.0.1",
|
||||
"prettier": "^2.6.2",
|
||||
},
|
||||
"license": "MIT",
|
||||
"name": "my-workspace",
|
||||
@ -41,7 +39,6 @@ Object {
|
||||
"@nrwl/react": "0.0.1",
|
||||
"@nrwl/workspace": "0.0.1",
|
||||
"nx": "0.0.1",
|
||||
"prettier": "^2.6.2",
|
||||
},
|
||||
"license": "MIT",
|
||||
"name": "my-workspace",
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
# Add files here to ignore them from prettier formatting
|
||||
|
||||
/dist
|
||||
/coverage
|
||||
@ -9,7 +9,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"nx": "<%= nxVersion %>",
|
||||
"@nrwl/workspace": "<%= nxVersion %>",
|
||||
"prettier": "<%= prettierVersion %>"
|
||||
"@nrwl/workspace": "<%= nxVersion %>"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
# Add files here to ignore them from prettier formatting
|
||||
|
||||
/dist
|
||||
/coverage
|
||||
@ -3,7 +3,6 @@
|
||||
<% if(cliCommand === 'ng') { %>
|
||||
"angular.ng-template",<% }
|
||||
%>
|
||||
"nrwl.angular-console",
|
||||
"esbenp.prettier-vscode"
|
||||
"nrwl.angular-console"
|
||||
]
|
||||
}
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
"dependencies": {
|
||||
},
|
||||
"devDependencies": {
|
||||
"nx": "<%= nxVersion %>",
|
||||
"prettier": "<%= prettierVersion %>"
|
||||
"nx": "<%= nxVersion %>"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
# Add files here to ignore them from prettier formatting
|
||||
|
||||
/dist
|
||||
/coverage
|
||||
@ -1,7 +1,6 @@
|
||||
{
|
||||
"recommendations": [<% if(cliCommand === 'ng') { %>
|
||||
"angular.ng-template",<% } %>
|
||||
"nrwl.angular-console",
|
||||
"esbenp.prettier-vscode"
|
||||
"nrwl.angular-console"
|
||||
]
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nrwl/workspace": "<%= nxVersion %>",
|
||||
"nx": "<%= nxVersion %>",
|
||||
"prettier": "<%= prettierVersion %>"
|
||||
"nx": "<%= nxVersion %>"
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,8 +22,6 @@ describe('@nrwl/workspace:generateWorkspaceFiles', () => {
|
||||
});
|
||||
expect(tree.exists('/proj/README.md')).toBe(true);
|
||||
expect(tree.exists('/proj/nx.json')).toBe(true);
|
||||
expect(tree.exists('/proj/.prettierrc')).toBe(true);
|
||||
expect(tree.exists('/proj/.prettierignore')).toBe(true);
|
||||
});
|
||||
|
||||
describe('README.md', () => {
|
||||
@ -158,16 +156,6 @@ describe('@nrwl/workspace:generateWorkspaceFiles', () => {
|
||||
`);
|
||||
});
|
||||
|
||||
it('should create a prettierrc file', async () => {
|
||||
await generateWorkspaceFiles(tree, {
|
||||
name: 'proj',
|
||||
directory: 'proj',
|
||||
preset: Preset.Empty,
|
||||
defaultBase: 'main',
|
||||
});
|
||||
expect(tree.read('proj/.prettierrc', 'utf-8')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should recommend vscode extensions', async () => {
|
||||
await generateWorkspaceFiles(tree, {
|
||||
name: 'proj',
|
||||
@ -237,7 +225,6 @@ describe('@nrwl/workspace:generateWorkspaceFiles', () => {
|
||||
"dependencies": Object {},
|
||||
"devDependencies": Object {
|
||||
"nx": "0.0.1",
|
||||
"prettier": "^2.6.2",
|
||||
},
|
||||
"license": "MIT",
|
||||
"name": "proj",
|
||||
@ -266,7 +253,6 @@ describe('@nrwl/workspace:generateWorkspaceFiles', () => {
|
||||
"dependencies": Object {},
|
||||
"devDependencies": Object {
|
||||
"nx": "0.0.1",
|
||||
"prettier": "^2.6.2",
|
||||
},
|
||||
"license": "MIT",
|
||||
"name": "proj",
|
||||
|
||||
@ -9,16 +9,12 @@ import {
|
||||
updateJson,
|
||||
writeJson,
|
||||
} from '@nrwl/devkit';
|
||||
import { nxVersion, prettierVersion } from '../../utils/versions';
|
||||
import { nxVersion } from '../../utils/versions';
|
||||
import { join, join as pathJoin } from 'path';
|
||||
import { Preset } from '../utils/presets';
|
||||
import { deduceDefaultBase } from '../../utilities/default-base';
|
||||
import { NormalizedSchema } from './new';
|
||||
|
||||
export const DEFAULT_NRWL_PRETTIER_CONFIG = {
|
||||
singleQuote: true,
|
||||
};
|
||||
|
||||
export async function generateWorkspaceFiles(
|
||||
tree: Tree,
|
||||
options: NormalizedSchema
|
||||
@ -30,7 +26,6 @@ export async function generateWorkspaceFiles(
|
||||
createReadme(tree, options);
|
||||
createFiles(tree, options);
|
||||
createNxJson(tree, options);
|
||||
createPrettierrc(tree, options);
|
||||
|
||||
const [packageMajor] = getPackageManagerVersion(
|
||||
options.packageManager as PackageManager
|
||||
@ -142,7 +137,6 @@ function createFiles(tree: Tree, options: NormalizedSchema) {
|
||||
tmpl: '',
|
||||
cliCommand: 'nx',
|
||||
nxCli: false,
|
||||
prettierVersion,
|
||||
...(options as object),
|
||||
nxVersion,
|
||||
packageManager: options.packageManager,
|
||||
@ -161,14 +155,6 @@ function createReadme(
|
||||
});
|
||||
}
|
||||
|
||||
function createPrettierrc(tree: Tree, options: NormalizedSchema) {
|
||||
writeJson(
|
||||
tree,
|
||||
join(options.directory, '.prettierrc'),
|
||||
DEFAULT_NRWL_PRETTIER_CONFIG
|
||||
);
|
||||
}
|
||||
|
||||
// ensure that pnpm install add all the missing peer deps
|
||||
|
||||
function createNpmrc(tree: Tree, options: NormalizedSchema) {
|
||||
|
||||
@ -46,8 +46,6 @@ export async function newGenerator(host: Tree, options: Schema) {
|
||||
const isCustomPreset = !Object.values(Preset).includes(options.preset as any);
|
||||
addCloudDependencies(host, options);
|
||||
|
||||
await formatFiles(host);
|
||||
|
||||
return async () => {
|
||||
installPackagesTask(host, false, options.directory, options.packageManager);
|
||||
// TODO: move all of these into create-nx-workspace
|
||||
|
||||
@ -11,10 +11,10 @@ import { Preset } from '../utils/presets';
|
||||
|
||||
export async function presetGenerator(tree: Tree, options: Schema) {
|
||||
options = normalizeOptions(options);
|
||||
await createPreset(tree, options);
|
||||
await formatFiles(tree);
|
||||
return () => {
|
||||
const presetTask = await createPreset(tree, options);
|
||||
return async () => {
|
||||
installPackagesTask(tree);
|
||||
if (presetTask) await presetTask();
|
||||
};
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
||||
applicationGenerator: angularApplicationGenerator,
|
||||
} = require('@nrwl' + '/angular/generators');
|
||||
|
||||
await angularApplicationGenerator(tree, {
|
||||
return angularApplicationGenerator(tree, {
|
||||
name: options.name,
|
||||
style: options.style,
|
||||
linter: options.linter,
|
||||
@ -40,7 +40,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
||||
applicationGenerator: angularApplicationGenerator,
|
||||
} = require('@nrwl' + '/angular/generators');
|
||||
|
||||
await angularApplicationGenerator(tree, {
|
||||
return angularApplicationGenerator(tree, {
|
||||
name: options.name,
|
||||
style: options.style,
|
||||
linter: options.linter,
|
||||
@ -53,7 +53,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
||||
applicationGenerator: reactApplicationGenerator,
|
||||
} = require('@nrwl' + '/react');
|
||||
|
||||
await reactApplicationGenerator(tree, {
|
||||
return reactApplicationGenerator(tree, {
|
||||
name: options.name,
|
||||
style: options.style,
|
||||
linter: options.linter,
|
||||
@ -64,7 +64,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
||||
applicationGenerator: reactApplicationGenerator,
|
||||
} = require('@nrwl' + '/react');
|
||||
|
||||
await reactApplicationGenerator(tree, {
|
||||
return reactApplicationGenerator(tree, {
|
||||
name: options.name,
|
||||
style: options.style,
|
||||
linter: options.linter,
|
||||
@ -77,7 +77,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
||||
const { applicationGenerator: nextApplicationGenerator } = require('@nrwl' +
|
||||
'/next');
|
||||
|
||||
await nextApplicationGenerator(tree, {
|
||||
return nextApplicationGenerator(tree, {
|
||||
name: options.name,
|
||||
style: options.style,
|
||||
linter: options.linter,
|
||||
@ -86,7 +86,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
||||
const { applicationGenerator: webApplicationGenerator } = require('@nrwl' +
|
||||
'/web');
|
||||
|
||||
await webApplicationGenerator(tree, {
|
||||
return webApplicationGenerator(tree, {
|
||||
name: options.name,
|
||||
style: options.style,
|
||||
linter: options.linter,
|
||||
@ -96,7 +96,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
||||
const { applicationGenerator: nestApplicationGenerator } = require('@nrwl' +
|
||||
'/nest');
|
||||
|
||||
await nestApplicationGenerator(tree, {
|
||||
return nestApplicationGenerator(tree, {
|
||||
name: options.name,
|
||||
linter: options.linter,
|
||||
});
|
||||
@ -104,36 +104,38 @@ async function createPreset(tree: Tree, options: Schema) {
|
||||
const {
|
||||
applicationGenerator: expressApplicationGenerator,
|
||||
} = require('@nrwl' + '/express');
|
||||
await expressApplicationGenerator(tree, {
|
||||
return expressApplicationGenerator(tree, {
|
||||
name: options.name,
|
||||
linter: options.linter,
|
||||
});
|
||||
} else if (options.preset === Preset.ReactNative) {
|
||||
const { reactNativeApplicationGenerator } = require('@nrwl' +
|
||||
'/react-native');
|
||||
await reactNativeApplicationGenerator(tree, {
|
||||
return reactNativeApplicationGenerator(tree, {
|
||||
name: options.name,
|
||||
linter: options.linter,
|
||||
e2eTestRunner: 'detox',
|
||||
});
|
||||
} else if (options.preset === Preset.Expo) {
|
||||
const { expoApplicationGenerator } = require('@nrwl' + '/expo');
|
||||
await expoApplicationGenerator(tree, {
|
||||
return expoApplicationGenerator(tree, {
|
||||
name: options.name,
|
||||
linter: options.linter,
|
||||
e2eTestRunner: 'detox',
|
||||
});
|
||||
} else if (options.preset === Preset.TS) {
|
||||
const c = readNxJson(tree);
|
||||
const { initGenerator } = require('@nrwl' + '/js');
|
||||
c.workspaceLayout = {
|
||||
appsDir: 'packages',
|
||||
libsDir: 'packages',
|
||||
};
|
||||
updateNxJson(tree, c);
|
||||
return initGenerator(tree, {});
|
||||
} else if (options.preset === Preset.NodeServer) {
|
||||
const { applicationGenerator: nodeApplicationGenerator } = require('@nrwl' +
|
||||
'/node');
|
||||
await nodeApplicationGenerator(tree, {
|
||||
return nodeApplicationGenerator(tree, {
|
||||
name: options.name,
|
||||
linter: options.linter,
|
||||
standaloneConfig: options.standaloneConfig,
|
||||
|
||||
@ -2,7 +2,6 @@ export const nxVersion = require('../../package.json').version;
|
||||
|
||||
export const angularCliVersion = '~15.2.0';
|
||||
export const typescriptVersion = '~4.9.5';
|
||||
export const prettierVersion = '^2.6.2';
|
||||
export const typescriptESLintVersion = '^5.36.1';
|
||||
export const eslintVersion = '~8.15.0';
|
||||
export const eslintConfigPrettierVersion = '8.1.0';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user