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