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

Commit

Permalink
feat: use lerna version now
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Dec 14, 2018
1 parent a6dbaa2 commit 11ede66
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 39 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
21 changes: 12 additions & 9 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ 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(Object.entries(scopesJson));
const scopes = Array.from(scopePropsMap.keys());
const generatorVersion = pkg.version;

module.exports = class extends Generator {
initializing() {
Expand Down Expand Up @@ -119,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 @@ -154,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 @@ -206,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
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 11ede66

Please sign in to comment.