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

Commit

Permalink
Merge 5f0f0b4 into f548fa7
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Dec 3, 2018
2 parents f548fa7 + 5f0f0b4 commit 7e84857
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 66 deletions.
138 changes: 106 additions & 32 deletions __tests__/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,44 @@ describe('generator-console-package:app:@easyops', () => {
`packages/${packageName}/src/index.module.ts`,
`export class ${pascalCaseName}Module`
);
assert.fileContent(
assert.jsonFileContent(
`packages/${packageName}/package.json`,
`"name": "@easyops/${packageName}"`
{
name: `@easyops/${packageName}`
}
);
assert.fileContent(
assert.jsonFileContent(
`packages/${packageName}/package.json`,
'"start": "ng-packagr -w -p package.json"'
{
scripts: {
start: "ng-packagr -w -p package.json"
}
}
);
});

it('should update files', () => {
assert.fileContent(
assert.jsonFileContent(
'angular.json',
`"${packageName}": {\n "root": "packages/${packageName}/src"`
);
assert.fileContent(
{
projects: {
[packageName]: {
root: `packages/${packageName}/src`
}
}
}
);
assert.jsonFileContent(
'tsconfig.json',
`"@easyops/${packageName}": [\n "packages/${packageName}"\n ]`
{
compilerOptions: {
paths: {
[`@easyops/${packageName}`]: [
`packages/${packageName}/public_api.ts`
]
}
}
}
);
});

Expand Down Expand Up @@ -191,26 +211,44 @@ describe('generator-console-package:app:@brick', () => {
);
assert.fileContent(
`@brick/${packageName}/src/index.module.ts`,
`export class ${pascalCaseName}Module`
`export class Brick${pascalCaseName}Module`
);
assert.fileContent(
assert.jsonFileContent(
`@brick/${packageName}/package.json`,
`"name": "@brick/${packageName}"`
{
name: `@brick/${packageName}`
}
);
assert.noFileContent(
assert.noJsonFileContent(
`@brick/${packageName}/package.json`,
'"start": "ng-packagr -w -p package.json"'
{
scripts: {
start: "ng-packagr -w -p package.json"
}
}
);
});

it('should update files', () => {
assert.fileContent(
assert.jsonFileContent(
'angular.json',
`"${packageName}": {\n "root": "@brick/${packageName}/src"`
);
assert.fileContent(
{
projects: {
[`brick-${packageName}`]: {
root: `@brick/${packageName}/src`
}
}
}
);
assert.jsonFileContent(
'tsconfig.json',
`"@brick/${packageName}": [\n "@brick/${packageName}"\n ]`
{
compilerOptions: {
paths: {
[`@brick/${packageName}`]: undefined
}
}
}
);
});

Expand Down Expand Up @@ -300,24 +338,42 @@ describe('generator-console-package:app:@plugin-common', () => {
`@plugin-common/${packageName}/src/index.module.ts`,
`export class ${pascalCaseName}Module`
);
assert.fileContent(
assert.jsonFileContent(
`@plugin-common/${packageName}/package.json`,
`"name": "@plugin-common/${packageName}"`
{
name: `@plugin-common/${packageName}`
}
);
assert.fileContent(
assert.jsonFileContent(
`@plugin-common/${packageName}/package.json`,
'"start": "ng-packagr -w -p package.json"'
{
scripts: {
start: "ng-packagr -w -p package.json"
}
}
);
});

it('should update files', () => {
assert.fileContent(
assert.jsonFileContent(
'angular.json',
`"${packageName}": {\n "root": "@plugin-common/${packageName}/src"`
);
assert.fileContent(
{
projects: {
[packageName]: {
root: `@plugin-common/${packageName}/src`
}
}
}
);
assert.jsonFileContent(
'tsconfig.json',
`"@plugin-common/${packageName}": [\n "@plugin-common/${packageName}"\n ]`
{
compilerOptions: {
paths: {
[`@plugin-common/${packageName}`]: undefined
}
}
}
);
});

Expand Down Expand Up @@ -386,16 +442,34 @@ describe('generator-console-package:app:@console-plugin', () => {
`packages/${packageName}/src/index.module.ts`,
`export class ${pascalCaseName}Module`
);
assert.fileContent(
assert.jsonFileContent(
`packages/${packageName}/package.json`,
`"name": "@console-plugin/${packageName}"`
{
name: `@console-plugin/${packageName}`
}
);
});

it('should update files', () => {
assert.fileContent(
assert.jsonFileContent(
'angular.json',
`"${packageName}": {\n "root": "packages/${packageName}/src"`
{
projects: {
[packageName]: {
root: `packages/${packageName}/src`
}
}
}
);
assert.jsonFileContent(
'tsconfig.json',
{
compilerOptions: {
paths: {
[`@console-plugin/${packageName}`]: undefined
}
}
}
);
});

Expand Down
48 changes: 28 additions & 20 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,32 @@ const scopePropsMap = new Map();
scopePropsMap.set('@easyops', {
repository: 'Console-W',
subPackagePath: 'packages',
removeScriptsStart: false
removeScriptsStart: false,
tsconfigPath: true,
isLibrary: true
});
scopePropsMap.set('@brick', {
repository: 'console-plugins',
subPackagePath: '@brick',
removeScriptsStart: true
removeScriptsStart: true,
tsconfigPath: false,
isLibrary: true,
projectNamePrefix: 'brick-',
moduleNamePrefix: 'Brick'
});
scopePropsMap.set('@plugin-common', {
repository: 'console-plugins',
subPackagePath: '@plugin-common',
removeScriptsStart: false
removeScriptsStart: false,
tsconfigPath: false,
isLibrary: true
});
scopePropsMap.set('@console-plugin', {
repository: 'console-plugins',
subPackagePath: 'packages',
removeScriptsStart: false
removeScriptsStart: false,
tsconfigPath: false,
isLibrary: false
});
const scopes = Array.from(scopePropsMap.keys());

Expand Down Expand Up @@ -79,7 +89,7 @@ module.exports = class extends Generator {
}
])
);
const { packageName } = this.props;
const { packageName, moduleNamePrefix, isLibrary } = 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
Expand All @@ -97,6 +107,7 @@ module.exports = class extends Generator {
name: 'moduleName',
message: "What's the name of your package's default module?",
default:
(moduleNamePrefix === undefined ? '' : moduleNamePrefix) +
packageName.replace(/^[a-z]|-[a-zA-Z0-9]/g, match =>
match.replace('-', '').toUpperCase()
) + 'Module'
Expand All @@ -105,7 +116,7 @@ module.exports = class extends Generator {
);

// component name
if (this._isLibrary()) {
if (isLibrary) {
Object.assign(
this.props,
await this.prompt([
Expand All @@ -124,14 +135,9 @@ module.exports = class extends Generator {
}
}

_isLibrary() {
return this.props.scope !== '@console-plugin';
}

writing() {
const { packageName, componentName, scope, subPackagePath } = this.props;
const { packageName, componentName, scope, subPackagePath, isLibrary, projectNamePrefix, tsconfigPath } = this.props;
const destPath = `${subPackagePath}/${packageName}`;
const isLibrary = this._isLibrary();
const srcPath = `${this.sourceRoot()}/${isLibrary ? 'library' : 'plugin'}`;

let srcPairs, tplPairs;
Expand Down Expand Up @@ -176,22 +182,23 @@ module.exports = class extends Generator {
this.fs.copyTpl(`${srcPath}/${from}`, `${destPath}/${to}`, this.props);
});

if (isLibrary) {
const tsconfigPath = 'tsconfig.json';
this.fs.copy(tsconfigPath, tsconfigPath, {
if (tsconfigPath) {
const tsconfigJson = 'tsconfig.json';
this.fs.copy(tsconfigJson, tsconfigJson, {
process: content => {
const tsconfig = JSON.parse(content);
tsconfig.compilerOptions.paths[`${scope}/${packageName}`] = [`${subPackagePath}/${packageName}`];
tsconfig.compilerOptions.paths[`${scope}/${packageName}`] = [`${subPackagePath}/${packageName}/public_api.ts`];
return JSON.stringify(tsconfig, null, ' ') + '\n';
}
});
}

const angularPath = 'angular.json';
const projectName = (projectNamePrefix === undefined ? '' : projectNamePrefix) + packageName;
this.fs.copy(angularPath, angularPath, {
process: content => {
const angular = JSON.parse(content);
angular.projects[packageName] = {
angular.projects[projectName] = {
"root": `${subPackagePath}/${packageName}/src`,
"projectType": "application",
"schematics": {
Expand Down Expand Up @@ -224,13 +231,14 @@ module.exports = class extends Generator {

install() {
const done = this.async();
let distPath = `${this.props.subPackagePath}/${this.props.packageName}`;
if (this._isLibrary()) {
const { subPackagePath, packageName, isLibrary } = this.props;
let distPath = `${subPackagePath}/${packageName}`;
if (isLibrary) {
distPath += '/dist';
}
const childOfYarnLink = this.spawnCommand('yarn', ['link'], { cwd: distPath });
childOfYarnLink.on("close", () => {
if (this._isLibrary()) {
if (isLibrary) {
done();
} else {
const childOfYarn = this.spawnCommand('yarn', [], { cwd: distPath });
Expand Down
2 changes: 1 addition & 1 deletion generators/app/templates/library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cd <%= subPackagePath %>/<%= packageName %>/dist
yarn link
# 3. 使用 link
cd ~/console-plugins/<%= subPackagePath %>/YOUR-PLUGIN
cd /PATH/TO/OTHER/PACKAGE
yarn link <%= scope %>/<%= packageName %>
```

Expand Down
6 changes: 5 additions & 1 deletion generators/app/templates/library/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
},
"ngPackage": {
"lib": {
"entryFile": "public_api.ts"
"entryFile": "public_api.ts",
"languageLevel": [
"dom",
"esnext"
]
}
},
"peerDependencies": {
Expand Down
24 changes: 12 additions & 12 deletions generators/app/templates/plugin/package-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@
"prepublishOnly": "npm test && npm run build"
},
"peerDependencies": {
"@angular/common": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/forms": "^6.0.3",
"@angular/platform-browser": "^6.0.3",
"@angular/router": "^6.0.3",
"@angular/common": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/platform-browser": "^6.1.0",
"@angular/router": "^6.1.0",
"@easyops/console-plugin-core": "^4.0.4",
"@easyops/console-vendors": "^7.0.0",
"@easyops/console-vendors": "^8.0.0",
"@uirouter/angular": "^2.0.0",
"@uirouter/core": "5.0.19",
"rxjs": "^6.0.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular/common": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/forms": "^6.0.3",
"@angular/platform-browser": "^6.0.3",
"@angular/router": "^6.0.3",
"@angular/common": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/platform-browser": "^6.1.0",
"@angular/router": "^6.1.0",
"@easyops/console-plugin-core": "^4.0.4",
"@easyops/console-vendors": "^7.0.0",
"@easyops/console-vendors": "^8.0.0",
"@uirouter/angular": "^2.0.0",
"@uirouter/core": "5.0.19",
"rxjs": "^6.0.0",
Expand Down

0 comments on commit 7e84857

Please sign in to comment.