Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Commit

Permalink
Merge f67d2c0 into da03927
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Nov 30, 2018
2 parents da03927 + f67d2c0 commit dfd3d37
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
coverage
/.idea
12 changes: 12 additions & 0 deletions __tests__/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { EventEmitter } = require('events');
const fs = require('fs-extra');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');
const Generator = require("../generators/app");
const { createSandbox } = require('sinon');

const sandbox = createSandbox();
Expand Down Expand Up @@ -410,3 +411,14 @@ describe('generator-console-package:app:@console-plugin', () => {
expect(mockSpawn.callCount).toBe(2);
});
});

describe('flattenModuleId', () => {
const testcases = [
['foo', 'bar', 'foo-bar'],
[undefined, 'bar/qux', 'bar-qux'],
['foo', 'bar/qux', 'foo-bar-qux']
];
it.each(testcases)("flattenModuleId(%s, %s) should return %s", (scope, packageName, expected) => {
expect(Generator.flattenModuleId(scope, packageName)).toBe(expected);
})
});
15 changes: 15 additions & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ module.exports = class extends Generator {
);
const { packageName } = this.props;

// generate flat module id
// For design, @see https://github.com/ng-packagr/ng-packagr/blob/v4.4.1/docs/DESIGN.md#tools-and-implementation-details
// For implementation, @see https://github.com/ng-packagr/ng-packagr/blob/v4.4.1/src/lib/ng-package-format/entry-point.ts#L157
Object.assign(this.props, {
flattenModuleId: Generator.flattenModuleId(scope, packageName)
});

// module name
Object.assign(
this.props,
Expand Down Expand Up @@ -234,3 +241,11 @@ module.exports = class extends Generator {
});
}
};

Generator.flattenModuleId = function (scope, packageName) {
const separator = "-";
if (scope !== undefined) {
return [scope].concat(packageName.split("/")).join(separator);
}
return packageName.split("/").join(separator);
}
8 changes: 1 addition & 7 deletions generators/app/templates/library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ yarn link <%= scope %>/<%= packageName %>

## publish

`lerna publish` 暂时无法用来发布 Angular Package, 你可以使用以下方式进行发布:

```
lerna publish --scope=<%= scope %>/<%= packageName %> --skip-npm
lerna run build --scope=<%= scope %>/<%= packageName %>
lerna exec --scope=<%= scope %>/<%= packageName %> npm publish ./dist -- --registry=https://registry.npm.easyops.local
lerna publish
```

注意,与`lerna publish` 不同,`npm publish` 是直接把当前目录发布到注册表中,因此需要先调用`lerna publish`的能力进行版本确定,但是跳过 npm 发布阶段,然后再单独执行`npm publish ./dist`发布 `ng-packagr` 生成的包。
21 changes: 14 additions & 7 deletions generators/app/templates/library/package.json.ejs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
{
"name": "<%= scope %>/<%= packageName %>",
"version": "0.0.0",
"main": "public_api.ts",
"types": "public_api.ts",
"main": "dist/bundles/<%= flattenModuleId %>.umd.js",
"repository": "https://git.easyops.local/anyclouds/<%= repository %>",
"license": "UNLICENSED",
"files": ["dist"],
"files": ["dist/"],
"scripts": {
<% if (!removeScriptsStart) { %>
"start": "ng-packagr -w -p package.json",
<% } %>
"prebuild": "rimraf dist",
"build": "ng-packagr -p package.json",
"prepublishOnly": "npm run build",
"postprebulishOnly": "cd dist"
"build": "ng-packagr -p package.json && rimraf dist/package.json",
"prepublishOnly": "npm run build"
},
"ngPackage": {
"lib": {
Expand All @@ -23,5 +21,14 @@
"peerDependencies": {
"@angular/common": "^6.0.3",
"@angular/core": "^6.0.3"
}
},
"module": "dist/fesm5/<%= flattenModuleId %>.js",
"es2015": "dist/fesm2015/<%= flattenModuleId %>.js",
"esm5": "dist/esm5/<%= flattenModuleId %>.js",
"esm2015": "dist/esm2015/<%= flattenModuleId %>.js",
"fesm5": "dist/fesm5/<%= flattenModuleId %>.js",
"fesm2015": "dist/fesm2015/<%= flattenModuleId %>.js",
"typings": "dist/<%= flattenModuleId %>.d.ts",
"metadata": "dist/<%= flattenModuleId %>.metadata.json",
"sideEffects": false
}

0 comments on commit dfd3d37

Please sign in to comment.