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

Commit

Permalink
Merge cf63962 into a39c258
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Feb 28, 2019
2 parents a39c258 + cf63962 commit fad9bf6
Show file tree
Hide file tree
Showing 24 changed files with 235 additions and 86 deletions.
29 changes: 17 additions & 12 deletions __tests__/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,15 @@ describe('generator-console-package:app:@brick', () => {
`@brick/${packageName}/src/components/${packageName}.component.spec.ts`,
`@brick/${packageName}/src/components/${packageName}.component.ts`,
`@brick/${packageName}/src/index.module.ts`,
`@brick/${packageName}/src/main.ts`,
`@brick/${packageName}/package.json`,
`@brick/${packageName}/public_api.ts`,
`@brick/${packageName}/README.md`,
`@brick/${packageName}/tsconfig.json`,
`@brick/${packageName}/.pkgbuild/PKGBUILD`,
`@brick/${packageName}/deploy/install_postscript.sh`,
`@brick/${packageName}/deploy/package.conf.yaml`,
`@brick/${packageName}/deploy/update_postscript.sh`,
`@brick/${packageName}/deploy/update_prescript.sh`,

// Modified files:
'angular.json',
Expand Down Expand Up @@ -212,20 +218,16 @@ describe('generator-console-package:app:@brick', () => {
`@brick/${packageName}/src/index.module.ts`,
`export class Brick${pascalCaseName}Module`
);
assert.fileContent(
`@brick/${packageName}/src/main.ts`,
`platformBrick("@brick/${packageName}")`
);
assert.jsonFileContent(
`@brick/${packageName}/package.json`,
{
name: `@brick/${packageName}`
}
);
assert.noJsonFileContent(
`@brick/${packageName}/package.json`,
{
scripts: {
start: "WATCH_MODE=true node ../../ng-packagr"
}
}
);
});

it('should update files', () => {
Expand Down Expand Up @@ -424,6 +426,7 @@ describe('generator-console-package:app:@console-plugin', () => {
`packages/${packageName}/src/pages/index/index.component.ts`,
`packages/${packageName}/src/index.module.ts`,
`packages/${packageName}/src/index.states.ts`,
`packages/${packageName}/src/main.ts`,
`packages/${packageName}/package.json`,
`packages/${packageName}/plugins-default.json`,
`packages/${packageName}/README.md`,
Expand All @@ -444,6 +447,10 @@ describe('generator-console-package:app:@console-plugin', () => {
`packages/${packageName}/src/index.module.ts`,
`export class ${pascalCaseName}Module`
);
assert.fileContent(
`packages/${packageName}/src/main.ts`,
`platformExtension("@console-plugin/${packageName}")`
);
assert.jsonFileContent(
`packages/${packageName}/package.json`,
{
Expand Down Expand Up @@ -486,9 +493,7 @@ describe('generator-console-package:app:@console-plugin', () => {
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.callCount).toBe(2);
expect(mockSpawn.callCount).toBe(1);
});
});

Expand Down
66 changes: 35 additions & 31 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = class extends Generator {
}
])
);
const { packageName, moduleNamePrefix, isLibrary } = this.props;
const { packageName, moduleNamePrefix, type } = 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 @@ -90,7 +90,7 @@ module.exports = class extends Generator {
);

// component name
if (isLibrary) {
if (type === 'library' || type === 'brick') {
Object.assign(
this.props,
await this.prompt([
Expand All @@ -110,13 +110,13 @@ module.exports = class extends Generator {
}

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

let srcPairs, tplPairs;

if (isLibrary) {
if (type === 'library') {
srcPairs = {
'public_api.ts': 'public_api.ts'
};
Expand All @@ -130,8 +130,11 @@ module.exports = class extends Generator {
return acc;
}, {})
}
} else {
} else if (type === 'plugin') {
srcPairs = {
'deploy/update_postscript.sh': 'deploy/update_postscript.sh',
'deploy/update_prescript.sh': 'deploy/update_prescript.sh',
'plugins-default.json': 'plugins-default.json',
'tsconfig.json': 'tsconfig.json',
'src/pages/index/index.component.html': 'src/pages/index/index.component.html',
'src/pages/index/index.component.scss': 'src/pages/index/index.component.scss',
Expand All @@ -140,25 +143,36 @@ module.exports = class extends Generator {
};

tplPairs = {
'.pkgbuild/PKGBUILD': '.pkgbuild/PKGBUILD',
'deploy/install_postscript.sh': 'deploy/install_postscript.sh',
'deploy/package.conf.yaml': 'deploy/package.conf.yaml',
'package-sample.json': 'package.json',
'README.md': 'README.md',
'src/index.module.ts': 'src/index.module.ts',
'src/index.states.ts': 'src/index.states.ts',
'src/main.ts': 'src/main.ts',
}
}

if (needPluginsConfig) {
srcPairs['plugins-default.json'] = 'plugins-default.json';
}

// 是否需要 Easyops 部署规范需要的额外文件
if (needDeployConfig) {
tplPairs['.pkgbuild/PKGBUILD'] = '.pkgbuild/PKGBUILD';
tplPairs['deploy/install_postscript.sh'] = 'deploy/install_postscript.sh';
tplPairs['deploy/package.conf.yaml'] = 'deploy/package.conf.yaml';
} else {
// type === 'brick'
srcPairs = {
'deploy/update_postscript.sh': 'deploy/update_postscript.sh',
'deploy/update_prescript.sh': 'deploy/update_prescript.sh',
'tsconfig.json': 'tsconfig.json'
};

srcPairs['deploy/update_postscript.sh'] = 'deploy/update_postscript.sh';
srcPairs['deploy/update_prescript.sh'] = 'deploy/update_prescript.sh';
tplPairs = {
'.pkgbuild/PKGBUILD': '.pkgbuild/PKGBUILD',
'deploy/install_postscript.sh': 'deploy/install_postscript.sh',
'deploy/package.conf.yaml': 'deploy/package.conf.yaml',
'package-sample.json': 'package.json',
'README.md': 'README.md',
'src/index.module.ts': 'src/index.module.ts',
'src/main.ts': 'src/main.ts',
...['html', 'scss', 'spec.ts', 'ts'].reduce((acc, ext) => {
acc[`src/components/template.component.${ext}`] = `src/components/${componentName}.component.${ext}`;
return acc;
}, {})
}
}

Object.entries(srcPairs).forEach(([from, to]) => {
Expand Down Expand Up @@ -221,20 +235,10 @@ module.exports = class extends Generator {

install() {
const done = this.async();
const { subPackagePath, scope, packageName, isLibrary } = this.props;
const distPath = `${subPackagePath}/${packageName}`;
const { scope, packageName } = this.props;
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
});
childOfYarn.on("close", () => {
done();
});
}
done();
});
}
};
22 changes: 5 additions & 17 deletions generators/app/scopes.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,27 @@
"@easyops": {
"repository": "Console-W",
"subPackagePath": "packages",
"removeScriptsStart": false,
"tsconfigPath": true,
"isLibrary": true,
"needPluginsConfig": false,
"needDeployConfig": false
"type": "library"
},
"@brick": {
"repository": "console-plugins",
"subPackagePath": "@brick",
"removeScriptsStart": true,
"tsconfigPath": false,
"isLibrary": true,
"needPluginsConfig": false,
"type": "brick",
"projectNamePrefix": "brick-",
"moduleNamePrefix": "Brick",
"needDeployConfig": false
"moduleNamePrefix": "Brick"
},
"@plugin-common": {
"repository": "console-plugins",
"subPackagePath": "@plugin-common",
"removeScriptsStart": false,
"tsconfigPath": false,
"isLibrary": true,
"needPluginsConfig": false,
"needDeployConfig": false
"type": "library"
},
"@console-plugin": {
"repository": "console-plugins",
"subPackagePath": "packages",
"removeScriptsStart": false,
"tsconfigPath": false,
"isLibrary": false,
"needPluginsConfig": true,
"needDeployConfig": true
"type": "plugin"
}
}
3 changes: 3 additions & 0 deletions generators/app/templates/brick/.pkgbuild/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "$startdir"/../../../.pkgbuild/brick/PKGBUILD
pkgname=<%= packageName %>-B
pkgver=0.0.0 # placeholder
25 changes: 25 additions & 0 deletions generators/app/templates/brick/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# <%= scope %>/<%= packageName %>

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 %>
# 2. 创建 link
cd <%= subPackagePath %>/<%= packageName %>
yarn link
# 3. 使用 link
cd ~/Console-W
yarn link <%= scope %>/<%= packageName %>
```

## publish

```
lerna version
```
20 changes: 20 additions & 0 deletions generators/app/templates/brick/deploy/install_postscript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

install_base="/usr/local/easyops" # Easyops 安装根目录
plugin_name="<%= packageName %>"
install_path="${install_base}/bricks/${plugin_name}-B" #多加了个-B后缀,这是我们的部署规范

console="console" # console目录应用
scope="@brick"
plugins_dir="${install_base}/${console}/src/www/plugins/"
builtin_plugins_dir="${install_base}/${console}/src/www/builtin-plugins/"

# 删除原有放在buildin-plugins的插件,小产品安装的都统一放在plugins
rm -rf "${builtin_plugins_dir:?}/${scope}/${plugin_name}"
# 删除上一个版本
rm -rf "${plugins_dir:?}/${plugin_name}"

# 确保存在插件目录
mkdir -p "${plugins_dir}"
# 这边转换插件的名字,不用-A后缀
ln -snf "${install_path}" "${plugins_dir}/${plugin_name}"
7 changes: 7 additions & 0 deletions generators/app/templates/brick/deploy/package.conf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
install_path: "/usr/local/easyops/bricks/<%= packageName %>-B"
user: easyops:easyops

dependencies:
- name: console
version: "^4.0.0"
local_deploy: true
4 changes: 4 additions & 0 deletions generators/app/templates/brick/deploy/update_postscript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# 先清理原有的main-xxxx.js
rm -rf ./dist/*
4 changes: 4 additions & 0 deletions generators/app/templates/brick/deploy/update_prescript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# 为保证一致,直接用install_postscript.sh
bash ./deploy/install_postscript.sh
32 changes: 32 additions & 0 deletions generators/app/templates/brick/package-sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "<%= scope %>/<%= packageName %>",
"private": true,
"version": "0.0.0",
"main": "dist/main.js",
"repository": "https://git.easyops.local/anyclouds/<%= repository %>",
"license": "UNLICENSED",
"files": [
"dist"
],
"scripts": {
"start": "npm run build:dev -- --watch",
"build:dev": "NODE_ENV=development webpack --mode development --config ../../webpack.config.js",
"prebuild": "rimraf dist",
"prestart": "rimraf dist",
"build": "NODE_ENV=production webpack --mode production --config ../../webpack.config.js",
"prepublishOnly": "npm test && npm run build"
},
"peerDependencies": {
"@angular/common": "7.1.4",
"@angular/core": "7.1.4",
"@angular/forms": "7.1.4",
"@angular/platform-browser": "7.1.4",
"@angular/router": "7.1.4",
"@easyops/console-plugin-core": "^5.0.0",
"@easyops/console-vendors": "^12.0.0",
"@uirouter/angular": "2.0.0",
"@uirouter/core": "5.0.19",
"rxjs": "^6.4.0",
"zone.js": "~0.8.26"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>
<%= componentName %> works!
</p>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { async, ComponentFixture, TestBed } from "@angular/core/testing";
import { <%= componentClassName %> } from "./<%= componentName %>.component";

describe("<%= componentClassName %>", () => {
let component: <%= componentClassName %>;
let fixture: ComponentFixture<<%= componentClassName %>>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ <%= componentClassName %> ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(<%= componentClassName %>);
component = fixture.componentInstance;
fixture.detectChanges();
});

it("should create", () => {
expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: "<%= componentName %>",
templateUrl: "./<%= componentName %>.component.html",
styleUrls: ["./<%= componentName %>.component.scss"]
})
export class <%= componentClassName %> implements OnInit {

constructor() { }

ngOnInit() {
}

}
13 changes: 13 additions & 0 deletions generators/app/templates/brick/src/index.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";

import { <%= componentClassName %> } from "./components/<%= componentName %>.component";

@NgModule({
imports: [
CommonModule
],
declarations: [<%= componentClassName %>],
entryComponents: [<%= componentClassName %>]
})
export class <%= moduleName %> {}
Loading

0 comments on commit fad9bf6

Please sign in to comment.