rigjs 1.0.34 → 2.0.0-alpha

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 (41) hide show
  1. package/bin/rig.js +1 -1
  2. package/built/index.js +47 -0
  3. package/demo/cicd.rig.json5 +50 -0
  4. package/demo/package.json +4 -3
  5. package/demo/package.rig.json5 +1 -6
  6. package/demo/rig_helper.js +7 -7
  7. package/demo/yarn.lock +32 -0
  8. package/lib/build/index.ts +17 -0
  9. package/lib/check/index.d.ts +6 -0
  10. package/lib/check/index.js +0 -1
  11. package/lib/classes/cicd/CICD.ts +110 -0
  12. package/lib/classes/cicd/CICDCmd.ts +65 -0
  13. package/lib/classes/cicd/Deploy/AliDeploy.ts +0 -0
  14. package/lib/classes/cicd/Deploy/HuaweiDeploy.ts +0 -0
  15. package/lib/classes/cicd/Deploy/index.ts +0 -0
  16. package/lib/classes/cicd/DirLevel.ts +49 -0
  17. package/lib/classes/cicd/Endpoint.ts +87 -0
  18. package/lib/define/index.ts +47 -0
  19. package/lib/deploy/index.ts +42 -0
  20. package/lib/deps/index.d.ts +6 -0
  21. package/lib/env/index.d.ts +4 -0
  22. package/lib/info/index.d.ts +6 -0
  23. package/lib/init/cicd.rig.json5 +17 -0
  24. package/lib/init/index.d.ts +6 -0
  25. package/lib/init/index.js +32 -40
  26. package/lib/init/rig_helper.js +14 -0
  27. package/lib/install/index.d.ts +5 -0
  28. package/lib/install/index.js +1 -2
  29. package/lib/postinstall/index.d.ts +6 -0
  30. package/lib/preinstall/index.d.ts +6 -0
  31. package/lib/rig/index.ts +48 -0
  32. package/lib/tag/index.d.ts +6 -0
  33. package/lib/tag/index.js +0 -3
  34. package/lib/utils/fsHelper.ts +10 -0
  35. package/lib/utils/index.js +4 -1
  36. package/lib/utils/{regex.js → regex.ts} +9 -3
  37. package/package.json +10 -2
  38. package/tsconfig.json +50 -0
  39. package/.github/workflows/npm-publish.yml +0 -44
  40. package/demo/package.rig2.json5 +0 -8
  41. package/lib/rig/index.js +0 -17
