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

Commit

Permalink
Merge 2a6a34a into ef9411a
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Nov 28, 2018
2 parents ef9411a + 2a6a34a commit d73c1fa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 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 @@ -5,6 +5,7 @@ const fs = require('fs-extra');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');
const { createSandbox } = require('sinon');
const Generator = require("../generators/app");

const sandbox = createSandbox();

Expand Down Expand Up @@ -295,3 +296,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 @@ -73,6 +73,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 @@ -226,3 +233,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` 生成的包。
16 changes: 12 additions & 4 deletions generators/app/templates/library/package-sample.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "<%= scope %>/<%= packageName %>",
"version": "0.0.0",
"main": "public_api.ts",
"main": "dist/bundles/<%= flattenModuleId %>.umd.js",
"types": "public_api.ts",
"repository": "https://git.easyops.local/anyclouds/<%= repository %>",
"license": "UNLICENSED",
"files": ["dist"],
"files": ["dist/"],
"scripts": {
"start": "ng-packagr -w -p package.json",
"prebuild": "rimraf dist",
"build": "ng-packagr -p package.json",
"build": "ng-packagr -p package.json && rimraf dist/package.json",
"prepublishOnly": "npm run build",
"postprebulishOnly": "cd dist"
},
Expand All @@ -21,5 +21,13 @@
"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"
}

0 comments on commit d73c1fa

Please sign in to comment.