ngx-deploy-npm
Advanced tools
Comparing version 1.3.3 to 1.4.1
@@ -44,6 +44,3 @@ "use strict"; | ||
const buildOptions = yield context.getTargetOptions(targetFromStr); | ||
if (!buildOptions.project || typeof buildOptions.project !== 'string') { | ||
throw new Error(`Cannot read the project path option of the Angular library '${buildTarget.name}' in angular.json`); | ||
} | ||
const outputPath = yield getOutPutPath(context.workspaceRoot, buildOptions.project); | ||
const outputPath = yield getOutPutPath(context.workspaceRoot, buildOptions, buildTarget.name); | ||
yield engine.run(outputPath, options, context.logger); | ||
@@ -53,22 +50,42 @@ }); | ||
exports.default = deploy; | ||
function getOutPutPath(projectRoot, relativeNgPackagePath) { | ||
function getOutPutPath(projectRoot, buildOptions, libName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const ngPackagePath = path.join(projectRoot, relativeNgPackagePath); | ||
let ngPackageContentStr; | ||
try { | ||
ngPackageContentStr = yield utils_1.readFileAsync(ngPackagePath, { | ||
encoding: 'utf8' | ||
}); | ||
if (buildOptions.outputPath) { | ||
return withOutputPath(); | ||
} | ||
catch (error) { | ||
throw new Error(`Error reading the ng-package.json`); | ||
else { | ||
return withoutOutputPath(); | ||
} | ||
const ngPackageContent = JSON.parse(ngPackageContentStr); | ||
if (!ngPackageContent.dest || typeof ngPackageContent.dest !== 'string') { | ||
throw new Error(`Cannot read the project 'dest' option of the ng-package.json`); | ||
function withOutputPath() { | ||
if (!buildOptions.outputPath || | ||
typeof buildOptions.outputPath !== 'string') { | ||
throw new Error(`Cannot read the project output path option of the library '${libName}' in the workspace`); | ||
} | ||
return path.join(projectRoot, buildOptions.outputPath); | ||
} | ||
const outputPath = path.join(path.dirname(ngPackagePath), ngPackageContent.dest); | ||
return outputPath; | ||
function withoutOutputPath() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!buildOptions.project || typeof buildOptions.project !== 'string') { | ||
throw new Error(`Cannot read the project path option of the library '${libName}' in the workspace`); | ||
} | ||
const ngPackagePath = path.join(projectRoot, buildOptions.project); | ||
let ngPackageContentStr; | ||
try { | ||
ngPackageContentStr = yield utils_1.readFileAsync(ngPackagePath, { | ||
encoding: 'utf8' | ||
}); | ||
} | ||
catch (error) { | ||
throw new Error(`Error reading the ng-package.json`); | ||
} | ||
const ngPackageContent = JSON.parse(ngPackageContentStr); | ||
if (!ngPackageContent.dest || typeof ngPackageContent.dest !== 'string') { | ||
throw new Error(`Cannot read the project 'dest' option of the ng-package.json`); | ||
} | ||
const outputPath = path.join(path.dirname(ngPackagePath), ngPackageContent.dest); | ||
return outputPath; | ||
}); | ||
} | ||
}); | ||
} | ||
//# sourceMappingURL=actions.js.map |
@@ -7,7 +7,7 @@ "use strict"; | ||
function getWorkspace(host) { | ||
const possibleFiles = ['/angular.json', '/.angular.json']; | ||
const possibleFiles = ['/angular.json', '/.angular.json', '/workspace.json']; | ||
const path = possibleFiles.filter(path => host.exists(path))[0]; | ||
const configBuffer = host.read(path); | ||
if (configBuffer === null) { | ||
throw new schematics_1.SchematicsException(`Could not find angular.json`); | ||
throw new schematics_1.SchematicsException(`Could not find workspace definition`); | ||
} | ||
@@ -20,3 +20,3 @@ const content = configBuffer.toString(); | ||
catch (e) { | ||
throw new schematics_1.SchematicsException(`Could not parse angular.json: ` + e.message); | ||
throw new schematics_1.SchematicsException(`Could not parse workspace definition: ` + e.message); | ||
} | ||
@@ -23,0 +23,0 @@ return { |
{ | ||
"name": "ngx-deploy-npm", | ||
"version": "1.3.3", | ||
"version": "1.4.1", | ||
"description": "Publish your angular packages to npm by just run `ng deploy`", | ||
@@ -14,2 +14,3 @@ "main": "index.js", | ||
"test": "jest", | ||
"test:cov": "jest --coverage", | ||
"test:debug": "node --inspect-brk=0.0.0.0 node_modules/.bin/jest --runInBand", | ||
@@ -16,0 +17,0 @@ "release": "standard-version" |
@@ -5,15 +5,22 @@ # ngx-deploy-npm π | ||
[![The MIT License][mit-licence-image]][mit-licence-url] | ||
[![Conventional Commits][conventional-commits-image]][conventional-commits-url] | ||
[![Discord Server][discord-image]][discord-url] | ||
[npm-url]: https://www.npmjs.com/package/ngx-deploy-npm | ||
<!-- 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-image]: https://img.shields.io/discord/748677963142135818?color=7289DA&label=%23ngx-deploy-npm&logo=discord&logoColor=white&style=flat-square | ||
[discord-url]: https://discord.gg/cPa78y6rXn | ||
[conventional-commits-url]: https://conventionalcommits.org | ||
### **Deploy your Angular Package to NPM directly from the Angular CLI! π** | ||
![Cover Image](docs/cover.png) | ||
## Publish any kind of library to NPM on an Angularπ °οΈ or Nxπ¬ Workspace | ||
--- | ||
@@ -23,3 +30,2 @@ | ||
- [β οΈ Prerequisites](#prerequisites) | ||
- [π Quick Start (local development)](#quick-start) | ||
@@ -45,19 +51,17 @@ - [π Continuous Delivery](#continuous-delivery) | ||
## β οΈ Prerequisites <a name="prerequisites"></a> | ||
> 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` | ||
This command has the following prerequisites: | ||
- Angular project created via [Angular CLI](https://github.com/angular/angular-cli) v8.3.0 or greater (execute `ng update @angular/cli @angular/core` to upgrade your project if necessary) | ||
## π Quick Start (local development) <a name="quick-start"></a> | ||
This quick start assumes that you already have an existing Angular project with a publishable package created and you already are logged in on npm using `npm login` | ||
This quick start assumes that you already have an existing Angular or a Nx workspace with a publishable | ||
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 | ||
```sh | ||
ng add ngx-deploy-npm | ||
``` | ||
| Angularπ °οΈ | Nxπ¬ | | ||
| :------------------------------------------- | :----------------------------------------------------- | | ||
| <pre lang="sh"> ng add ngx-deploy-npm </pre> | <pre lang="sh"> nx generate ngx-deploy-npm:init </pre> | | ||
2. Deploy your library to NPM with all default settings. Your library will be automatically built in production mode. | ||
2. Deploy your library to NPM with all default settings. | ||
@@ -68,3 +72,3 @@ ```sh | ||
3. Your library should be published on npm. So go and check npm.js | ||
3. Your library should be published on npm. So go and check `npmjs.com/YOUR-PACKAGE` | ||
@@ -83,4 +87,6 @@ ## π Continuous Delivery <a name="continuous-delivery"></a> | ||
2. **Indicate how to find the token** | ||
- Before publishing, we must indicate to npm how to find that token, do it by creating a step with `run: echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > YOUR_REPO_DIRECTORY/.npmrc` | ||
- Replace `YOUR_REPO_DIRECTORY` for the path of your project, commonly is `/home/circleci/repo` | ||
- Before publishing, we must indicate to npm how to find that token, | ||
do it by creating a step with `run: echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > YOUR_REPO_DIRECTORY/.npmrc` | ||
- Replace `YOUR_REPO_DIRECTORY` for the path of your project, | ||
commonly is `/home/circleci/repo` | ||
3. **(Optional) check that you are logged** | ||
@@ -90,7 +96,15 @@ - Creating a step with `run: npm whoami` | ||
4. **Deploy your package** | ||
- Create a step with `run: npx ng deploy YOUR_LIBRARY` | ||
- **NOTE:** You may want to execute a script that executes some pre-steps before publishing and inside that script execute `ng 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 | ||
- Create a step with: | ||
| 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 | ||
5. **Enjoy your just released package ππ¦** | ||
The job full example is | ||
The job full example is for an Angular project is | ||
@@ -108,3 +122,3 @@ ```yml | ||
- run: npm whoami | ||
- run: ngx ng deploy YOUR_PACKAGE | ||
- run: npx ng deploy YOUR_PACKAGE | ||
``` | ||
@@ -140,4 +154,2 @@ | ||
> **This is a proposal from [RFC #1](https://github.com/angular-schule/ngx-deploy-starter/issues/1).** | ||
#### --package-version | ||
@@ -189,3 +201,7 @@ | ||
To avoid all these command-line cmd options, you can write down your 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: | ||
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 | ||
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: | ||
@@ -220,3 +236,3 @@ - access | ||
And just run `ng deploy` π. | ||
And just run `ng deploy YOUR-LIBRARY` π. | ||
@@ -241,28 +257,4 @@ > βΉοΈ You can always use the [--dry-run](#dry-run) option to verify if your configuration is right. | ||
A publishable library is one that can be built. Here we detect that if the library in the `angular.json` has the architect **build**. | ||
For Nx workspace, only publishable libraries are going to be configured | ||
The `angular.json` look like | ||
```json | ||
{ | ||
"publishable-library": { | ||
"projectType": "library", | ||
"root": "libs/publishable-library", | ||
"sourceRoot": "libs/publishable-library/src", | ||
"prefix": "myworkspace", | ||
"architect": { | ||
"build": { | ||
"builder": "any-builder-of-your-preference", | ||
"options": { | ||
"tsConfig": "libs/publishable-library/tsconfig.lib.json", | ||
"project": "libs/publishable-library/ng-package.json" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
This takes a special context on a [NX](https://nx.dev) environment. | ||
## π Next milestones <a name="next-milestones"></a> | ||
@@ -269,0 +261,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50493
397
276