@rife/cli 0.0.6-beta.2 → 0.0.6-beta.20
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/cli.cjs +25 -0
- package/dist/cjs/index.cjs +79 -0
- package/dist/cjs/logger.cjs +48 -0
- package/dist/cjs/plugin/commander.cjs +66 -0
- package/dist/cjs/plugin/config.cjs +107 -0
- package/dist/cjs/plugin/index.cjs +79 -0
- package/dist/cjs/plugin/package.cjs +71 -0
- package/dist/cjs/plugin/release.cjs +129 -0
- package/dist/cjs/runner.cjs +140 -0
- package/dist/{sync.js → cjs/sync.cjs} +12 -23
- package/dist/cjs/util.cjs +67 -0
- package/dist/esm/cli.mjs +21 -0
- package/dist/esm/index.mjs +6 -0
- package/dist/esm/logger.mjs +16 -0
- package/dist/esm/plugin/commander.mjs +34 -0
- package/dist/esm/plugin/config.mjs +65 -0
- package/dist/esm/plugin/index.mjs +6 -0
- package/dist/{plugin/package.js → esm/plugin/package.mjs} +9 -12
- package/dist/esm/plugin/release.mjs +97 -0
- package/dist/esm/runner.mjs +95 -0
- package/dist/esm/sync.mjs +46 -0
- package/dist/esm/util.mjs +12 -0
- package/package.json +29 -27
- package/src/cli.ts +23 -19
- package/src/index.ts +4 -3
- package/src/logger.ts +17 -34
- package/src/plugin/commander.ts +49 -44
- package/src/plugin/config.ts +24 -9
- package/src/plugin/index.ts +1 -1
- package/src/plugin/package.ts +0 -3
- package/src/plugin/release.ts +113 -32
- package/src/runner.ts +132 -88
- package/src/sync.ts +63 -63
- package/src/util.ts +14 -0
- package/dist/build.js +0 -3
- package/dist/build.js.map +0 -1
- package/dist/cli.js +0 -18
- package/dist/cli.js.map +0 -1
- package/dist/index.js +0 -7
- package/dist/index.js.map +0 -1
- package/dist/logger.js +0 -26
- package/dist/logger.js.map +0 -1
- package/dist/plugin/commander.js +0 -42
- package/dist/plugin/commander.js.map +0 -1
- package/dist/plugin/compiler/compiler.js +0 -166
- package/dist/plugin/compiler/compiler.js.map +0 -1
- package/dist/plugin/compiler/index.js +0 -83
- package/dist/plugin/compiler/index.js.map +0 -1
- package/dist/plugin/compiler/swc.js +0 -47
- package/dist/plugin/compiler/swc.js.map +0 -1
- package/dist/plugin/compiler/tsc.js +0 -75
- package/dist/plugin/compiler/tsc.js.map +0 -1
- package/dist/plugin/config.js +0 -61
- package/dist/plugin/config.js.map +0 -1
- package/dist/plugin/index.js +0 -8
- package/dist/plugin/index.js.map +0 -1
- package/dist/plugin/package.js.map +0 -1
- package/dist/plugin/release.js +0 -32
- package/dist/plugin/release.js.map +0 -1
- package/dist/pnpmfile.js +0 -153
- package/dist/runner.js +0 -53
- package/dist/runner.js.map +0 -1
- package/dist/sync.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/build.ts +0 -0
- package/src/plugin/compiler/compiler.ts +0 -198
- package/src/plugin/compiler/index.ts +0 -109
- package/src/plugin/compiler/swc.ts +0 -55
- package/src/plugin/compiler/tsc.ts +0 -101
- package/src/pnpmfile.ts +0 -147
- package/src/test/pnpmfile.test.ts +0 -223
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import 'module';
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
async function sync(name) {
|
|
4
|
+
const res = await fetch(`https://registry-direct.npmmirror.com/-/package/${name}/syncs`, {
|
|
5
|
+
headers: {
|
|
6
|
+
accept: '*/*',
|
|
7
|
+
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
|
8
|
+
'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
|
|
9
|
+
'sec-ch-ua-mobile': '?0',
|
|
10
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
11
|
+
'sec-fetch-dest': 'empty',
|
|
12
|
+
'sec-fetch-mode': 'cors',
|
|
13
|
+
'sec-fetch-site': 'same-site',
|
|
14
|
+
Referer: 'https://npmmirror.com/',
|
|
15
|
+
'Referrer-Policy': 'strict-origin-when-cross-origin'
|
|
16
|
+
},
|
|
17
|
+
body: null,
|
|
18
|
+
method: 'PUT'
|
|
19
|
+
});
|
|
20
|
+
const body = await res.json();
|
|
21
|
+
if (true === body.ok) console.log(`同步 ${name} 成功`);
|
|
22
|
+
return body;
|
|
23
|
+
}
|
|
24
|
+
const list = [
|
|
25
|
+
'@rife/config',
|
|
26
|
+
'@rife/cli'
|
|
27
|
+
];
|
|
28
|
+
async function main() {
|
|
29
|
+
for (const item of list)await sync(item);
|
|
30
|
+
poll();
|
|
31
|
+
}
|
|
32
|
+
main();
|
|
33
|
+
async function get(name) {
|
|
34
|
+
try {
|
|
35
|
+
const res = await fetch(`https://r.cnpmjs.org/${name}?t=${Date.now()}&cache=0`);
|
|
36
|
+
const data = await res.json();
|
|
37
|
+
return `${name} ${data?.['dist-tags']?.['latest']}`;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return `${name} error`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function poll() {
|
|
43
|
+
const res = await Promise.all(list.map(get));
|
|
44
|
+
console.log(`${res.join('\n')}\n`);
|
|
45
|
+
setTimeout(poll, 1000);
|
|
46
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'module';
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import fs_extra from "fs-extra";
|
|
6
|
+
import * as __rspack_external_glob from "glob";
|
|
7
|
+
const getDuration = (perfStart)=>{
|
|
8
|
+
const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
|
|
9
|
+
return `耗时 ${duration} s`;
|
|
10
|
+
};
|
|
11
|
+
const resolve = (...args)=>path.resolve(path.dirname(fileURLToPath(import.meta.url)), ...args);
|
|
12
|
+
export { fs_extra as fs, getDuration, __rspack_external_glob as glob, resolve };
|
package/package.json
CHANGED
|
@@ -1,49 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rife/cli",
|
|
3
|
-
"version": "0.0.6-beta.
|
|
3
|
+
"version": "0.0.6-beta.20",
|
|
4
4
|
"description": "",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"require": "./dist/cjs/index.cjs",
|
|
9
|
+
"import": "./dist/esm/index.mjs",
|
|
10
|
+
"types": "./src/index.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
7
13
|
"bin": {
|
|
8
|
-
"rife": "./dist/cli.
|
|
14
|
+
"rife": "./dist/esm/cli.mjs"
|
|
9
15
|
},
|
|
10
16
|
"files": [
|
|
11
17
|
"dist/**/*",
|
|
12
18
|
"src/**/*"
|
|
13
19
|
],
|
|
14
|
-
"keywords": [],
|
|
15
|
-
"author": "",
|
|
16
|
-
"license": "ISC",
|
|
17
20
|
"dependencies": {
|
|
18
|
-
"@types/fs-extra": "^11.0.4",
|
|
19
|
-
"@types/node": "^22.13.1",
|
|
20
|
-
"typescript": "^5.7.3",
|
|
21
|
-
"tslib": "^2.8.1",
|
|
22
|
-
"@swc/cli": "^0.6.0",
|
|
23
|
-
"@swc/helpers": "^0.5.15",
|
|
24
|
-
"chokidar": "^4.0.3",
|
|
25
21
|
"commander": "^10.0.1",
|
|
26
|
-
"consola": "^3.4.
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"tapable": "^2.
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
"consola": "^3.4.2",
|
|
23
|
+
"fs-extra": "^11.3.2",
|
|
24
|
+
"glob": "^11.0.3",
|
|
25
|
+
"tapable": "^2.3.0",
|
|
26
|
+
"zod": "^3.25.76"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@rslib/core": "^0.18.5",
|
|
30
|
+
"@types/fs-extra": "^11.0.4",
|
|
31
|
+
"@types/node": "^22.16.0",
|
|
32
|
+
"vitest": "^4.0.16",
|
|
33
|
+
"@rsbuild/plugin-type-check": "^1.3.0",
|
|
34
|
+
"@rife/config": "0.0.6-beta.11"
|
|
33
35
|
},
|
|
34
36
|
"rife": {
|
|
35
37
|
"hostDependencies": {
|
|
36
38
|
"@types/node": true,
|
|
37
39
|
"@rife/config": true,
|
|
38
|
-
"
|
|
39
|
-
"@
|
|
40
|
-
"vitest": true
|
|
40
|
+
"fs-extra": true,
|
|
41
|
+
"@types/fs-extra": true
|
|
41
42
|
}
|
|
42
43
|
},
|
|
43
44
|
"scripts": {
|
|
44
|
-
"dev": "
|
|
45
|
-
"build": "
|
|
45
|
+
"dev": "rslib build --watch",
|
|
46
|
+
"build": "rslib build",
|
|
46
47
|
"test": "vitest",
|
|
47
|
-
"release": "pnpm publish --registry https://registry.npmjs.org --no-git-checks"
|
|
48
|
+
"release": "rslib build && pnpm publish --registry https://registry.npmjs.org --no-git-checks --access public --tag beta",
|
|
49
|
+
"lint": "eslint"
|
|
48
50
|
}
|
|
49
51
|
}
|
package/src/cli.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import { pluginCommander, pluginConfig, pluginPackage } from './plugin';
|
|
2
|
-
import { Plugin, createRunner } from './runner';
|
|
3
|
-
|
|
4
|
-
const plugins: Plugin[] = [
|
|
5
|
-
pluginPackage(), //
|
|
6
|
-
pluginConfig(),
|
|
7
|
-
pluginCommander(),
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
await runner.hook.
|
|
17
|
-
await runner.hook.
|
|
18
|
-
await runner.hook.
|
|
19
|
-
|
|
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,3 +1,4 @@
|
|
|
1
|
-
export * from './runner';
|
|
2
|
-
export * from './plugin';
|
|
3
|
-
export * from './logger';
|
|
1
|
+
export * from './runner';
|
|
2
|
+
export * from './plugin';
|
|
3
|
+
export * from './logger';
|
|
4
|
+
export * from './util';
|
package/src/logger.ts
CHANGED
|
@@ -1,34 +1,17 @@
|
|
|
1
|
-
import { createConsola } from 'consola';
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// colors: false,
|
|
19
|
-
compact: false,
|
|
20
|
-
date: false,
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const logger: Logger = {
|
|
25
|
-
debug: (message, ...args) => instance.info(message, ...args),
|
|
26
|
-
info: (message, ...args) => instance.info(message, ...args),
|
|
27
|
-
error: (message, ...args) => instance.error(message, ...args),
|
|
28
|
-
success: (message, ...args) => instance.success(message, ...args),
|
|
29
|
-
fail: (message, ...args) => instance.fail(message, ...args),
|
|
30
|
-
withTag: tag => instance.withTag(tag),
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
return logger;
|
|
34
|
-
}
|
|
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,44 +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, config, z } = runner;
|
|
8
|
-
|
|
9
|
-
hook.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
@@ -6,18 +6,32 @@ export function pluginConfig() {
|
|
|
6
6
|
const plugin: Plugin = {
|
|
7
7
|
name: pluginConfig.name,
|
|
8
8
|
apply: runner => {
|
|
9
|
-
const { logger, hook, config, fs, z } = runner;
|
|
9
|
+
const { logger, hook, config, command, fs, z } = runner;
|
|
10
10
|
const log = logger.withTag(pluginConfig.name);
|
|
11
11
|
|
|
12
12
|
hook.loadConfig.tapPromise(pluginConfig.name, async () => {
|
|
13
|
-
|
|
14
|
-
const
|
|
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
|
+
}
|
|
15
24
|
log.debug(`filePath %s`, filePath);
|
|
16
|
-
if (!
|
|
17
|
-
log.error(`找不到配置文件
|
|
25
|
+
if (!filePath) {
|
|
26
|
+
log.error(`找不到配置文件 app.(c|m)?js`);
|
|
18
27
|
process.exit(1);
|
|
19
28
|
}
|
|
20
|
-
|
|
29
|
+
let all: Config[] = [];
|
|
30
|
+
if (isEsm) {
|
|
31
|
+
all = (await import(filePath)).default;
|
|
32
|
+
} else {
|
|
33
|
+
all = require(filePath);
|
|
34
|
+
}
|
|
21
35
|
runner.config.all = all;
|
|
22
36
|
});
|
|
23
37
|
|
|
@@ -36,12 +50,13 @@ export function pluginConfig() {
|
|
|
36
50
|
}
|
|
37
51
|
});
|
|
38
52
|
|
|
39
|
-
hook.applyConfig.tapPromise(pluginConfig.name, async
|
|
53
|
+
hook.applyConfig.tapPromise(pluginConfig.name, async () => {
|
|
40
54
|
const result = z
|
|
41
55
|
.object({
|
|
42
|
-
name: z.string().trim().
|
|
56
|
+
name: z.string().trim().default(''),
|
|
43
57
|
})
|
|
44
|
-
.
|
|
58
|
+
.default({})
|
|
59
|
+
.safeParse(command.opts());
|
|
45
60
|
const name = result.data?.name;
|
|
46
61
|
if (!name) {
|
|
47
62
|
log.debug('没有指定 --name,默认使用列表第一个');
|
package/src/plugin/index.ts
CHANGED
package/src/plugin/package.ts
CHANGED
package/src/plugin/release.ts
CHANGED
|
@@ -1,32 +1,113 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
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 --tag beta ${
|
|
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
|
+
}
|