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

Commit

Permalink
Merge 11ede66 into 8cba59e
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Dec 14, 2018
2 parents 8cba59e + 11ede66 commit f7ab661
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 74 deletions.
28 changes: 9 additions & 19 deletions __tests__/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ describe('generator-console-package:app:@easyops', () => {
);
});

it('should run `yarn link`', () => {
expect(mockSpawn.calledOnceWithExactly('yarn', ['link'], {
cwd: `packages/${packageName}/dist`
})).toBe(true);
it('should run `lerna exec yarn link`', () => {
expect(mockSpawn.calledOnceWithExactly('lerna', ['exec', 'yarn', 'link', `--scope=@easyops/${packageName}`])).toBe(true);

expect(mockSpawn.callCount).toBe(1);
});
Expand Down Expand Up @@ -252,10 +250,8 @@ describe('generator-console-package:app:@brick', () => {
);
});

it('should run `yarn link`', () => {
expect(mockSpawn.calledOnceWithExactly('yarn', ['link'], {
cwd: `@brick/${packageName}/dist`
})).toBe(true);
it('should run `lerna exec yarn link`', () => {
expect(mockSpawn.calledOnceWithExactly('lerna', ['exec', 'yarn', 'link', `--scope=@brick/${packageName}`])).toBe(true);

expect(mockSpawn.callCount).toBe(1);
});
Expand Down Expand Up @@ -377,10 +373,8 @@ describe('generator-console-package:app:@plugin-common', () => {
);
});

it('should run `yarn link`', () => {
expect(mockSpawn.calledOnceWithExactly('yarn', ['link'], {
cwd: `@plugin-common/${packageName}/dist`
})).toBe(true);
it('should run `lerna exec yarn link`', () => {
expect(mockSpawn.calledOnceWithExactly('lerna', ['exec', 'yarn', 'link', `--scope=@plugin-common/${packageName}`])).toBe(true);

expect(mockSpawn.callCount).toBe(1);
});
Expand Down Expand Up @@ -474,14 +468,10 @@ describe('generator-console-package:app:@console-plugin', () => {
);
});

it('should run `yarn link` and `yarn`', () => {
expect(mockSpawn.calledWithExactly('yarn', ['link'], {
cwd: `packages/${packageName}`
})).toBe(true);
it('should run `lerna exec yarn link` and `yarn`', () => {
expect(mockSpawn.calledWithExactly('lerna', ['exec', 'yarn', 'link', `--scope=@console-plugin/${packageName}`])).toBe(true);

expect(mockSpawn.calledWithExactly('yarn', [], {
cwd: `packages/${packageName}`
})).toBe(true);
expect(mockSpawn.calledWithExactly('yarn', [], { cwd: `packages/${packageName}` })).toBe(true);

expect(mockSpawn.callCount).toBe(2);
});
Expand Down
58 changes: 14 additions & 44 deletions generators/app/index.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,12 @@
const fs = require('fs');
const Generator = require('yeoman-generator');
const yosay = require('yosay');
const scopesJson = require('./scopes.json');
const pkg = require('../../package.json');

const scopePropsMap = new Map();
scopePropsMap.set('@easyops', {
repository: 'Console-W',
subPackagePath: 'packages',
removeScriptsStart: false,
tsconfigPath: true,
isLibrary: true,
needPluginsConfig: false
});
scopePropsMap.set('@brick', {
repository: 'console-plugins',
subPackagePath: '@brick',
removeScriptsStart: true,
tsconfigPath: false,
isLibrary: true,
needPluginsConfig: false,
projectNamePrefix: 'brick-',
moduleNamePrefix: 'Brick'
});
scopePropsMap.set('@plugin-common', {
repository: 'console-plugins',
subPackagePath: '@plugin-common',
removeScriptsStart: false,
tsconfigPath: false,
isLibrary: true,
needPluginsConfig: false
});
scopePropsMap.set('@console-plugin', {
repository: 'console-plugins',
subPackagePath: 'packages',
removeScriptsStart: false,
tsconfigPath: false,
isLibrary: false,
needPluginsConfig: true
});
const scopePropsMap = new Map(Object.entries(scopesJson));
const scopes = Array.from(scopePropsMap.keys());
const generatorVersion = pkg.version;

module.exports = class extends Generator {
initializing() {
Expand Down Expand Up @@ -152,7 +121,6 @@ module.exports = class extends Generator {
};

tplPairs = {
'dist/package-for-yarn-link.json': 'dist/package.json',
'package.json.ejs': 'package.json',
'README.md': 'README.md',
'src/index.module.ts': 'src/index.module.ts',
Expand Down Expand Up @@ -187,7 +155,10 @@ module.exports = class extends Generator {
});

Object.entries(tplPairs).forEach(([from, to]) => {
this.fs.copyTpl(`${srcPath}/${from}`, `${destPath}/${to}`, this.props);
this.fs.copyTpl(`${srcPath}/${from}`, `${destPath}/${to}`, {
...this.props,
generatorVersion
});
});

if (tsconfigPath) {
Expand Down Expand Up @@ -239,17 +210,16 @@ module.exports = class extends Generator {

install() {
const done = this.async();
const { subPackagePath, packageName, isLibrary } = this.props;
let distPath = `${subPackagePath}/${packageName}`;
if (isLibrary) {
distPath += '/dist';
}
const childOfYarnLink = this.spawnCommand('yarn', ['link'], { cwd: distPath });
const { subPackagePath, scope, packageName, isLibrary } = this.props;
const distPath = `${subPackagePath}/${packageName}`;
const childOfYarnLink = this.spawnCommand('lerna', ['exec', 'yarn', 'link', `--scope=${scope}/${packageName}`]);
childOfYarnLink.on("close", () => {
if (isLibrary) {
done();
} else {
const childOfYarn = this.spawnCommand('yarn', [], { cwd: distPath });
const childOfYarn = this.spawnCommand('yarn', [], {
cwd: distPath
});
childOfYarn.on("close", () => {
done();
});
Expand Down
36 changes: 36 additions & 0 deletions generators/app/scopes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"@easyops": {
"repository": "Console-W",
"subPackagePath": "packages",
"removeScriptsStart": false,
"tsconfigPath": true,
"isLibrary": true,
"needPluginsConfig": false
},
"@brick": {
"repository": "console-plugins",
"subPackagePath": "@brick",
"removeScriptsStart": true,
"tsconfigPath": false,
"isLibrary": true,
"needPluginsConfig": false,
"projectNamePrefix": "brick-",
"moduleNamePrefix": "Brick"
},
"@plugin-common": {
"repository": "console-plugins",
"subPackagePath": "@plugin-common",
"removeScriptsStart": false,
"tsconfigPath": false,
"isLibrary": true,
"needPluginsConfig": false
},
"@console-plugin": {
"repository": "console-plugins",
"subPackagePath": "packages",
"removeScriptsStart": false,
"tsconfigPath": false,
"isLibrary": false,
"needPluginsConfig": true
}
}
10 changes: 5 additions & 5 deletions generators/app/templates/library/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# <%= scope %>/<%= packageName %>

Generated by [generator-console-package](https://github.com/easyops-cn/generator-console-package)
Generated by [generator-console-package](https://github.com/easyops-cn/generator-console-package) v<%= generatorVersion %>

## Develop

```
# 1. 开启监听构建
cd ~/<%= repository %>
lerna run start --scope=<%= scope %>/<%= packageName %> --stream
lerna run start --scope=<%= scope %>/<%= packageName %>
# 2. 创建 link
cd <%= subPackagePath %>/<%= packageName %>/dist
# 2. 创建 link(同一 git 仓库内不需 link)
cd <%= subPackagePath %>/<%= packageName %>
yarn link
# 3. 使用 link
Expand All @@ -21,5 +21,5 @@ yarn link <%= scope %>/<%= packageName %>
## publish

```
lerna publish
lerna version
```

This file was deleted.

4 changes: 2 additions & 2 deletions generators/app/templates/plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# <%= scope %>/<%= packageName %>

Generated by [generator-console-package](https://github.com/easyops-cn/generator-console-package)
Generated by [generator-console-package](https://github.com/easyops-cn/generator-console-package) v<%= generatorVersion %>

## Develop

Expand All @@ -21,5 +21,5 @@ yarn link <%= scope %>/<%= packageName %>
## publish

```
lerna publish
lerna version
```

0 comments on commit f7ab661

Please sign in to comment.