From 63566efdb73dc0f8f42fa697a18fc3cbf58a51c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Fri, 25 Nov 2022 15:13:45 +0100 Subject: [PATCH] feat(misc): add support for angular cli workspaces to nx init --- e2e/angular-core/src/ng-add.test.ts | 89 ++++----- .../migrate-from-angular-cli.spec.ts.snap | 172 +++++++++++++++--- .../ng-add/migrate-from-angular-cli.spec.ts | 53 +++--- .../ng-add/migrate-from-angular-cli.ts | 35 ++-- .../ng-add/utilities/format-files-task.ts | 18 ++ .../src/generators/ng-add/utilities/index.ts | 1 + .../generators/ng-add/utilities/workspace.ts | 95 ++++++++-- packages/nx/src/command-line/init.ts | 7 +- 8 files changed, 342 insertions(+), 128 deletions(-) create mode 100644 packages/angular/src/generators/ng-add/utilities/format-files-task.ts diff --git a/e2e/angular-core/src/ng-add.test.ts b/e2e/angular-core/src/ng-add.test.ts index a359029fca72e..7ab805600afaf 100644 --- a/e2e/angular-core/src/ng-add.test.ts +++ b/e2e/angular-core/src/ng-add.test.ts @@ -32,7 +32,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => { updateFile( 'e2e/src/app.e2e-spec.ts', `describe('app', () => { - it('should pass', { + it('should pass', () => { expect(true).toBe(true); }); });` @@ -148,39 +148,42 @@ describe('convert Angular CLI workspace to an Nx workspace', () => { cli: { packageManager: packageManager, }, - defaultProject: project, - implicitDependencies: { - '.eslintrc.json': '*', - 'package.json': { - dependencies: '*', - devDependencies: '*', - }, - }, npmScope: 'projscope', - targetDefaults: { - build: { - dependsOn: ['^build'], - }, - }, tasksRunnerOptions: { default: { options: { - cacheableOperations: ['build', 'lint', 'test', 'e2e'], + cacheableOperations: ['build', 'test', 'e2e'], }, runner: 'nx/tasks-runners/default', }, }, - }); - - // check angular.json - expect(readJson('angular.json')).toStrictEqual({ - version: 2, - projects: { - [project]: `apps/${project}`, - [`${project}-e2e`]: `apps/${project}-e2e`, + namedInputs: { + default: ['{projectRoot}/**/*', 'sharedGlobals'], + production: [ + 'default', + '!{projectRoot}/tsconfig.spec.json', + '!{projectRoot}/**/*.spec.[jt]s', + '!{projectRoot}/karma.conf.js', + ], + sharedGlobals: [], + }, + targetDefaults: { + build: { + dependsOn: ['^build'], + inputs: ['production', '^production'], + }, + e2e: { + inputs: ['default', '^production'], + }, + test: { + inputs: ['default', '^production', '{workspaceRoot}/karma.conf.js'], + }, }, }); + // check angular.json does not exist + checkFilesDoNotExist('angular.json'); + // check project configuration const projectConfig = readJson(`apps/${project}/project.json`); expect(projectConfig.sourceRoot).toEqual(`apps/${project}/src`); @@ -513,15 +516,8 @@ describe('convert Angular CLI workspace to an Nx workspace', () => { runNgAdd('@nrwl/angular', '--npm-scope projscope'); - // check angular.json - expect(readJson('angular.json')).toStrictEqual({ - version: 2, - projects: { - [project]: `apps/${project}`, - [lib1]: `libs/${lib1}`, - [lib2]: `libs/${lib2}`, - }, - }); + // check angular.json does not exist + checkFilesDoNotExist('angular.json'); // check building lib1 let output = runCLI(`build ${lib1}`); @@ -563,14 +559,8 @@ describe('convert Angular CLI workspace to an Nx workspace', () => { runNgAdd('@nrwl/angular', '--npm-scope projscope'); - // check angular.json - expect(readJson('angular.json')).toStrictEqual({ - version: 2, - projects: { - [project]: `apps/${project}`, - [app1]: `apps/${app1}`, - }, - }); + // check angular.json does not exist + checkFilesDoNotExist('angular.json'); // check building project let output = runCLI(`build ${project} --outputHashing none`); @@ -616,18 +606,13 @@ describe('convert Angular CLI workspace to an Nx workspace', () => { runNgAdd('@nrwl/angular', '--preserve-angular-cli-layout'); - // check config still uses Angular CLI layout - const updatedAngularJson = readJson('angular.json'); - expect(updatedAngularJson.projects[project].root).toEqual(''); - expect(updatedAngularJson.projects[project].sourceRoot).toEqual('src'); - expect(updatedAngularJson.projects.app2.root).toEqual('projects/app2'); - expect(updatedAngularJson.projects.app2.sourceRoot).toEqual( - 'projects/app2/src' - ); - expect(updatedAngularJson.projects.lib1.root).toEqual('projects/lib1'); - expect(updatedAngularJson.projects.lib1.sourceRoot).toEqual( - 'projects/lib1/src' - ); + // check project configs + const projectJson = readJson('project.json'); + expect(projectJson.sourceRoot).toEqual('src'); + const app2ProjectJson = readJson('projects/app2/project.json'); + expect(app2ProjectJson.sourceRoot).toEqual('projects/app2/src'); + const lib1ProjectJson = readJson('projects/lib1/project.json'); + expect(lib1ProjectJson.sourceRoot).toEqual('projects/lib1/src'); // check building an app let output = runCLI(`build ${project} --outputHashing none`); diff --git a/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap b/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap index aa6e220520722..0c5064ea186e0 100644 --- a/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap +++ b/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap @@ -5,18 +5,25 @@ Object { "affected": Object { "defaultBase": "main", }, - "implicitDependencies": Object { - ".eslintrc.json": "*", - "package.json": Object { - "dependencies": "*", - "devDependencies": "*", - }, + "namedInputs": Object { + "default": Array [ + "{projectRoot}/**/*", + "sharedGlobals", + ], + "production": Array [ + "default", + ], + "sharedGlobals": Array [], }, "targetDefaults": Object { "build": Object { "dependsOn": Array [ "^build", ], + "inputs": Array [ + "production", + "^production", + ], }, }, "tasksRunnerOptions": Object { @@ -24,9 +31,6 @@ Object { "options": Object { "cacheableOperations": Array [ "build", - "lint", - "test", - "e2e", ], }, "runner": "nx/tasks-runners/default", @@ -44,19 +48,41 @@ Object { "affected": Object { "defaultBase": "main", }, - "defaultProject": "app1", - "implicitDependencies": Object { - ".eslintrc.json": "*", - "package.json": Object { - "dependencies": "*", - "devDependencies": "*", - }, + "namedInputs": Object { + "default": Array [ + "{projectRoot}/**/*", + "sharedGlobals", + ], + "production": Array [ + "default", + "!{projectRoot}/tsconfig.spec.json", + "!{projectRoot}/**/*.spec.[jt]s", + "!{projectRoot}/karma.conf.js", + ], + "sharedGlobals": Array [], }, "targetDefaults": Object { "build": Object { "dependsOn": Array [ "^build", ], + "inputs": Array [ + "production", + "^production", + ], + }, + "e2e": Object { + "inputs": Array [ + "default", + "^production", + ], + }, + "test": Object { + "inputs": Array [ + "default", + "^production", + "{workspaceRoot}/karma.conf.js", + ], }, }, "tasksRunnerOptions": Object { @@ -64,7 +90,6 @@ Object { "options": Object { "cacheableOperations": Array [ "build", - "lint", "test", "e2e", ], @@ -79,6 +104,81 @@ Object { } `; +exports[`workspace --preserve-angular-cli-layout should support multiple projects 2`] = ` +Object { + "name": "app1", + "sourceRoot": "src", + "targets": Object { + "build": Object { + "executor": "@angular-devkit/build-angular:browser", + "options": Object { + "tsConfig": "tsconfig.app.json", + }, + }, + "e2e": Object { + "executor": "@angular-devkit/build-angular:protractor", + "options": Object { + "protractorConfig": "e2e/protractor.conf.js", + }, + }, + "test": Object { + "executor": "@angular-devkit/build-angular:karma", + "options": Object { + "tsConfig": "tsconfig.spec.json", + }, + }, + }, +} +`; + +exports[`workspace --preserve-angular-cli-layout should support multiple projects 3`] = ` +Object { + "name": "app2", + "sourceRoot": "projects/app2/src", + "targets": Object { + "build": Object { + "executor": "@angular-devkit/build-angular:browser", + "options": Object { + "tsConfig": "projects/app2/tsconfig.app.json", + }, + }, + "e2e": Object { + "executor": "@angular-devkit/build-angular:protractor", + "options": Object { + "protractorConfig": "projects/app2/e2e/protractor.conf.js", + }, + }, + "test": Object { + "executor": "@angular-devkit/build-angular:karma", + "options": Object { + "tsConfig": "projects/app2/tsconfig.spec.json", + }, + }, + }, +} +`; + +exports[`workspace --preserve-angular-cli-layout should support multiple projects 4`] = ` +Object { + "name": "lib1", + "sourceRoot": "projects/lib1/src", + "targets": Object { + "build": Object { + "executor": "@angular-devkit/build-angular:ng-packagr", + "options": Object { + "tsConfig": "projects/lib1/tsconfig.lib.json", + }, + }, + "test": Object { + "executor": "@angular-devkit/build-angular:karma", + "options": Object { + "tsConfig": "projects/lib1/tsconfig.spec.json", + }, + }, + }, +} +`; + exports[`workspace move to nx layout should create a root eslint config 1`] = ` Object { "ignorePatterns": Array [ @@ -163,12 +263,19 @@ Object { "defaultBase": "main", }, "defaultProject": "myApp", - "implicitDependencies": Object { - ".eslintrc.json": "*", - "package.json": Object { - "dependencies": "*", - "devDependencies": "*", - }, + "namedInputs": Object { + "default": Array [ + "{projectRoot}/**/*", + "sharedGlobals", + ], + "production": Array [ + "default", + "!{projectRoot}/tsconfig.spec.json", + "!{projectRoot}/**/*.spec.[jt]s", + "!{projectRoot}/karma.conf.js", + "!{projectRoot}/.eslintrc.json", + ], + "sharedGlobals": Array [], }, "npmScope": "my-org", "targetDefaults": Object { @@ -176,6 +283,16 @@ Object { "dependsOn": Array [ "^build", ], + "inputs": Array [ + "production", + "^production", + ], + }, + "e2e": Object { + "inputs": Array [ + "default", + "^production", + ], }, "lint": Object { "inputs": Array [ @@ -183,14 +300,21 @@ Object { "{workspaceRoot}/.eslintrc.json", ], }, + "test": Object { + "inputs": Array [ + "default", + "^production", + "{workspaceRoot}/karma.conf.js", + ], + }, }, "tasksRunnerOptions": Object { "default": Object { "options": Object { "cacheableOperations": Array [ "build", - "lint", "test", + "lint", "e2e", ], }, diff --git a/packages/angular/src/generators/ng-add/migrate-from-angular-cli.spec.ts b/packages/angular/src/generators/ng-add/migrate-from-angular-cli.spec.ts index 4aaa49c01744f..9cb5f4f635437 100644 --- a/packages/angular/src/generators/ng-add/migrate-from-angular-cli.spec.ts +++ b/packages/angular/src/generators/ng-add/migrate-from-angular-cli.spec.ts @@ -6,6 +6,7 @@ import { writeJson, } from '@nrwl/devkit'; import { createTree } from '@nrwl/devkit/testing'; +import * as prettierUtils from '@nrwl/workspace/src/utilities/prettier'; import { migrateFromAngularCli } from './migrate-from-angular-cli'; describe('workspace', () => { @@ -174,7 +175,7 @@ describe('workspace', () => { ); }); - it('should remove the newProjectRoot key from configuration', async () => { + it('should remove the angular.json file', async () => { tree.write( '/angular.json', JSON.stringify({ @@ -229,9 +230,7 @@ describe('workspace', () => { await migrateFromAngularCli(tree, {}); - const a = readJson(tree, '/angular.json'); - - expect(a.newProjectRoot).toBeUndefined(); + expect(tree.exists('angular.json')).toBe(false); }); it('should set the default collection to @nrwl/angular', async () => { @@ -350,15 +349,11 @@ describe('workspace', () => { await migrateFromAngularCli(tree, {}); - expect(readJson(tree, 'angular.json')).toStrictEqual({ - version: 2, - projects: { - app1: 'apps/app1', - 'app1-e2e': 'apps/app1-e2e', - app2: 'apps/app2', - 'app2-e2e': 'apps/app2-e2e', - }, - }); + expect(tree.exists('angular.json')).toBe(false); + expect(tree.exists('apps/app1/project.json')).toBe(true); + expect(tree.exists('apps/app1-e2e/project.json')).toBe(true); + expect(tree.exists('apps/app2/project.json')).toBe(true); + expect(tree.exists('apps/app2-e2e/project.json')).toBe(true); const app1 = readProjectConfiguration(tree, 'app1'); expect(app1.root).toBe('apps/app1'); expect(app1.sourceRoot).toBe('apps/app1/src'); @@ -450,15 +445,11 @@ describe('workspace', () => { await migrateFromAngularCli(tree, {}); - expect(readJson(tree, 'angular.json')).toStrictEqual({ - version: 2, - projects: { - app1: 'apps/app1', - 'app1-e2e': 'apps/app1-e2e', - lib1: 'libs/lib1', - lib2: 'libs/lib2', - }, - }); + expect(tree.exists('angular.json')).toBe(false); + expect(tree.exists('apps/app1/project.json')).toBe(true); + expect(tree.exists('apps/app1-e2e/project.json')).toBe(true); + expect(tree.exists('libs/lib1/project.json')).toBe(true); + expect(tree.exists('libs/lib2/project.json')).toBe(true); const lib1 = readProjectConfiguration(tree, 'lib1'); expect(lib1.root).toBe('libs/lib1'); expect(lib1.sourceRoot).toBe('libs/lib1/src'); @@ -478,7 +469,10 @@ describe('workspace', () => { 'package.json', JSON.stringify({ name: 'my-scope', devDependencies: {} }) ); - tree.write('angular.json', JSON.stringify({ projects: { myproj: {} } })); + tree.write( + 'angular.json', + JSON.stringify({ projects: { myproj: { root: '' } } }) + ); tree.write('tsconfig.json', '{"compilerOptions": {}}'); }); @@ -488,6 +482,7 @@ describe('workspace', () => { const { devDependencies } = readJson(tree, 'package.json'); expect(devDependencies['@nrwl/workspace']).toBeDefined(); expect(devDependencies['nx']).toBeDefined(); + expect(devDependencies['prettier']).toBeDefined(); }); it('should create nx.json', async () => { @@ -566,14 +561,22 @@ describe('workspace', () => { }, }; tree.write('/angular.json', JSON.stringify(angularJson)); + jest + .spyOn(prettierUtils, 'resolveUserExistingPrettierConfig') + .mockReturnValue(Promise.resolve(null)); await migrateFromAngularCli(tree, { preserveAngularCliLayout: true }); - expect(readJson(tree, 'angular.json')).toStrictEqual(angularJson); - expect(tree.exists('/decorate-angular-cli.js')).toBe(true); + expect(tree.exists('angular.json')).toBe(false); + expect(tree.exists('decorate-angular-cli.js')).toBe(true); + expect(tree.exists('.prettierignore')).toBe(true); + expect(tree.exists('.prettierrc')).toBe(true); const { scripts } = readJson(tree, 'package.json'); expect(scripts.postinstall).toBe('node ./decorate-angular-cli.js'); expect(readJson(tree, 'nx.json')).toMatchSnapshot(); + expect(readJson(tree, 'project.json')).toMatchSnapshot(); + expect(readJson(tree, 'projects/app2/project.json')).toMatchSnapshot(); + expect(readJson(tree, 'projects/lib1/project.json')).toMatchSnapshot(); }); }); }); diff --git a/packages/angular/src/generators/ng-add/migrate-from-angular-cli.ts b/packages/angular/src/generators/ng-add/migrate-from-angular-cli.ts index cc8c3c3a865b2..f2b20858f6172 100755 --- a/packages/angular/src/generators/ng-add/migrate-from-angular-cli.ts +++ b/packages/angular/src/generators/ng-add/migrate-from-angular-cli.ts @@ -1,13 +1,14 @@ -import type { Tree } from '@nrwl/devkit'; +import type { GeneratorCallback, Tree } from '@nrwl/devkit'; import { addDependenciesToPackageJson, - formatFiles, installPackagesTask, readJson, readWorkspaceConfiguration, updateJson, updateWorkspaceConfiguration, } from '@nrwl/devkit'; +import { convertToNxProjectGenerator } from '@nrwl/workspace/generators'; +import { prettierVersion } from '@nrwl/workspace/src/utils/versions'; import { nxVersion } from '../../utils/versions'; import type { ProjectMigrator } from './migrators'; import { AppMigrator, LibMigrator } from './migrators'; @@ -18,12 +19,16 @@ import { createRootKarmaConfig, createWorkspaceFiles, decorateAngularCli, + deleteAngularJson, + formatFilesTask, getAllProjects, getWorkspaceRootFileTypesInfo, normalizeOptions, updatePackageJson, + updatePrettierConfig, updateRootEsLintConfig, updateRootTsConfig, + updateVsCodeRecommendedExtensions, updateWorkspaceConfigDefaults, validateProjects, validateWorkspace, @@ -32,13 +37,11 @@ import { export async function migrateFromAngularCli( tree: Tree, rawOptions: GeneratorOptions -) { +): Promise { validateWorkspace(tree); const projects = getAllProjects(tree); const options = normalizeOptions(tree, rawOptions, projects); - const defaultProject = projects.apps.find((app) => app.config.root === ''); - if (options.preserveAngularCliLayout) { addDependenciesToPackageJson( tree, @@ -46,10 +49,21 @@ export async function migrateFromAngularCli( { nx: nxVersion, '@nrwl/workspace': nxVersion, + prettier: prettierVersion, } ); createNxJson(tree, options, true); decorateAngularCli(tree); + updateVsCodeRecommendedExtensions(tree); + await updatePrettierConfig(tree); + + // convert workspace config format to standalone project configs + updateJson(tree, 'angular.json', (json) => ({ + ...json, + version: 2, + $schema: undefined, + })); + await convertToNxProjectGenerator(tree, { all: true, skipFormat: true }); } else { const migrators: ProjectMigrator[] = [ ...projects.apps.map((app) => new AppMigrator(tree, options, app)), @@ -105,21 +119,14 @@ export async function migrateFromAngularCli( updateRootEsLintConfig(tree, eslintConfig, options.unitTestRunner); cleanupEsLintPackages(tree); } - - await formatFiles(tree); } - if (defaultProject) { - const workspaceConfig = readWorkspaceConfiguration(tree); - updateWorkspaceConfiguration(tree, { - ...workspaceConfig, - defaultProject: defaultProject.name, - }); - } + deleteAngularJson(tree); if (!options.skipInstall) { return () => { installPackagesTask(tree); + formatFilesTask(tree); }; } } diff --git a/packages/angular/src/generators/ng-add/utilities/format-files-task.ts b/packages/angular/src/generators/ng-add/utilities/format-files-task.ts new file mode 100644 index 0000000000000..e1cbcdaf74414 --- /dev/null +++ b/packages/angular/src/generators/ng-add/utilities/format-files-task.ts @@ -0,0 +1,18 @@ +import type { Tree } from '@nrwl/devkit'; +import { getPackageManagerCommand } from '@nrwl/devkit'; +import { execSync } from 'child_process'; + +export function formatFilesTask(tree: Tree): void { + if ( + !tree + .listChanges() + .some((change) => change.type === 'CREATE' || change.type === 'UPDATE') + ) { + return; + } + + const pmc = getPackageManagerCommand(); + try { + execSync(`${pmc.exec} nx format`, { cwd: tree.root, stdio: [0, 1, 2] }); + } catch {} +} diff --git a/packages/angular/src/generators/ng-add/utilities/index.ts b/packages/angular/src/generators/ng-add/utilities/index.ts index 470975b4f83ec..c757a0ab332d4 100644 --- a/packages/angular/src/generators/ng-add/utilities/index.ts +++ b/packages/angular/src/generators/ng-add/utilities/index.ts @@ -1,4 +1,5 @@ export * from './file-change-recorder'; +export * from './format-files-task'; export * from './get-all-projects'; export * from './logger'; export * from './normalize-options'; diff --git a/packages/angular/src/generators/ng-add/utilities/workspace.ts b/packages/angular/src/generators/ng-add/utilities/workspace.ts index e2bd1184f8ffa..3eada06687ea3 100644 --- a/packages/angular/src/generators/ng-add/utilities/workspace.ts +++ b/packages/angular/src/generators/ng-add/utilities/workspace.ts @@ -1,10 +1,12 @@ import type { NxJsonConfiguration, Tree } from '@nrwl/devkit'; import { generateFiles, + getProjects, joinPathFragments, readJson, readWorkspaceConfiguration, updateJson, + updateProjectConfiguration, updateWorkspaceConfiguration, writeJson, } from '@nrwl/devkit'; @@ -49,28 +51,61 @@ export function createNxJson( const { newProjectRoot = '' } = readJson(tree, 'angular.json'); const { npmScope } = options; + const targets = getWorkspaceCommonTargets(tree); + writeJson(tree, 'nx.json', { ...(npmScope ? { npmScope } : {}), affected: { defaultBase: options.defaultBase ?? deduceDefaultBase(), }, - implicitDependencies: { - 'package.json': { - dependencies: '*', - devDependencies: '*', - }, - '.eslintrc.json': '*', - }, tasksRunnerOptions: { default: { runner: 'nx/tasks-runners/default', options: { - cacheableOperations: ['build', 'lint', 'test', 'e2e'], + cacheableOperations: [ + 'build', + targets.test ? 'test' : undefined, + targets.lint ? 'lint' : undefined, + targets.e2e ? 'e2e' : undefined, + ].filter(Boolean), }, }, }, + namedInputs: { + sharedGlobals: [], + default: ['{projectRoot}/**/*', 'sharedGlobals'], + production: [ + 'default', + ...(targets.test + ? [ + '!{projectRoot}/tsconfig.spec.json', + '!{projectRoot}/**/*.spec.[jt]s', + '!{projectRoot}/karma.conf.js', + ] + : []), + targets.lint ? '!{projectRoot}/.eslintrc.json' : undefined, + ].filter(Boolean), + }, targetDefaults: { - build: { dependsOn: ['^build'] }, + build: { + dependsOn: ['^build'], + inputs: ['production', '^production'], + }, + test: targets.test + ? { + inputs: ['default', '^production', '{workspaceRoot}/karma.conf.js'], + } + : undefined, + lint: targets.lint + ? { + inputs: ['default', '{workspaceRoot}/.eslintrc.json'], + } + : undefined, + e2e: targets.e2e + ? { + inputs: ['default', '^production'], + } + : undefined, }, workspaceLayout: setWorkspaceLayoutAsNewProjectRoot ? { appsDir: newProjectRoot, libsDir: newProjectRoot } @@ -78,6 +113,33 @@ export function createNxJson( }); } +function getWorkspaceCommonTargets(tree: Tree): { + e2e: boolean; + lint: boolean; + test: boolean; +} { + const targets = { e2e: false, lint: false, test: false }; + const projects = getProjects(tree); + + for (const [, project] of projects) { + if (!targets.e2e && project.targets?.e2e) { + targets.e2e = true; + } + if (!targets.lint && project.targets?.lint) { + targets.lint = true; + } + if (!targets.test && project.targets?.test) { + targets.test = true; + } + + if (targets.e2e && targets.lint && targets.test) { + return targets; + } + } + + return targets; +} + export function decorateAngularCli(tree: Tree): void { const nrwlWorkspacePath = readModulePackageJson('@nrwl/workspace').path; const decorateCli = readFileSync( @@ -98,7 +160,7 @@ export function decorateAngularCli(tree: Tree): void { // if exists, add execution of this script json.scripts.postinstall += ' && node ./decorate-angular-cli.js'; } else { - if (!json.scripts) json.scripts = {}; + json.scripts ??= {}; // if doesn't exist, set to execute this script json.scripts.postinstall = 'node ./decorate-angular-cli.js'; } @@ -293,7 +355,7 @@ export function getWorkspaceRootFileTypesInfo( return workspaceRootFileTypesInfo; } -function updateVsCodeRecommendedExtensions(tree: Tree): void { +export function updateVsCodeRecommendedExtensions(tree: Tree): void { const recommendations = [ 'nrwl.angular-console', 'angular.ng-template', @@ -322,7 +384,7 @@ function updateVsCodeRecommendedExtensions(tree: Tree): void { } } -async function updatePrettierConfig(tree: Tree): Promise { +export async function updatePrettierConfig(tree: Tree): Promise { const existingPrettierConfig = await resolveUserExistingPrettierConfig(); if (!existingPrettierConfig) { writeJson(tree, '.prettierrc', DEFAULT_NRWL_PRETTIER_CONFIG); @@ -337,3 +399,12 @@ async function updatePrettierConfig(tree: Tree): Promise { ); } } + +export function deleteAngularJson(tree: Tree): void { + const projects = getProjects(tree); + for (const [project, config] of projects) { + config.name = project; + updateProjectConfiguration(tree, project, config); + } + tree.delete('angular.json'); +} diff --git a/packages/nx/src/command-line/init.ts b/packages/nx/src/command-line/init.ts index 5a9a27e0d3301..7282e0428a904 100644 --- a/packages/nx/src/command-line/init.ts +++ b/packages/nx/src/command-line/init.ts @@ -6,7 +6,12 @@ import { addNxToNpmRepo } from '../nx-init/add-nx-to-npm-repo'; export async function initHandler() { const args = process.argv.slice(2).join(' '); if (existsSync('package.json')) { - if (isMonorepo()) { + if (existsSync('angular.json')) { + // TODO(leo): remove make-angular-cli-faster + execSync(`npx --yes make-angular-cli-faster@latest ${args}`, { + stdio: [0, 1, 2], + }); + } else if (isMonorepo()) { // TODO: vsavkin remove add-nx-to-monorepo execSync(`npx --yes add-nx-to-monorepo@latest ${args}`, { stdio: [0, 1, 2],