Skip to content

Commit

Permalink
feat(@schematics/angular): install packages when creating a new appli…
Browse files Browse the repository at this point in the history
…cation

Fixes #12719
  • Loading branch information
alan-agius4 authored and Keen Yee Liau committed Nov 1, 2018
1 parent a3b05a0 commit 90a5a7d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
template,
url,
} from '@angular-devkit/schematics';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
import { Schema as E2eOptions } from '../e2e/schema';
import {
addProjectToWorkspace,
Expand Down Expand Up @@ -63,8 +64,8 @@ import { Schema as ApplicationOptions } from './schema';
// );
// }

function addDependenciesToPackageJson() {
return (host: Tree) => {
function addDependenciesToPackageJson(options: ApplicationOptions) {
return (host: Tree, context: SchematicContext) => {
[
{
type: NodeDependencyType.Dev,
Expand All @@ -83,6 +84,10 @@ function addDependenciesToPackageJson() {
},
].forEach(dependency => addPackageJsonDependency(host, dependency));

if (!options.skipInstall) {
context.addTask(new NodePackageInstallTask());
}

return host;
};
}
Expand Down Expand Up @@ -299,7 +304,6 @@ export default function (options: ApplicationOptions): Rule {

return chain([
addAppToWorkspaceFile(options, workspace),
options.skipPackageJson ? noop() : addDependenciesToPackageJson(),
mergeWith(
apply(url('./files/src'), [
options.minimal ? filter(minimalPathFilter) : noop(),
Expand Down Expand Up @@ -369,6 +373,7 @@ export default function (options: ApplicationOptions): Rule {
move(sourceDir),
]), MergeStrategy.Overwrite),
schematic('e2e', e2eOptions),
options.skipPackageJson ? noop() : addDependenciesToPackageJson(options),
]);
};
}
5 changes: 5 additions & 0 deletions packages/schematics/angular/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
"description": "Create a barebones project without any testing frameworks",
"type": "boolean",
"default": false
},
"skipInstall": {
"description": "Skip installing dependency packages.",
"type": "boolean",
"default": false
}
},
"required": [
Expand Down
2 changes: 2 additions & 0 deletions packages/schematics/angular/ng-new/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export default function (options: NgNewOptions): Rule {
style: options.style,
skipTests: options.skipTests,
skipPackageJson: false,
// always 'skipInstall' here, so that we do it after the move
skipInstall: true,
};

return chain([
Expand Down

0 comments on commit 90a5a7d

Please sign in to comment.