Skip to content

Commit ae9817b

Browse files
Broccohansl
authored andcommitted
feat(@angular/cli): Update commands to extract meta data into JSON
1 parent 9ce4987 commit ae9817b

Some content is hidden

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

45 files changed

+1012
-468
lines changed

packages/angular/cli/commands.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"add": "./commands/add.json",
3+
"build": "./commands/build.json",
4+
"config": "./commands/config.json",
5+
"doc": "./commands/doc.json",
6+
"e2e": "./commands/e2e.json",
7+
"make-this-awesome": "./commands/easter-egg.json",
8+
"eject": "./commands/eject.json",
9+
"generate": "./commands/generate.json",
10+
"get": "./commands/getset.json",
11+
"set": "./commands/getset.json",
12+
"help": "./commands/help.json",
13+
"lint": "./commands/lint.json",
14+
"new": "./commands/new.json",
15+
"run": "./commands/run.json",
16+
"serve": "./commands/serve.json",
17+
"test": "./commands/test.json",
18+
"update": "./commands/update.json",
19+
"version": "./commands/version.json",
20+
"xi18n": "./commands/xi18n.json"
21+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"id": "AddCommandOptions",
4+
"description": "Add support for a library to your project.",
5+
"$longDescription": "",
6+
7+
"$scope": "in",
8+
"$impl": "./add#AddCommand",
9+
10+
"type": "object",
11+
"properties": {
12+
"collection": {
13+
"type": "string",
14+
"description": "The package to be added.",
15+
"$default": {
16+
"$source": "argv",
17+
"index": 0
18+
}
19+
}
20+
},
21+
"required": [
22+
]
23+
}

packages/angular/cli/commands/add.ts

+4-13
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,31 @@
99
// tslint:disable:no-global-tslint-disable no-any
1010
import { tags, terminal } from '@angular-devkit/core';
1111
import { NodePackageDoesNotSupportSchematics } from '@angular-devkit/schematics/tools';
12-
import { CommandScope, Option } from '../models/command';
1312
import { parseOptions } from '../models/command-runner';
1413
import { SchematicCommand } from '../models/schematic-command';
1514
import { NpmInstall } from '../tasks/npm-install';
1615
import { getPackageManager } from '../utilities/config';
1716

1817

