Skip to content

Commit 5df50ba

Browse files
mgechevvikerman
authored andcommitted
feat(@angular/cli): implement deploy command
1 parent 4287d57 commit 5df50ba

File tree

7 files changed

+105
-3
lines changed

7 files changed

+105
-3
lines changed

packages/angular/cli/BUILD

+9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ ts_library(
5454
":analytics_schema",
5555
":build_schema",
5656
":config_schema",
57+
":deploy_schema",
5758
":deprecated_schema",
5859
":doc_schema",
5960
":e2e_schema",
@@ -95,6 +96,14 @@ ts_json_schema(
9596
],
9697
)
9798

99+
ts_json_schema(
100+
name = "deploy_schema",
101+
src = "commands/deploy.json",
102+
data = [
103+
"commands/definitions.json",
104+
],
105+
)
106+
98107
ts_json_schema(
99108
name = "config_schema",
100109
src = "commands/config.json",

packages/angular/cli/commands.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"analytics": "./commands/analytics.json",
44
"build": "./commands/build.json",
55
"config": "./commands/config.json",
6+
"deploy": "./commands/deploy.json",
67
"doc": "./commands/doc.json",
78
"e2e": "./commands/e2e.json",
89
"make-this-awesome": "./commands/easter-egg.json",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';
9+
import { Arguments } from '../models/interface';
10+
import { Schema as DeployCommandSchema } from './deploy';
11+
12+
const BuilderMissing = `
13+
14+
Cannot find "deploy" target for the specified project.
15+
16+
You should add a package that implements deployment capabilities for your
17+
favorite platform.
18+
19+
For example:
20+
ng add @angular/fire
21+
ng add @azure/ng-deploy
22+
ng add @zeit/ng-deploy
23+
24+
Find more packages on npm https://www.npmjs.com/search?q=ng%20deploy
25+
`;
26+
27+
export class DeployCommand extends ArchitectCommand<DeployCommandSchema> {
28+
public readonly target = 'deploy';
29+
public readonly missingTargetError = BuilderMissing;
30+
31+
public async run(options: ArchitectCommandOptions & Arguments) {
32+
return this.runArchitectTarget(options);
33+
}
34+
35+
public async initialize(options: DeployCommandSchema & Arguments): Promise<void> {
36+
if (!options.help) {
37+
return super.initialize(options);
38+
}
39+
}
40+
41+
async reportAnalytics(
42+
paths: string[],
43+
options: DeployCommandSchema & Arguments,
44+
dimensions: (boolean | number | string)[] = [],
45+
metrics: (boolean | number | string)[] = [],
46+
): Promise<void> {
47+
return super.reportAnalytics(paths, options, dimensions, metrics);
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The `ng deploy` command is a shortcut for:
2+
3+
```
4+
ng run [PROJECT_NAME]:deploy
5+
```
6+
7+
It takes an optional project name, as specified in the `projects` section of the `angular.json` workspace configuration file.
8+
9+
When a project name is not supplied, the CLI will execute the `deploy` builder for the default project.
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"$id": "ng-cli://commands/deploy.json",
4+
"description": "Invokes the deploy builder for a specified project. If no project is specified, the CLI will invoke the deploy builder for the default project in the workspace.",
5+
"$longDescription": "./deploy-long.md",
6+
7+
"$aliases": [ "d" ],
8+
"$scope": "in",
9+
"$type": "architect",
10+
"$impl": "./deploy-impl#DeployCommand",
11+
12+
"allOf": [
13+
{
14+
"properties": {
15+
"project": {
16+
"type": "string",
17+
"description": "The name of the project to deploy.",
18+
"$default": {
19+
"$source": "argv",
20+
"index": 0
21+
}
22+
}
23+
},
24+
"required": [
25+
]
26+
},
27+
{
28+
"$ref": "./definitions.json#/definitions/base"
29+
}
30+
]
31+
}

packages/angular/cli/models/architect-command.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export abstract class ArchitectCommand<
3535
protected multiTarget = false;
3636

3737
target: string | undefined;
38+
missingTargetError: string | undefined;
3839

3940
public async initialize(options: T & Arguments): Promise<void> {
4041
await super.initialize(options);
@@ -75,11 +76,12 @@ export abstract class ArchitectCommand<
7576
}
7677

7778
if (targetProjectNames.length === 0) {
78-
throw new Error(`No projects support the '${this.target}' target.`);
79+
throw new Error(this.missingTargetError || `No projects support the '${this.target}' target.`);
7980
}
8081

8182
if (projectName && !targetProjectNames.includes(projectName)) {
82-
throw new Error(`Project '${projectName}' does not support the '${this.target}' target.`);
83+
throw new Error(this.missingTargetError ||
84+
`Project '${projectName}' does not support the '${this.target}' target.`);
8385
}
8486

8587
if (!projectName && commandLeftovers && commandLeftovers.length > 0) {
@@ -156,7 +158,7 @@ export abstract class ArchitectCommand<
156158
// This is a special case where we just return.
157159
return;
158160
} else {
159-
throw new Error('Cannot determine project or target for command.');
161+
throw new Error(this.missingTargetError || 'Cannot determine project or target for command.');
160162
}
161163
}
162164

packages/angular/cli/models/command-runner.ts

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const standardCommands = {
3131
'add': '../commands/add.json',
3232
'analytics': '../commands/analytics.json',
3333
'build': '../commands/build.json',
34+
'deploy': '../commands/deploy.json',
3435
'config': '../commands/config.json',
3536
'doc': '../commands/doc.json',
3637
'e2e': '../commands/e2e.json',

0 commit comments

Comments
 (0)