feat(schematics): add the packageManager property to ngNew

This commit is contained in:
Victor Savkin 2018-08-02 12:06:22 -04:00
parent 205e7ad7ef
commit d3362e06c8
6 changed files with 39 additions and 19 deletions

View File

@ -35,6 +35,7 @@ Whats 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.** 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 # 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. 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.

View File

@ -23,7 +23,7 @@ if (parsedArgs.help) {
Options: Options:
directory path to the workspace root directory 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) --bazel use bazel instead of webpack (default to false)
[ng new options] any 'ng new' options [ng new options] any 'ng new' options
@ -109,31 +109,25 @@ if (useYarn) {
execSync('npm install --silent', { cwd: tmpDir, stdio: [0, 1, 2] }); execSync('npm install --silent', { cwd: tmpDir, stdio: [0, 1, 2] });
} }
const packageManagerOption = useYarn ? '--packageManager=yarn' : '';
// creating the app itself // creating the app itself
const args = process.argv const args = process.argv
.slice(2) .slice(2)
.filter(a => a !== '--yarn' && a !== '--bazel') .filter(a => a !== '--yarn' && a !== '--bazel')
.map(a => `"${a}"`) .map(a => `"${a}"`)
.join(' '); .join(' ');
console.log(`ng new ${args} --collection=${nxTool.packageName}`); console.log(
`ng new ${args} --collection=${nxTool.packageName} ${packageManagerOption}`
);
execSync( execSync(
`${path.join( `${path.join(
tmpDir, tmpDir,
'node_modules', 'node_modules',
'.bin', '.bin',
'ng' 'ng'
)} new ${args} --skip-install --collection=${nxTool.packageName}`, )} new ${args} --collection=${nxTool.packageName} ${packageManagerOption}`,
{ {
stdio: [0, 1, 2] 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 });
}

View File

@ -8,6 +8,7 @@
"typescriptMismatch": false, "typescriptMismatch": false,
"versionMismatch": false "versionMismatch": false
}, },
"defaultCollection": "@nrwl/schematics" "defaultCollection": "@nrwl/schematics"<% if(packageManager) { %>,<% } %>
<% if(packageManager) { %>"packageManager": "<%= packageManager %>"<% } %>
} }
} }

View File

@ -1,10 +1,6 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path'; import * as path from 'path';
import { Tree, VirtualTree } from '@angular-devkit/schematics'; import { Tree } 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';
describe('app', () => { describe('app', () => {
const schematicRunner = new SchematicTestRunner( 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');
});
}); });

View File

@ -4,5 +4,6 @@ export interface Schema {
npmScope?: string; npmScope?: string;
skipInstall?: boolean; skipInstall?: boolean;
skipGit?: boolean; skipGit?: boolean;
packageManager?: string;
commit?: { name: string; email: string; message?: string }; commit?: { name: string; email: string; message?: string };
} }

View File

@ -34,6 +34,10 @@
"default": false, "default": false,
"alias": "g" "alias": "g"
}, },
"packageManager": {
"type": "string",
"description": "Package manager used in the project."
},
"commit": { "commit": {
"description": "Initial repository commit information.", "description": "Initial repository commit information.",
"oneOf": [ "oneOf": [