Skip to content

Commit 8e33b28

Browse files
Merge pull request #34 from ngx-builders/refactor--Align-options-with-RFC-1-of-ngx-deploy-starter
refactor: align options with ngx-deploy-starter
2 parents d705fd0 + 9958ee4 commit 8e33b28

File tree

8 files changed

+126
-52
lines changed

8 files changed

+126
-52
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
*.js
22
*.map
33
node_modules
4-
*.d.ts
54
*.js
65
*.js.map
76
.gitignore

builder-test/angular.json

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@
1313
"deploy": {
1414
"builder": "@netlify-builder/deploy:deploy",
1515
"options": {
16-
"command": "deploy",
1716
"outputPath": "dist/builder-test",
1817
"netlifyToken": "tokenValue",
19-
"siteId": "siteId",
20-
"args": [
21-
"src/main.ts"
22-
]
18+
"siteId": "siteId"
2319
}
2420
},
2521
"build": {
@@ -64,6 +60,30 @@
6460
"maximumError": "5mb"
6561
}
6662
]
63+
},
64+
"test": {
65+
"fileReplacements": [
66+
{
67+
"replace": "src/environments/environment.ts",
68+
"with": "src/environments/environment.prod.ts"
69+
}
70+
],
71+
"optimization": true,
72+
"outputHashing": "all",
73+
"sourceMap": true,
74+
"extractCss": true,
75+
"namedChunks": false,
76+
"aot": false,
77+
"extractLicenses": true,
78+
"vendorChunk": false,
79+
"buildOptimizer": true,
80+
"budgets": [
81+
{
82+
"type": "initial",
83+
"maximumWarning": "2mb",
84+
"maximumError": "5mb"
85+
}
86+
]
6787
}
6888
}
6989
},

builder-test/package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@
1111
},
1212
"private": true,
1313
"dependencies": {
14-
"@angular/animations": "~8.0.0-beta.11",
15-
"@angular/common": "~8.0.0-beta.11",
16-
"@angular/compiler": "~8.0.0-beta.11",
17-
"@angular/core": "~8.0.0-beta.11",
18-
"@angular/forms": "~8.0.0-beta.11",
19-
"@angular/platform-browser": "~8.0.0-beta.11",
20-
"@angular/platform-browser-dynamic": "~8.0.0-beta.11",
21-
"@angular/router": "~8.0.0-beta.11",
14+
"@angular/animations": "~8.2.4",
15+
"@angular/common": "~8.2.4",
16+
"@angular/compiler": "~8.2.4",
17+
"@angular/core": "~8.2.4",
18+
"@angular/forms": "~8.2.4",
19+
"@angular/platform-browser": "~8.2.4",
20+
"@angular/platform-browser-dynamic": "~8.2.4",
21+
"@angular/router": "~8.2.4",
2222
"core-js": "^2.5.4",
23-
"rxjs": "~6.4.0",
23+
"rxjs": "~6.5.2",
2424
"tslib": "^1.9.0",
25-
"zone.js": "~0.9.0"
25+
"zone.js": "~0.9.1"
2626
},
2727
"devDependencies": {
28-
"@angular-devkit/build-angular": "~0.800.0-beta.7",
29-
"@angular/cli": "~8.0.0-beta.11",
30-
"@angular/compiler-cli": "~8.0.0-beta.11",
31-
"@angular/language-service": "~8.0.0-beta.11",
28+
"@angular-devkit/build-angular": "~0.803.2",
29+
"@angular/cli": "~8.3.2",
30+
"@angular/compiler-cli": "~8.2.4",
31+
"@angular/language-service": "~8.2.4",
3232
"@example/command-runner": "file:../command-builder",
3333
"@types/jasmine": "~3.3.8",
3434
"@types/jasminewd2": "~2.0.3",
@@ -44,6 +44,6 @@
4444
"protractor": "~5.4.0",
4545
"ts-node": "~7.0.0",
4646
"tslint": "~5.13.1",
47-
"typescript": "~3.3.3333"
47+
"typescript": "~3.5.3"
4848
}
49-
}
49+
}

command-builder/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,35 @@ This command will configure everything, you just need to provide API ID and Pers
2525

2626
Now whenever you want to deploy your angular project just run a command `ng run [YOUR_PROJECT_NAME]:deploy` and your project got live with new update.
2727

