diff --git a/README.md b/README.md index ee27dc6f..851063bb 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,14 @@ [![Discord Server][discord-image]][discord-url] + [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 + [npm-url]: https://www.npmjs.com/package/ngx-deploy-npm [mit-licence-url]: http://opensource.org/licenses/MIT [discord-url]: https://discord.gg/cPa78y6rXn @@ -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) @@ -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) @@ -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🐬 | | :------------------------------------------- | :----------------------------------------------------- | |
 ng add ngx-deploy-npm 
|
 nx generate ngx-deploy-npm:init 
| @@ -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🐬 | | :-------------------------------------------- | :-------------------------------------------- | |
 ng deploy your-library 
|
 nx deploy your-library 
| - **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 @@ -120,20 +126,21 @@ jobs: ## 📦 Options -#### --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: @@ -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 @@ -191,13 +198,13 @@ For testing: Run through without making any changes. Execute with --dry-run and ## 📁 Configuration File 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 @@ -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. diff --git a/src/LICENSE b/src/LICENSE index 6133c5ce..a45a55b4 100644 --- a/src/LICENSE +++ b/src/LICENSE @@ -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 diff --git a/src/deploy/actions.spec.ts b/src/deploy/actions.spec.ts index b57d77a0..e9f1f23a 100644 --- a/src/deploy/actions.spec.ts +++ b/src/deploy/actions.spec.ts @@ -59,6 +59,7 @@ describe('Deploy Angular apps', () => { await deploy(mockEngine, context, getBuildTarget(), {}); expect(spy).toHaveBeenCalledWith({ + configuration: 'production', target: 'build', project: PROJECT, }); @@ -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({ @@ -207,6 +208,6 @@ const createBuilderOutputMock = ( }; }; -const getBuildTarget = (): BuildTarget => ({ - name: `${PROJECT}:build:production`, +const getBuildTarget = (customConf: string = 'production'): BuildTarget => ({ + name: `${PROJECT}:build:${customConf}`, }); diff --git a/src/deploy/actions.ts b/src/deploy/actions.ts index f22453c4..21877694 100644 --- a/src/deploy/actions.ts +++ b/src/deploy/actions.ts @@ -30,25 +30,12 @@ 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) { @@ -56,8 +43,9 @@ export default async function deploy( } } - 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, diff --git a/src/deploy/builder.ts b/src/deploy/builder.ts index f792a592..18b4799b 100644 --- a/src/deploy/builder.ts +++ b/src/deploy/builder.ts @@ -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}`, }; diff --git a/src/deploy/schema.json b/src/deploy/schema.json index a91cb512..078f534b 100644 --- a/src/deploy/schema.json +++ b/src/deploy/schema.json @@ -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", diff --git a/src/ng-add.spec.ts b/src/ng-add.spec.ts index 3a29dd74..6f6e04f2 100644 --- a/src/ng-add.spec.ts +++ b/src/ng-add.spec.ts @@ -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)); diff --git a/src/ng-add.ts b/src/ng-add.ts index 1a6f3fbd..d0f1a0f3 100644 --- a/src/ng-add.ts +++ b/src/ng-add.ts @@ -85,10 +85,10 @@ function getLibraries({ projects }: Workspace): WorkspaceProject[] { */ function setUpProductionModeIfHasIt( lib: WorkspaceProject -): Pick { +): Pick { return lib.architect?.build?.configurations?.production ? { - configuration: 'production', + buildTarget: 'production', } : {}; }