ngx-deploy-npm
Advanced tools
Comparing version 1.0.5 to 1.1.0
@@ -6,2 +6,3 @@ "use strict"; | ||
const defaults_1 = require("./engine/defaults"); | ||
const publishableLibBuilder = '@angular-devkit/build-ng-packagr:build'; | ||
function getWorkspace(host) { | ||
@@ -27,3 +28,3 @@ const possibleFiles = ['/angular.json', '/.angular.json']; | ||
} | ||
exports.ngAdd = ({ project: DeployOptions }) => (tree, options) => { | ||
exports.ngAdd = () => (tree) => { | ||
const { path: workspacePath, workspace } = getWorkspace(tree); | ||
@@ -48,6 +49,9 @@ const libraries = getLibraries(workspace); | ||
function getLibraries({ projects }) { | ||
return Object.keys(projects) | ||
return (Object.keys(projects) | ||
.map(projectKey => projects[projectKey]) | ||
.filter(proj => proj.projectType === 'library'); | ||
.filter(proj => proj.projectType === 'library' && | ||
proj.architect && | ||
proj.architect.build && | ||
proj.architect.build.builder === publishableLibBuilder)); | ||
} | ||
//# sourceMappingURL=ng-add.js.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const schematics_1 = require("@angular-devkit/schematics"); | ||
const ng_add_1 = require("./ng-add"); | ||
const LIBRARY_NAME = 'pie-ka-chu'; | ||
const LIBRARY_ROOT = 'pirojok'; | ||
const OTHER_LIBRARY_NAME = 'pi-catch-you'; | ||
describe('ng-add', () => { | ||
let originalAngularJSON; | ||
let expectedAngularJSON; | ||
beforeEach(() => { | ||
originalAngularJSON = { | ||
version: 1, | ||
projects: { | ||
testing: { | ||
projectType: 'application', | ||
schematics: { | ||
'@nrwl/angular:component': { | ||
style: 'scss' | ||
} | ||
}, | ||
root: 'apps/testing', | ||
sourceRoot: 'apps/testing/src', | ||
prefix: 'myworkspace', | ||
architect: { | ||
build: { | ||
a: 'a', | ||
b: 'b' | ||
} | ||
} | ||
}, | ||
publishable: { | ||
projectType: 'library', | ||
root: 'libs/publishable', | ||
sourceRoot: 'libs/publishable/src', | ||
prefix: 'myworkspace', | ||
architect: { | ||
build: { | ||
builder: '@angular-devkit/build-ng-packagr:build', | ||
a: 'a', | ||
b: 'b' | ||
} | ||
}, | ||
schematics: {} | ||
}, | ||
publishable2: { | ||
projectType: 'library', | ||
root: 'libs/publishable', | ||
sourceRoot: 'libs/publishable/src', | ||
prefix: 'myworkspace', | ||
architect: { | ||
build: { | ||
builder: '@angular-devkit/build-ng-packagr:build', | ||
a: 'a', | ||
b: 'b' | ||
} | ||
}, | ||
schematics: {} | ||
}, | ||
'non-publishable': { | ||
projectType: 'library', | ||
root: 'libs/non-publishable', | ||
sourceRoot: 'libs/non-publishable/src', | ||
prefix: 'myworkspace', | ||
architect: { | ||
lint: { | ||
a: 'a', | ||
b: 'b' | ||
} | ||
}, | ||
schematics: {} | ||
}, | ||
'non-publishable2': { | ||
projectType: 'library', | ||
root: 'libs/non-publishable', | ||
sourceRoot: 'libs/non-publishable/src', | ||
prefix: 'myworkspace', | ||
architect: { | ||
lint: { | ||
a: 'a', | ||
b: 'b' | ||
} | ||
}, | ||
schematics: {} | ||
} | ||
}, | ||
defaultProject: 'testing' | ||
}; | ||
expectedAngularJSON = JSON.parse(JSON.stringify(originalAngularJSON)); | ||
['publishable', 'publishable2'] | ||
.map(publishableProjectKey => expectedAngularJSON.projects[publishableProjectKey]) | ||
.forEach(project => { | ||
if (project.architect) { | ||
project.architect.deploy = { | ||
builder: 'ngx-deploy-npm:deploy', | ||
options: { | ||
access: 'public' | ||
} | ||
}; | ||
} | ||
}); | ||
}); | ||
describe('generating files', () => { | ||
@@ -21,182 +104,34 @@ let tree; | ||
tree = schematics_1.Tree.empty(); | ||
tree.create('angular.json', JSON.stringify(generateAngularJson())); | ||
tree.create('angular.json', JSON.stringify(originalAngularJSON)); | ||
}); | ||
xit('generates new files if starting from scratch', () => __awaiter(this, void 0, void 0, function* () { | ||
const result = ng_add_1.ngAdd({ | ||
project: LIBRARY_NAME | ||
})(tree, {}); | ||
expect(result.read('angular.json').toString()).toEqual(initialAngularJson); | ||
})); | ||
xit('overrides existing files', () => __awaiter(this, void 0, void 0, function* () { | ||
const tempTree = ng_add_1.ngAdd({ | ||
project: LIBRARY_NAME | ||
})(tree, {}); | ||
const result = ng_add_1.ngAdd({ | ||
project: OTHER_LIBRARY_NAME | ||
})(tempTree, {}); | ||
expect(result.read('angular.json').toString()).toEqual(projectAngularJson); | ||
})); | ||
it('should set the deployer only on publishable libraries', () => { | ||
const result = ng_add_1.ngAdd()(tree); | ||
const angularJsonModified = JSON.parse(result.read('angular.json').toString()); | ||
expect(angularJsonModified).toEqual(expectedAngularJSON); | ||
}); | ||
}); | ||
describe('error handling', () => { | ||
it('Should throw if angular.json not found', () => __awaiter(this, void 0, void 0, function* () { | ||
expect(() => ng_add_1.ngAdd({ | ||
project: LIBRARY_NAME | ||
})(schematics_1.Tree.empty(), {})).toThrowError(/Could not find angular.json/); | ||
})); | ||
it('Should throw if angular.json can not be parsed', () => __awaiter(this, void 0, void 0, function* () { | ||
it('Should throw if angular.json not found', () => { | ||
expect(() => ng_add_1.ngAdd()(schematics_1.Tree.empty())).toThrowError('Could not find angular.json'); | ||
}); | ||
it('Should throw if angular.json can not be parsed', () => { | ||
const tree = schematics_1.Tree.empty(); | ||
tree.create('angular.json', 'hi'); | ||
expect(() => ng_add_1.ngAdd({ | ||
project: LIBRARY_NAME | ||
})(tree, {})).toThrowError(/Could not parse angular.json/); | ||
})); | ||
xit('Should throw if specified library does not exist ', () => __awaiter(this, void 0, void 0, function* () { | ||
const tree = schematics_1.Tree.empty(); | ||
tree.create('angular.json', JSON.stringify({ projects: {} })); | ||
expect(() => ng_add_1.ngAdd({ | ||
project: LIBRARY_NAME | ||
})(tree, {})).toThrowError(/No Angular project selected and no default project in the workspace/); | ||
})); | ||
xit('Should throw if specified project is not library', () => __awaiter(this, void 0, void 0, function* () { | ||
const tree = schematics_1.Tree.empty(); | ||
tree.create('angular.json', JSON.stringify({ | ||
projects: { [LIBRARY_NAME]: { projectType: 'pokemon' } } | ||
})); | ||
expect(() => ng_add_1.ngAdd({ | ||
project: LIBRARY_NAME | ||
})(tree, {})).toThrowError(/No Angular project selected and no default project in the workspace/); | ||
})); | ||
xit('Should throw if app does not have architect configured', () => __awaiter(this, void 0, void 0, function* () { | ||
const tree = schematics_1.Tree.empty(); | ||
tree.create('angular.json', JSON.stringify({ | ||
projects: { [LIBRARY_NAME]: { projectType: 'application' } } | ||
})); | ||
expect(() => ng_add_1.ngAdd({ | ||
project: LIBRARY_NAME | ||
})(tree, {})).toThrowError(/No Angular project selected and no default project in the workspace/); | ||
})); | ||
expect(() => ng_add_1.ngAdd()(tree)).toThrowError('Could not parse angular.json'); | ||
}); | ||
it('Should throw if angular.json can not be parsed', () => { | ||
expect(() => ng_add_1.ngAdd()(schematics_1.Tree.empty())).toThrowError('Could not find angular.json'); | ||
}); | ||
it('should throw if there is no library to add the deployer', () => { | ||
Object.keys(originalAngularJSON.projects) | ||
.filter(projectKey => originalAngularJSON.projects[projectKey].projectType === 'library') | ||
.forEach(libraryKey => { | ||
delete originalAngularJSON.projects[libraryKey]; | ||
}); | ||
const treeWithoutLibs = schematics_1.Tree.empty(); | ||
treeWithoutLibs.create('angular.json', JSON.stringify(originalAngularJSON)); | ||
expect(() => ng_add_1.ngAdd()(treeWithoutLibs)).toThrowError('There is no libraries to add this deployer'); | ||
}); | ||
}); | ||
}); | ||
function generateAngularJson() { | ||
return { | ||
defaultProject: LIBRARY_NAME, | ||
projects: { | ||
[LIBRARY_NAME]: { | ||
projectType: 'application', | ||
root: LIBRARY_ROOT, | ||
architect: { | ||
build: { | ||
options: { | ||
outputPath: 'dist/ikachu' | ||
} | ||
} | ||
} | ||
}, | ||
[OTHER_LIBRARY_NAME]: { | ||
projectType: 'application', | ||
root: LIBRARY_ROOT, | ||
architect: { | ||
build: { | ||
options: { | ||
outputPath: 'dist/ikachu' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
const initialAngularJson = `{ | ||
\"defaultProject\": \"pie-ka-chu\", | ||
\"projects\": { | ||
\"pie-ka-chu\": { | ||
\"projectType\": \"application\", | ||
\"root\": \"pirojok\", | ||
\"architect\": { | ||
\"build\": { | ||
\"options\": { | ||
\"outputPath\": \"dist/ikachu\" | ||
} | ||
}, | ||
\"deploy\": { | ||
\"builder\": \"ngx-deploy-npm:deploy\", | ||
\"options\": {} | ||
} | ||
} | ||
}, | ||
\"pi-catch-you\": { | ||
\"projectType\": \"application\", | ||
\"root\": \"pirojok\", | ||
\"architect\": { | ||
\"build\": { | ||
\"options\": { | ||
\"outputPath\": \"dist/ikachu\" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}`; | ||
const overwriteAngularJson = `{ | ||
\"defaultProject\": \"pie-ka-chu\", | ||
\"projects\": { | ||
\"pie-ka-chu\": { | ||
\"projectType\": \"application\", | ||
\"root\": \"pirojok\", | ||
\"architect\": { | ||
\"build\": { | ||
\"options\": { | ||
\"outputPath\": \"dist/ikachu\" | ||
} | ||
}, | ||
\"deploy\": { | ||
\"builder\": \"ngx-deploy-npm:deploy\", | ||
\"options\": {} | ||
} | ||
} | ||
}, | ||
\"pi-catch-you\": { | ||
\"projectType\": \"application\", | ||
\"root\": \"pirojok\", | ||
\"architect\": { | ||
\"build\": { | ||
\"options\": { | ||
\"outputPath\": \"dist/ikachu\" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}`; | ||
const projectAngularJson = `{ | ||
\"defaultProject\": \"pie-ka-chu\", | ||
\"projects\": { | ||
\"pie-ka-chu\": { | ||
\"projectType\": \"application\", | ||
\"root\": \"pirojok\", | ||
\"architect\": { | ||
\"build\": { | ||
\"options\": { | ||
\"outputPath\": \"dist/ikachu\" | ||
} | ||
}, | ||
\"deploy\": { | ||
\"builder\": \"ngx-deploy-npm:deploy\", | ||
\"options\": {} | ||
} | ||
} | ||
}, | ||
\"pi-catch-you\": { | ||
\"projectType\": \"application\", | ||
\"root\": \"pirojok\", | ||
\"architect\": { | ||
\"build\": { | ||
\"options\": { | ||
\"outputPath\": \"dist/ikachu\" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}`; | ||
//# sourceMappingURL=ng-add.spec.js.map |
{ | ||
"name": "ngx-deploy-npm", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"description": "Publish your angular packages to npm by just run `npm deploy your-packages`", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -42,3 +42,3 @@ # ngx-deploy-npm π | ||
1. Add `ngx-deploy-npm` to your project. It will configure all your libraries present in the project | ||
1. Add `ngx-deploy-npm` to your project. It will configure all your publishable libraries present in the project | ||
@@ -184,6 +184,10 @@ ```sh | ||
### Readme and Licence | ||
### README, LICENCE and CHANGELOG | ||
The licence and the readme must be in the root of the library. They are being copied at the moment of deployment | ||
Those files must be in the root of the library. They are being copied by the builder at the moment of deployment. | ||
If you have those files outside the project's root, you can create a symbolic link to solve that problem. | ||
> See [symbolic links on git](https://www.mokacoding.com/blog/symliks-in-git/) to know how to create them properly. | ||
### Version bumping | ||
@@ -193,2 +197,30 @@ | ||
### Only publishable libraries are being configured | ||
A publishable library is one that can be built. Here we detect that if the library in the `angular.json` has the architect **build** with the builder `@angular-devkit/build-ng-packagr:build`. | ||
The `angular.json` look like | ||
```json | ||
{ | ||
"publishable-library": { | ||
"projectType": "library", | ||
"root": "libs/publishable-library", | ||
"sourceRoot": "libs/publishable-library/src", | ||
"prefix": "myworkspace", | ||
"architect": { | ||
"build": { | ||
"builder": "@angular-devkit/build-ng-packagr:build", | ||
"options": { | ||
"tsConfig": "libs/publishable-library/tsconfig.lib.json", | ||
"project": "libs/publishable-library/ng-package.json" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
This take special context in [NX](https://nx.dev) environment. | ||
**You must take care about the version by yourself. Maybe using a script that sets the version** | ||
@@ -205,7 +237,4 @@ | ||
- Specify which library add the deployer on the `ng add` | ||
- Compatibility with [Nx](https://nx.dev) | ||
- Continuous Delivery Documentation | ||
- Add all the RFC proposals of [ngx-deploy-starter](https://github.com/angular-schule/ngx-deploy-starter) | ||
- ChangeLog Compatibility | ||
- Custom Readme and Licence Paths | ||
- Custom README, LICENCE and CHANGELOG paths | ||
@@ -212,0 +241,0 @@ Your feature that's not on the list 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
249
79715
671