Skip to content

Commit f90489d

Browse files
clydinhansl
authored andcommitted
feat(@angular/cli): transfer CLI to devkit
1 parent 005af91 commit f90489d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+5043
-0
lines changed

.monorepo.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@
4949
"version": "0.7.0-beta.1",
5050
"hash": "84924cc4aa8c0961e0f64d862d478549"
5151
},
52+
"@angular/cli": {
53+
"name": "Angular CLI",
54+
"links": [
55+
{
56+
"label": "README",
57+
"url": "https://github.com/angular/devkit/blob/master/packages/angular/cli/README.md"
58+
}
59+
],
60+
"version": "6.1.0-beta.0",
61+
"snapshotRepo": "angular/cli-builds"
62+
},
5263
"@angular/pwa": {
5364
"name": "Angular PWA Schematics",
5465
"section": "Schematics",

packages/angular/cli/bin/ng

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
// Provide a title to the process in `ps`.
5+
// Due to an obscure Mac bug, do not start this title with any symbol.
6+
process.title = 'ng';
7+
8+
var version = process.version.substr(1).split('.');
9+
if (Number(version[0]) < 8 || (Number(version[0]) === 8 && Number(version[1]) < 9)) {
10+
process.stderr.write(
11+
'You are running version ' + process.version + ' of Node.js, which is not supported by Angular CLI v6.\n' +
12+
'The official Node.js version that is supported is 8.9 and greater.\n\n' +
13+
'Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.\n'
14+
);
15+
16+
process.exit(3);
17+
}
18+
19+
require('../lib/init');
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
// Check if the current directory contains '.angular-cli.json'. If it does, show a message to the user that they
5+
// should use the migration script.
6+
7+
const fs = require('fs');
8+
const path = require('path');
9+
const os = require('os');
10+
11+
12+
let found = false;
13+
let current = path.dirname(path.dirname(__dirname));
14+
while (current !== path.dirname(current)) {
15+
if (fs.existsSync(path.join(current, 'angular-cli.json'))
16+
|| fs.existsSync(path.join(current, '.angular-cli.json'))) {
17+
found = os.homedir() !== current || fs.existsSync(path.join(current, 'package.json'));
18+
break;
19+
}
20+
if (fs.existsSync(path.join(current, 'angular.json'))
21+
|| fs.existsSync(path.join(current, '.angular.json'))
22+
|| fs.existsSync(path.join(current, 'package.json'))) {
23+
break;
24+
}
25+
26+
current = path.dirname(current);
27+
}
28+
29+
30+
if (found) {
31+
// ------------------------------------------------------------------------------------------
32+
// If changing this message, please update the same message in
33+
// `packages/@angular/cli/models/command-runner.ts`
34+
35+
// eslint-disable-next-line no-console
36+
console.error(`\u001b[31m
37+
${'='.repeat(80)}
38+
The Angular CLI configuration format has been changed, and your existing configuration can
39+
be updated automatically by running the following command:
40+
41+
ng update @angular/cli
42+
${'='.repeat(80)}
43+
\u001b[39m`.replace(/^ {4}/gm, ''));
44+
}

packages/angular/cli/commands/add.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// tslint:disable:no-any
2+
import { tags, terminal } from '@angular-devkit/core';
3+
import { NodePackageDoesNotSupportSchematics } from '@angular-devkit/schematics/tools';
4+
import { CommandScope, Option } from '../models/command';
5+
import { parseOptions } from '../models/command-runner';
6+
import { SchematicCommand } from '../models/schematic-command';
7+
import { NpmInstall } from '../tasks/npm-install';
8+
import { getPackageManager } from '../utilities/config';
9+
10+
11+
export default class AddCommand extends SchematicCommand {
12+
readonly name = 'add';
13+
readonly description = 'Add support for a library to your project.';
14+
readonly allowPrivateSchematics = true;
15+
scope = CommandScope.inProject;
16+
arguments = ['collection'];
17+
options: Option[] = [];
18+
19+
private async _parseSchematicOptions(collectionName: string): Promise<any> {
20+
const schematicOptions = await this.getOptions({
21+
schematicName: 'ng-add',
22+
collectionName,
23+
});
24+
25+
const options = this.options.concat(schematicOptions.options);
26+
const args = schematicOptions.arguments.map(arg => arg.name);
27+
28+
return parseOptions(this._rawArgs, options, args, this.argStrategy);
29+
}
30+
31+
validate(options: any) {
32+
const collectionName = options._[0];
33+
34+
if (!collectionName) {
35+
this.logger.fatal(
36+
`The "ng ${this.name}" command requires a name argument to be specified eg. `
37+
+ `${terminal.yellow('ng add [name] ')}. For more details, use "ng help".`,
38+
);
39+
40+
return false;
41+
}
42+
43+
return true;
44+
}
45+
46+
async run(options: any) {
47+
const firstArg = options._[0];
48+
49+
if (!firstArg) {
50+
this.logger.fatal(
51+
`The "ng ${this.name}" command requires a name argument to be specified eg. `
52+
+ `${terminal.yellow('ng add [name] ')}. For more details, use "ng help".`,
53+
);
54+
55+
return 1;
56+
}
57+
58+
const packageManager = getPackageManager();
59+
60+
const npmInstall: NpmInstall = require('../tasks/npm-install').default;
61+
62+
const packageName = firstArg.startsWith('@')
63+
? firstArg.split('/', 2).join('/')
64+
: firstArg.split('/', 1)[0];
65+
66+
// Remove the tag/version from the package name.
67+
const collectionName = (
68+
packageName.startsWith('@')
69+
? packageName.split('@', 2).join('@')
70+
: packageName.split('@', 1).join('@')
71+
) + firstArg.slice(packageName.length);
72+
73+
// We don't actually add the package to package.json, that would be the work of the package
74+
// itself.
75+
await npmInstall(
76+
packageName,
77+
this.logger,
78+
packageManager,
79+
this.project.root,
80+
);
81+
82+
// Reparse the options with the new schematic accessible.
83+
options = await this._parseSchematicOptions(collectionName);
84+
85+
const runOptions = {
86+
schematicOptions: options,
87+
workingDir: this.project.root,
88+
collectionName,
89+
schematicName: 'ng-add',
90+
allowPrivate: true,
91+
dryRun: false,
92+
force: false,
93+
};
94+
95+
try {
96+
return await this.runSchematic(runOptions);
97+
} catch (e) {
98+
if (e instanceof NodePackageDoesNotSupportSchematics) {
99+
this.logger.error(tags.oneLine`
100+
The package that you are trying to add does not support schematics. You can try using
101+
a different version of the package or contact the package author to add ng-add support.
102+
`);
103+
104+
return 1;
105+
}
106+
107+
throw e;
108+
}
109+
}
110+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';
2+
import { CommandScope, Option } from '../models/command';
3+
import { Version } from '../upgrade/version';
4+
5+
export default class BuildCommand extends ArchitectCommand {
6+
public readonly name = 'build';
7+
public readonly target = 'build';
8+
public readonly description =
9+
'Builds your app and places it into the output path (dist/ by default).';
10+
public static aliases = ['b'];
11+
public scope = CommandScope.inProject;
12+
public options: Option[] = [
13+
this.prodOption,
14+
this.configurationOption,
15+
];
16+
17+
public validate(options: ArchitectCommandOptions) {
18+
// Check Angular and TypeScript versions.
19+
Version.assertCompatibleAngularVersion(this.project.root);
20+
Version.assertTypescriptVersion(this.project.root);
21+
22+
return super.validate(options);
23+
}
24+
25+
public async run(options: ArchitectCommandOptions) {
26+
return this.runArchitectTarget(options);
27+
}
28+
}

0 commit comments

Comments
 (0)