rigjs 2.1.29 → 3.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 (54) hide show
  1. package/README.md +146 -183
  2. package/README_CN.md +144 -141
  3. package/built/index.js +143 -173
  4. package/demo/package.json +8 -6
  5. package/demo/package.rig.json5 +64 -10
  6. package/demo/rig_dev/.gitkeep +0 -0
  7. package/demo/rig_helper.js +5 -9
  8. package/demo/vue.config.js +1 -1
  9. package/demo/yarn.lock +20 -7
  10. package/doc/cicd_cn.md +120 -0
  11. package/doc/cmd_cn.md +0 -0
  12. package/doc/dependencies.md +0 -0
  13. package/doc/dependencies_cn.md +28 -0
  14. package/doc/share_cn.md +8 -0
  15. package/jest/test.rig.json5 +14 -0
  16. package/jest.config.ts +10 -1
  17. package/lib/add/index.ts +37 -0
  18. package/lib/build/build.md +6 -0
  19. package/lib/build/index.ts +64 -59
  20. package/lib/classes/RigConfig.test.ts +14 -0
  21. package/lib/classes/RigConfig.ts +191 -0
  22. package/lib/classes/cicd/CICD.ts +6 -7
  23. package/lib/classes/cicd/CICDCmd.ts +1 -0
  24. package/lib/classes/cicd/DirLevel.ts +1 -1
  25. package/lib/classes/cicd/Endpoint.ts +7 -1
  26. package/lib/classes/dependencies/Dep.ts +56 -0
  27. package/lib/dev/index.ts +44 -0
  28. package/lib/init/index.ts +118 -0
  29. package/lib/install/{index.js → index.ts} +3 -6
  30. package/lib/postinstall/{index.js → index.ts} +12 -20
  31. package/lib/preinstall/index.ts +78 -0
  32. package/lib/print/index.ts +38 -0
  33. package/lib/publish/index.ts +4 -4
  34. package/lib/rig/index.ts +29 -13
  35. package/lib/sync/index.test.ts +4 -0
  36. package/lib/sync/index.ts +32 -0
  37. package/lib/utils/fsHelper.ts +37 -1
  38. package/lib/utils/objectHelper.ts +12 -0
  39. package/lib/utils/regexHelper.test.ts +12 -0
  40. package/lib/utils/{regex.ts → regexHelper.ts} +4 -1
  41. package/package.json +9 -8
  42. package/package.rig.json5 +8 -0
  43. package/tsconfig.json +4 -2
  44. package/demo/cicd.rig.json5 +0 -56
  45. package/lib/init/cicd.rig.json5 +0 -11
  46. package/lib/init/index.d.ts +0 -6
  47. package/lib/init/index.js +0 -189
  48. package/lib/init/rig_helper.js +0 -14
  49. package/lib/install/index.d.ts +0 -5
  50. package/lib/postinstall/index.d.ts +0 -6
  51. package/lib/preinstall/index.d.ts +0 -7
  52. package/lib/preinstall/index.js +0 -198
  53. package/lib/preinstall/index.test.js +0 -16
  54. package/lib/print/index.js +0 -33
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @ignore
3
+ * @Description nothing
4
+ * @author Wang Bo (ralwayne@163.com)
5
+ * @date 2020/10/20 7:32 PM
6
+ */
7
+ const ora = require('ora');
8
+ const chalk = require('chalk');
9
+
10
+ let printer = ora();
11
+
12
+ const start = (str: string) => {
13
+ printer.start(chalk.blueBright(str));
14
+ }
15
+
16
+ const info = (str: string) => {
17
+ printer.info(chalk.hex('#37BA85')(str));
18
+ }
19
+
20
+ const error = (str: string) => {
21
+ printer.fail(chalk.hex('#FF4848')(str));
22
+ }
23
+
24
+ const warn = (str: string) => {
25
+ printer.warn(chalk.yellowBright(str));
26
+ }
27
+
28
+ const succeed = (str: string) => {
29
+ printer.succeed(chalk.greenBright(str));
30
+ }
31
+
32
+ export default {
33
+ start,
34
+ info,
35
+ error,
36
+ warn,
37
+ succeed,
38
+ }
@@ -22,7 +22,7 @@ const setRewriteUri = async (
22
22
  );
