@rife/cli 0.0.6-beta.14 → 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/logger.cjs +2 -0
- package/dist/cjs/plugin/commander.cjs +5 -5
- package/dist/cjs/plugin/config.cjs +4 -4
- package/dist/cjs/plugin/index.cjs +3 -12
- package/dist/cjs/plugin/package.cjs +2 -2
- package/dist/cjs/plugin/release.cjs +16 -16
- package/dist/cjs/runner.cjs +9 -6
- 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/cli.mjs +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/logger.mjs +3 -1
- package/dist/esm/plugin/commander.mjs +6 -6
- package/dist/esm/plugin/config.mjs +6 -6
- package/dist/esm/plugin/index.mjs +1 -2
- package/dist/esm/plugin/package.mjs +4 -4
- package/dist/esm/plugin/release.mjs +17 -17
- package/dist/esm/runner.mjs +14 -11
- package/dist/esm/sync.mjs +2 -2
- package/dist/esm/util.mjs +4 -4
- 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/{src/plugin/compiler/compiler.ts → dist/plugin/compiler/compiler.js} +39 -71
- 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/{src/plugin/compiler/swc.ts → dist/plugin/compiler/swc.js} +48 -56
- package/dist/plugin/compiler/swc.js.map +1 -0
- package/{src/plugin/compiler/tsc.ts → dist/plugin/compiler/tsc.js} +75 -101
- 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 -18
- package/src/cli.ts +23 -23
- package/src/index.ts +3 -9
- package/src/logger.ts +17 -16
- package/src/plugin/commander.ts +49 -49
- package/src/plugin/config.ts +78 -78
- package/src/plugin/index.ts +0 -1
- package/src/plugin/release.ts +113 -113
- package/src/runner.ts +132 -128
- package/src/sync.ts +63 -63
- package/src/util.ts +9 -9
- package/dist/cjs/plugin/compiler/compiler.cjs +0 -207
- package/dist/cjs/plugin/compiler/index.cjs +0 -126
- package/dist/cjs/plugin/compiler/swc.cjs +0 -107
- package/dist/cjs/plugin/compiler/tsc.cjs +0 -115
- package/dist/esm/plugin/compiler/compiler.mjs +0 -160
- package/dist/esm/plugin/compiler/index.mjs +0 -94
- package/dist/esm/plugin/compiler/swc.mjs +0 -75
- package/dist/esm/plugin/compiler/tsc.mjs +0 -73
- package/src/plugin/compiler/index.ts +0 -115
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rife/cli",
|
|
3
|
-
"version": "0.0.6-beta.
|
|
3
|
+
"version": "0.0.6-beta.16",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -18,35 +18,25 @@
|
|
|
18
18
|
"src/**/*"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@swc/cli": "^0.6.0",
|
|
22
|
-
"@swc/core": "^1.12.9",
|
|
23
|
-
"@swc/helpers": "^0.5.17",
|
|
24
|
-
"chokidar": "^4.0.3",
|
|
25
21
|
"commander": "^10.0.1",
|
|
26
22
|
"consola": "^3.4.2",
|
|
27
|
-
"
|
|
28
|
-
"eslint": "^9.30.1",
|
|
29
|
-
"fs-extra": "^11.3.0",
|
|
23
|
+
"fs-extra": "^11.3.2",
|
|
30
24
|
"glob": "^11.0.3",
|
|
31
|
-
"tapable": "^2.
|
|
32
|
-
"
|
|
33
|
-
"typescript": "^5.8.3",
|
|
34
|
-
"zod": "^3.25.71"
|
|
25
|
+
"tapable": "^2.3.0",
|
|
26
|
+
"zod": "^3.25.76"
|
|
35
27
|
},
|
|
36
28
|
"devDependencies": {
|
|
37
|
-
"@rslib/core": "^0.
|
|
29
|
+
"@rslib/core": "^0.17.2",
|
|
38
30
|
"@types/fs-extra": "^11.0.4",
|
|
39
31
|
"@types/node": "^22.16.0",
|
|
40
|
-
"vitest": "^
|
|
41
|
-
"@
|
|
32
|
+
"vitest": "^4.0.0",
|
|
33
|
+
"@rsbuild/plugin-type-check": "^1.3.0",
|
|
34
|
+
"@rife/config": "0.0.6-beta.10"
|
|
42
35
|
},
|
|
43
36
|
"rife": {
|
|
44
37
|
"hostDependencies": {
|
|
45
|
-
"tslib": "prod",
|
|
46
|
-
"@swc/helpers": "prod",
|
|
47
38
|
"@types/node": true,
|
|
48
39
|
"@rife/config": true,
|
|
49
|
-
"vitest": true,
|
|
50
40
|
"fs-extra": true,
|
|
51
41
|
"@types/fs-extra": true
|
|
52
42
|
}
|
package/src/cli.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { pluginCommander, pluginConfig, pluginPackage, pluginRelease } from './plugin';
|
|
2
|
-
import { Plugin, createRunner } from './runner';
|
|
3
|
-
|
|
4
|
-
const plugins: Plugin[] = [
|
|
5
|
-
pluginPackage(), //
|
|
6
|
-
pluginConfig(),
|
|
7
|
-
pluginCommander(),
|
|
8
|
-
pluginRelease(),
|
|
9
|
-
];
|
|
10
|
-
|
|
11
|
-
const runner = createRunner();
|
|
12
|
-
|
|
13
|
-
plugins.forEach(plugin => plugin.apply(runner));
|
|
14
|
-
|
|
15
|
-
(async () => {
|
|
16
|
-
await runner.hook.loadPackage.promise();
|
|
17
|
-
await runner.hook.loadConfig.promise();
|
|
18
|
-
await runner.hook.validateConfig.promise();
|
|
19
|
-
await runner.hook.applyConfig.promise();
|
|
20
|
-
await runner.hook.validatePlugin.promise();
|
|
21
|
-
await runner.hook.registerCommand.promise();
|
|
22
|
-
await runner.hook.startCommand.promise();
|
|
23
|
-
})();
|
|
1
|
+
import { pluginCommander, pluginConfig, pluginPackage, pluginRelease } from './plugin';
|
|
2
|
+
import { Plugin, createRunner } from './runner';
|
|
3
|
+
|
|
4
|
+
const plugins: Plugin[] = [
|
|
5
|
+
pluginPackage(), //
|
|
6
|
+
pluginConfig(),
|
|
7
|
+
pluginCommander(),
|
|
8
|
+
pluginRelease(),
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const runner = createRunner();
|
|
12
|
+
|
|
13
|
+
plugins.forEach(plugin => plugin.apply(runner));
|
|
14
|
+
|
|
15
|
+
(async () => {
|
|
16
|
+
await runner.hook.loadPackage.promise();
|
|
17
|
+
await runner.hook.loadConfig.promise();
|
|
18
|
+
await runner.hook.validateConfig.promise();
|
|
19
|
+
await runner.hook.applyConfig.promise();
|
|
20
|
+
await runner.hook.validatePlugin.promise();
|
|
21
|
+
await runner.hook.registerCommand.promise();
|
|
22
|
+
await runner.hook.startCommand.promise();
|
|
23
|
+
})();
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export * from './runner';
|
|
2
|
-
export * from './plugin';
|
|
3
|
-
export * from './logger';
|
|
4
|
-
|
|
5
|
-
import type { glob } from 'glob';
|
|
6
|
-
|
|
7
|
-
type Glob = typeof glob;
|
|
8
|
-
export type { Glob };
|
|
9
|
-
export type { ConsolaInstance } from 'consola';
|
|
1
|
+
export * from './runner';
|
|
2
|
+
export * from './plugin';
|
|
3
|
+
export * from './logger';
|
package/src/logger.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { createConsola } from 'consola';
|
|
2
|
-
|
|
3
|
-
export function createLogger(options?: { debug?: boolean }) {
|
|
4
|
-
const instance = createConsola({
|
|
5
|
-
level: options?.debug ? 4 : 3,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { createConsola } from 'consola';
|
|
2
|
+
|
|
3
|
+
export function createLogger(options?: { debug?: boolean }) {
|
|
4
|
+
const instance = createConsola({
|
|
5
|
+
level: options?.debug ? 4 : 3,
|
|
6
|
+
throttle: 10,
|
|
7
|
+
throttleMin: 500,
|
|
8
|
+
formatOptions: {
|
|
9
|
+
// columns: 80,
|
|
10
|
+
// colors: false,
|
|
11
|
+
compact: false,
|
|
12
|
+
date: false,
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return instance;
|
|
17
|
+
}
|
package/src/plugin/commander.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import type { Plugin } from '../runner';
|
|
2
|
-
|
|
3
|
-
export function pluginCommander() {
|
|
4
|
-
const plugin: Plugin = {
|
|
5
|
-
name: pluginCommander.name,
|
|
6
|
-
apply: runner => {
|
|
7
|
-
const { hook, command, config, z, logger } = runner;
|
|
8
|
-
const log = logger.withTag(pluginCommander.name);
|
|
9
|
-
hook.registerCommand.tapPromise(pluginCommander.name, async () => {
|
|
10
|
-
command
|
|
11
|
-
.command('dev')
|
|
12
|
-
.description('启动开发')
|
|
13
|
-
.action(async () => {
|
|
14
|
-
process.env.NODE_ENV = 'development';
|
|
15
|
-
await hook.dev.promise();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
command
|
|
19
|
-
.command('build')
|
|
20
|
-
.description('构建项目')
|
|
21
|
-
.action(async () => {
|
|
22
|
-
process.env.NODE_ENV = 'production';
|
|
23
|
-
await hook.build.promise();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
command
|
|
27
|
-
.command('release')
|
|
28
|
-
.description('发布包')
|
|
29
|
-
.action(async () => {
|
|
30
|
-
await hook.release.promise();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
command
|
|
34
|
-
.command('deploy')
|
|
35
|
-
.description('部署项目')
|
|
36
|
-
.action(async () => {
|
|
37
|
-
await hook.deploy.promise().catch(e => {
|
|
38
|
-
log.fail(`部署失败,${runner.duration},${e.message}`);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
hook.startCommand.tapPromise(pluginCommander.name, async () => {
|
|
44
|
-
await command.parseAsync(process.argv);
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
return plugin;
|
|
49
|
-
}
|
|
1
|
+
import type { Plugin } from '../runner';
|
|
2
|
+
|
|
3
|
+
export function pluginCommander() {
|
|
4
|
+
const plugin: Plugin = {
|
|
5
|
+
name: pluginCommander.name,
|
|
6
|
+
apply: runner => {
|
|
7
|
+
const { hook, command, config, z, logger } = runner;
|
|
8
|
+
const log = logger.withTag(pluginCommander.name);
|
|
9
|
+
hook.registerCommand.tapPromise(pluginCommander.name, async () => {
|
|
10
|
+
command
|
|
11
|
+
.command('dev')
|
|
12
|
+
.description('启动开发')
|
|
13
|
+
.action(async () => {
|
|
14
|
+
process.env.NODE_ENV = 'development';
|
|
15
|
+
await hook.dev.promise();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
command
|
|
19
|
+
.command('build')
|
|
20
|
+
.description('构建项目')
|
|
21
|
+
.action(async () => {
|
|
22
|
+
process.env.NODE_ENV = 'production';
|
|
23
|
+
await hook.build.promise();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
command
|
|
27
|
+
.command('release')
|
|
28
|
+
.description('发布包')
|
|
29
|
+
.action(async () => {
|
|
30
|
+
await hook.release.promise();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
command
|
|
34
|
+
.command('deploy')
|
|
35
|
+
.description('部署项目')
|
|
36
|
+
.action(async () => {
|
|
37
|
+
await hook.deploy.promise().catch(e => {
|
|
38
|
+
log.fail(`部署失败,${runner.duration},${e.message}`);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
hook.startCommand.tapPromise(pluginCommander.name, async () => {
|
|
44
|
+
await command.parseAsync(process.argv);
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
return plugin;
|
|
49
|
+
}
|
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/index.ts
CHANGED
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
|
+
}
|