rigjs 1.0.33 → 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/bin/rig.js +1 -1
  2. package/built/index.js +70 -0
  3. package/demo/babel.config.js +5 -0
  4. package/demo/cicd.rig.json5 +9 -0
  5. package/demo/jsconfig.json +19 -0
  6. package/demo/package.json +41 -11
  7. package/demo/package.rig.json5 +0 -6
  8. package/demo/public/favicon.ico +0 -0
  9. package/demo/public/index.html +17 -0
  10. package/demo/rig_helper.js +7 -7
  11. package/demo/src/App.vue +28 -0
  12. package/demo/src/assets/logo.png +0 -0
  13. package/demo/src/components/HelloWorld.vue +58 -0
  14. package/demo/src/main.js +8 -0
  15. package/demo/vue.config.js +4 -0
  16. package/demo/yarn.lock +5644 -0
  17. package/lib/build/index.ts +17 -0
  18. package/lib/check/index.d.ts +6 -0
  19. package/lib/check/index.js +0 -1
  20. package/lib/classes/cicd/CICD.ts +110 -0
  21. package/lib/classes/cicd/CICDCmd.ts +65 -0
  22. package/lib/classes/cicd/Deploy/AliDeploy.ts +0 -0
  23. package/lib/classes/cicd/Deploy/HuaweiDeploy.ts +0 -0
  24. package/lib/classes/cicd/Deploy/index.ts +0 -0
  25. package/lib/classes/cicd/DirLevel.ts +49 -0
  26. package/lib/classes/cicd/Endpoint.ts +87 -0
  27. package/lib/define/index.ts +47 -0
  28. package/lib/deploy/index.ts +41 -0
  29. package/lib/deps/index.d.ts +6 -0
  30. package/lib/env/index.d.ts +4 -0
  31. package/lib/info/index.d.ts +6 -0
  32. package/lib/info/index.js +1 -0
  33. package/lib/init/cicd.rig.json5 +9 -0
  34. package/lib/init/index.d.ts +6 -0
  35. package/lib/init/index.js +49 -34
  36. package/lib/init/rig_helper.js +14 -0
  37. package/lib/install/index.d.ts +5 -0
  38. package/lib/install/index.js +1 -2
  39. package/lib/postinstall/index.d.ts +6 -0
  40. package/lib/preinstall/index.d.ts +6 -0
  41. package/lib/rig/index.ts +48 -0
  42. package/lib/tag/index.d.ts +6 -0
  43. package/lib/tag/index.js +0 -3
  44. package/lib/utils/fsHelper.ts +10 -0
  45. package/lib/utils/index.js +4 -1
  46. package/lib/utils/{regex.js → regex.ts} +9 -3
  47. package/package.json +10 -2
  48. package/tsconfig.json +50 -0
  49. package/.github/workflows/npm-publish.yml +0 -44
  50. package/demo/package.rig2.json5 +0 -8
  51. package/demo/test.js +0 -18
  52. package/lib/rig/index.js +0 -17
@@ -0,0 +1,17 @@
1
+ import fsHelper from '../utils/fsHelper';
2
+ import CICD from '@/classes/cicd/CICD';
3
+ import CICDCmd from '@/classes/cicd/CICDCmd';
4
+ import shell from 'shelljs';
5
+
6
+ export default async (cmd: any) => {
7
+ //create cicd object
8
+ const cicd = CICD.createByDefault(cmd);
9
+ //construct cmd object
10
+ const cicdCmd = new CICDCmd(cmd, cicd);
11
+ //build by cicdCmd and cicdConfig
12
+ console.log(cicdCmd.endpoints);
13
+ for (let i = 0; i < cicdCmd.endpoints.length; i++) {
14
+ const ep = cicdCmd.endpoints[i];
15
+ shell.exec(ep.build);
16
+ }
17
+ }
@@ -0,0 +1,6 @@
1
+ declare namespace check {
2
+ const name: string;
3
+
4
+ function load(): void;
5
+ }
6
+ export default check;
@@ -4,7 +4,6 @@
4
4
  * @author Wang Bo (ralwayne@163.com)
5
5
  * @date 2020/10/14 6:59 PM
6
6
  */