28+
29+
## 📦 Options <a name="options"></a>
30+
31+
#### --configuration <a name="configuration"></a>
32+
* __optional__
33+
* Alias: `-c`
34+
* Default: `production` (string)
35+
* Example:
36+
* `ng deploy` – Angular project is build in production mode
37+
* `ng deploy --configuration=test` – Angular project is using the configuration `test` (this configuration must exist in the `angular.json` file)
38+
39+
A named build target, as specified in the `configurations` section of `angular.json`.
40+
Each named target is accompanied by a configuration of option defaults for that target.
41+
Same as `ng build --configuration=XXX`.
42+
This command has no effect if the option `--no-build` option is active.
43+
44+
45+
#### --no-build <a name="no-build"></a>
46+
* __optional__
47+
* Default: `false` (string)
48+
* Example:
49+
* `ng deploy` – Angular project is build in production mode before the deployment
50+
* `ng deploy --no-build` – Angular project is NOT build
51+
52+
Skip build process during deployment.
53+
This can be used when you are sure that you haven't changed anything and want to deploy with the latest artifact.
54+
This command causes the `--configuration` setting to have no effect.
55+
56+
2857
## License
2958

3059
MIT

command-builder/deploy/index.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
22
import { JsonObject } from '@angular-devkit/core';
3-
const NetlifyAPI = require('netlify');
4-
3+
import { Schema } from './schema';
54

6-
interface Options extends JsonObject {
7-
outputPath: string;
8-
netlifyToken: string,
9-
siteId: string,
10-
configuration: string;
11-
}
5+
const NetlifyAPI = require('netlify');
126

13-
export default createBuilder<Options>(
14-
async (builderConfig: Options, context: BuilderContext): Promise<BuilderOutput> => {
7+
export default createBuilder<any>(
8+
async (builderConfig: Schema, context: BuilderContext): Promise<BuilderOutput> => {
159
context.reportStatus(`Executing deploy...`);
1610
context.logger.info(`Executing deploy command ...... `);
11+
let buildResult;
12+
if (builderConfig.noBuild) {
13+
context.logger.info(`📦 Skipping build`);
14+
buildResult = true;
15+
} else {
16+
const configuration = builderConfig.configuration ? builderConfig.configuration : 'production';
1717

18-
const configuration = builderConfig.configuration ? builderConfig.configuration : 'production';
18+
if (!context.target) {
19+
throw new Error('Cannot deploy the application without a target');
20+
}
1921

20-
const build = await context.scheduleTarget({
21-
target: 'build',
22-
project: context.target !== undefined ? context.target.project : '',
23-
configuration
24-
});
22+
const build = await context.scheduleTarget({
23+
target: 'build',
24+
project: context.target !== undefined ? context.target.project : '',
25+
configuration
26+
});
2527

26-
let buildResult = await build.result;
28+
buildResult = await build.result;
29+
}
2730

28-
if (buildResult.success) {
31+
if (buildResult.success || buildResult) {
2932
context.logger.info(`✔ Build Completed`);
3033
const netlifyToken = process.env.NETLIFY_TOKEN || builderConfig.netlifyToken;
3134
if (netlifyToken == '' || netlifyToken == undefined) {

command-builder/deploy/schema.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface Schema {
2+
configuration?: string;
3+
noBuild? : boolean;
4+
outputPath? : boolean;
5+
netlifyToken?: string;
6+
siteId?: string;
7+
}

command-builder/deploy/schema.json

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
{
2-
"$schema": "http://json-schema.org/schema",
3-
"type": "object",
2+
"id": "Schema",
3+
"title": "schema",
4+
"description": "Deployment of Angular CLI applications to Netlify",
45
"properties": {
5-
"command": {
6-
"type": "string"
7-
},
8-
"args": {
9-
"type": "array",
10-
"items": {
11-
"type": "string"
12-
}
6+
"configuration": {
7+
"type": "string",
8+
"default": "production",
9+
"description": "A named build target, as specified in the `configurations` section of angular.json. Each named target is accompanied by a configuration of option defaults for that target. Same as `ng build --configuration=XXX`.",
10+
"alias": "c"
11+
},
12+
"noBuild": {
13+
"type": "boolean",
14+
"default": false,
15+
"description": "Skip build process during deployment."
16+
},
17+
"outputPath": {
18+
"type": "string",
19+
"description": "This is one of the options you can freely choose according to your needs. --- We will 'deploy' to this folder."
20+
},
21+
"netlifyToken": {
22+
"type": "string",
23+
"description": "Acess token give you the ability to communicate with netlify over API."
24+
},
25+
"siteId": {
26+
"type": "string",
27+
"description": "Every netlify app have a API ID which uniquly identify that app."
1328
}
1429
}
15-
}
30+
}

command-builder/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"moduleResolution": "node",
44
"module": "commonjs",
5-
"target": "es6",
5+
"target": "es2015",
66
"lib": [
77
"es2015",
88
"dom",
@@ -18,6 +18,7 @@
1818
"strictNullChecks": true,
1919
"sourceMap": true,
2020
"declaration": false,
21+
"inlineSources": true,
2122
"stripInternal": true,
2223
"skipLibCheck": true,
2324
"noImplicitAny": false,

0 commit comments

Comments
 (0)