Skip to content

fix!: change configuration parameter for buildTarget #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
[![Discord Server][discord-image]][discord-url]

<!-- Images -->

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

<!-- URLs -->

[npm-url]: https://www.npmjs.com/package/ngx-deploy-npm
[mit-licence-url]: http://opensource.org/licenses/MIT
[discord-url]: https://discord.gg/cPa78y6rXn
Expand All @@ -30,7 +32,7 @@
- [🚀 Continuous Delivery](#continuous-delivery)
- [CircleCI](#circleci)
- [📦 Options](#options)
- [--configuration](#--configuration)
- [--build-target](#--build-target)
- [--no-build](#--no-build)
- [--package-version](#--package-version)
- [--tag](#--tag)
Expand All @@ -46,8 +48,10 @@

---

> Note: all the examples are focused on Angular, if you don't see an
> explicit command for an Nx workspace just change `ng` for `nx`
> **Note:** all the examples are focused on Angular, if you don't see an
> explicit command for an Nx workspace just change `ng` for `nx`.
>
> Also, you may find references to `angular.json`, if you are in a Nx workspace you can change it for `workspace.json`

## 🚀 Quick Start (local development) <a name="quick-start"></a>

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

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

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

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

- Create a step with:

| Angular🅰️ | Nx🐬 |
| Angular🅰️ | Nx🐬 |
| :-------------------------------------------- | :-------------------------------------------- |
| <pre lang="sh"> ng deploy your-library </pre> | <pre lang="sh"> nx deploy your-library </pre> |

- **NOTE:** You may want to execute a script that executes some pre-steps
before publishing and inside that script execute`ng/nx deploy YOUR_LIBRARY`.
If you want to make that script on JavaScript and put it on the package.json,
**execute it using `npm` not with yarn**, there is an [issue](https://github.com/yarnpkg/yarn/issues/5683) associated with that
before publishing and inside that script execute`ng/nx deploy YOUR_LIBRARY`.
If you want to make that script on JavaScript and put it on the package.json,
**execute it using `npm` not with yarn**, there is an [issue](https://github.com/yarnpkg/yarn/issues/5683) associated with that

5. **Enjoy your just released package 🎉📦**

The job full example is for an Angular project is
Expand All @@ -120,20 +126,21 @@ jobs:

## 📦 Options <a name="options"></a>

#### --configuration
#### --build-target

- **optional**
- Alias: `-c`
- Default: Doesn't have any default value (string)
- Example:
- `ng deploy --configuration=production` – The configuration `production` is being used to build your package
- `ng deploy --build-target=production` – The configuration `production` is being used to build your package

The `buildTarget` simply points to an existing build configuration for your project,
as specified in the `configurations` section of `angular.json`.

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`.
This is equivalent to calling the command `ng build --configuration=XXX`.
This command has no effect if the option `--no-build` option is active.

#### --no-build

- **optional**
- Default: `false` (string)
- Example:
Expand All @@ -142,7 +149,7 @@ This command has no effect if the option `--no-build` option is active.

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

#### --package-version

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

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

- access
- configuration
- buildTarget
- dryRun
- packageVersion
- otp
Expand All @@ -224,7 +231,7 @@ becomes
}
```

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

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

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
9 changes: 5 additions & 4 deletions src/deploy/actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('Deploy Angular apps', () => {
await deploy(mockEngine, context, getBuildTarget(), {});

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

await deploy(mockEngine, context, getBuildTarget(), {
configuration: customConf,
await deploy(mockEngine, context, getBuildTarget(customConf), {
buildTarget: customConf,
});

expect(spy).toHaveBeenCalledWith({
Expand Down Expand Up @@ -207,6 +208,6 @@ const createBuilderOutputMock = (
};
};

const getBuildTarget = (): BuildTarget => ({
name: `${PROJECT}:build:production`,
const getBuildTarget = (customConf: string = 'production'): BuildTarget => ({
name: `${PROJECT}:build:${customConf}`,
});
26 changes: 7 additions & 19 deletions src/deploy/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,22 @@ export default async function deploy(
throw new Error('Cannot execute the build target');
}

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

context.logger.info(
`📦 Building "${context.target.project}". ${
configuration ? `Configuration "${configuration}"` : ''
}`
const build = await context.scheduleTarget(
targetFromTargetString(buildTarget.name)
);

const target = {
target: 'build',
project: context.target.project,
} as Target;

// Set the configuration if set on the options
if (configuration) {
target.configuration = configuration;
}

const build = await context.scheduleTarget(target);
const buildResult = await build.result;

if (!buildResult.success) {
throw new Error(buildResult.error);
}
}

const targetFromStr = targetFromTargetString(buildTarget.name);
const buildOptions = await context.getTargetOptions(targetFromStr);
const buildOptions = await context.getTargetOptions(
targetFromTargetString(buildTarget.name)
);

const outputPath = await getOutPutPath(
context.workspaceRoot,
Expand Down
4 changes: 1 addition & 3 deletions src/deploy/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export default createBuilder(
throw new Error('Cannot deploy the application without a target');
}

const configuration = options.configuration
? `:${options.configuration}`
: '';
const configuration = options.buildTarget ? `:${options.buildTarget}` : '';
const buildTarget = {
name: `${context.target.project}:build${configuration}`,
};
Expand Down
7 changes: 3 additions & 4 deletions src/deploy/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
"title": "schema",
"description": "Publish your angular packages to npm by just run `ng deploy`",
"properties": {
"configuration": {
"buildTarget": {
"type": "string",
"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`.",
"alias": "c"
"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`."
},
"noBuild": {
"type": "boolean",
"default": false,
"description": "This is a proposal from RFC #1. --- Skip build process during deployment."
"description": "Skip build process during deployment."
},
"packageVersion": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion src/ng-add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('ng-add', () => {
};
originalWorkspaceDefinition.projects.publishable.architect!.build.configurations = productionConfig;
expectedWorkspaceDefinition.projects.publishable.architect!.build.configurations = productionConfig;
expectedWorkspaceDefinition.projects.publishable.architect!.deploy.options!.configuration =
expectedWorkspaceDefinition.projects.publishable.architect!.deploy.options!.buildTarget =
'production';
tree.create('angular.json', JSON.stringify(originalWorkspaceDefinition));

Expand Down
4 changes: 2 additions & 2 deletions src/ng-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ function getLibraries({ projects }: Workspace): WorkspaceProject[] {
*/
function setUpProductionModeIfHasIt(
lib: WorkspaceProject
): Pick<Schema, 'configuration'> {
): Pick<Schema, 'buildTarget'> {
return lib.architect?.build?.configurations?.production
? {
configuration: 'production',
buildTarget: 'production',
}
: {};
}