7
- const shell = require('shelljs');
8
7
  const fs = require('fs');
9
8
  const json5 = require('json5');
10
9
  const print = require('../print');
@@ -0,0 +1,110 @@
1
+ import DirLevel from '@/classes/cicd/DirLevel';
2
+ import Endpoint, { EndpointDict} from '@/classes/cicd/Endpoint';
3
+ import fs from 'fs';
4
+ import {Dir} from 'fs';
5
+ import fsHelper from '@/utils/fsHelper';
6
+ import CICDCmd from '@/classes/cicd/CICDCmd';
7
+
8
+ const JSON5 = require('json5');
9
+ import qs from 'querystring';
10
+ export enum CloudType {
11
+ alicloud = 'alicloud',
12
+ }
13
+
14
+ /**
15
+ * Bundle source
16
+ */
17
+ interface DeploySource {
18
+ root_path: string
19
+ }
20
+
21
+ /**
22
+ * Deploy target
23
+ */
24
+ interface DeployTarget {
25
+ id: string;
26
+ type: CloudType;
27
+ bucket: string;
28
+ access_key: string;
29
+ access_secret: string;
30
+ root_path: '/';
31
+ }
32
+
33
+ /**
34
+ * @interface DirGroup
35
+ * Only dynamic Dirlevel can use DirGroup
36
+ */
37
+ export interface DirGroup {
38
+ name: string,
39
+ /**
40
+ * Name in DirLevel,
41
+ */
42
+ level: string,
43
+ includes: string[],
44
+ }
45
+ export interface Define{
46
+ [replace: string]: String;
47
+ }
48
+ export interface DefineDict{
49
+ [group: string]: Define;
50
+ }
51
+
52
+ /**
53
+ * Whole CI/CD config
54
+ */
55
+ export interface CICDConfig {
56
+ tree_schema: string;
57
+ source: DeploySource;
58
+ target: DeployTarget | DeployTarget[];
59
+ endpoints: EndpointDict;
60
+ groups: DirGroup[];
61
+ }
62
+
63
+
64
+ class CICD {
65
+ /**
66
+ * schema of the directory tree
67
+ * @type {string}
68
+ */
69
+ treeSchema: string;
70
+ /**
71
+ * DirLevel shows every level of the directory structure
72
+ * @type {DirLevel[]}
73
+ */
74
+ schema: DirLevel[];
75
+ /**
76
+ * endpoints contains build info and deploy info.
77
+ * @type {Endpoint[]}
78
+ */
79
+ endpoints: Endpoint[];
80
+ source: DeploySource;
81
+ target: DeployTarget | DeployTarget[];
82
+ groups: DirGroup[];
83
+
84
+ constructor(config: CICDConfig) {
85
+ this.treeSchema = config.tree_schema;
86
+ this.schema = DirLevel.createSchema(this.treeSchema);
87
+ this.endpoints = Endpoint.createEndpointArr(config,this.schema);
88
+ this.source = config.source;
89
+ this.target = config.target;
90
+ this.groups = config.groups;
91
+ }
92
+ static createByDefault(cmd:any){
93
+ //replace params
94
+ let cicdStr = fs.readFileSync(`${process.cwd()}/cicd.rig.json5`).toString();
95
+ const paramsStr = cmd.params;
96
+ const params = qs.parse(paramsStr);
97
+ Object.keys(params).forEach(key => {
98
+ const regStr = `\\$\\{${key}\\}`;
99
+ const regex = new RegExp(regStr, 'g');
100
+ cicdStr = cicdStr.replace(regex, params[key] as string);
101
+ });
102
+ return new CICD(JSON5.parse(cicdStr));
103
+ }
104
+
105
+ matchEndpoints(cmdDirStrArr: string[]) {
106
+
107
+ }
108
+ }
109
+
110
+ export default CICD;
@@ -0,0 +1,65 @@
1
+ import Endpoint from '@/classes/cicd/Endpoint';
2
+ import CICD, {CICDConfig} from '@/classes/cicd/CICD';
3
+ import qs, {ParsedUrlQuery} from 'querystring';
4
+ import path from 'path'
5
+ import fsHelper from '@/utils/fsHelper';
6
+
7
+ /**
8
+ * @class CICDCmd
9
+ * @property dir string Original specific dir in cmd.
10
+ * @property dirArr array Splitted dir.
11
+ * @property endpoints array Tageted endpoints used to build,define or deploy
12
+ */
13
+ class CICDCmd {
14
+ /**
15
+ * @property dir string Whole directory
16
+ * @type {string}
17
+ */
18
+ dir: string;
19
+ /**
20
+ *
21
+ * @type {string[]}
22
+ */
23
+ dirInSchemaStrArr: string[];
24
+ dirStrArr: string[];
25
+ endpoints: Endpoint[] = [];
26
+ cicd: CICD;
27
+
28
+ constructor(cmd: any, cicd: CICD) {
29
+ const cmdArgs = cmd.args;
30
+ this.dir = cmdArgs[0];
31
+ //获取需要被设置的schema变量
32
+ const schemaKeys = this.dir.match(/(?<=\{)[a-zA-Z]+(?=\})/g) || [];
33
+ //解析schema变量
34
+ let schema: ParsedUrlQuery = qs.parse(cmd.schema);
35
+ for (let key of schemaKeys) {
36
+ const val = schema[key];
37
+ if (val) {
38
+ this.dir = this.dir.replace(`{${key}}`, val as string);
39
+ } else {
40
+ throw new Error(`${key} is not set`);
41
+ }
42
+ }
43
+ //whole user's target dir
44
+ this.dirStrArr = this.dir.split('/').filter((dirStr, index) => dirStr.length > 0);
45
+ //dir within the schema
46
+ this.dirInSchemaStrArr = this.dir.split('/').filter((dirStr, index) => dirStr.length > 0 && index < cicd.schema.length);
47
+ this.cicd = cicd;
48
+ this.createTargetEndpoints();
49
+ }
50
+
51
+ private createTargetEndpoints() {
52
+ const allEndpints = this.cicd.endpoints;
53
+ this.endpoints = allEndpints.filter(endpoint => endpoint.matchCmd(this.dirInSchemaStrArr, this.cicd.groups));
54
+ if (this.dirStrArr.length > this.dirInSchemaStrArr.length) {
55
+ const sufDir = this.dirStrArr.slice(this.dirInSchemaStrArr.length, this.dirStrArr.length).join('/');
56
+ this.endpoints = this.endpoints.map(ep => {
57
+ ep.deployDir = path.join(ep.deployDir, sufDir);
58
+ return ep;
59
+ });
60
+ }
61
+
62
+ }
63
+ }
64
+
65
+ export default CICDCmd;
File without changes
File without changes
File without changes
@@ -0,0 +1,49 @@
1
+ import regex from '../../utils/regex';
2
+
3
+ /**
4
+ * contain attributes of every level in the directory schema
5
+ */
6
+ class DirLevel {
7
+ /**
8
+ * Means that is this level's name can be set dynamically.
9
+ * @type {boolean}
10
+ */
11
+ dynamic: boolean;
12
+ /**
13
+ * The meaning of this level.Can be changed when [this.dynamic] is true.
14
+ * % matches all dir name.
15
+ * @type {string}
16
+ */
17
+ name: string | '%';
18
+ /**
19
+ * The level in the directory schema
20
+ * @type {number}
21
+ */
22
+ level: number;
23
+
24
+ constructor(dirName: string, level: number) {
25
+ this.dynamic = regex.dynamicDir.test(dirName);
26
+ this.name = dirName;
27
+ this.level = level;
28
+ }
29
+
30
+ static createSchema(treeSchema: string) {
31
+ let dirStrArr = treeSchema.split('/');
32
+ dirStrArr = dirStrArr.filter(dirStr => dirStr.length > 0);
33
+ return dirStrArr.map((dirStr, index) => {
34
+ return new DirLevel(dirStr, index);
35
+ });
36
+ }
37
+
38
+ static createDirArr(dir: string, schema: DirLevel[]) {
39
+ let dirStrArr = dir.split('/');
40
+ dirStrArr = dirStrArr.filter(dirStr => dirStr.length > 0);
41
+ return dirStrArr.map((dirStr, index) => {
42
+ const level = new DirLevel(dirStr, index);
43
+ level.dynamic = schema[index].dynamic;
44
+ return level;
45
+ });
46
+ }
47
+ }
48
+
49
+ export default DirLevel;
@@ -0,0 +1,87 @@
1
+ import {CICDConfig, DefineDict, DirGroup} from './CICD';
2
+ import {mkdirSync} from 'fs';
3
+ import DirLevel from '@/classes/cicd/DirLevel';
4
+
5
+ interface EndpointInfo {
6
+ build: string;
7
+ target: string;
8
+ domain: string;
9
+ define: DefineDict;
10
+ }
11
+
12
+ export interface EndpointDict {
13
+ [dir: string]: EndpointInfo;
14
+ }
15
+
16
+ class Endpoint {
17
+ dir: string;
18
+ dirStrArr: string[];
19
+ dirArr: DirLevel[];
20
+ target: string;
21
+ build: string;
22
+ domain: string;
23
+ deployDir: string;
24
+ define: DefineDict;
25
+
26
+
27
+ constructor(dir: string, info: EndpointInfo, schema: DirLevel[]) {
28
+ this.dir = dir;
29
+ this.deployDir = dir;
30
+ this.dirStrArr = dir.split('/').filter(d => d.length > 0);
31
+ this.dirArr = DirLevel.createDirArr(dir, schema);
32
+ this.target = info.target;
33
+ this.build = info.build;
34
+ this.domain = info.domain;
35
+ this.define = info.define;
36
+ }
37
+
38
+ static createEndpointArr(cicdConfig: CICDConfig, schema: DirLevel[]) {
39
+ const endpointDict = cicdConfig.endpoints;
40
+ return Object.keys(endpointDict).map(dir => {
41
+ const info = endpointDict[dir];
42
+ return new Endpoint(dir, info, schema);
43
+ });
44
+ }
45
+
46
+ matchCmd(dirSchemaStrArr: string[], groups: DirGroup[]) {
47
+ if (this.dirStrArr.length < dirSchemaStrArr.length) {
48
+ return false;
49
+ }
50
+ for (let i = 0; i < dirSchemaStrArr.length; i++) {
51
+ const cmdDir = dirSchemaStrArr[i];
52
+ const dir = this.dirStrArr[i];
53
+ const dirLevel = this.dirArr[i];
54
+ //check if dir is wildcard
55
+ if (cmdDir !== '%') {
56
+ //not wildcard
57
+ //check if dir is group alias
58
+ if (cmdDir.indexOf('%') === 0) {
59
+ //dir is group
60
+ //find group
61
+ const group = groups.find(g => g.name === cmdDir);
62
+ if (group) {
63
+ //group found
64
+ //check if group includes this dir
65
+ if (group.includes.indexOf(dir) < 0) {
66
+ //not include
67
+ return false;
68
+ }
69
+ } else {
70
+ return false;
71
+ }
72
+
73
+ } else {
74
+ //cmdDir is not group
75
+ if (cmdDir !== dir) {
76
+ return false;
77
+ }
78
+ }
79
+ } else {
80
+ if (!dirLevel.dynamic) return false;
81
+ }
82
+ }
83
+ return true;
84
+ }
85
+ }
86
+
87
+ export default Endpoint;
@@ -0,0 +1,47 @@
1
+ import fsHelper from '../utils/fsHelper';
2
+ import CICD, {Define} from '@/classes/cicd/CICD';
3
+ import CICDCmd from '@/classes/cicd/CICDCmd';
4
+ import fs from 'fs';
5
+ import path from 'path';
6
+ const replaceDefine = (target:string,define?:Define)=>{
7
+ const dirs = fs.readdirSync(target);
8
+ for (let dir of dirs){
9
+ const stat = fs.statSync(path.join(target, dir));
10
+ if (stat.isDirectory()){
11
+ replaceDefine(path.join(target, dir),define);
12
+ }else{
13
+ if (define){
14
+ const namePieces = dir.split('.');
15
+ const fileType = namePieces[namePieces.length - 1];
16
+ if (['js','json','json5','yml','ts'].indexOf(fileType)>=0){
17
+ let file = fs.readFileSync(path.join(target, dir)).toString();
18
+ const replaceArr = Object.keys(define);
19
+ for (let replace of replaceArr){
20
+ file = file.replace(new RegExp(replace,'g'),define[replace] as string);
21
+ }
22
+ fs.writeFileSync(path.join(target, dir),file);
23
+ }
24
+ }
25
+ }
26
+ }
27
+ }
28
+ export default async (cmd: any) => {
29
+ // let phase = 'start define';
30
+ // try{
31
+ // const cicdConfigJson = fsHelper.readCICDConfig();
32
+ // const cicdConfig = new CICD(cicdConfigJson);
33
+ // const args: string[] = cmd.args;
34
+ // const define = cicdConfig.defines[args[1]];
35
+ // //construct cmd object
36
+ // const cicdCmd = new CICDCmd(cmd, cicdConfig);
37
+ // console.log(cicdCmd);
38
+ // //define by cicdCmd and cicdConfig
39
+ // phase = 'start replacement';
40
+ // for (let i = 0; i < cicdCmd.endpoints.length; i++) {
41
+ // const ep = cicdCmd.endpoints[i];
42
+ // replaceDefine(path.join(cicdConfig.source.root_path, ep.dir),define);
43
+ // }
44
+ // }catch (e) {
45
+ // throw new Error(`${phase}:${e.message}`)
46
+ // }
47
+ }
@@ -0,0 +1,41 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import aliOSS from "ali-oss";
4
+ import fsHelper from "../utils/fsHelper";
5
+ import CICD from "@/classes/cicd/CICD";
6
+ import CICDCmd from "@/classes/cicd/CICDCmd";
7
+ //
8
+ // const progress = (p: number, filePath: string, ossPath: string) => {
9
+ // // 上传进度。
10
+ // process.stdout.clearLine(-1);
11
+ // process.stdout.cursorTo(0);
12
+ // process.stdout.write(
13
+ // `progress: ${p.toFixed(2)}%, Upload '${filePath}' To OSS_PATH:${ossPath}`
14
+ // );
15
+ // };
16
+ //
17
+ // let filesList: string[] = [];
18
+ // const traverseFolder = (url: string) => {
19
+ // if (fs.existsSync(url)) {
20
+ // const files = fs.readdirSync(url);
21
+ // files.forEach((file) => {
22
+ // const curPath = path.join(url, file);
23
+ // if (fs.statSync(curPath).isDirectory()) {
24
+ // traverseFolder(curPath);
25
+ // } else {
26
+ // filesList.push(curPath);
27
+ // }
28
+ // });
29
+ // }
30
+ // };
31
+ //
32
+ export default async (cmd: any) => {
33
+ try {
34
+ //create cicd object
35
+ const cicd = CICD.createByDefault(cmd);
36
+ //construct cmd object
37
+ const cicdCmd = new CICDCmd(cmd, cicd);
38
+ }catch (e) {
39
+ throw e;
40
+ }
41
+ }
@@ -0,0 +1,6 @@
1
+ declare namespace deps {
2
+ const name: string;
3
+
4
+ function load(): void;
5
+ }
6
+ export default deps;
@@ -0,0 +1,4 @@
1
+ declare namespace env {
2
+ function load(): void;
3
+ }
4
+ export default env;
@@ -0,0 +1,6 @@
1
+ declare namespace info {
2
+ function load(): void;
3
+ function info(): void;
4
+
5
+ }
6
+ export default info;
package/lib/info/index.js CHANGED
@@ -10,6 +10,7 @@ const json5 = require('json5');
10
10
  const print = require('../print');
