Skip to content

Commit f987eec

Browse files
authored
Merge pull request #59 from bikecoders/migrate-configuration-to-build-target
fix!: change configuration parameter for buildTarget
2 parents 62bf5e5 + f13bb6b commit f987eec

File tree

8 files changed

+35
-47
lines changed

8 files changed

+35
-47
lines changed

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
- [🚀 Continuous Delivery](#continuous-delivery)
3333
- [CircleCI](#circleci)
3434
- [📦 Options](#options)
35-
- [--configuration](#--configuration)
35+
- [--build-target](#--build-target)
3636
- [--no-build](#--no-build)
3737
- [--package-version](#--package-version)
3838
- [--tag](#--tag)
@@ -48,8 +48,10 @@
4848

4949
---
5050

51-
> Note: all the examples are focused on Angular, if you don't see an
52-
> explicit command for an Nx workspace just change `ng` for `nx`
51+
> **Note:** all the examples are focused on Angular, if you don't see an
52+
> explicit command for an Nx workspace just change `ng` for `nx`.
53+
>
54+
> Also, you may find references to `angular.json`, if you are in a Nx workspace you can change it for `workspace.json`
5355
5456
## 🚀 Quick Start (local development) <a name="quick-start"></a>
5557

@@ -124,17 +126,17 @@ jobs:
124126
125127
## 📦 Options <a name="options"></a>
126128
127-
#### --configuration
129+
#### --build-target
128130
129131
- **optional**
130-
- Alias: `-c`
131132
- Default: Doesn't have any default value (string)
132133
- Example:
133-
- `ng deploy --configuration=production` – The configuration `production` is being used to build your package
134+
- `ng deploy --build-target=production` – The configuration `production` is being used to build your package
134135

135-
A named build target, as specified in the `configurations` section of `angular.json`.
136-
Each named target is accompanied by a configuration of option defaults for that target.
137-
Same as `ng build --configuration=XXX`.
136+
The `buildTarget` simply points to an existing build configuration for your project,
137+
as specified in the `configurations` section of `angular.json`.
138+
139+
This is equivalent to calling the command `ng build --configuration=XXX`.
138140
This command has no effect if the option `--no-build` option is active.
139141

140142
#### --no-build
@@ -147,7 +149,7 @@ This command has no effect if the option `--no-build` option is active.
147149

148150
Skip build process during deployment.
149151
This can be used when you are sure that you haven't changed anything and want to deploy with the latest artifact.
150-
This command causes the `--configuration` setting to have no effect.
152+
This command causes the `--build-target` setting to have no effect.
151153

152154
#### --package-version
153155

@@ -196,13 +198,13 @@ For testing: Run through without making any changes. Execute with --dry-run and
196198
## 📁 Configuration File <a name="configuration-file"></a>
197199

198200
To avoid all these command-line cmd options, you can write down your
199-
configuration in the `angular.json` or `workspace.json` file in the `options` attribute
201+
configuration in the `angular.json` file in the `options` attribute
200202
of your deploy project's architect.
201203
Just change the kebab-case to lower camel case.
202204
This is the notation of all options in lower camel case:
203205

204206
- access
205-
- configuration
207+
- buildTarget
206208
- dryRun
207209
- packageVersion
208210
- otp
@@ -229,7 +231,7 @@ becomes
229231
}
230232
```
231233

232-
And just run `ng deploy YOUR-LIBRARY` 😄.
234+
Now you can just run `ng deploy YOUR-LIBRARY` without all the options in the command line! 😄
233235

234236
> ℹ️ You can always use the [--dry-run](#dry-run) option to verify if your configuration is right.
235237

src/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2019 Diego Juliao, Yossely Mendoza
3+
Copyright (c) 2019-2021 Diego Juliao, Yossely Mendoza
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

src/deploy/actions.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ describe('Deploy Angular apps', () => {
5959
await deploy(mockEngine, context, getBuildTarget(), {});
6060

6161
expect(spy).toHaveBeenCalledWith({
62+
configuration: 'production',
6263
target: 'build',
6364
project: PROJECT,
6465
});
@@ -67,8 +68,8 @@ describe('Deploy Angular apps', () => {
6768
it('should invoke the builder with the right configuration', async () => {
6869
const customConf = 'my-custom-conf';
6970

70-
await deploy(mockEngine, context, getBuildTarget(), {
71-
configuration: customConf,
71+
await deploy(mockEngine, context, getBuildTarget(customConf), {
72+
buildTarget: customConf,
7273
});
7374

7475
expect(spy).toHaveBeenCalledWith({
@@ -207,6 +208,6 @@ const createBuilderOutputMock = (
207208
};
208209
};
209210

210-
const getBuildTarget = (): BuildTarget => ({
211-
name: `${PROJECT}:build:production`,
211+
const getBuildTarget = (customConf: string = 'production'): BuildTarget => ({
212+
name: `${PROJECT}:build:${customConf}`,
212213
});

src/deploy/actions.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,22 @@ export default async function deploy(
3030
throw new Error('Cannot execute the build target');
3131
}
3232

33-
const configuration = options.configuration;
33+
context.logger.info(`📦 Building "${context.target.project}"`);
34+
context.logger.info(`📦 Build target "${buildTarget.name}"`);
3435

35-
context.logger.info(
36-
`📦 Building "${context.target.project}". ${
37-
configuration ? `Configuration "${configuration}"` : ''
38-
}`
36+
const build = await context.scheduleTarget(
37+
targetFromTargetString(buildTarget.name)
3938
);
40-
41-
const target = {
42-
target: 'build',
43-
project: context.target.project,
44-
} as Target;
45-
46-
// Set the configuration if set on the options
47-
if (configuration) {
48-
target.configuration = configuration;
49-
}
50-
51-
const build = await context.scheduleTarget(target);
5239
const buildResult = await build.result;
5340

5441
if (!buildResult.success) {
5542
throw new Error(buildResult.error);
5643
}
5744
}
5845

59-
const targetFromStr = targetFromTargetString(buildTarget.name);
60-
const buildOptions = await context.getTargetOptions(targetFromStr);
46+
const buildOptions = await context.getTargetOptions(
47+
targetFromTargetString(buildTarget.name)
48+
);
6149

6250
const outputPath = await getOutPutPath(
6351
context.workspaceRoot,

src/deploy/builder.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ export default createBuilder(
1616
throw new Error('Cannot deploy the application without a target');
1717
}
1818

19-
const configuration = options.configuration
20-
? `:${options.configuration}`
21-
: '';
19+
const configuration = options.buildTarget ? `:${options.buildTarget}` : '';
2220
const buildTarget = {
2321
name: `${context.target.project}:build${configuration}`,
2422
};

src/deploy/schema.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
"title": "schema",
44
"description": "Publish your libraries to NPM with just one command",
55
"properties": {
6-
"configuration": {
6+
"buildTarget": {
77
"type": "string",
8-
"description": "This is a proposal from RFC #1. --- 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`.",
9-
"alias": "c"
8+
"description": "A named build target, as specified in the `configurations` section of workspace/angular.json. Each named target is accompanied by a configuration of option defaults for that target. This is equivalent to calling the command `[nx|ng] build --configuration=XXX`."
109
},
1110
"noBuild": {
1211
"type": "boolean",
1312
"default": false,
14-
"description": "This is a proposal from RFC #1. --- Skip build process during deployment."
13+
"description": "Skip build process during deployment."
1514
},
1615
"packageVersion": {
1716
"type": "string",

src/ng-add.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe('ng-add', () => {
129129
};
130130
originalWorkspaceDefinition.projects.publishable.architect!.build.configurations = productionConfig;
131131
expectedWorkspaceDefinition.projects.publishable.architect!.build.configurations = productionConfig;
132-
expectedWorkspaceDefinition.projects.publishable.architect!.deploy.options!.configuration =
132+
expectedWorkspaceDefinition.projects.publishable.architect!.deploy.options!.buildTarget =
133133
'production';
134134
tree.create('angular.json', JSON.stringify(originalWorkspaceDefinition));
135135

src/ng-add.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ function getLibraries({ projects }: Workspace): WorkspaceProject[] {
8585
*/
8686
function setUpProductionModeIfHasIt(
8787
lib: WorkspaceProject
88-
): Pick<Schema, 'configuration'> {
88+
): Pick<Schema, 'buildTarget'> {
8989
return lib.architect?.build?.configurations?.production
9090
? {
91-
configuration: 'production',
91+
buildTarget: 'production',
9292
}
9393
: {};
9494
}

0 commit comments

Comments
 (0)