@rife/cli 0.0.6-beta.15 → 0.0.6-beta.16
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/dist/cjs/plugin/commander.cjs +5 -5
- package/dist/cjs/plugin/config.cjs +4 -4
- package/dist/cjs/plugin/package.cjs +2 -2
- package/dist/cjs/plugin/release.cjs +16 -16
- package/dist/cjs/runner.cjs +5 -5
- package/dist/cjs/sync.cjs +1 -1
- package/dist/cjs/util.cjs +2 -2
- package/dist/cli.js +22 -0
- package/dist/cli.js.map +1 -0
- package/dist/esm/plugin/commander.mjs +5 -5
- package/dist/esm/plugin/config.mjs +4 -4
- package/dist/esm/plugin/package.mjs +2 -2
- package/dist/esm/plugin/release.mjs +16 -16
- package/dist/esm/runner.mjs +5 -5
- package/dist/esm/sync.mjs +1 -1
- package/dist/esm/util.mjs +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.js +18 -0
- package/dist/logger.js.map +1 -0
- package/dist/plugin/commander.js +47 -0
- package/dist/plugin/commander.js.map +1 -0
- package/dist/plugin/compiler/compiler.js +166 -0
- package/dist/plugin/compiler/compiler.js.map +1 -0
- package/dist/plugin/compiler/index.js +87 -0
- package/dist/plugin/compiler/index.js.map +1 -0
- package/dist/plugin/compiler/swc.js +48 -0
- package/dist/plugin/compiler/swc.js.map +1 -0
- package/dist/plugin/compiler/tsc.js +75 -0
- package/dist/plugin/compiler/tsc.js.map +1 -0
- package/dist/plugin/config.js +77 -0
- package/dist/plugin/config.js.map +1 -0
- package/dist/plugin/index.js +9 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/package.js +32 -0
- package/dist/plugin/package.js.map +1 -0
- package/dist/plugin/release.js +102 -0
- package/dist/plugin/release.js.map +1 -0
- package/dist/runner.js +82 -0
- package/dist/runner.js.map +1 -0
- package/dist/sync.js +60 -0
- package/dist/sync.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/util.js +14 -0
- package/dist/util.js.map +1 -0
- package/package.json +8 -8
- package/src/cli.ts +23 -23
- package/src/index.ts +3 -3
- package/src/logger.ts +17 -17
- package/src/plugin/commander.ts +49 -49
- package/src/plugin/config.ts +78 -78
- package/src/plugin/release.ts +113 -113
- package/src/runner.ts +132 -132
- package/src/sync.ts +63 -63
- package/src/util.ts +9 -9
package/src/plugin/config.ts
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
|
|
3
|
-
import type { Config, Plugin } from '../runner';
|
|
4
|
-
|
|
5
|
-
export function pluginConfig() {
|
|
6
|
-
const plugin: Plugin = {
|
|
7
|
-
name: pluginConfig.name,
|
|
8
|
-
apply: runner => {
|
|
9
|
-
const { logger, hook, config, command, fs, z } = runner;
|
|
10
|
-
const log = logger.withTag(pluginConfig.name);
|
|
11
|
-
|
|
12
|
-
hook.loadConfig.tapPromise(pluginConfig.name, async () => {
|
|
13
|
-
let filePath = '';
|
|
14
|
-
const mjs = 'app.mjs';
|
|
15
|
-
const fileNames = ['app.js', 'app.cjs', mjs];
|
|
16
|
-
let isEsm = false;
|
|
17
|
-
for (const fileName of fileNames) {
|
|
18
|
-
if (await fs.exists(fileName)) {
|
|
19
|
-
filePath = path.posix.resolve(fileName);
|
|
20
|
-
isEsm = fileName === mjs;
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
log.debug(`filePath %s`, filePath);
|
|
25
|
-
if (!filePath) {
|
|
26
|
-
log.error(`找不到配置文件 app.(c|m)?js`);
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
let all: Config[] = [];
|
|
30
|
-
if (isEsm) {
|
|
31
|
-
all = (await import(filePath)).default;
|
|
32
|
-
} else {
|
|
33
|
-
all = require(filePath);
|
|
34
|
-
}
|
|
35
|
-
runner.config.all = all;
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
hook.validateConfig.tapPromise(pluginConfig.name, async () => {
|
|
39
|
-
const validation = z
|
|
40
|
-
.array(
|
|
41
|
-
z.object({
|
|
42
|
-
name: z.string().trim().min(1),
|
|
43
|
-
}),
|
|
44
|
-
)
|
|
45
|
-
.min(1)
|
|
46
|
-
.safeParse(config.all);
|
|
47
|
-
if (!validation.success) {
|
|
48
|
-
log.error(validation.error.message);
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
hook.applyConfig.tapPromise(pluginConfig.name, async () => {
|
|
54
|
-
const result = z
|
|
55
|
-
.object({
|
|
56
|
-
name: z.string().trim().default(''),
|
|
57
|
-
})
|
|
58
|
-
.default({})
|
|
59
|
-
.safeParse(command.opts());
|
|
60
|
-
const name = result.data?.name;
|
|
61
|
-
if (!name) {
|
|
62
|
-
log.debug('没有指定 --name,默认使用列表第一个');
|
|
63
|
-
config.current = config.all[0];
|
|
64
|
-
} else {
|
|
65
|
-
log.debug(`指定 --name ${name}`);
|
|
66
|
-
const find = config.all.find(t => t.name === name);
|
|
67
|
-
if (!find) {
|
|
68
|
-
log.error(`未找到 name '%s'`, name);
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
config.current = find;
|
|
72
|
-
}
|
|
73
|
-
config.current.plugins.forEach(plugin => plugin.apply(runner));
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
return plugin;
|
|
78
|
-
}
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
import type { Config, Plugin } from '../runner';
|
|
4
|
+
|
|
5
|
+
export function pluginConfig() {
|
|
6
|
+
const plugin: Plugin = {
|
|
7
|
+
name: pluginConfig.name,
|
|
8
|
+
apply: runner => {
|
|
9
|
+
const { logger, hook, config, command, fs, z } = runner;
|
|
10
|
+
const log = logger.withTag(pluginConfig.name);
|
|
11
|
+
|
|
12
|
+
hook.loadConfig.tapPromise(pluginConfig.name, async () => {
|
|
13
|
+
let filePath = '';
|
|
14
|
+
const mjs = 'app.mjs';
|
|
15
|
+
const fileNames = ['app.js', 'app.cjs', mjs];
|
|
16
|
+
let isEsm = false;
|
|
17
|
+
for (const fileName of fileNames) {
|
|
18
|
+
if (await fs.exists(fileName)) {
|
|
19
|
+
filePath = path.posix.resolve(fileName);
|
|
20
|
+
isEsm = fileName === mjs;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
log.debug(`filePath %s`, filePath);
|
|
25
|
+
if (!filePath) {
|
|
26
|
+
log.error(`找不到配置文件 app.(c|m)?js`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
let all: Config[] = [];
|
|
30
|
+
if (isEsm) {
|
|
31
|
+
all = (await import(filePath)).default;
|
|
32
|
+
} else {
|
|
33
|
+
all = require(filePath);
|
|
34
|
+
}
|
|
35
|
+
runner.config.all = all;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
hook.validateConfig.tapPromise(pluginConfig.name, async () => {
|
|
39
|
+
const validation = z
|
|
40
|
+
.array(
|
|
41
|
+
z.object({
|
|
42
|
+
name: z.string().trim().min(1),
|
|
43
|
+
}),
|
|
44
|
+
)
|
|
45
|
+
.min(1)
|
|
46
|
+
.safeParse(config.all);
|
|
47
|
+
if (!validation.success) {
|
|
48
|
+
log.error(validation.error.message);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
hook.applyConfig.tapPromise(pluginConfig.name, async () => {
|
|
54
|
+
const result = z
|
|
55
|
+
.object({
|
|
56
|
+
name: z.string().trim().default(''),
|
|
57
|
+
})
|
|
58
|
+
.default({})
|
|
59
|
+
.safeParse(command.opts());
|
|
60
|
+
const name = result.data?.name;
|
|
61
|
+
if (!name) {
|
|
62
|
+
log.debug('没有指定 --name,默认使用列表第一个');
|
|
63
|
+
config.current = config.all[0];
|
|
64
|
+
} else {
|
|
65
|
+
log.debug(`指定 --name ${name}`);
|
|
66
|
+
const find = config.all.find(t => t.name === name);
|
|
67
|
+
if (!find) {
|
|
68
|
+
log.error(`未找到 name '%s'`, name);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
config.current = find;
|
|
72
|
+
}
|
|
73
|
+
config.current.plugins.forEach(plugin => plugin.apply(runner));
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
return plugin;
|
|
78
|
+
}
|
package/src/plugin/release.ts
CHANGED
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
2
|
-
|
|
3
|
-
import type { Plugin } from '../runner';
|
|
4
|
-
|
|
5
|
-
export function pluginRelease() {
|
|
6
|
-
const plugin: Plugin = {
|
|
7
|
-
name: pluginRelease.name,
|
|
8
|
-
apply: runner => {
|
|
9
|
-
const { logger, hook, fs } = runner;
|
|
10
|
-
const log = logger.withTag(pluginRelease.name);
|
|
11
|
-
hook.release.tapPromise(pluginRelease.name, async () => {
|
|
12
|
-
runner.clear();
|
|
13
|
-
await hook.build.promise();
|
|
14
|
-
|
|
15
|
-
log.start('开始发布');
|
|
16
|
-
const packageVersion = runner.package.version;
|
|
17
|
-
const packageName = runner.package.name;
|
|
18
|
-
const url = `https://registry.npmjs.org/${packageName}`;
|
|
19
|
-
let nextVersion = packageVersion;
|
|
20
|
-
log.debug(`查询版本号 ${packageVersion} 是否存在`);
|
|
21
|
-
const res = await (await fetch(url)).json();
|
|
22
|
-
const exist = res?.versions?.[packageVersion];
|
|
23
|
-
if (exist) {
|
|
24
|
-
const split = packageVersion.split('.');
|
|
25
|
-
split[split.length - 1] = Number(split[split.length - 1]) + 1;
|
|
26
|
-
nextVersion = split.join('.');
|
|
27
|
-
log.debug(`版本号 ${packageVersion} 存在,更新版本号为 ${nextVersion}`);
|
|
28
|
-
const text = fs.readFileSync('./package.json').toString();
|
|
29
|
-
const nextText = text.replace(new RegExp(`"version":\\s*"${packageVersion}"`), `"version": "${nextVersion}"`);
|
|
30
|
-
fs.writeFileSync('./package.json', nextText);
|
|
31
|
-
}
|
|
32
|
-
log.debug(`版本号 ${packageVersion} 不存在`);
|
|
33
|
-
log.info(`版本号为 ${nextVersion}`);
|
|
34
|
-
|
|
35
|
-
const tempDir = `./node_modules/.rife/release/`;
|
|
36
|
-
log.info(`清空目录 ${tempDir}`);
|
|
37
|
-
fs.emptyDirSync(tempDir);
|
|
38
|
-
|
|
39
|
-
const pack = `pnpm pack --pack-destination ${tempDir} --json`;
|
|
40
|
-
log.info(`打包文件 ${pack}`);
|
|
41
|
-
const packOutput = JSON.parse(execSync(pack).toString());
|
|
42
|
-
const filename = packOutput.filename;
|
|
43
|
-
for (const item of packOutput.files) {
|
|
44
|
-
log.debug(item.path);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const debug = false;
|
|
48
|
-
const publish = `pnpm publish ${filename} --registry https://registry.npmjs.org --no-git-checks ${
|
|
49
|
-
debug ? '--dry-run' : ''
|
|
50
|
-
}`;
|
|
51
|
-
log.info(`发布文件 ${publish}`);
|
|
52
|
-
execSync(publish, { stdio: 'inherit' });
|
|
53
|
-
log.success(`发布成功,${runner.duration}`);
|
|
54
|
-
|
|
55
|
-
log.info('同步版本');
|
|
56
|
-
let hasSync = false;
|
|
57
|
-
while (true) {
|
|
58
|
-
const res = await queryVersion(packageName);
|
|
59
|
-
const nextManifest = res?.versions?.[nextVersion];
|
|
60
|
-
const exist = Boolean(nextManifest);
|
|
61
|
-
const latest = res?.['dist-tags']?.latest;
|
|
62
|
-
if (exist) {
|
|
63
|
-
log.debug(`同步版本存在`);
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
log.info(`检查版本 ${nextVersion} 不存在,最新版本为 ${latest}`);
|
|
67
|
-
if (!hasSync) {
|
|
68
|
-
hasSync = true;
|
|
69
|
-
log.start(`开始同步`);
|
|
70
|
-
const sync = await syncVersion(packageName);
|
|
71
|
-
if (sync.ok === true) {
|
|
72
|
-
log.info(
|
|
73
|
-
`调用同步接口成功,日志 https://registry.npmmirror.com/-/package/${packageName}/syncs/${sync.id}/log`,
|
|
74
|
-
);
|
|
75
|
-
} else {
|
|
76
|
-
log.debug(`调用同步接口失败,%j`, sync);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
80
|
-
}
|
|
81
|
-
log.success(`同步成功,${runner.duration}`);
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
return plugin;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function queryVersion(packageName: string) {
|
|
89
|
-
const res = await (await fetch(`https://registry.npmmirror.com/${packageName}?t=${Math.random()}`)).json();
|
|
90
|
-
return res;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function syncVersion(packageName: string) {
|
|
94
|
-
const sync = await (
|
|
95
|
-
await fetch(`https://registry-direct.npmmirror.com/-/package/${packageName}/syncs`, {
|
|
96
|
-
headers: {
|
|
97
|
-
accept: '*/*',
|
|
98
|
-
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
|
99
|
-
'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
|
|
100
|
-
'sec-ch-ua-mobile': '?0',
|
|
101
|
-
'sec-ch-ua-platform': '"Windows"',
|
|
102
|
-
'sec-fetch-dest': 'empty',
|
|
103
|
-
'sec-fetch-mode': 'cors',
|
|
104
|
-
'sec-fetch-site': 'same-site',
|
|
105
|
-
Referer: 'https://npmmirror.com/',
|
|
106
|
-
'Referrer-Policy': 'strict-origin-when-cross-origin',
|
|
107
|
-
},
|
|
108
|
-
body: null,
|
|
109
|
-
method: 'PUT',
|
|
110
|
-
})
|
|
111
|
-
).json();
|
|
112
|
-
return sync;
|
|
113
|
-
}
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
|
|
3
|
+
import type { Plugin } from '../runner';
|
|
4
|
+
|
|
5
|
+
export function pluginRelease() {
|
|
6
|
+
const plugin: Plugin = {
|
|
7
|
+
name: pluginRelease.name,
|
|
8
|
+
apply: runner => {
|
|
9
|
+
const { logger, hook, fs } = runner;
|
|
10
|
+
const log = logger.withTag(pluginRelease.name);
|
|
11
|
+
hook.release.tapPromise(pluginRelease.name, async () => {
|
|
12
|
+
runner.clear();
|
|
13
|
+
await hook.build.promise();
|
|
14
|
+
|
|
15
|
+
log.start('开始发布');
|
|
16
|
+
const packageVersion = runner.package.version;
|
|
17
|
+
const packageName = runner.package.name;
|
|
18
|
+
const url = `https://registry.npmjs.org/${packageName}`;
|
|
19
|
+
let nextVersion = packageVersion;
|
|
20
|
+
log.debug(`查询版本号 ${packageVersion} 是否存在`);
|
|
21
|
+
const res = await (await fetch(url)).json();
|
|
22
|
+
const exist = res?.versions?.[packageVersion];
|
|
23
|
+
if (exist) {
|
|
24
|
+
const split = packageVersion.split('.');
|
|
25
|
+
split[split.length - 1] = Number(split[split.length - 1]) + 1;
|
|
26
|
+
nextVersion = split.join('.');
|
|
27
|
+
log.debug(`版本号 ${packageVersion} 存在,更新版本号为 ${nextVersion}`);
|
|
28
|
+
const text = fs.readFileSync('./package.json').toString();
|
|
29
|
+
const nextText = text.replace(new RegExp(`"version":\\s*"${packageVersion}"`), `"version": "${nextVersion}"`);
|
|
30
|
+
fs.writeFileSync('./package.json', nextText);
|
|
31
|
+
}
|
|
32
|
+
log.debug(`版本号 ${packageVersion} 不存在`);
|
|
33
|
+
log.info(`版本号为 ${nextVersion}`);
|
|
34
|
+
|
|
35
|
+
const tempDir = `./node_modules/.rife/release/`;
|
|
36
|
+
log.info(`清空目录 ${tempDir}`);
|
|
37
|
+
fs.emptyDirSync(tempDir);
|
|
38
|
+
|
|
39
|
+
const pack = `pnpm pack --pack-destination ${tempDir} --json`;
|
|
40
|
+
log.info(`打包文件 ${pack}`);
|
|
41
|
+
const packOutput = JSON.parse(execSync(pack).toString());
|
|
42
|
+
const filename = packOutput.filename;
|
|
43
|
+
for (const item of packOutput.files) {
|
|
44
|
+
log.debug(item.path);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const debug = false;
|
|
48
|
+
const publish = `pnpm publish ${filename} --registry https://registry.npmjs.org --no-git-checks ${
|
|
49
|
+
debug ? '--dry-run' : ''
|
|
50
|
+
}`;
|
|
51
|
+
log.info(`发布文件 ${publish}`);
|
|
52
|
+
execSync(publish, { stdio: 'inherit' });
|
|
53
|
+
log.success(`发布成功,${runner.duration}`);
|
|
54
|
+
|
|
55
|
+
log.info('同步版本');
|
|
56
|
+
let hasSync = false;
|
|
57
|
+
while (true) {
|
|
58
|
+
const res = await queryVersion(packageName);
|
|
59
|
+
const nextManifest = res?.versions?.[nextVersion];
|
|
60
|
+
const exist = Boolean(nextManifest);
|
|
61
|
+
const latest = res?.['dist-tags']?.latest;
|
|
62
|
+
if (exist) {
|
|
63
|
+
log.debug(`同步版本存在`);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
log.info(`检查版本 ${nextVersion} 不存在,最新版本为 ${latest}`);
|
|
67
|
+
if (!hasSync) {
|
|
68
|
+
hasSync = true;
|
|
69
|
+
log.start(`开始同步`);
|
|
70
|
+
const sync = await syncVersion(packageName);
|
|
71
|
+
if (sync.ok === true) {
|
|
72
|
+
log.info(
|
|
73
|
+
`调用同步接口成功,日志 https://registry.npmmirror.com/-/package/${packageName}/syncs/${sync.id}/log`,
|
|
74
|
+
);
|
|
75
|
+
} else {
|
|
76
|
+
log.debug(`调用同步接口失败,%j`, sync);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
80
|
+
}
|
|
81
|
+
log.success(`同步成功,${runner.duration}`);
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
return plugin;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function queryVersion(packageName: string) {
|
|
89
|
+
const res = await (await fetch(`https://registry.npmmirror.com/${packageName}?t=${Math.random()}`)).json();
|
|
90
|
+
return res;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function syncVersion(packageName: string) {
|
|
94
|
+
const sync = await (
|
|
95
|
+
await fetch(`https://registry-direct.npmmirror.com/-/package/${packageName}/syncs`, {
|
|
96
|
+
headers: {
|
|
97
|
+
accept: '*/*',
|
|
98
|
+
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
|
99
|
+
'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
|
|
100
|
+
'sec-ch-ua-mobile': '?0',
|
|
101
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
102
|
+
'sec-fetch-dest': 'empty',
|
|
103
|
+
'sec-fetch-mode': 'cors',
|
|
104
|
+
'sec-fetch-site': 'same-site',
|
|
105
|
+
Referer: 'https://npmmirror.com/',
|
|
106
|
+
'Referrer-Policy': 'strict-origin-when-cross-origin',
|
|
107
|
+
},
|
|
108
|
+
body: null,
|
|
109
|
+
method: 'PUT',
|
|
110
|
+
})
|
|
111
|
+
).json();
|
|
112
|
+
return sync;
|
|
113
|
+
}
|
package/src/runner.ts
CHANGED
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
import type { ConsolaInstance } from 'consola';
|
|
2
|
-
import { colors } from 'consola/utils';
|
|
3
|
-
import { AsyncSeriesHook } from 'tapable';
|
|
4
|
-
import zod from 'zod';
|
|
5
|
-
|
|
6
|
-
import { createLogger } from './logger';
|
|
7
|
-
import { fs, glob } from './util';
|
|
8
|
-
|
|
9
|
-
export interface Config {
|
|
10
|
-
name: string;
|
|
11
|
-
plugins: Plugin[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface Runner {
|
|
15
|
-
env: 'prod' | 'dev';
|
|
16
|
-
hook: {
|
|
17
|
-
loadPackage: AsyncSeriesHook<[]>;
|
|
18
|
-
loadConfig: AsyncSeriesHook<[]>;
|
|
19
|
-
validateConfig: AsyncSeriesHook<[]>;
|
|
20
|
-
applyConfig: AsyncSeriesHook<[]>;
|
|
21
|
-
validatePlugin: AsyncSeriesHook<[]>;
|
|
22
|
-
registerCommand: AsyncSeriesHook<[]>;
|
|
23
|
-
startCommand: AsyncSeriesHook<[]>;
|
|
24
|
-
finishCommand: AsyncSeriesHook<[]>;
|
|
25
|
-
dev: AsyncSeriesHook<[]>;
|
|
26
|
-
build: AsyncSeriesHook<[]>;
|
|
27
|
-
test: AsyncSeriesHook<[]>;
|
|
28
|
-
release: AsyncSeriesHook<[]>;
|
|
29
|
-
deploy: AsyncSeriesHook<[]>;
|
|
30
|
-
lint: AsyncSeriesHook<[]>;
|
|
31
|
-
};
|
|
32
|
-
logger: ConsolaInstance;
|
|
33
|
-
config: {
|
|
34
|
-
all: Config[];
|
|
35
|
-
current: Config;
|
|
36
|
-
};
|
|
37
|
-
command: import('commander').Command;
|
|
38
|
-
package: any;
|
|
39
|
-
z: typeof zod;
|
|
40
|
-
fs: typeof import('fs-extra');
|
|
41
|
-
glob: typeof import('glob')['glob'];
|
|
42
|
-
duration: string;
|
|
43
|
-
tempDir: string;
|
|
44
|
-
clear: () => void;
|
|
45
|
-
throwError: (message?: string, options?: ErrorOptions) => never;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface Plugin {
|
|
49
|
-
name: string;
|
|
50
|
-
apply: (runner: Runner) => any;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (typeof Promise.withResolvers === 'undefined') {
|
|
54
|
-
Promise.withResolvers = <T>() => {
|
|
55
|
-
let resolve: (value: T | PromiseLike<T>) => void;
|
|
56
|
-
let reject: (reason?: unknown) => void;
|
|
57
|
-
const promise = new Promise<T>((res, rej) => {
|
|
58
|
-
resolve = res;
|
|
59
|
-
reject = rej;
|
|
60
|
-
});
|
|
61
|
-
return { promise, resolve: resolve!, reject: reject! };
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function createRunner() {
|
|
66
|
-
const perfStart = performance.now();
|
|
67
|
-
|
|
68
|
-
const { Command } = require('commander') as typeof import('commander');
|
|
69
|
-
const command = new Command();
|
|
70
|
-
|
|
71
|
-
command.option('--debug', '打开调试日志');
|
|
72
|
-
command.option('-n, --name <string>', '执行指定配置');
|
|
73
|
-
command.option('-h, --help', '帮助');
|
|
74
|
-
command.parse();
|
|
75
|
-
|
|
76
|
-
const args = zod
|
|
77
|
-
.object({
|
|
78
|
-
debug: zod.boolean().default(false),
|
|
79
|
-
})
|
|
80
|
-
.default({})
|
|
81
|
-
.safeParse(command.opts());
|
|
82
|
-
|
|
83
|
-
const runner: Runner = {
|
|
84
|
-
env: 'prod',
|
|
85
|
-
hook: {
|
|
86
|
-
loadPackage: new AsyncSeriesHook([]),
|
|
87
|
-
loadConfig: new AsyncSeriesHook([]),
|
|
88
|
-
validateConfig: new AsyncSeriesHook([]),
|
|
89
|
-
applyConfig: new AsyncSeriesHook([]),
|
|
90
|
-
validatePlugin: new AsyncSeriesHook([]),
|
|
91
|
-
registerCommand: new AsyncSeriesHook([]),
|
|
92
|
-
startCommand: new AsyncSeriesHook([]),
|
|
93
|
-
finishCommand: new AsyncSeriesHook([]),
|
|
94
|
-
dev: new AsyncSeriesHook([]),
|
|
95
|
-
build: new AsyncSeriesHook([]),
|
|
96
|
-
test: new AsyncSeriesHook([]),
|
|
97
|
-
release: new AsyncSeriesHook([]),
|
|
98
|
-
deploy: new AsyncSeriesHook([]),
|
|
99
|
-
lint: new AsyncSeriesHook([]),
|
|
100
|
-
},
|
|
101
|
-
logger: createLogger(args.data),
|
|
102
|
-
command,
|
|
103
|
-
config: {
|
|
104
|
-
all: [],
|
|
105
|
-
// @ts-expect-error
|
|
106
|
-
current: undefined,
|
|
107
|
-
},
|
|
108
|
-
package: {},
|
|
109
|
-
z: zod,
|
|
110
|
-
fs,
|
|
111
|
-
glob: glob.glob,
|
|
112
|
-
get duration() {
|
|
113
|
-
const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
|
|
114
|
-
return `耗时 ${duration} s`;
|
|
115
|
-
},
|
|
116
|
-
tempDir: './node_modules/.rife/',
|
|
117
|
-
clear: () => {
|
|
118
|
-
console.clear();
|
|
119
|
-
process.stdout.write('\x1b[3J');
|
|
120
|
-
console.log(`${colors.bgBlue(' 项目名称 ')} ${runner.package.name} \n`);
|
|
121
|
-
},
|
|
122
|
-
throwError: (message?: string, options?: ErrorOptions) => {
|
|
123
|
-
throw new Error(message, options);
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
return runner;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function defineConfig(all: Config[]) {
|
|
131
|
-
return all;
|
|
132
|
-
}
|
|
1
|
+
import type { ConsolaInstance } from 'consola';
|
|
2
|
+
import { colors } from 'consola/utils';
|
|
3
|
+
import { AsyncSeriesHook } from 'tapable';
|
|
4
|
+
import zod from 'zod';
|
|
5
|
+
|
|
6
|
+
import { createLogger } from './logger';
|
|
7
|
+
import { fs, glob } from './util';
|
|
8
|
+
|
|
9
|
+
export interface Config {
|
|
10
|
+
name: string;
|
|
11
|
+
plugins: Plugin[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface Runner {
|
|
15
|
+
env: 'prod' | 'dev';
|
|
16
|
+
hook: {
|
|
17
|
+
loadPackage: AsyncSeriesHook<[]>;
|
|
18
|
+
loadConfig: AsyncSeriesHook<[]>;
|
|
19
|
+
validateConfig: AsyncSeriesHook<[]>;
|
|
20
|
+
applyConfig: AsyncSeriesHook<[]>;
|
|
21
|
+
validatePlugin: AsyncSeriesHook<[]>;
|
|
22
|
+
registerCommand: AsyncSeriesHook<[]>;
|
|
23
|
+
startCommand: AsyncSeriesHook<[]>;
|
|
24
|
+
finishCommand: AsyncSeriesHook<[]>;
|
|
25
|
+
dev: AsyncSeriesHook<[]>;
|
|
26
|
+
build: AsyncSeriesHook<[]>;
|
|
27
|
+
test: AsyncSeriesHook<[]>;
|
|
28
|
+
release: AsyncSeriesHook<[]>;
|
|
29
|
+
deploy: AsyncSeriesHook<[]>;
|
|
30
|
+
lint: AsyncSeriesHook<[]>;
|
|
31
|
+
};
|
|
32
|
+
logger: ConsolaInstance;
|
|
33
|
+
config: {
|
|
34
|
+
all: Config[];
|
|
35
|
+
current: Config;
|
|
36
|
+
};
|
|
37
|
+
command: import('commander').Command;
|
|
38
|
+
package: any;
|
|
39
|
+
z: typeof zod;
|
|
40
|
+
fs: typeof import('fs-extra');
|
|
41
|
+
glob: typeof import('glob')['glob'];
|
|
42
|
+
duration: string;
|
|
43
|
+
tempDir: string;
|
|
44
|
+
clear: () => void;
|
|
45
|
+
throwError: (message?: string, options?: ErrorOptions) => never;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface Plugin {
|
|
49
|
+
name: string;
|
|
50
|
+
apply: (runner: Runner) => any;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (typeof Promise.withResolvers === 'undefined') {
|
|
54
|
+
Promise.withResolvers = <T>() => {
|
|
55
|
+
let resolve: (value: T | PromiseLike<T>) => void;
|
|
56
|
+
let reject: (reason?: unknown) => void;
|
|
57
|
+
const promise = new Promise<T>((res, rej) => {
|
|
58
|
+
resolve = res;
|
|
59
|
+
reject = rej;
|
|
60
|
+
});
|
|
61
|
+
return { promise, resolve: resolve!, reject: reject! };
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function createRunner() {
|
|
66
|
+
const perfStart = performance.now();
|
|
67
|
+
|
|
68
|
+
const { Command } = require('commander') as typeof import('commander');
|
|
69
|
+
const command = new Command();
|
|
70
|
+
|
|
71
|
+
command.option('--debug', '打开调试日志');
|
|
72
|
+
command.option('-n, --name <string>', '执行指定配置');
|
|
73
|
+
command.option('-h, --help', '帮助');
|
|
74
|
+
command.parse();
|
|
75
|
+
|
|
76
|
+
const args = zod
|
|
77
|
+
.object({
|
|
78
|
+
debug: zod.boolean().default(false),
|
|
79
|
+
})
|
|
80
|
+
.default({})
|
|
81
|
+
.safeParse(command.opts());
|
|
82
|
+
|
|
83
|
+
const runner: Runner = {
|
|
84
|
+
env: 'prod',
|
|
85
|
+
hook: {
|
|
86
|
+
loadPackage: new AsyncSeriesHook([]),
|
|
87
|
+
loadConfig: new AsyncSeriesHook([]),
|
|
88
|
+
validateConfig: new AsyncSeriesHook([]),
|
|
89
|
+
applyConfig: new AsyncSeriesHook([]),
|
|
90
|
+
validatePlugin: new AsyncSeriesHook([]),
|
|
91
|
+
registerCommand: new AsyncSeriesHook([]),
|
|
92
|
+
startCommand: new AsyncSeriesHook([]),
|
|
93
|
+
finishCommand: new AsyncSeriesHook([]),
|
|
94
|
+
dev: new AsyncSeriesHook([]),
|
|
95
|
+
build: new AsyncSeriesHook([]),
|
|
96
|
+
test: new AsyncSeriesHook([]),
|
|
97
|
+
release: new AsyncSeriesHook([]),
|
|
98
|
+
deploy: new AsyncSeriesHook([]),
|
|
99
|
+
lint: new AsyncSeriesHook([]),
|
|
100
|
+
},
|
|
101
|
+
logger: createLogger(args.data),
|
|
102
|
+
command,
|
|
103
|
+
config: {
|
|
104
|
+
all: [],
|
|
105
|
+
// @ts-expect-error
|
|
106
|
+
current: undefined,
|
|
107
|
+
},
|
|
108
|
+
package: {},
|
|
109
|
+
z: zod,
|
|
110
|
+
fs,
|
|
111
|
+
glob: glob.glob,
|
|
112
|
+
get duration() {
|
|
113
|
+
const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
|
|
114
|
+
return `耗时 ${duration} s`;
|
|
115
|
+
},
|
|
116
|
+
tempDir: './node_modules/.rife/',
|
|
117
|
+
clear: () => {
|
|
118
|
+
console.clear();
|
|
119
|
+
process.stdout.write('\x1b[3J');
|
|
120
|
+
console.log(`${colors.bgBlue(' 项目名称 ')} ${runner.package.name} \n`);
|
|
121
|
+
},
|
|
122
|
+
throwError: (message?: string, options?: ErrorOptions) => {
|
|
123
|
+
throw new Error(message, options);
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
return runner;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function defineConfig(all: Config[]) {
|
|
131
|
+
return all;
|
|
132
|
+
}
|