diff --git a/README.md b/README.md index d07b1a1d76..19f4dbac29 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ What’s different about large organizations is that they have hundreds of Angul In other words, small organizations can often get by with informal ad-hoc processes, whereas large organizations cannot. **Large organizations must rely on tooling to enable that. Nx is this tooling.** + # Getting Started An Nx workspace is an Angular CLI project that has been enhanced to be enterprise ready. Being an Angular CLI project means it will be handy to have the Angular CLI installed globally, which can be done via npm or yarn as well. diff --git a/packages/schematics/bin/create-nx-workspace.ts b/packages/schematics/bin/create-nx-workspace.ts index 8a906174e2..d33f347e1c 100644 --- a/packages/schematics/bin/create-nx-workspace.ts +++ b/packages/schematics/bin/create-nx-workspace.ts @@ -23,7 +23,7 @@ if (parsedArgs.help) { Options: directory path to the workspace root directory - --yarn use yarn instead of npm (default to false) + --yarn use yarn (default to false) --bazel use bazel instead of webpack (default to false) [ng new options] any 'ng new' options @@ -109,31 +109,25 @@ if (useYarn) { execSync('npm install --silent', { cwd: tmpDir, stdio: [0, 1, 2] }); } +const packageManagerOption = useYarn ? '--packageManager=yarn' : ''; + // creating the app itself const args = process.argv .slice(2) .filter(a => a !== '--yarn' && a !== '--bazel') .map(a => `"${a}"`) .join(' '); -console.log(`ng new ${args} --collection=${nxTool.packageName}`); +console.log( + `ng new ${args} --collection=${nxTool.packageName} ${packageManagerOption}` +); execSync( `${path.join( tmpDir, 'node_modules', '.bin', 'ng' - )} new ${args} --skip-install --collection=${nxTool.packageName}`, + )} new ${args} --collection=${nxTool.packageName} ${packageManagerOption}`, { stdio: [0, 1, 2] } ); - -const dir = parsedArgs.directory; - -const cwd = dir ? dir.split('=')[1] : projectName; - -if (useYarn) { - execSync(`yarn install`, { stdio: [0, 1, 2], cwd }); -} else { - execSync(`npm install`, { stdio: [0, 1, 2], cwd }); -} diff --git a/packages/schematics/src/collection/ng-new/files/__directory__/angular.json b/packages/schematics/src/collection/ng-new/files/__directory__/angular.json index 16674162b0..c3e93e932d 100644 --- a/packages/schematics/src/collection/ng-new/files/__directory__/angular.json +++ b/packages/schematics/src/collection/ng-new/files/__directory__/angular.json @@ -8,6 +8,7 @@ "typescriptMismatch": false, "versionMismatch": false }, - "defaultCollection": "@nrwl/schematics" + "defaultCollection": "@nrwl/schematics"<% if(packageManager) { %>,<% } %> + <% if(packageManager) { %>"packageManager": "<%= packageManager %>"<% } %> } } \ No newline at end of file diff --git a/packages/schematics/src/collection/ng-new/ng-new.spec.ts b/packages/schematics/src/collection/ng-new/ng-new.spec.ts index a8b10cb3dd..3150b981e1 100644 --- a/packages/schematics/src/collection/ng-new/ng-new.spec.ts +++ b/packages/schematics/src/collection/ng-new/ng-new.spec.ts @@ -1,10 +1,6 @@ import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import * as path from 'path'; -import { Tree, VirtualTree } from '@angular-devkit/schematics'; -import { createEmptyWorkspace } from '../../utils/testing-utils'; -import { getFileContent } from '@schematics/angular/utility/test'; -import * as stripJsonComments from 'strip-json-comments'; -import { readJsonInTree } from '../../utils/ast-utils'; +import { Tree } from '@angular-devkit/schematics'; describe('app', () => { const schematicRunner = new SchematicTestRunner( @@ -63,4 +59,27 @@ module.exports = () => { ` ); }); + + it('should not set package manager by default', () => { + const treeNoPackages = schematicRunner.runSchematic( + 'ng-new', + { name: 'proj' }, + projectTree + ); + expect( + JSON.parse(treeNoPackages.readContent('/proj/angular.json')).cli + .packageManager + ).toBeUndefined(); + }); + + it('should set package manager when provided', () => { + const tree = schematicRunner.runSchematic( + 'ng-new', + { name: 'proj', packageManager: 'yarn' }, + projectTree + ); + expect( + JSON.parse(tree.readContent('/proj/angular.json')).cli.packageManager + ).toEqual('yarn'); + }); }); diff --git a/packages/schematics/src/collection/ng-new/schema.d.ts b/packages/schematics/src/collection/ng-new/schema.d.ts index 34c2f3da6a..ef60d955c9 100644 --- a/packages/schematics/src/collection/ng-new/schema.d.ts +++ b/packages/schematics/src/collection/ng-new/schema.d.ts @@ -4,5 +4,6 @@ export interface Schema { npmScope?: string; skipInstall?: boolean; skipGit?: boolean; + packageManager?: string; commit?: { name: string; email: string; message?: string }; } diff --git a/packages/schematics/src/collection/ng-new/schema.json b/packages/schematics/src/collection/ng-new/schema.json index f7026de511..e0c6fa9662 100644 --- a/packages/schematics/src/collection/ng-new/schema.json +++ b/packages/schematics/src/collection/ng-new/schema.json @@ -34,6 +34,10 @@ "default": false, "alias": "g" }, + "packageManager": { + "type": "string", + "description": "Package manager used in the project." + }, "commit": { "description": "Initial repository commit information.", "oneOf": [