Skip to content

Commit

Permalink
feat(@angular/cli): implement deploy command
Browse files Browse the repository at this point in the history
  • Loading branch information
mgechev committed Jul 18, 2019
1 parent 076b295 commit 31b1dde
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/angular/cli/BUILD
Expand Up @@ -54,6 +54,7 @@ ts_library(
":analytics_schema",
":build_schema",
":config_schema",
":deploy_schema",
":deprecated_schema",
":doc_schema",
":e2e_schema",
Expand Down Expand Up @@ -95,6 +96,14 @@ ts_json_schema(
],
)

ts_json_schema(
name = "deploy_schema",
src = "commands/deploy.json",
data = [
"commands/definitions.json",
],
)

ts_json_schema(
name = "config_schema",
src = "commands/config.json",
Expand Down
1 change: 1 addition & 0 deletions packages/angular/cli/commands.json
Expand Up @@ -2,6 +2,7 @@
"add": "./commands/add.json",
"analytics": "./commands/analytics.json",
"build": "./commands/build.json",
"deploy": "./commands/deploy.json",
"config": "./commands/config.json",
"doc": "./commands/doc.json",
"e2e": "./commands/e2e.json",
Expand Down
35 changes: 35 additions & 0 deletions packages/angular/cli/commands/deploy-impl.ts
@@ -0,0 +1,35 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';
import { Arguments } from '../models/interface';
import { Schema as DeployCommandSchema } from './deploy';

export class DeployCommand extends ArchitectCommand<DeployCommandSchema> {
public readonly target = 'deploy';
public readonly error = `Cannot find "deploy" target for the specified project.
You can find a package that implements deployment capabilities for your
favorite platform on npm: https://www.npmjs.com/search?q=ng%20deploy
After that add the package to your project using:
ng add [package name]
`;

public async run(options: ArchitectCommandOptions & Arguments) {
return this.runArchitectTarget(options);
}

async reportAnalytics(
paths: string[],
options: DeployCommandSchema & Arguments,
dimensions: (boolean | number | string)[] = [],
metrics: (boolean | number | string)[] = [],
): Promise<void> {
return super.reportAnalytics(paths, options, dimensions, metrics);
}
}
9 changes: 9 additions & 0 deletions packages/angular/cli/commands/deploy-long.md
@@ -0,0 +1,9 @@
The `ng deploy` command is a shortcut for:

```
ng run [PROJECT_NAME]:deploy
```

It takes an optional project name, as specified in the `projects` section of the `angular.json` workspace configuration file.

When a project name is not supplied, the CLI will execute the `deploy` builder for the default project.
31 changes: 31 additions & 0 deletions packages/angular/cli/commands/deploy.json
@@ -0,0 +1,31 @@
{
"$schema": "http://json-schema.org/schema",
"$id": "ng-cli://commands/deploy.json",
"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 thw workspace.",
"$longDescription": "./deploy-long.md",

"$aliases": [ "d" ],
"$scope": "in",
"$type": "architect",
"$impl": "./deploy-impl#DeployCommand",

"allOf": [
{
"properties": {
"project": {
"type": "string",
"description": "The name of the project to deploy.",
"$default": {
"$source": "argv",
"index": 0
}
}
},
"required": [
]
},
{
"$ref": "./definitions.json#/definitions/base"
}
]
}
6 changes: 4 additions & 2 deletions packages/angular/cli/models/architect-command.ts
Expand Up @@ -35,6 +35,7 @@ export abstract class ArchitectCommand<
protected multiTarget = false;

target: string | undefined;
error: string | undefined;

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

if (targetProjectNames.length === 0) {
throw new Error(`No projects support the '${this.target}' target.`);
throw new Error(this.error || `No projects support the '${this.target}' target.`);
}

if (projectName && !targetProjectNames.includes(projectName)) {
throw new Error(`Project '${projectName}' does not support the '${this.target}' target.`);
throw new Error(this.error ||
`Project '${projectName}' does not support the '${this.target}' target.`);
}

if (!projectName && commandLeftovers && commandLeftovers.length > 0) {
Expand Down
1 change: 1 addition & 0 deletions packages/angular/cli/models/command-runner.ts
Expand Up @@ -31,6 +31,7 @@ const standardCommands = {
'add': '../commands/add.json',
'analytics': '../commands/analytics.json',
'build': '../commands/build.json',
'deploy': '../commands/deploy.json',
'config': '../commands/config.json',
'doc': '../commands/doc.json',
'e2e': '../commands/e2e.json',
Expand Down

0 comments on commit 31b1dde

Please sign in to comment.