Skip to content

feat(@schematics/angular): install packages when creating a new application #12730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -56,6 +56,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