@rife/cli 0.0.6-beta.2 → 0.0.6-beta.21
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 +109 -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 +141 -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 +67 -0
- package/dist/esm/plugin/index.mjs +6 -0
- package/dist/{plugin/package.js → esm/plugin/package.mjs} +10 -13
- package/dist/esm/plugin/release.mjs +97 -0
- package/dist/esm/runner.mjs +96 -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 +51 -44
- package/src/plugin/config.ts +26 -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 +134 -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,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
commander (module) {
|
|
4
|
+
module.exports = require("commander");
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
var __webpack_module_cache__ = {};
|
|
8
|
+
function __webpack_require__(moduleId) {
|
|
9
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
10
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
11
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
12
|
+
exports: {}
|
|
13
|
+
};
|
|
14
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
15
|
+
return module.exports;
|
|
16
|
+
}
|
|
17
|
+
(()=>{
|
|
18
|
+
__webpack_require__.n = (module)=>{
|
|
19
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
20
|
+
__webpack_require__.d(getter, {
|
|
21
|
+
a: getter
|
|
22
|
+
});
|
|
23
|
+
return getter;
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
(()=>{
|
|
27
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
28
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: definition[key]
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
34
|
+
(()=>{
|
|
35
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
36
|
+
})();
|
|
37
|
+
(()=>{
|
|
38
|
+
__webpack_require__.r = (exports1)=>{
|
|
39
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
40
|
+
value: 'Module'
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
43
|
+
value: true
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
var __webpack_exports__ = {};
|
|
48
|
+
(()=>{
|
|
49
|
+
__webpack_require__.r(__webpack_exports__);
|
|
50
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
51
|
+
defineConfig: ()=>defineConfig,
|
|
52
|
+
createRunner: ()=>createRunner
|
|
53
|
+
});
|
|
54
|
+
const utils_namespaceObject = require("consola/utils");
|
|
55
|
+
const external_tapable_namespaceObject = require("tapable");
|
|
56
|
+
const external_zod_namespaceObject = require("zod");
|
|
57
|
+
var external_zod_default = /*#__PURE__*/ __webpack_require__.n(external_zod_namespaceObject);
|
|
58
|
+
const external_logger_cjs_namespaceObject = require("./logger.cjs");
|
|
59
|
+
const external_util_cjs_namespaceObject = require("./util.cjs");
|
|
60
|
+
if (void 0 === Promise.withResolvers) Promise.withResolvers = ()=>{
|
|
61
|
+
let resolve;
|
|
62
|
+
let reject;
|
|
63
|
+
const promise = new Promise((res, rej)=>{
|
|
64
|
+
resolve = res;
|
|
65
|
+
reject = rej;
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
promise,
|
|
69
|
+
resolve: resolve,
|
|
70
|
+
reject: reject
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
function createRunner() {
|
|
74
|
+
const perfStart = performance.now();
|
|
75
|
+
const { Command } = __webpack_require__("commander");
|
|
76
|
+
const command = new Command();
|
|
77
|
+
command.option('--debug', '打开调试日志');
|
|
78
|
+
command.option('-n, --name <string>', '执行指定配置');
|
|
79
|
+
command.option('-h, --help', '帮助');
|
|
80
|
+
const args = external_zod_default().object({
|
|
81
|
+
debug: external_zod_default().boolean()
|
|
82
|
+
}).default({
|
|
83
|
+
debug: false
|
|
84
|
+
}).safeParse(command.opts());
|
|
85
|
+
const runner = {
|
|
86
|
+
env: 'prod',
|
|
87
|
+
hook: {
|
|
88
|
+
loadPackage: new external_tapable_namespaceObject.AsyncSeriesHook([]),
|
|
89
|
+
loadConfig: new external_tapable_namespaceObject.AsyncSeriesHook([]),
|
|
90
|
+
validateConfig: new external_tapable_namespaceObject.AsyncSeriesHook([]),
|
|
91
|
+
applyConfig: new external_tapable_namespaceObject.AsyncSeriesHook([]),
|
|
92
|
+
validatePlugin: new external_tapable_namespaceObject.AsyncSeriesHook([]),
|
|
93
|
+
registerCommand: new external_tapable_namespaceObject.AsyncSeriesHook([]),
|
|
94
|
+
startCommand: new external_tapable_namespaceObject.AsyncSeriesHook([]),
|
|
95
|
+
finishCommand: new external_tapable_namespaceObject.AsyncSeriesHook([]),
|
|
96
|
+
dev: new external_tapable_namespaceObject.AsyncSeriesHook([]),
|
|
97
|
+
build: new external_tapable_namespaceObject.AsyncSeriesHook([]),
|
|
98
|
+
test: new external_tapable_namespaceObject.AsyncSeriesHook([]),
|
|
99
|
+
release: new external_tapable_namespaceObject.AsyncSeriesHook([]),
|
|
100
|
+
deploy: new external_tapable_namespaceObject.AsyncSeriesHook([]),
|
|
101
|
+
lint: new external_tapable_namespaceObject.AsyncSeriesHook([])
|
|
102
|
+
},
|
|
103
|
+
logger: (0, external_logger_cjs_namespaceObject.createLogger)(args.data),
|
|
104
|
+
command,
|
|
105
|
+
config: {
|
|
106
|
+
all: [],
|
|
107
|
+
current: void 0
|
|
108
|
+
},
|
|
109
|
+
package: {},
|
|
110
|
+
z: external_zod_default(),
|
|
111
|
+
fs: external_util_cjs_namespaceObject.fs,
|
|
112
|
+
glob: external_util_cjs_namespaceObject.glob.glob,
|
|
113
|
+
get duration () {
|
|
114
|
+
const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
|
|
115
|
+
return `耗时 ${duration} s`;
|
|
116
|
+
},
|
|
117
|
+
tempDir: './node_modules/.rife/',
|
|
118
|
+
clear: ()=>{
|
|
119
|
+
console.clear();
|
|
120
|
+
process.stdout.write('\x1b[3J');
|
|
121
|
+
console.log(`${utils_namespaceObject.colors.bgBlue(' 项目名称 ')} ${runner.package.name} \n`);
|
|
122
|
+
},
|
|
123
|
+
throwError: (message, options)=>{
|
|
124
|
+
throw new Error(message, options);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
return runner;
|
|
128
|
+
}
|
|
129
|
+
function defineConfig(all) {
|
|
130
|
+
return all;
|
|
131
|
+
}
|
|
132
|
+
})();
|
|
133
|
+
exports.createRunner = __webpack_exports__.createRunner;
|
|
134
|
+
exports.defineConfig = __webpack_exports__.defineConfig;
|
|
135
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
136
|
+
"createRunner",
|
|
137
|
+
"defineConfig"
|
|
138
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
139
|
+
Object.defineProperty(exports, '__esModule', {
|
|
140
|
+
value: true
|
|
141
|
+
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
var __webpack_exports__ = {};
|
|
3
2
|
async function sync(name) {
|
|
4
3
|
const res = await fetch(`https://registry-direct.npmmirror.com/-/package/${name}/syncs`, {
|
|
5
4
|
headers: {
|
|
@@ -12,33 +11,21 @@ async function sync(name) {
|
|
|
12
11
|
'sec-fetch-mode': 'cors',
|
|
13
12
|
'sec-fetch-site': 'same-site',
|
|
14
13
|
Referer: 'https://npmmirror.com/',
|
|
15
|
-
'Referrer-Policy': 'strict-origin-when-cross-origin'
|
|
14
|
+
'Referrer-Policy': 'strict-origin-when-cross-origin'
|
|
16
15
|
},
|
|
17
16
|
body: null,
|
|
18
|
-
method: 'PUT'
|
|
17
|
+
method: 'PUT'
|
|
19
18
|
});
|
|
20
19
|
const body = await res.json();
|
|
21
|
-
if (body.ok
|
|
22
|
-
console.log(`同步 ${name} 成功`);
|
|
23
|
-
}
|
|
20
|
+
if (true === body.ok) console.log(`同步 ${name} 成功`);
|
|
24
21
|
return body;
|
|
25
22
|
}
|
|
26
23
|
const list = [
|
|
27
|
-
'@rife/config',
|
|
28
|
-
'@rife/cli'
|
|
29
|
-
// '@rife/infra',
|
|
30
|
-
'@rife/logger',
|
|
31
|
-
// '@rife/react',
|
|
32
|
-
// '@rife/next',
|
|
33
|
-
// '@rife/nest',
|
|
34
|
-
// '@rife/wxa',
|
|
35
|
-
'@rife/fast',
|
|
24
|
+
'@rife/config',
|
|
25
|
+
'@rife/cli'
|
|
36
26
|
];
|
|
37
27
|
async function main() {
|
|
38
|
-
for (const item of list)
|
|
39
|
-
// https://registry.npmmirror.com/-/package/@rife/infra/syncs/65a255a2afa293666acf6655/log
|
|
40
|
-
await sync(item);
|
|
41
|
-
}
|
|
28
|
+
for (const item of list)await sync(item);
|
|
42
29
|
poll();
|
|
43
30
|
}
|
|
44
31
|
main();
|
|
@@ -47,8 +34,7 @@ async function get(name) {
|
|
|
47
34
|
const res = await fetch(`https://r.cnpmjs.org/${name}?t=${Date.now()}&cache=0`);
|
|
48
35
|
const data = await res.json();
|
|
49
36
|
return `${name} ${data?.['dist-tags']?.['latest']}`;
|
|
50
|
-
}
|
|
51
|
-
catch (e) {
|
|
37
|
+
} catch (e) {
|
|
52
38
|
return `${name} error`;
|
|
53
39
|
}
|
|
54
40
|
}
|
|
@@ -57,4 +43,7 @@ async function poll() {
|
|
|
57
43
|
console.log(`${res.join('\n')}\n`);
|
|
58
44
|
setTimeout(poll, 1000);
|
|
59
45
|
}
|
|
60
|
-
|
|
46
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
47
|
+
Object.defineProperty(exports, '__esModule', {
|
|
48
|
+
value: true
|
|
49
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
3
|
+
return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
4
|
+
}();
|
|
5
|
+
var __webpack_require__ = {};
|
|
6
|
+
(()=>{
|
|
7
|
+
__webpack_require__.n = (module)=>{
|
|
8
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
9
|
+
__webpack_require__.d(getter, {
|
|
10
|
+
a: getter
|
|
11
|
+
});
|
|
12
|
+
return getter;
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
17
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: definition[key]
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
25
|
+
})();
|
|
26
|
+
(()=>{
|
|
27
|
+
__webpack_require__.r = (exports1)=>{
|
|
28
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
29
|
+
value: 'Module'
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
32
|
+
value: true
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __webpack_exports__ = {};
|
|
37
|
+
__webpack_require__.r(__webpack_exports__);
|
|
38
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
39
|
+
getDuration: ()=>getDuration,
|
|
40
|
+
glob: ()=>external_glob_namespaceObject,
|
|
41
|
+
fs: ()=>external_fs_extra_default(),
|
|
42
|
+
resolve: ()=>resolve
|
|
43
|
+
});
|
|
44
|
+
const external_node_url_namespaceObject = require("node:url");
|
|
45
|
+
const external_path_namespaceObject = require("path");
|
|
46
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
47
|
+
const external_fs_extra_namespaceObject = require("fs-extra");
|
|
48
|
+
var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
|
|
49
|
+
const external_glob_namespaceObject = require("glob");
|
|
50
|
+
const getDuration = (perfStart)=>{
|
|
51
|
+
const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
|
|
52
|
+
return `耗时 ${duration} s`;
|
|
53
|
+
};
|
|
54
|
+
const resolve = (...args)=>external_path_default().resolve(external_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__)), ...args);
|
|
55
|
+
exports.fs = __webpack_exports__.fs;
|
|
56
|
+
exports.getDuration = __webpack_exports__.getDuration;
|
|
57
|
+
exports.glob = __webpack_exports__.glob;
|
|
58
|
+
exports.resolve = __webpack_exports__.resolve;
|
|
59
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
60
|
+
"fs",
|
|
61
|
+
"getDuration",
|
|
62
|
+
"glob",
|
|
63
|
+
"resolve"
|
|
64
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
65
|
+
Object.defineProperty(exports, '__esModule', {
|
|
66
|
+
value: true
|
|
67
|
+
});
|
package/dist/esm/cli.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { pluginCommander, pluginConfig, pluginPackage, pluginRelease } from "./plugin/index.mjs";
|
|
4
|
+
import { createRunner } from "./runner.mjs";
|
|
5
|
+
const plugins = [
|
|
6
|
+
pluginPackage(),
|
|
7
|
+
pluginConfig(),
|
|
8
|
+
pluginCommander(),
|
|
9
|
+
pluginRelease()
|
|
10
|
+
];
|
|
11
|
+
const runner = createRunner();
|
|
12
|
+
plugins.forEach((plugin)=>plugin.apply(runner));
|
|
13
|
+
(async ()=>{
|
|
14
|
+
await runner.hook.loadPackage.promise();
|
|
15
|
+
await runner.hook.loadConfig.promise();
|
|
16
|
+
await runner.hook.validateConfig.promise();
|
|
17
|
+
await runner.hook.applyConfig.promise();
|
|
18
|
+
await runner.hook.validatePlugin.promise();
|
|
19
|
+
await runner.hook.registerCommand.promise();
|
|
20
|
+
await runner.hook.startCommand.promise();
|
|
21
|
+
})();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { createConsola } from "consola";
|
|
4
|
+
function createLogger(options) {
|
|
5
|
+
const instance = createConsola({
|
|
6
|
+
level: options?.debug ? 4 : 3,
|
|
7
|
+
throttle: 10,
|
|
8
|
+
throttleMin: 500,
|
|
9
|
+
formatOptions: {
|
|
10
|
+
compact: false,
|
|
11
|
+
date: false
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return instance;
|
|
15
|
+
}
|
|
16
|
+
export { createLogger };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
function pluginCommander() {
|
|
4
|
+
const 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.command('dev').description('启动开发').action(async ()=>{
|
|
11
|
+
process.env.NODE_ENV = 'development';
|
|
12
|
+
await hook.dev.promise();
|
|
13
|
+
});
|
|
14
|
+
command.command('build').description('构建项目').action(async ()=>{
|
|
15
|
+
process.env.NODE_ENV = 'production';
|
|
16
|
+
await hook.build.promise();
|
|
17
|
+
});
|
|
18
|
+
command.command('release').description('发布包').action(async ()=>{
|
|
19
|
+
await hook.release.promise();
|
|
20
|
+
});
|
|
21
|
+
command.command('deploy').description('部署项目').action(async ()=>{
|
|
22
|
+
await hook.deploy.promise().catch((e)=>{
|
|
23
|
+
log.fail(`部署失败,${runner.duration},${e.message}`);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
hook.startCommand.tapPromise(pluginCommander.name, async ()=>{
|
|
28
|
+
await command.parseAsync(process.argv);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return plugin;
|
|
33
|
+
}
|
|
34
|
+
export { pluginCommander };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import __rslib_shim_module__ from "node:module";
|
|
2
|
+
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
3
|
+
import path from "path";
|
|
4
|
+
function pluginConfig() {
|
|
5
|
+
const plugin = {
|
|
6
|
+
name: pluginConfig.name,
|
|
7
|
+
apply: (runner)=>{
|
|
8
|
+
const { logger, hook, config, command, fs, z } = runner;
|
|
9
|
+
const log = logger.withTag(pluginConfig.name);
|
|
10
|
+
hook.loadConfig.tapPromise(pluginConfig.name, async ()=>{
|
|
11
|
+
let filePath = '';
|
|
12
|
+
const mjs = 'app.mjs';
|
|
13
|
+
const fileNames = [
|
|
14
|
+
'app.js',
|
|
15
|
+
'app.cjs',
|
|
16
|
+
mjs
|
|
17
|
+
];
|
|
18
|
+
let isEsm = false;
|
|
19
|
+
for (const fileName of fileNames)if (await fs.exists(fileName)) {
|
|
20
|
+
filePath = path.posix.resolve(fileName);
|
|
21
|
+
isEsm = fileName === mjs;
|
|
22
|
+
break;
|
|
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 = [];
|
|
30
|
+
all = isEsm ? (await import(filePath)).default : require(filePath);
|
|
31
|
+
runner.config.all = all;
|
|
32
|
+
});
|
|
33
|
+
hook.validateConfig.tapPromise(pluginConfig.name, async ()=>{
|
|
34
|
+
const validation = z.array(z.object({
|
|
35
|
+
name: z.string().trim().min(1)
|
|
36
|
+
})).min(1).safeParse(config.all);
|
|
37
|
+
if (!validation.success) {
|
|
38
|
+
log.error(validation.error.message);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
hook.applyConfig.tapPromise(pluginConfig.name, async ()=>{
|
|
43
|
+
const result = z.object({
|
|
44
|
+
name: z.string().trim()
|
|
45
|
+
}).default({
|
|
46
|
+
name: ''
|
|
47
|
+
}).safeParse(command.opts());
|
|
48
|
+
const name = result.data?.name;
|
|
49
|
+
if (name) {
|
|
50
|
+
log.debug(`指定 --name ${name}`);
|
|
51
|
+
const find = config.all.find((t)=>t.name === name);
|
|
52
|
+
if (!find) {
|
|
53
|
+
log.error("未找到 name '%s'", name);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
config.current = find;
|
|
57
|
+
} else {
|
|
58
|
+
log.debug('没有指定 --name,默认使用列表第一个');
|
|
59
|
+
config.current = config.all[0];
|
|
60
|
+
}
|
|
61
|
+
config.current.plugins.forEach((plugin)=>plugin.apply(runner));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
return plugin;
|
|
66
|
+
}
|
|
67
|
+
export { pluginConfig };
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
1
|
+
import __rslib_shim_module__ from "node:module";
|
|
2
|
+
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
3
|
+
import path from "path";
|
|
6
4
|
function pluginPackage() {
|
|
7
5
|
const plugin = {
|
|
8
6
|
name: pluginPackage.name,
|
|
9
|
-
apply: runner
|
|
7
|
+
apply: (runner)=>{
|
|
10
8
|
const { logger, hook, fs } = runner;
|
|
11
9
|
const log = logger.withTag(pluginPackage.name);
|
|
12
|
-
hook.loadPackage.tapPromise(pluginPackage.name, async ()
|
|
10
|
+
hook.loadPackage.tapPromise(pluginPackage.name, async ()=>{
|
|
13
11
|
const fileName = 'package.json';
|
|
14
|
-
const filePath =
|
|
12
|
+
const filePath = path.resolve(fileName);
|
|
15
13
|
if (!fs.existsSync(filePath)) {
|
|
16
14
|
log.error(`找不到文件 ${fileName}`);
|
|
17
15
|
process.exit(1);
|
|
@@ -19,14 +17,13 @@ function pluginPackage() {
|
|
|
19
17
|
try {
|
|
20
18
|
const data = require(filePath);
|
|
21
19
|
runner.package = data;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
log.error(`读取文件失败`, e.message);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
log.error("读取文件失败", e.message);
|
|
25
22
|
process.exit(1);
|
|
26
23
|
}
|
|
27
24
|
});
|
|
28
|
-
}
|
|
25
|
+
}
|
|
29
26
|
};
|
|
30
27
|
return plugin;
|
|
31
28
|
}
|
|
32
|
-
|
|
29
|
+
export { pluginPackage };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { execSync } from "child_process";
|
|
4
|
+
function pluginRelease() {
|
|
5
|
+
const plugin = {
|
|
6
|
+
name: pluginRelease.name,
|
|
7
|
+
apply: (runner)=>{
|
|
8
|
+
const { logger, hook, fs } = runner;
|
|
9
|
+
const log = logger.withTag(pluginRelease.name);
|
|
10
|
+
hook.release.tapPromise(pluginRelease.name, async ()=>{
|
|
11
|
+
runner.clear();
|
|
12
|
+
await hook.build.promise();
|
|
13
|
+
log.start('开始发布');
|
|
14
|
+
const packageVersion = runner.package.version;
|
|
15
|
+
const packageName = runner.package.name;
|
|
16
|
+
const url = `https://registry.npmjs.org/${packageName}`;
|
|
17
|
+
let nextVersion = packageVersion;
|
|
18
|
+
log.debug(`查询版本号 ${packageVersion} 是否存在`);
|
|
19
|
+
const res = await (await fetch(url)).json();
|
|
20
|
+
const exist = res?.versions?.[packageVersion];
|
|
21
|
+
if (exist) {
|
|
22
|
+
const split = packageVersion.split('.');
|
|
23
|
+
split[split.length - 1] = Number(split[split.length - 1]) + 1;
|
|
24
|
+
nextVersion = split.join('.');
|
|
25
|
+
log.debug(`版本号 ${packageVersion} 存在,更新版本号为 ${nextVersion}`);
|
|
26
|
+
const text = fs.readFileSync('./package.json').toString();
|
|
27
|
+
const nextText = text.replace(new RegExp(`"version":\\s*"${packageVersion}"`), `"version": "${nextVersion}"`);
|
|
28
|
+
fs.writeFileSync('./package.json', nextText);
|
|
29
|
+
}
|
|
30
|
+
log.debug(`版本号 ${packageVersion} 不存在`);
|
|
31
|
+
log.info(`版本号为 ${nextVersion}`);
|
|
32
|
+
const tempDir = "./node_modules/.rife/release/";
|
|
33
|
+
log.info(`清空目录 ${tempDir}`);
|
|
34
|
+
fs.emptyDirSync(tempDir);
|
|
35
|
+
const pack = `pnpm pack --pack-destination ${tempDir} --json`;
|
|
36
|
+
log.info(`打包文件 ${pack}`);
|
|
37
|
+
const packOutput = JSON.parse(execSync(pack).toString());
|
|
38
|
+
const filename = packOutput.filename;
|
|
39
|
+
for (const item of packOutput.files)log.debug(item.path);
|
|
40
|
+
const debug = false;
|
|
41
|
+
const publish = `pnpm publish ${filename} --registry https://registry.npmjs.org --no-git-checks --tag beta ${debug ? '--dry-run' : ''}`;
|
|
42
|
+
log.info(`发布文件 ${publish}`);
|
|
43
|
+
execSync(publish, {
|
|
44
|
+
stdio: 'inherit'
|
|
45
|
+
});
|
|
46
|
+
log.success(`发布成功,${runner.duration}`);
|
|
47
|
+
log.info('同步版本');
|
|
48
|
+
let hasSync = false;
|
|
49
|
+
while(true){
|
|
50
|
+
const res = await queryVersion(packageName);
|
|
51
|
+
const nextManifest = res?.versions?.[nextVersion];
|
|
52
|
+
const exist = Boolean(nextManifest);
|
|
53
|
+
const latest = res?.['dist-tags']?.latest;
|
|
54
|
+
if (exist) {
|
|
55
|
+
log.debug("同步版本存在");
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
log.info(`检查版本 ${nextVersion} 不存在,最新版本为 ${latest}`);
|
|
59
|
+
if (!hasSync) {
|
|
60
|
+
hasSync = true;
|
|
61
|
+
log.start("开始同步");
|
|
62
|
+
const sync = await syncVersion(packageName);
|
|
63
|
+
if (true === sync.ok) log.info(`调用同步接口成功,日志 https://registry.npmmirror.com/-/package/${packageName}/syncs/${sync.id}/log`);
|
|
64
|
+
else log.debug("调用同步接口失败,%j", sync);
|
|
65
|
+
}
|
|
66
|
+
await new Promise((resolve)=>setTimeout(resolve, 2000));
|
|
67
|
+
}
|
|
68
|
+
log.success(`同步成功,最新版本为 ${nextVersion},${runner.duration}`);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
return plugin;
|
|
73
|
+
}
|
|
74
|
+
async function queryVersion(packageName) {
|
|
75
|
+
const res = await (await fetch(`https://registry.npmmirror.com/${packageName}?t=${Math.random()}`)).json();
|
|
76
|
+
return res;
|
|
77
|
+
}
|
|
78
|
+
async function syncVersion(packageName) {
|
|
79
|
+
const sync = await (await fetch(`https://registry-direct.npmmirror.com/-/package/${packageName}/syncs`, {
|
|
80
|
+
headers: {
|
|
81
|
+
accept: '*/*',
|
|
82
|
+
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
|
83
|
+
'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
|
|
84
|
+
'sec-ch-ua-mobile': '?0',
|
|
85
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
86
|
+
'sec-fetch-dest': 'empty',
|
|
87
|
+
'sec-fetch-mode': 'cors',
|
|
88
|
+
'sec-fetch-site': 'same-site',
|
|
89
|
+
Referer: 'https://npmmirror.com/',
|
|
90
|
+
'Referrer-Policy': 'strict-origin-when-cross-origin'
|
|
91
|
+
},
|
|
92
|
+
body: null,
|
|
93
|
+
method: 'PUT'
|
|
94
|
+
})).json();
|
|
95
|
+
return sync;
|
|
96
|
+
}
|
|
97
|
+
export { pluginRelease };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import * as __rspack_external_commander from "commander";
|
|
4
|
+
import { colors } from "consola/utils";
|
|
5
|
+
import { AsyncSeriesHook } from "tapable";
|
|
6
|
+
import zod from "zod";
|
|
7
|
+
import { createLogger } from "./logger.mjs";
|
|
8
|
+
import { fs, glob } from "./util.mjs";
|
|
9
|
+
var __webpack_modules__ = {
|
|
10
|
+
commander (module) {
|
|
11
|
+
module.exports = __rspack_external_commander;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var __webpack_module_cache__ = {};
|
|
15
|
+
function __webpack_require__(moduleId) {
|
|
16
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
17
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
18
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
19
|
+
exports: {}
|
|
20
|
+
};
|
|
21
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
22
|
+
return module.exports;
|
|
23
|
+
}
|
|
24
|
+
if (void 0 === Promise.withResolvers) Promise.withResolvers = ()=>{
|
|
25
|
+
let resolve;
|
|
26
|
+
let reject;
|
|
27
|
+
const promise = new Promise((res, rej)=>{
|
|
28
|
+
resolve = res;
|
|
29
|
+
reject = rej;
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
promise,
|
|
33
|
+
resolve: resolve,
|
|
34
|
+
reject: reject
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
function createRunner() {
|
|
38
|
+
const perfStart = performance.now();
|
|
39
|
+
const { Command } = __webpack_require__("commander");
|
|
40
|
+
const command = new Command();
|
|
41
|
+
command.option('--debug', '打开调试日志');
|
|
42
|
+
command.option('-n, --name <string>', '执行指定配置');
|
|
43
|
+
command.option('-h, --help', '帮助');
|
|
44
|
+
const args = zod.object({
|
|
45
|
+
debug: zod.boolean()
|
|
46
|
+
}).default({
|
|
47
|
+
debug: false
|
|
48
|
+
}).safeParse(command.opts());
|
|
49
|
+
const runner = {
|
|
50
|
+
env: 'prod',
|
|
51
|
+
hook: {
|
|
52
|
+
loadPackage: new AsyncSeriesHook([]),
|
|
53
|
+
loadConfig: new AsyncSeriesHook([]),
|
|
54
|
+
validateConfig: new AsyncSeriesHook([]),
|
|
55
|
+
applyConfig: new AsyncSeriesHook([]),
|
|
56
|
+
validatePlugin: new AsyncSeriesHook([]),
|
|
57
|
+
registerCommand: new AsyncSeriesHook([]),
|
|
58
|
+
startCommand: new AsyncSeriesHook([]),
|
|
59
|
+
finishCommand: new AsyncSeriesHook([]),
|
|
60
|
+
dev: new AsyncSeriesHook([]),
|
|
61
|
+
build: new AsyncSeriesHook([]),
|
|
62
|
+
test: new AsyncSeriesHook([]),
|
|
63
|
+
release: new AsyncSeriesHook([]),
|
|
64
|
+
deploy: new AsyncSeriesHook([]),
|
|
65
|
+
lint: new AsyncSeriesHook([])
|
|
66
|
+
},
|
|
67
|
+
logger: createLogger(args.data),
|
|
68
|
+
command,
|
|
69
|
+
config: {
|
|
70
|
+
all: [],
|
|
71
|
+
current: void 0
|
|
72
|
+
},
|
|
73
|
+
package: {},
|
|
74
|
+
z: zod,
|
|
75
|
+
fs: fs,
|
|
76
|
+
glob: glob.glob,
|
|
77
|
+
get duration () {
|
|
78
|
+
const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
|
|
79
|
+
return `耗时 ${duration} s`;
|
|
80
|
+
},
|
|
81
|
+
tempDir: './node_modules/.rife/',
|
|
82
|
+
clear: ()=>{
|
|
83
|
+
console.clear();
|
|
84
|
+
process.stdout.write('\x1b[3J');
|
|
85
|
+
console.log(`${colors.bgBlue(' 项目名称 ')} ${runner.package.name} \n`);
|
|
86
|
+
},
|
|
87
|
+
throwError: (message, options)=>{
|
|
88
|
+
throw new Error(message, options);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return runner;
|
|
92
|
+
}
|
|
93
|
+
function defineConfig(all) {
|
|
94
|
+
return all;
|
|
95
|
+
}
|
|
96
|
+
export { createRunner, defineConfig };
|