1918
export class AddCommand extends SchematicCommand {
20-
readonly name = 'add';
21-
readonly description = 'Add support for a library to your project.';
2219
readonly allowPrivateSchematics = true;
23-
static aliases = [];
24-
static scope = CommandScope.inProject;
25-
arguments = ['collection'];
26-
options: Option[] = [];
2720

2821
private async _parseSchematicOptions(collectionName: string): Promise<any> {
2922
const schematicOptions = await this.getOptions({
3023
schematicName: 'ng-add',
3124
collectionName,
3225
});
26+
this.addOptions(schematicOptions);
3327

34-
const options = this.options.concat(schematicOptions.options);
35-
const args = schematicOptions.arguments.map(arg => arg.name);
36-
37-
return parseOptions(this._rawArgs, options, args, this.argStrategy);
28+
return parseOptions(this._rawArgs, this.options);
3829
}
3930

4031
validate(options: any) {
4132
const collectionName = options._[0];
4233

4334
if (!collectionName) {
4435
this.logger.fatal(
45-
`The "ng ${this.name}" command requires a name argument to be specified eg. `
36+
`The "ng add" command requires a name argument to be specified eg. `
4637
+ `${terminal.yellow('ng add [name] ')}. For more details, use "ng help".`,
4738
);
4839

@@ -57,7 +48,7 @@ export class AddCommand extends SchematicCommand {
5748

5849
if (!firstArg) {
5950
this.logger.fatal(
60-
`The "ng ${this.name}" command requires a name argument to be specified eg. `
51+
`The "ng add" command requires a name argument to be specified eg. `
6152
+ `${terminal.yellow('ng add [name] ')}. For more details, use "ng help".`,
6253
);
6354

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"id": "BuildCommandOptions",
4+
"description": "Builds your app and places it into the output path (dist/ by default).",
5+
"$longDescription": "",
6+
7+
"$aliases": [ "b" ],
8+
"$scope": "in",
9+
"$type": "architect",
10+
"$impl": "./build#BuildCommand",
11+
12+
"type": "object",
13+
"properties": {
14+
"project": {
15+
"type": "string",
16+
"description": "The name of the project to build.",
17+
"$default": {
18+
"$source": "argv",
19+
"index": 0
20+
}
21+
},
22+
"configuration": {
23+
"description": "Specify the configuration to use.",
24+
"type": "string",
25+
"aliases": ["c"]
26+
},
27+
"prod": {
28+
"description": "Flag to set configuration to 'production'.",
29+
"type": "boolean"
30+
}
31+
},
32+
"required": [
33+
]
34+
}

packages/angular/cli/commands/build.ts

-10
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,10 @@
77
*/
88

99
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';
10-
import { CommandScope, Option } from '../models/command';
1110
import { Version } from '../upgrade/version';
1211

1312
export class BuildCommand extends ArchitectCommand {
14-
public readonly name = 'build';
1513
public readonly target = 'build';
16-
public readonly description =
17-
'Builds your app and places it into the output path (dist/ by default).';
18-
public static aliases = ['b'];
19-
public static scope = CommandScope.inProject;
20-
public options: Option[] = [
21-
this.prodOption,
22-
this.configurationOption,
23-
];
2414

2515
public validate(options: ArchitectCommandOptions) {
2616
// Check Angular and TypeScript versions.
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"id": "ConfigCommandOptions",
4+
"description": "Get/set configuration values.",
5+
"$longDescription": "",
6+
7+
"$aliases": [],
8+
"$scope": "in",
9+
"$impl": "./config#ConfigCommand",
10+
11+
"type": "object",
12+
"properties": {
13+
"jsonPath": {
14+
"type": "string",
15+
"description": "The path to the value to get/set.",
16+
"$default": {
17+
"$source": "argv",
18+
"index": 0
19+
}
20+
},
21+
"value": {
22+
"type": "string",
23+
"description": "The new value to be set.",
24+
"$default": {
25+
"$source": "argv",
26+
"index": 1
27+
}
28+
},
29+
"global": {
30+
"type": "boolean",
31+
"description": "Get/set the value in the global configuration (in your home directory).",
32+
"default": false,
33+
"aliases": ["g"]
34+
}
35+
},
36+
"required": [
37+
]
38+
}

packages/angular/cli/commands/config.ts

+1-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
tags,
1818
} from '@angular-devkit/core';
1919
import { writeFileSync } from 'fs';
20-
import { Command, Option } from '../models/command';
20+
import { Command } from '../models/command';
2121
import {
2222
getWorkspace,
2323
getWorkspaceRaw,
@@ -179,19 +179,6 @@ function normalizeValue(value: string, path: string): JsonValue {
179179
}
180180

181181
export class ConfigCommand extends Command {
182-
public readonly name = 'config';
183-
public readonly description = 'Get/set configuration values.';
184-
public readonly arguments = ['jsonPath', 'value'];
185-
public readonly options: Option[] = [
186-
{
187-
name: 'global',
188-
type: Boolean,
189-
'default': false,
190-
aliases: ['g'],
191-
description: 'Get/set the value in the global configuration (in your home directory).',
192-
},
193-
];
194-
195182
public run(options: ConfigOptions) {
196183
const level = options.global ? 'global' : 'local';
197184

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"id": "DocCommandOptions",
4+
"description": "Opens the official Angular API documentation for a given keyword.",
5+
"$longDescription": "",
6+
7+
"$aliases": [ "d" ],
8+
"$type": "",
9+
"$impl": "./doc#DocCommand",
10+
11+
"type": "object",
12+
"properties": {
13+
"keyword": {
14+
"type": "string",
15+
"description": "The query to search upon.",
16+
"$default": {
17+
"$source": "argv",
18+
"index": 0
19+
}
20+
},
21+
"search": {
22+
"aliases": ["s"],
23+
"type": "boolean",
24+
"default": false,
25+
"description": "Search whole angular.io instead of just api."
26+
}
27+
},
28+
"required": [
29+
]
30+
}

packages/angular/cli/commands/doc.ts

-14
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,6 @@ export interface Options {
1515
}
1616

1717
export class DocCommand extends Command {
18-
public readonly name = 'doc';
19-
public readonly description = 'Opens the official Angular API documentation for a given keyword.';
20-
public static aliases = ['d'];
21-
public readonly arguments = ['keyword'];
22-
public readonly options = [
23-
{
24-
name: 'search',
25-
aliases: ['s'],
26-
type: Boolean,
27-
default: false,
28-
description: 'Search whole angular.io instead of just api.',
29-
},
30-
];
31-
3218
public validate(options: Options) {
3319
if (!options.keyword) {
3420
this.logger.error(`keyword argument is required.`);
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"id": "E2eCommandOptions",
4+
"description": "",
5+
"$longDescription": "",
6+
7+
"$aliases": [ "e" ],
8+
"$scope": "in",
9+
"$type": "architect",
10+
"$impl": "./e2e#E2eCommand",
11+
12+
"type": "object",
13+
"properties": {
14+
"configuration": {
15+
"description": "Specify the configuration to use.",
16+
"type": "string",
17+
"aliases": ["c"]
18+
},
19+
"prod": {
20+
"description": "Flag to set configuration to 'production'.",
21+
"type": "boolean"
22+
}
23+
},
24+
"required": [
25+
]
26+
}

packages/angular/cli/commands/e2e.ts

-9
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,11 @@
77
*/
88

99
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';
10-
import { CommandScope, Option } from '../models/command';
1110

1211

1312
export class E2eCommand extends ArchitectCommand {
14-
public readonly name = 'e2e';
1513
public readonly target = 'e2e';
16-
public readonly description = 'Run e2e tests in existing project.';
17-
public static aliases: string[] = ['e'];
18-
public static scope = CommandScope.inProject;
1914
public readonly multiTarget = true;
20-
public readonly options: Option[] = [
21-
this.prodOption,
22-
this.configurationOption,
23-
];
2415

2516
public async run(options: ArchitectCommandOptions) {
2617
return this.runArchitectTarget(options);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"id": "EasterEggCommandOptions",
4+
"description": "",
5+
"$longDescription": "",
6+
"$hidden": true,
7+
8+
"$impl": "./easter-egg#AwesomeCommand",
9+
10+
"type": "object"
11+
}

packages/angular/cli/commands/easter-egg.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,13 @@
77
*/
88

99
import { terminal } from '@angular-devkit/core';
10-
import { Command, Option } from '../models/command';
10+
import { Command } from '../models/command';
1111

1212
function pickOne(of: string[]): string {
1313
return of[Math.floor(Math.random() * of.length)];
1414
}
1515

1616
export class AwesomeCommand extends Command {
17-
public readonly name = 'make-this-awesome';
18-
public readonly description = '';
19-
public readonly hidden = true;
20-
readonly arguments: string[] = [];
21-
readonly options: Option[] = [];
22-
2317
run() {
2418
const phrase = pickOne([
2519
`You're on it, there's nothing for me to do!`,
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"id": "CommandOptions",
4+
"description": "Temporarily disabled. Ejects your app and output the proper webpack configuration and scripts.",
5+
"$longDescription": "",
6+
7+
"$hidden": true,
8+
"$scope": "in",
9+
"$impl": "./eject#EjectCommand",
10+
11+
"type": "object"
12+
}

0 commit comments

Comments
 (0)