23
23
 
24
24
  const configId = rwriteResult?.DomainConfigList.DomainConfigModel[0].ConfigId;
25
- for (let i = 0; i <= 200; i++) {
25
+ for (let i = 0; i <= 100; i++) {
26
26
  const configInfo = await cdn.describeCdnDomainConfigs(domain, configId);
27
27
  const domainConfigs = configInfo.DomainConfigs.DomainConfig;
28
28
  let successCount = 0;
@@ -36,7 +36,7 @@ const setRewriteUri = async (
36
36
  if (successCount === domainConfigs.length) {
37
37
  break;
38
38
  }
39
- if (i === 200) {
39
+ if (i === 100) {
40
40
  throw new Error('cdn rewrite timeout 10min');
41
41
  }
42
42
  await delay(3000);
@@ -46,7 +46,7 @@ const setRewriteUri = async (
46
46
  const refreshCache = async (urls: string[], cdn: CDN) => {
47
47
  const refreshResult = await cdn.refreshCache(urls.join('\n'));
48
48
  console.log('Please Wait For RefreshCache...');
49
- for (let i = 0; i <= 200; i++) {
49
+ for (let i = 0; i <= 100; i++) {
50
50
  const desResult = await cdn.describeRefreshTaskById(
51
51
  refreshResult.RefreshTaskId
52
52
  );
@@ -61,7 +61,7 @@ const refreshCache = async (urls: string[], cdn: CDN) => {
61
61
  if (successCount === desResult.Tasks.length) {
62
62
  break;
63
63
  }
64
- if (i === 200) {
64
+ if (i === 100) {
65
65
  throw new Error('refresh cache timeout 10min');
66
66
  }
67
67
  await delay(3000);
package/lib/rig/index.ts CHANGED
@@ -1,30 +1,46 @@
1
+ import semver from 'semver';
2
+ import print from '../print';
3
+ import add from '../add';
4
+ import dev from '../dev';
5
+ import preinstall from '../preinstall';
6
+ import postinstall from '../postinstall';
7
+ import build from '../build';
8
+ import deploy from '../deploy';
9
+ import publish from '../publish';
10
+
11
+ import sync from '../sync';
12
+ const nodeMin = '14.0.0';
13
+ if (semver.gte(nodeMin,process.version)){
14
+ print.error('NodeJS version must be at least 14.');
15
+ process.exit(0);
16
+ }
1
17
  import {Command} from 'commander';
2
18
 
3
19
  const program = new Command();
4
- console.log('Hello');
5
20
 
6
21
  import check from '../check';
7
22
 
8
23
  program.command('check').action(check.load);
9
24
  import init from '../init';
10
25
 
11
- program.command('init').action(init.load);
26
+ program.command('init').action(init);
12
27
  import install from '../install';
13
28
 
14
- program.command('install').action(install.load);
15
- program.command('i').action(install.load);
16
- import preinstall from '../preinstall';
17
- import postinstall from '../postinstall';
29
+ program.command('install').action(install);
30
+ program.command('i').action(install);
18
31
 
19
- program.command('preinstall').action(preinstall.load);
20
- program.command('postinstall').action(postinstall.load);
32
+ program.command('preinstall').action(preinstall);
33
+ program.command('postinstall').action(postinstall);
21
34
  import tag from '../tag';
22
35
 
23
36
  program.command('tag').action(tag.load);
24
37
  import info from '../info';
25
38
 
26
39
  program.command('info').action(info.load);
27
- import build from '../build';
40
+
41
+ program.command('add').action(add);
42
+
43
+ program.command('dev').action(dev);
28
44
 
29
45
  program.command('build')
30
46
  .option('-s, --schema <schema>', 'specify params in tree_schema')
@@ -36,20 +52,20 @@ program.command('build')
36
52
  // .option('-s, --schema <schema>', 'specify params in tree_schema')
37
53
  // .option('-p , --params <params>', 'replace words in cicd.rig.json5, only words in ${} are replacable')
38
54
  // .action(define);
39
- import deploy from '../deploy';
40
-
41
55
  program.command('deploy')
42
56
  .option('-s, --schema <schema>', 'specify params in tree_schema')
43
57
  .option('-p , --params <params>', 'replace words in cicd.rig.json5, only words in ${} are replacable')
44
58
  .action(deploy);
45
59
 
46
- import publish from '../publish';
47
-
48
60
  program.command('publish')
49
61
  .option('-s, --schema <schema>', 'specify params in tree_schema')
50
62
  .option('-p , --params <params>', 'replace words in cicd.rig.json5, only words in ${} are replacable')
51
63
  .action(publish);
52
64
 
65
+ program.command('sync')
66
+ .option('-f, --force <force>', 'force to overwrite files from package.rig.json5')
67
+ .action(sync);
68
+
53
69
  import env from '../vue-env';
54
70
 
55
71
  program.option('--vueenv <vueenv>', 'specify vue env').action(env.load);
@@ -0,0 +1,4 @@
1
+ import path from 'path';
2
+ import url from 'url';
3
+
4
+ console.log(path.basename(url.parse('https://dafa.com/fafa.txt?a=1').pathname!));
@@ -0,0 +1,32 @@
1
+ import axios from 'axios';
2
+ import RigConfig from '@/classes/RigConfig';
3
+ import url from 'url';
4
+ import path from 'path';
5
+ import fs from 'fs';
6
+ import print from '../print';
7
+
8
+ const syncFile = async (shareContent: string, force: boolean = false) => {
9
+ const filename = path.basename(url.parse(shareContent).pathname!);
10
+ const shareFilePath = path.join(process.cwd(), filename);
11
+ if (fs.existsSync(shareFilePath) && !force) {
12
+ print.info(`${filename} already exists.`);
13
+ return;
14
+ }
15
+ print.info(`Start downloading ${filename}`);
16
+ const fileStr = (await axios.get(shareContent)).data;
17
+ fs.writeFileSync(shareFilePath, fileStr);
18
+ };
19
+ export default async (cmd: any) => {
20
+ const rigConfig = RigConfig.createFromCWD();
21
+ for (let key in rigConfig.share) {
22
+ if (Array.isArray(rigConfig.share[key])) {
23
+ const shareContentArr = rigConfig.share[key] as string[];
24
+ for (let shareContent of shareContentArr) {
25
+ await syncFile(shareContent, cmd.force);
26
+ }
27
+ } else {
28
+ const shareContent = rigConfig.share[key] as string;
29
+ await syncFile(shareContent, cmd.force);
30
+ }
31
+ }
32
+ }
@@ -5,6 +5,42 @@ const readCICDConfig = () => {
5
5
  const cicdStr = fs.readFileSync(`${process.cwd()}/cicd.rig.json5`);
6
6
  return JSON5.parse(cicdStr);
7
7
  }
8
+ /**
9
+ * 读取rig配置文件
10
+ * @param {string} path absolute path to config json5.
11
+ * @returns {any}
12
+ */
13
+ const readConfig = (path: string = '') => {
14
+ try {
15
+ if (path) {
16
+ const rigJson5Str = fs.readFileSync(path);
17
+ return JSON5.parse(rigJson5Str);
18
+ }
19
+ const rigJson5Str = fs.readFileSync(`${process.cwd()}/package.rig.json5`);
20
+ return JSON5.parse(rigJson5Str);
21
+ } catch (e) {
22
+ throw new Error(`readConfig failed:${e.message}`);
23
+ }
24
+ }
25
+
26
+ const writeConfig = (config: any, path: string = '') => {
27
+ try {
28
+ if (path) {
29
+ fs.writeFileSync(path, config.toString());
30
+ } else {
31
+ fs.writeFileSync(`${process.cwd()}/package.rig.json5`, config.toString());
32
+ }
33
+ } catch (e) {
34
+ throw new Error(`rig writeConfig failed:${e.message}`);
35
+ }
36
+ }
37
+ const readPkgStrInRepo = (rigRepoName: string) => {
38
+ return fs.readFileSync(`${process.cwd()}/rig_dev/${rigRepoName}/package.json`).toString();
39
+ }
40
+
8
41
  export default {
9
- readCICDConfig
42
+ readCICDConfig,
43
+ readConfig,
44
+ writeConfig,
45
+ readPkgStrInRepo
10
46
  }
@@ -0,0 +1,12 @@
1
+ const sortKeys = (obj: any) => {
2
+ return Object.keys(obj).sort().reduce(
3
+ (sortedObj: any, key) => {
4
+ sortedObj[key] = obj[key];
5
+ return sortedObj;
6
+ },
7
+ {}
8
+ );
9
+ }
10
+ export default {
11
+ sortKeys
12
+ }
@@ -0,0 +1,12 @@
1
+ import regexHelper from '@/utils/regexHelper';
2
+ test('matchGitName', () => {
3
+ const retGit = 'git@git.domain.com:f2e-common/r-test.git'.match(regexHelper.matchGitName);
4
+ const retHttp = 'https://git.domain.com/f2e-common/r-test.git'.match(regexHelper.matchGitName);
5
+ if (retGit) {
6
+ expect(retGit[2]).toContain('r-test');
7
+ }
8
+ if (retHttp) {
9
+ expect(retHttp[2]).toContain('r-test');
10
+ }
11
+ });
12
+
@@ -4,7 +4,9 @@
4
4
  * @author Wang Bo (ralwayne@163.com)
5
5
  * @date 2020/10/10 3:57 PM
6
6
  */
7
+ // `^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)`,
7
8
  const gitURL = /(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)(\/?|\#[-\d\w._]+?)$/;
9
+ const matchGitName = /^(git|http).*\/(.*)(\.git)$/;
8
10
  const path = /^(\/\w+){0,2}\/?$/;
9
11
  /**
10
12
  * 文字下划线中划线
@@ -14,5 +16,6 @@ const dynamicDir = /(^\[[\w\-]+\]$)|(^\{[\w\-]+\}$)/
14
16
  export default {
15
17
  gitURL,
16
18
  path,
17
- dynamicDir
19
+ dynamicDir,
20
+ matchGitName
18
21
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "rigjs",
3
- "version": "2.1.29",
4
- "description": "A multi-repos dev tool based on yarn and git.Rig is inspired by cocoapods. Not like those monorepo solutions,rig is a tool for organizing multi-repos.",
3
+ "version": "3.0.0-alpha",
4
+ "description": "A multi-repos dev tool based on yarn and git.Rigjs is intended to be the simplest way to develop,share and deliver codes between different developers or different projects.",
5
5
  "keywords": [
6
6
  "modular",
7
7
  "lerna",
8
8
  "monorepo",
9
9
  "multirepos",
10
- "cocoapods",
10
+ "carthage",
11
11
  "symlink",
12
12
  "npm link",
13
13
  "workspaces"
@@ -21,8 +21,7 @@
21
21
  },
22
22
  "scripts": {
23
23
  "test": "jest",
24
- "init": "cd demo && node ../lib/rig/index.js init",
25
- "i": "cd demo && node ../lib/rig/index.js install",
24
+ "test:init": "yarn build && cd demo && ts-node ../built/index.js init",
26
25
  "p": "cd demo && node ../lib/rig/index.js publish",
27
26
  "prei": "cd demo && node ../lib/rig/index.js preinstall",
28
27
  "posti": "cd demo && node ../lib/rig/index.js postinstall",
@@ -37,6 +36,7 @@
37
36
  "@types/ali-oss": "^6.16.3",
38
37
  "@types/json5": "^2.2.0",
39
38
  "@types/qs": "^6.9.7",
39
+ "@types/semver": "^7.3.10",
40
40
  "@types/shelljs": "^0.8.11",
41
41
  "@types/uuid": "^8.3.4",
42
42
  "ali-oss": "^6.17.1",
@@ -48,15 +48,16 @@
48
48
  "inquirer": "7.3.3",
49
49
  "json5": "2.1.3",
50
50
  "ora": "^5.1.0",
51
- "semver": "^7.3.6",
51
+ "semver": "^7.3.7",
52
52
  "shelljs": "^0.8.4",
53
53
  "uuid": "^8.3.2"
54
54
  },
55
55
  "devDependencies": {
56
- "@types/jest": "^27.4.1",
56
+ "@types/jest": "^28.1.1",
57
57
  "@types/node": "^17.0.21",
58
58
  "jest": "^27.5.1",
59
- "ts-node": "^10.7.0",
59
+ "ts-jest": "^28.0.5",
60
+ "ts-node": "^10.8.1",
60
61
  "typescript": "^4.6.3"
61
62
  }
62
63
  }
@@ -0,0 +1,8 @@
1
+ {
2
+ dependencies: {
3
+ 'rig-test-1': {
4
+ name: 'rig-test-1',
5
+ source: 'git@github.com:FlashHand/rig-test-1.git',
6
+ },
7
+ },
8
+ }
package/tsconfig.json CHANGED
@@ -15,7 +15,8 @@
15
15
  "outDir": "./built",
16
16
  "allowJs": true,
17
17
  "types": [
18
- "node"
18
+ "node",
19
+ "jest",
19
20
  ],
20
21
  "paths": {
21
22
  "@/*": [
@@ -38,9 +39,10 @@
38
39
  "include": [
39
40
  "index.ts",
40
41
  "rigs/**/*.ts",
41
- "src/**/*.ts",
42
42
  "lib/**/*.ts",
43
43
  "lib/**/*.d.ts",
44
+ "lib/**/*.test.ts",
45
+ "lib/**/*.spec.ts",
44
46
  "lib/**/*.js",
45
47
  "test/**/*.ts",
46
48
  "typings/**/*.ts",
@@ -1,56 +0,0 @@
1
- {
2
- tree_schema: 'ykp/{env}/{oem}',
3
- source: {
4
- root_path: 'dist',
5
- },
6
- target: {
7
- id: 'alicloud',
8
- type: 'alicloud',
9
- bucket: 'cdn-rys-com',
10
- region: 'oss-cn-beijing',
11
- access_key: '${ak}',
12
- access_secret: '${as}',
13
- root_path: '/',
14
- uri_rewrite: {
15
- original: '/',
16
- }
17
- },
18
- endpoints: {
19
- 'ykp/test/oem1': {
20
- build: 'cross-env PUBLIC_PATH=$public_path npx vue-cli-service build --mode oem1',
21
- defines: {
22
- NGINX_REPLACE_B: 'http://',
23
- NGINX_REPLACE_A: '替换了',
24
- RIG_REPLACE_PUBLIC: '$public_path',
25
- },
26
- domain: 'cdn.rys.com',
27
- },
28
- 'ykp/test/oem2': {
29
- // build: 'yarn build:test:oem2',
30
- build: 'cross-env PUBLIC_PATH=$public_path npx vue-cli-service build --mode oem2',
31
- defines: {
32
- NGINX_REPLACE_B: 'http://',
33
- NGINX_REPLACE_A: '替换了',
34
- },
35
- domain: 'cdn.rys.com'
36
- },
37
- },
38
- groups: [
39
- {
40
- name: '%group1',
41
- level: 'oem',
42
- includes: [
43
- 'rys',
44
- 'zhs',
45
- ],
46
- },
47
- {
48
- name: '%group1',
49
- level: 'oem',
50
- includes: [
51
- 'zhs',
52
- 'cy',
53
- ],
54
- }
55
- ],
56
- }
@@ -1,11 +0,0 @@
1
- {
2
- tree_schema: '{app}/{env}/{oem}',
3
- source: {
4
- root_path: 'dist',
5
- },
6
- target: {},
7
- endpoints: {
8
-
9
- },
10
- groups: [],
11
- }
@@ -1,6 +0,0 @@
1
- declare namespace init {
2
- const name: string;
3
-
4
- function load(): void;
5
- }
6
- export default init;
package/lib/init/index.js DELETED
@@ -1,189 +0,0 @@
1
- /**
2
- * @ignore
3
- * @Description nothing
4
- * @author Wang Bo (ralwayne@163.com)
5
- * @date 2020/10/9 6:14 PM
6
- */
7
- const fs = require('fs');
8
- const json5 = require('json5');
9
- const chalk = require('chalk');
10
- let log = console.log;
11
- let green = chalk.green;
12
- let redBright = chalk.redBright;
13
-
14
- //加载命令控制器
15
-
16
- const load = async () => {
17
- try {
18
- console.log(chalk.blue('exec init'));
19
- const pkg = JSON.parse(fs.readFileSync(`${process.cwd()}/package.json`));
20
-
21
-
22
-
23
- //检查当前目录是否存在package.json
24
- if (!(fs.existsSync('package.json') && fs.lstatSync('package.json').isFile())) {
25
- console.log(chalk.red('Please run this in the root directory of project!Must have a validate package.json'));
26
- return;
27
- }
28
- //检查是否存在package.rig.json5
29
- if (fs.existsSync('package.rig.json5')) {
30
- console.log(chalk.green('package.rig.json5 already exists~'));
31
- } else {
32
- //创建package.rig.json5.json5
33
- let template = `[
34
- // {
35
- // name: "your project name",
36
- // source: "git ssh url",
37
- // version: "semver version(like 1.0.0)",
38
- // },
39
- ]
40
- `
41
- console.log(chalk.green('create package.rig.json5'));
42
- fs.writeFileSync('./package.rig.json5', template);
43
- }
44
- if (fs.existsSync(`${process.cwd()}/rig_helper.js`)) {
45
- console.log(chalk.green('rig_helper.js already exists~'));
46
- } else {
47
- console.log(chalk.green('create rig_helper.js'));
48
- let template = `const json5 = require('json5');
49
- const fs = require('fs');
50
- const getPkgs = () => {
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;
57
- }
58
-
59
- module.exports = {
60
- \tgetPkgs
61
- }
62
- `
63
- fs.writeFileSync(`${process.cwd()}/rig_helper.js`, template);
64
- }
65
- //检查是否存在cicd.rig.json5
66
- if (fs.existsSync(`${process.cwd()}/cicd.rig.json5`)) {
67
- console.log(chalk.green('cicd.rig.json5 already exists~'));
68
- } else {
69
- console.log(chalk.green('create cicd.rig.json5'));
70
- let template = `{
71
- tree_schema: '{app}/{env}/{oem}',
72
- source: {
73
- root_path: 'dist',
74
- },
75
- target: {},
76
- endpoints: {},
77
- groups: [],
78
- }
79
- `;
80
- fs.writeFileSync(`${process.cwd()}/cicd.rig.json5`, template);
81
-
82
- }
83
- //检查是否存在env.rig.json5
84
- if (fs.existsSync(`${process.cwd()}/env.rig.json5`)) {
85
- console.log(chalk.green('env.rig.json5 already exists~'));
86
- } else {
87
- console.log(chalk.green('create env.rig.json5'));
88
- let template = `{}`;
89
- fs.writeFileSync(`${process.cwd()}/cicd.rig.json5`, template);
90
- }
91
- //检查rigs是否存在
92
- if (fs.existsSync('./rigs') && fs.lstatSync('./rigs').isDirectory()) {
93
- console.log(chalk.green('folder rigs already exists~'));
94
- } else {
95
- console.log(chalk.green('create folder rigs'));
96
- fs.mkdirSync('rigs');
97
- fs.writeFileSync('rigs/.gitkeep', '')
98
-
99
- }
100
- //检查rigs_dev是否存在
101
- // if (fs.existsSync('./rigs_dev') && fs.lstatSync('./rigs_dev').isDirectory()) {
102
- // console.log(green('folder rigs_dev already exists~'));
103
- // } else {
104
- // console.log(green('create folder rigs_dev'));
105
- // fs.mkdirSync('rigs_dev');
106
- // fs.writeFileSync('rigs_dev/.gitkeep', '')
107
- // }
108
- //填充gitignore
109
- let rigIgnoreStrArr = [
110
- 'rigs/*',
111
- 'rigs_dev/*',
112
- '.env.rig',
113
- '!rigs/.gitkeep',
114
- '!rigs_dev/.gitkeep'
115
- ];
116
- let gitignoreStr = ''
117
- if (fs.existsSync('.gitignore')) {
118
- gitignoreStr = fs.readFileSync('.gitignore').toString();
119
- }
120
- for (let i of rigIgnoreStrArr) {
121
- if (gitignoreStr.indexOf(i) > -1) {
122
- console.log(green(`${i} already in .gitignore`))
123
- } else {
124
- console.log(green(`append ${i} to .gitignore`));
125
- gitignoreStr += '\n' + i;
126
- }
127
- }
128
- fs.writeFileSync('.gitignore', gitignoreStr);
129
- //modify package.json
130
- let pkgJSONStr = fs.readFileSync('./package.json').toString();
131
- let pkgJSON = JSON.parse(pkgJSONStr);
132
- let inserted = {
133
- private: true,
134
- workspaces: [
135
- "rigs/*",
136
- "rigs_dev/*"
137
- ],
138
- scripts: {
139
- preinstall: "rig preinstall",
140
- postinstall: "rig postinstall",
141
- },
142
- devDependencies: {
143
- json5: '2.1.3'
144
- }
145
- }
146
- pkgJSON.private = inserted.private;
147
- //初始化workspaces
148
- if (pkgJSON.workspaces && pkgJSON.workspaces instanceof Array) {
149
- if (pkgJSON.workspaces.indexOf('rigs/*') === -1) {
150
- pkgJSON.workspaces.push('rigs/*')
151
- }
152
- if (pkgJSON.workspaces.indexOf('rigs_dev/*') === -1) {
153
- pkgJSON.workspaces.push('rigs_dev/*')
154
- }
155
-
156
- } else {
157
- pkgJSON.workspaces = inserted.workspaces
158
- }
159
- //初始化pre/post-install
160
- if (pkgJSON.scripts && pkgJSON.scripts instanceof Object) {
161
- if (pkgJSON.scripts.preinstall && pkgJSON.scripts.preinstall.indexOf(inserted.scripts.preinstall) < 0) {
162
- pkgJSON.scripts.preinstall = `${pkgJSON.scripts.preinstall} && ${inserted.scripts.preinstall}`
163
- } else {
164
- pkgJSON.scripts.preinstall = inserted.scripts.preinstall;
165
- }
166
- if (pkgJSON.scripts.postinstall && pkgJSON.scripts.postinstall.indexOf(inserted.scripts.postinstall) < 0) {
167
- pkgJSON.scripts.postinstall = `${pkgJSON.scripts.postinstall} && ${inserted.scripts.postinstall}`
168
- } else {
169
- pkgJSON.scripts.postinstall = inserted.scripts.postinstall;
170
- }
171
- } else {
172
- pkgJSON.scripts = inserted.scripts
173
- }
174
- if (pkgJSON.devDependencies) {
175
- //TODO:可优化
176
- pkgJSON.devDependencies.json5 = inserted.devDependencies.json5;
177
- } else {
178
- pkgJSON.devDependencies = inserted.devDependencies;
179
- }
180
- fs.writeFileSync('package.json', JSON.stringify(pkgJSON, null, 2));
181
- log(green('package.json updated'))
182
- } catch (e) {
183
- log(redBright(e.message));
184
- }
185
- }
186
- module.exports = {
187
- name: 'init',
188
- load
189
- }
@@ -1,14 +0,0 @@
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
- }
@@ -1,5 +0,0 @@
1
- declare namespace install {
2
- function load(): void;
3
-
4
- }
5
- export default install;
@@ -1,6 +0,0 @@
1
- declare namespace postinstall {
2
- function load(): void;
3
- const name: string;
4
-
5
- }
6
- export default postinstall;
@@ -1,7 +0,0 @@
1
- declare namespace preinstall {
2
- function load(): void;
3
- const name: string;
4
- const checkDepsValid: (rigJSON5:any) => void
5
-
6
- }
7
- export default preinstall;