11
11
  //加载命令控制器
12
12
  const info = () => {
13
+ console.log('process.platform');
13
14
  print.info(`start checking modules|OS:${process.platform} `);
14
15
  let rigJson5 = json5.parse(fs.readFileSync('package.rig.json5'));
15
16
  for (let dep of rigJson5) {
@@ -0,0 +1,9 @@
1
+ {
2
+ tree_schema: '{app}/{env}/{oem}',
3
+ source: {
4
+ root_path: 'dist',
5
+ },
6
+ target: {},
7
+ endpoints: {},
8
+ groups: [],
9
+ }
@@ -0,0 +1,6 @@
1
+ declare namespace init {
2
+ const name: string;
3
+
4
+ function load(): void;
5
+ }
6
+ export default init;
package/lib/init/index.js CHANGED
@@ -4,24 +4,22 @@
4
4
  * @author Wang Bo (ralwayne@163.com)
5
5
  * @date 2020/10/9 6:14 PM
6
6
  */
7
- const shell = require('shelljs');
8
7
  const fs = require('fs');
9
- const path = require('path');
10
8
  const json5 = require('json5');
11
- const inquirer = require('inquirer');
12
9
  const chalk = require('chalk');
13
10
  let log = console.log;
14
11
  let green = chalk.green;
15
- let red = chalk.red;
16
12
  let redBright = chalk.redBright;
17
13
 
18
- let yellow = chalk.yellow;
19
-
20
14
  //加载命令控制器
21
15
 
22
- const load = async (cmd) => {
16
+ const load = async () => {
23
17
  try {
24
18
  console.log(chalk.blue('exec init'));
19
+ const pkg = JSON.parse(fs.readFileSync(`${process.cwd()}/package.json`));
20
+
21
+
22
+
25
23
  //检查当前目录是否存在package.json
26
24
  if (!(fs.existsSync('package.json') && fs.lstatSync('package.json').isFile())) {
27
25
  console.log(chalk.red('Please run this in the root directory of project!Must have a validate package.json'));
@@ -32,7 +30,7 @@ const load = async (cmd) => {
32
30
  console.log(chalk.green('package.rig.json5 already exists~'));
33
31
  } else {
34
32
  //创建package.rig.json5.json5
35
- let template =`[
33
+ let template = `[
36
34
  // {
37
35
  // name: "your project name",
38
36
  // source: "git ssh url",
@@ -43,26 +41,43 @@ const load = async (cmd) => {
43
41
  console.log(chalk.green('create package.rig.json5'));
44
42
  fs.writeFileSync('./package.rig.json5', template);
45
43
  }
46
- if (fs.existsSync('rig_helper.js')){
44
+ if (fs.existsSync(`${process.cwd()}/rig_helper.js`)) {
47
45
  console.log(chalk.green('rig_helper.js already exists~'));
48
- }else{
49
- let rigHelper = `const json5 = require('json5');
46
+ } else {
47
+ console.log(chalk.green('create rig_helper.js'));
48
+ let template = `const json5 = require('json5');
50
49
  const fs = require('fs');
51
50
  const getPkgs = () => {
52
- let pkgArr = json5.parse(fs.readFileSync('./package.rig.json5'));
53
- let flatPkgArr = pkgArr.map((item, index) => {
54
- return item.name;
55
- });
56
- console.log(flatPkgArr);
57
- return flatPkgArr;
51
+ \tlet pkgArr = json5.parse(fs.readFileSync('./package.rig.json5'));
52
+ \tlet flatPkgArr = pkgArr.map((item, index) => {
53
+ \t\treturn item.name;
54
+ \t});
55
+ \tconsole.log(flatPkgArr);
56
+ \treturn flatPkgArr;
58
57
  }
59
58
 
60
59
  module.exports = {
61
- getPkgs
60
+ \tgetPkgs
62
61
  }
63
62
  `
64
- console.log(chalk.green('create rig_helper.js'));
65
- fs.writeFileSync('./rig_helper.js', rigHelper);
63
+ fs.writeFileSync(`${process.cwd()}/rig_helper.js`, template);
64
+ }
65
+ if (fs.existsSync(`${process.cwd()}/cicd.rig.json5`)) {
66
+ console.log(chalk.green('cicd.rig.json5 already exists~'));
67
+ } else {
68
+ console.log(chalk.green('create cicd.rig.json5'));
69
+ let template = `{
70
+ tree_schema: '{app}/{env}/{oem}',
71
+ source: {
72
+ root_path: 'dist',
73
+ },
74
+ target: {},
75
+ endpoints: {},
76
+ groups: [],
77
+ }
78
+ `;
79
+ fs.writeFileSync(`${process.cwd()}/cicd.rig.json5`, template);
80
+
66
81
  }
67
82
  //检查rigs是否存在
68
83
  if (fs.existsSync('./rigs') && fs.lstatSync('./rigs').isDirectory()) {
@@ -111,21 +126,21 @@ module.exports = {
111
126
  "rigs/*",
112
127
  "rigs_dev/*"
113
128
  ],
114
- scripts:{
115
- preinstall:"rig preinstall",
116
- postinstall:"rig postinstall",
129
+ scripts: {
130
+ preinstall: "rig preinstall",
131
+ postinstall: "rig postinstall",
117
132
  },
118
- devDependencies:{
119
- json5:'2.1.3'
133
+ devDependencies: {
134
+ json5: '2.1.3'
120
135
  }
121
136
  }
122
137
  pkgJSON.private = inserted.private;
123
138
  //初始化workspaces
124
139
  if (pkgJSON.workspaces && pkgJSON.workspaces instanceof Array) {
125
- if (pkgJSON.workspaces.indexOf('rigs/*')===-1) {
140
+ if (pkgJSON.workspaces.indexOf('rigs/*') === -1) {
126
141
  pkgJSON.workspaces.push('rigs/*')
127
142
  }
128
- if (pkgJSON.workspaces.indexOf('rigs_dev/*')===-1) {
143
+ if (pkgJSON.workspaces.indexOf('rigs_dev/*') === -1) {
129
144
  pkgJSON.workspaces.push('rigs_dev/*')
130
145
  }
131
146
 
@@ -134,26 +149,26 @@ module.exports = {
134
149
  }
135
150
  //初始化pre/post-install
136
151
  if (pkgJSON.scripts && pkgJSON.scripts instanceof Object) {
137
- if (pkgJSON.scripts.preinstall && pkgJSON.scripts.preinstall.indexOf(inserted.scripts.preinstall)<0) {
152
+ if (pkgJSON.scripts.preinstall && pkgJSON.scripts.preinstall.indexOf(inserted.scripts.preinstall) < 0) {
138
153
  pkgJSON.scripts.preinstall = `${pkgJSON.scripts.preinstall} && ${inserted.scripts.preinstall}`
139
- }else{
154
+ } else {
140
155
  pkgJSON.scripts.preinstall = inserted.scripts.preinstall;
141
156
  }
142
- if (pkgJSON.scripts.postinstall && pkgJSON.scripts.postinstall.indexOf(inserted.scripts.postinstall)<0) {
157
+ if (pkgJSON.scripts.postinstall && pkgJSON.scripts.postinstall.indexOf(inserted.scripts.postinstall) < 0) {
143
158
  pkgJSON.scripts.postinstall = `${pkgJSON.scripts.postinstall} && ${inserted.scripts.postinstall}`
144
- }else{
159
+ } else {
145
160
  pkgJSON.scripts.postinstall = inserted.scripts.postinstall;
146
161
  }
147
162
  } else {
148
163
  pkgJSON.scripts = inserted.scripts
149
164
  }
150
- if (pkgJSON.devDependencies){
165
+ if (pkgJSON.devDependencies) {
151
166
  //TODO:可优化
152
167
  pkgJSON.devDependencies.json5 = inserted.devDependencies.json5;
153
- }else{
168
+ } else {
154
169
  pkgJSON.devDependencies = inserted.devDependencies;
155
170
  }
156
- fs.writeFileSync('package.json', JSON.stringify(pkgJSON,null,2));
171
+ fs.writeFileSync('package.json', JSON.stringify(pkgJSON, null, 2));
157
172
  log(green('package.json updated'))
158
173
  } catch (e) {
159
174
  log(redBright(e.message));
@@ -0,0 +1,14 @@
1
+ const json5 = require('json5');
2
+ const fs = require('fs');
3
+ const getPkgs = () => {
4
+ let pkgArr = json5.parse(fs.readFileSync('./package.rig.json5'));
5
+ let flatPkgArr = pkgArr.map((item, index) => {
6
+ return item.name;
7
+ });
8
+ console.log(flatPkgArr);
9
+ return flatPkgArr;
10
+ }
11
+
12
+ module.exports = {
13
+ getPkgs
14
+ }
@@ -0,0 +1,5 @@
1
+ declare namespace install {
2
+ function load(): void;
3
+
4
+ }
5
+ export default install;