rigjs 2.1.29 → 3.0.1-alpha.2
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.
- package/README.md +146 -183
- package/README_CN.md +144 -141
- package/built/index.js +143 -173
- package/demo/package.json +8 -6
- package/demo/package.rig.json5 +64 -10
- package/demo/rig_dev/.gitkeep +0 -0
- package/demo/rig_helper.js +5 -9
- package/demo/vue.config.js +1 -1
- package/doc/cicd_cn.md +120 -0
- package/doc/cmd_cn.md +0 -0
- package/doc/dependencies.md +0 -0
- package/doc/dependencies_cn.md +28 -0
- package/doc/share_cn.md +8 -0
- package/jest/test.rig.json5 +14 -0
- package/jest.config.ts +10 -1
- package/lib/add/index.ts +37 -0
- package/lib/build/build.md +6 -0
- package/lib/build/index.ts +64 -59
- package/lib/classes/RigConfig.test.ts +14 -0
- package/lib/classes/RigConfig.ts +191 -0
- package/lib/classes/cicd/CICD.ts +6 -7
- package/lib/classes/cicd/CICDCmd.ts +1 -0
- package/lib/classes/cicd/DirLevel.ts +1 -1
- package/lib/classes/cicd/Endpoint.ts +7 -1
- package/lib/classes/dependencies/Dep.ts +56 -0
- package/lib/dev/index.ts +44 -0
- package/lib/init/index.ts +118 -0
- package/lib/install/{index.js → index.ts} +3 -6
- package/lib/postinstall/{index.js → index.ts} +12 -20
- package/lib/preinstall/index.ts +78 -0
- package/lib/print/index.ts +38 -0
- package/lib/publish/index.ts +4 -4
- package/lib/rig/index.ts +29 -13
- package/lib/sync/index.test.ts +4 -0
- package/lib/sync/index.ts +32 -0
- package/lib/utils/fsHelper.ts +37 -1
- package/lib/utils/objectHelper.ts +12 -0
- package/lib/utils/regexHelper.test.ts +12 -0
- package/lib/utils/{regex.ts → regexHelper.ts} +4 -1
- package/package.json +10 -8
- package/package.rig.json5 +8 -0
- package/tsconfig.json +4 -2
- package/demo/cicd.rig.json5 +0 -56
- package/demo/yarn.lock +0 -6068
- package/lib/init/cicd.rig.json5 +0 -11
- package/lib/init/index.d.ts +0 -6
- package/lib/init/index.js +0 -189
- package/lib/init/rig_helper.js +0 -14
- package/lib/install/index.d.ts +0 -5
- package/lib/postinstall/index.d.ts +0 -6
- package/lib/preinstall/index.d.ts +0 -7
- package/lib/preinstall/index.js +0 -198
- package/lib/preinstall/index.test.js +0 -16
- 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
|
+
}
|
package/lib/publish/index.ts
CHANGED
|
@@ -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 <=
|
|
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 ===
|
|
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 <=
|
|
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 ===
|
|
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
|
|
26
|
+
program.command('init').action(init);
|
|
12
27
|
import install from '../install';
|
|
13
28
|
|
|
14
|
-
program.command('install').action(install
|
|
15
|
-
program.command('i').action(install
|
|
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
|
|
20
|
-
program.command('postinstall').action(postinstall
|
|
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
|
-
|
|
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,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
|
+
}
|
package/lib/utils/fsHelper.ts
CHANGED
|
@@ -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
|
+
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": "
|
|
4
|
-
"description": "A multi-repos dev tool based on yarn and git.
|
|
3
|
+
"version": "3.0.1-alpha.2",
|
|
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
|
-
"
|
|
10
|
+
"carthage",
|
|
11
11
|
"symlink",
|
|
12
12
|
"npm link",
|
|
13
13
|
"workspaces"
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"test": "jest",
|
|
24
|
-
"init": "cd demo && node ../
|
|
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",
|
|
29
28
|
"c": "d demo && node ../lib/rig/index.js check",
|
|
30
29
|
"envmake": "cd demo && node ../lib/rig/index.js --env prod_view_zhs",
|
|
31
30
|
"t": "node lib/rig/index.js tag",
|
|
31
|
+
"publish": "npm publish --registry=https://registry.npmjs.org",
|
|
32
32
|
"deliver": "rig tag & yarn build & npm publish --registry=https://registry.npmjs.org",
|
|
33
33
|
"deliver:alpha": "rig tag & yarn build & npm publish --registry=https://registry.npmjs.org --tag alpha",
|
|
34
34
|
"build": "esbuild lib/rig/index.ts --platform=node --bundle --sourcemap=inline --minify --outfile=built/index.js --external:shelljs"
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@types/ali-oss": "^6.16.3",
|
|
38
38
|
"@types/json5": "^2.2.0",
|
|
39
39
|
"@types/qs": "^6.9.7",
|
|
40
|
+
"@types/semver": "^7.3.10",
|
|
40
41
|
"@types/shelljs": "^0.8.11",
|
|
41
42
|
"@types/uuid": "^8.3.4",
|
|
42
43
|
"ali-oss": "^6.17.1",
|
|
@@ -48,15 +49,16 @@
|
|
|
48
49
|
"inquirer": "7.3.3",
|
|
49
50
|
"json5": "2.1.3",
|
|
50
51
|
"ora": "^5.1.0",
|
|
51
|
-
"semver": "^7.3.
|
|
52
|
+
"semver": "^7.3.7",
|
|
52
53
|
"shelljs": "^0.8.4",
|
|
53
54
|
"uuid": "^8.3.2"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@types/jest": "^
|
|
57
|
+
"@types/jest": "^28.1.1",
|
|
57
58
|
"@types/node": "^17.0.21",
|
|
58
59
|
"jest": "^27.5.1",
|
|
59
|
-
"ts-
|
|
60
|
+
"ts-jest": "^28.0.5",
|
|
61
|
+
"ts-node": "^10.8.1",
|
|
60
62
|
"typescript": "^4.6.3"
|
|
61
63
|
}
|
|
62
64
|
}
|
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",
|
package/demo/cicd.rig.json5
DELETED
|
@@ -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
|
-
}
|