Skip to content

Commit f13bb6b

Browse files
committed
fix!: change configuration parameter for buildTarget
BREAKING CHANGE, the parameter configuration is migrated to buildTarget. Just change --configuration for --build-target on the command line and on the configuration file configuration for buildTarget
1 parent 85c97f2 commit f13bb6b

File tree

8 files changed

+45
-52
lines changed

8 files changed

+45
-52
lines changed

README.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
[![Discord Server][discord-image]][discord-url]
88

99
<!-- Images -->
10+
1011
[npm-image]: https://badge.fury.io/js/ngx-deploy-npm.svg
1112
[mit-licence-image]: https://img.shields.io/badge/license-MIT-orange.svg?color=blue&style=flat-square
1213
[conventional-commits-image]: https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg
1314
[discord-image]: https://img.shields.io/discord/748677963142135818?color=7289DA&label=%23ngx-deploy-npm&logo=discord&logoColor=white&style=flat-square
1415

1516
<!-- URLs -->
17+
1618
[npm-url]: https://www.npmjs.com/package/ngx-deploy-npm
1719
[mit-licence-url]: http://opensource.org/licenses/MIT
1820
[discord-url]: https://discord.gg/cPa78y6rXn
@@ -30,7 +32,7 @@
3032
- [🚀 Continuous Delivery](#continuous-delivery)
3133
- [CircleCI](#circleci)
3234
- [📦 Options](#options)
33-
- [--configuration](#--configuration)
35+
- [--build-target](#--build-target)
3436
- [--no-build](#--no-build)
3537
- [--package-version](#--package-version)
3638
- [--tag](#--tag)
@@ -46,8 +48,10 @@
4648

4749
---
4850

49-
> Note: all the examples are focused on Angular, if you don't see an
50-
> 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`
5155
5256
## 🚀 Quick Start (local development) <a name="quick-start"></a>
5357

@@ -56,7 +60,7 @@ package created and you already are logged in on npm using `npm login`
5660

5761
1. Add `ngx-deploy-npm` to your project. It will configure all your publishable libraries present in the project
5862

59-
| Angular🅰️ | Nx🐬 |
63+
| Angular🅰️ | Nx🐬 |
6064
| :------------------------------------------- | :----------------------------------------------------- |
6165
| <pre lang="sh"> ng add ngx-deploy-npm </pre> | <pre lang="sh"> nx generate ngx-deploy-npm:init </pre> |
6266

@@ -88,16 +92,18 @@ Independently of the CI/CD that you are using you must create an NPM token. To d
8892
- Creating a step with `run: npm whoami`
8993
- The output should be the username of your npm account
9094
4. **Deploy your package**
95+
9196
- Create a step with:
9297

93-
| Angular🅰️ | Nx🐬 |
98+
| Angular🅰️ | Nx🐬 |
9499
| :-------------------------------------------- | :-------------------------------------------- |
95100
| <pre lang="sh"> ng deploy your-library </pre> | <pre lang="sh"> nx deploy your-library </pre> |
96101

97102
- **NOTE:** You may want to execute a script that executes some pre-steps
98-
before publishing and inside that script execute`ng/nx deploy YOUR_LIBRARY`.
99-
If you want to make that script on JavaScript and put it on the package.json,
100-
**execute it using `npm` not with yarn**, there is an [issue](https://github.com/yarnpkg/yarn/issues/5683) associated with that
103+
before publishing and inside that script execute`ng/nx deploy YOUR_LIBRARY`.
104+
If you want to make that script on JavaScript and put it on the package.json,
105+
**execute it using `npm` not with yarn**, there is an [issue](https://github.com/yarnpkg/yarn/issues/5683) associated with that
106+
101107
5. **Enjoy your just released package 🎉📦**
102108

103109
The job full example is for an Angular project is
@@ -120,20 +126,21 @@ jobs:
120126
121127
## 📦 Options <a name="options"></a>
122128
123-
#### --configuration
129+
#### --build-target
124130
125131
- **optional**
126-
- Alias: `-c`
127132
- Default: Doesn't have any default value (string)
128133
- Example:
129-
- `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
135+
136+
The `buildTarget` simply points to an existing build configuration for your project,
137+
as specified in the `configurations` section of `angular.json`.
130138

131-
A named build target, as specified in the `configurations` section of `angular.json`.
132-
Each named target is accompanied by a configuration of option defaults for that target.
133-
Same as `ng build --configuration=XXX`.
139+
This is equivalent to calling the command `ng build --configuration=XXX`.
134140
This command has no effect if the option `--no-build` option is active.
135141

136142
#### --no-build
143+
137144
- **optional**
138145
- Default: `false` (string)
139146
- Example:
@@ -142,7 +149,7 @@ This command has no effect if the option `--no-build` option is active.
142149

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

147154
#### --package-version
148155

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

193200
To avoid all these command-line cmd options, you can write down your
194-
configuration in the `angular.json` or `workspace.json` file in the `options` attribute
201+
configuration in the `angular.json` file in the `options` attribute
195202
of your deploy project's architect.
196203
Just change the kebab-case to lower camel case.
197204
This is the notation of all options in lower camel case:
198205

199206
- access
200-
- configuration
207+
- buildTarget
201208
- dryRun
202209
- packageVersion
203210
- otp
@@ -224,7 +231,7 @@ becomes
224231
}
225232
```
226233

227-
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! 😄
228235

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

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 angular packages to npm by just run `ng deploy`",
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)