@@ -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,42 @@
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
+
39
+ }catch (e) {
40
+ throw e;
41
+ }
42
+ }
@@ -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;
@@ -0,0 +1,17 @@
1
+ {
2
+ tree_schema: '',//tree_schema help to indicate every level of directory's meaning
3
+ source: {
4
+ path: 'dist',
5
+ },
6
+ target: {
7
+ type: '',
8
+ bucket: '',
9
+ access_token: '',
10
+ root_path: '/',
11
+ },
12
+ predefines: {},//relpace special string in your bundle,so you can use the same bundle in different enviroments without building multiple times.
13
+ endpoints: [],
14
+ alias: []
15
+ }
16
+
17
+
@@ -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,20 @@ 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');
50
- const fs = require('fs');
51
- 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;
58
- }
59
-
60
- module.exports = {
61
- getPkgs
62
- }
63
- `
46
+ } else {
64
47
  console.log(chalk.green('create rig_helper.js'));
65
- fs.writeFileSync('./rig_helper.js', rigHelper);
48
+ let rigHelper = fs.readFileSync(`${__dirname}/rig_helper.js`);
49
+ fs.writeFileSync(`${process.cwd()}/rig_helper.js`, rigHelper);
50
+ }
51
+ if (fs.existsSync(`${process.cwd()}/cicd.rig.json5`)) {
52
+ console.log(chalk.green('cicd.rig.json5 already exists~'));
53
+ } else {
54
+ console.log(chalk.green('create cicd.rig.json5'));
55
+ let cicdConfig = json5.parse(fs.readFileSync(`${__dirname}/cicd.rig.json5`));
56
+ cicdConfig.tree_prefix_schema = `${pkg.name}`
57
+ fs.writeFileSync(`${process.cwd()}/cicd.rig.json5`, json5.stringify(cicdConfig,null,2));
66
58
  }
67
59
  //检查rigs是否存在
68
60
  if (fs.existsSync('./rigs') && fs.lstatSync('./rigs').isDirectory()) {
@@ -111,21 +103,21 @@ module.exports = {
111
103
  "rigs/*",
112
104
  "rigs_dev/*"
113
105
  ],
114
- scripts:{
115
- preinstall:"rig preinstall",
116
- postinstall:"rig postinstall",
106
+ scripts: {
107
+ preinstall: "rig preinstall",
108
+ postinstall: "rig postinstall",
117
109
  },
118
- devDependencies:{
119
- json5:'2.1.3'
110
+ devDependencies: {
111
+ json5: '2.1.3'
120
112
  }
121
113
  }
122
114
  pkgJSON.private = inserted.private;
123
115
  //初始化workspaces
124
116
  if (pkgJSON.workspaces && pkgJSON.workspaces instanceof Array) {
125
- if (pkgJSON.workspaces.indexOf('rigs/*')===-1) {
117
+ if (pkgJSON.workspaces.indexOf('rigs/*') === -1) {
126
118
  pkgJSON.workspaces.push('rigs/*')
127
119
  }
128
- if (pkgJSON.workspaces.indexOf('rigs_dev/*')===-1) {
120
+ if (pkgJSON.workspaces.indexOf('rigs_dev/*') === -1) {
129
121
  pkgJSON.workspaces.push('rigs_dev/*')
130
122
  }
131
123
 
@@ -134,26 +126,26 @@ module.exports = {
134
126
  }
135
127
  //初始化pre/post-install
136
128
  if (pkgJSON.scripts && pkgJSON.scripts instanceof Object) {
137
- if (pkgJSON.scripts.preinstall && pkgJSON.scripts.preinstall.indexOf(inserted.scripts.preinstall)<0) {
129
+ if (pkgJSON.scripts.preinstall && pkgJSON.scripts.preinstall.indexOf(inserted.scripts.preinstall) < 0) {
138
130
  pkgJSON.scripts.preinstall = `${pkgJSON.scripts.preinstall} && ${inserted.scripts.preinstall}`
139
- }else{
131
+ } else {
140
132
  pkgJSON.scripts.preinstall = inserted.scripts.preinstall;
141
133
  }
142
- if (pkgJSON.scripts.postinstall && pkgJSON.scripts.postinstall.indexOf(inserted.scripts.postinstall)<0) {
134
+ if (pkgJSON.scripts.postinstall && pkgJSON.scripts.postinstall.indexOf(inserted.scripts.postinstall) < 0) {
143
135
  pkgJSON.scripts.postinstall = `${pkgJSON.scripts.postinstall} && ${inserted.scripts.postinstall}`
144
- }else{
136
+ } else {
145
137
  pkgJSON.scripts.postinstall = inserted.scripts.postinstall;
146
138
  }
147
139
  } else {
148
140
  pkgJSON.scripts = inserted.scripts
149
141
  }
150
- if (pkgJSON.devDependencies){
142
+ if (pkgJSON.devDependencies) {
151
143
  //TODO:可优化
152
144
  pkgJSON.devDependencies.json5 = inserted.devDependencies.json5;
153
- }else{
145
+ } else {
154
146
  pkgJSON.devDependencies = inserted.devDependencies;
155
147
  }
156
- fs.writeFileSync('package.json', JSON.stringify(pkgJSON,null,2));
148
+ fs.writeFileSync('package.json', JSON.stringify(pkgJSON, null, 2));
157
149
  log(green('package.json updated'))
158
150
  } catch (e) {
159
151
  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;
@@ -7,7 +7,7 @@
7
7
  const shell = require('shelljs');
8
8
  const print = require('../print')
9
9
  //加载命令控制器
10
- const load = async (cmd) => {
10
+ const load = async () => {
11
11
  print.info('start installing\n');
12
12
  try {
13
13
  let yarnProcess = shell.exec('yarn install',{silent:true});
@@ -24,6 +24,5 @@ const load = async (cmd) => {
24
24
  }
25
25
  }
26
26
  module.exports = {
27
- name: 'install',
28
27
  load
29
28
  }
@@ -0,0 +1,6 @@
1
+ declare namespace postinstall {
2
+ function load(): void;
3
+ const name: string;
4
+
5
+ }
6
+ export default postinstall;
@@ -0,0 +1,6 @@
1
+ declare namespace preinstall {
2
+ function load(): void;
3
+ const name: string;
4
+
5
+ }
6
+ export default preinstall;