Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 39e1636

Browse files
committedFeb 8, 2018
feat(@angular/cli): use schematic tasks for application init
1 parent 1ce4db6 commit 39e1636

File tree

9 files changed

+56
-225
lines changed

9 files changed

+56
-225
lines changed
 

Diff for: ‎package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
},
4242
"homepage": "https://github.com/angular/angular-cli",
4343
"dependencies": {
44-
"@angular-devkit/build-optimizer": "0.2.0",
45-
"@angular-devkit/core": "0.2.0",
46-
"@angular-devkit/schematics": "0.2.0",
47-
"@schematics/angular": "0.2.0",
48-
"@schematics/package-update": "0.2.0",
44+
"@angular-devkit/build-optimizer": "0.3.1",
45+
"@angular-devkit/core": "0.3.1",
46+
"@angular-devkit/schematics": "0.3.1",
47+
"@schematics/angular": "0.3.1",
48+
"@schematics/package-update": "0.3.1",
4949
"autoprefixer": "^7.2.3",
5050
"cache-loader": "^1.2.0",
5151
"chalk": "~2.2.0",

Diff for: ‎packages/@angular/cli/commands/new.ts

-22
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,6 @@ const NewCommand = Command.extend({
3636
aliases: ['v'],
3737
description: 'Adds more details to output logging.'
3838
},
39-
{
40-
name: 'link-cli',
41-
type: Boolean,
42-
default: false,
43-
aliases: ['lc'],
44-
description: 'Automatically link the `@angular/cli` package.',
45-
hidden: true
46-
},
47-
{
48-
name: 'skip-install',
49-
type: Boolean,
50-
default: false,
51-
aliases: ['si'],
52-
description: 'Skip installing packages.'
53-
},
54-
{
55-
name: 'skip-commit',
56-
type: Boolean,
57-
default: false,
58-
aliases: ['sc'],
59-
description: 'Skip committing the first commit to git.'
60-
},
6139
{
6240
name: 'collection',
6341
type: String,

Diff for: ‎packages/@angular/cli/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
},
2828
"homepage": "https://github.com/angular/angular-cli",
2929
"dependencies": {
30-
"@angular-devkit/build-optimizer": "0.2.0",
31-
"@angular-devkit/core": "0.2.0",
32-
"@angular-devkit/schematics": "0.2.0",
30+
"@angular-devkit/build-optimizer": "0.3.1",
31+
"@angular-devkit/core": "0.3.1",
32+
"@angular-devkit/schematics": "0.3.1",
3333
"@ngtools/json-schema": "1.1.0",
3434
"@ngtools/webpack": "1.10.0-beta.3",
35-
"@schematics/angular": "0.2.0",
36-
"@schematics/package-update": "0.2.0",
35+
"@schematics/angular": "0.3.1",
36+
"@schematics/package-update": "0.3.1",
3737
"autoprefixer": "^7.2.3",
3838
"cache-loader": "^1.2.0",
3939
"chalk": "~2.2.0",

Diff for: ‎packages/@angular/cli/tasks/git-init.ts

-73
This file was deleted.

Diff for: ‎packages/@angular/cli/tasks/init.ts

+21-53
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,21 @@
11
import chalk from 'chalk';
2-
import LinkCli from '../tasks/link-cli';
3-
import NpmInstall from '../tasks/npm-install';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
4+
import { checkYarnOrCNPM } from '../utilities/check-package-manager';
45
import { validateProjectName } from '../utilities/validate-project-name';
5-
import {checkYarnOrCNPM} from '../utilities/check-package-manager';
6-
import {CliConfig} from '../models/config';
6+
import { CliConfig } from '../models/config';
77

88
const Task = require('../ember-cli/lib/models/task');
99
const SilentError = require('silent-error');
10-
const GitInit = require('../tasks/git-init');
1110
const packageJson = require('../package.json');
1211

1312

1413
export default Task.extend({
1514

16-
run: function (commandOptions: any, rawArgs: string[]) {
15+
run: function (commandOptions: any, _rawArgs: string[]) {
1716
if (commandOptions.dryRun) {
1817
commandOptions.skipInstall = true;
19-
}
20-
21-
// needs an explicit check in case it's just 'undefined'
22-
// due to passing of options from 'new' and 'addon'
23-
let gitInit: any;
24-
if (commandOptions.skipGit === false) {
25-
gitInit = new GitInit({
26-
ui: this.ui,
27-
project: this.project
28-
});
29-
}
30-
31-
const packageManager = CliConfig.fromGlobal().get('packageManager');
32-
33-
let npmInstall: any;
34-
if (!commandOptions.skipInstall) {
35-
npmInstall = new NpmInstall({
36-
ui: this.ui,
37-
project: this.project,
38-
packageManager
39-
});
40-
}
41-
42-
let linkCli: any;
43-
if (commandOptions.linkCli) {
44-
linkCli = new LinkCli({
45-
ui: this.ui,
46-
project: this.project,
47-
packageManager
48-
});
18+
commandOptions.skipGit = true;
4919
}
5020

5121
const project = this.project;
@@ -75,6 +45,18 @@ export default Task.extend({
7545
const schematicName = CliConfig.fromGlobal().get('defaults.schematics.newApp');
7646
commandOptions.version = packageJson.version;
7747

48+
if (!commandOptions.skipCommit) {
49+
const commitMessage = fs.readFileSync(
50+
path.join(__dirname, '../utilities/INITIAL_COMMIT_MESSAGE.txt'),
51+
'utf-8',
52+
);
53+
commandOptions.commit = {
54+
message: commitMessage,
55+
name: process.env.GIT_AUTHOR_NAME || 'Angular CLI',
56+
email: process.env.GIT_AUTHOR_EMAIL || 'angular-cli@angular.io',
57+
};
58+
}
59+
7860
const runOptions = {
7961
taskOptions: commandOptions,
8062
workingDir: cwd,
@@ -84,28 +66,14 @@ export default Task.extend({
8466
};
8567

8668
return schematicRunTask.run(runOptions)
87-
.then(function () {
88-
if (!commandOptions.dryRun) {
89-
process.chdir(commandOptions.directory);
90-
}
91-
})
92-
.then(function () {
69+
.then(() => {
9370
if (!commandOptions.skipInstall) {
94-
return checkYarnOrCNPM().then(() => npmInstall.run());
95-
}
96-
})
97-
.then(function () {
98-
if (!commandOptions.dryRun && commandOptions.skipGit === false) {
99-
return gitInit.run(commandOptions, rawArgs);
100-
}
101-
})
102-
.then(function () {
103-
if (!commandOptions.dryRun && commandOptions.linkCli) {
104-
return linkCli.run();
71+
return checkYarnOrCNPM();
10572
}
10673
})
10774
.then(() => {
10875
if (!commandOptions.dryRun) {
76+
process.chdir(commandOptions.directory);
10977
this.ui.writeLine(chalk.green(`Project '${packageName}' successfully created.`));
11078
}
11179
});

Diff for: ‎packages/@angular/cli/tasks/link-cli.ts

-26
This file was deleted.

Diff for: ‎packages/@angular/cli/tasks/npm-install.ts

-39
This file was deleted.

Diff for: ‎packages/@angular/cli/tasks/schematic-get-help-output.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const hiddenOptions = [
2222
'name',
2323
'path',
2424
'source-dir',
25-
'app-root'
25+
'app-root',
26+
'link-cli',
2627
];
2728

2829
export default Task.extend({

Diff for: ‎packages/@angular/cli/tasks/schematic-run.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import {
77
Schematic,
88
Tree
99
} from '@angular-devkit/schematics';
10+
import { BuiltinTaskExecutor } from '@angular-devkit/schematics/tasks/node';
1011
import { FileSystemHost } from '@angular-devkit/schematics/tools';
1112
import { of as observableOf } from 'rxjs/observable/of';
1213
import * as path from 'path';
1314
import chalk from 'chalk';
1415
import { CliConfig } from '../models/config';
1516
import { concat, concatMap, ignoreElements, map } from 'rxjs/operators';
16-
import { getCollection, getSchematic } from '../utilities/schematics';
17+
import { getCollection, getSchematic, getEngineHost, getEngine } from '../utilities/schematics';
1718

1819
const { green, red, yellow } = chalk;
1920
const Task = require('../ember-cli/lib/models/task');
@@ -48,6 +49,20 @@ export default Task.extend({
4849

4950
const ui = this.ui;
5051

52+
const packageManager = CliConfig.fromGlobal().get('packageManager');
53+
const engineHost = getEngineHost();
54+
engineHost.registerTaskExecutor(
55+
BuiltinTaskExecutor.NodePackage,
56+
{
57+
rootDirectory: workingDir,
58+
packageManager: packageManager === 'default' ? 'npm' : packageManager,
59+
},
60+
);
61+
engineHost.registerTaskExecutor(
62+
BuiltinTaskExecutor.RepositoryInitializer,
63+
{ rootDirectory: workingDir },
64+
);
65+
5166
const collection = getCollection(collectionName);
5267
const schematic = getSchematic(collection, schematicName);
5368

@@ -129,6 +144,13 @@ export default Task.extend({
129144
return fsSink.commit(tree).pipe(
130145
ignoreElements(),
131146
concat(observableOf(tree)));
147+
}),
148+
concatMap(() => {
149+
if (!opts.dryRun) {
150+
return getEngine().executePostTasks();
151+
} else {
152+
return [];
153+
}
132154
}))
133155
.subscribe({
134156
error(err) {

0 commit comments

Comments
 (0)
Please sign in to comment.