node-karin 0.12.2-5.pr.206.cb04dd6 → 0.12.2-5.pr.206.df41fea
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/cli/index.cjs +408 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +402 -0
- package/{lib → dist}/index.d.ts +9 -44
- package/dist/index.js +12643 -0
- package/dist/module/dotenv.cjs +22 -0
- package/dist/module/dotenv.d.ts +2 -0
- package/dist/module/dotenv.js +2 -0
- package/dist/root.d.ts +40 -0
- package/dist/root.js +44 -0
- package/package.json +85 -75
- package/LICENSE +0 -21
- package/README.md +0 -29
- package/lib/index.js +0 -38
- /package/{packages → dist}/module/art-template.cjs +0 -0
- /package/{packages → dist}/module/art-template.d.ts +0 -0
- /package/{packages → dist}/module/art-template.js +0 -0
- /package/{packages → dist}/module/axios.cjs +0 -0
- /package/{packages → dist}/module/axios.d.ts +0 -0
- /package/{packages → dist}/module/axios.js +0 -0
- /package/{packages → dist}/module/chalk.cjs +0 -0
- /package/{packages → dist}/module/chalk.d.ts +0 -0
- /package/{packages → dist}/module/chalk.js +0 -0
- /package/{packages → dist}/module/chokidar.cjs +0 -0
- /package/{packages → dist}/module/chokidar.d.ts +0 -0
- /package/{packages → dist}/module/chokidar.js +0 -0
- /package/{packages → dist}/module/commander.cjs +0 -0
- /package/{packages → dist}/module/commander.d.ts +0 -0
- /package/{packages → dist}/module/commander.js +0 -0
- /package/{packages → dist}/module/express.cjs +0 -0
- /package/{packages → dist}/module/express.d.ts +0 -0
- /package/{packages → dist}/module/express.js +0 -0
- /package/{packages → dist}/module/level.cjs +0 -0
- /package/{packages → dist}/module/level.d.ts +0 -0
- /package/{packages → dist}/module/level.js +0 -0
- /package/{packages → dist}/module/lodash.cjs +0 -0
- /package/{packages → dist}/module/lodash.d.ts +0 -0
- /package/{packages → dist}/module/lodash.js +0 -0
- /package/{packages → dist}/module/log4js.cjs +0 -0
- /package/{packages → dist}/module/log4js.d.ts +0 -0
- /package/{packages → dist}/module/log4js.js +0 -0
- /package/{packages → dist}/module/moment.cjs +0 -0
- /package/{packages → dist}/module/moment.d.ts +0 -0
- /package/{packages → dist}/module/moment.js +0 -0
- /package/{packages → dist}/module/node-schedule.cjs +0 -0
- /package/{packages → dist}/module/node-schedule.d.ts +0 -0
- /package/{packages → dist}/module/node-schedule.js +0 -0
- /package/{packages → dist}/module/redis.cjs +0 -0
- /package/{packages → dist}/module/redis.d.ts +0 -0
- /package/{packages → dist}/module/redis.js +0 -0
- /package/{packages → dist}/module/ws.cjs +0 -0
- /package/{packages → dist}/module/ws.d.ts +0 -0
- /package/{packages → dist}/module/ws.js +0 -0
- /package/{packages → dist}/module/yaml.cjs +0 -0
- /package/{packages → dist}/module/yaml.d.ts +0 -0
- /package/{packages → dist}/module/yaml.js +0 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var fs2 = require('fs');
|
|
5
|
+
var path2 = require('path');
|
|
6
|
+
var child_process = require('child_process');
|
|
7
|
+
var url = require('url');
|
|
8
|
+
var dotenv = require('dotenv');
|
|
9
|
+
var promises = require('fs/promises');
|
|
10
|
+
var commander = require('commander');
|
|
11
|
+
|
|
12
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
|
|
15
|
+
var fs2__default = /*#__PURE__*/_interopDefault(fs2);
|
|
16
|
+
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
17
|
+
var dotenv__default = /*#__PURE__*/_interopDefault(dotenv);
|
|
18
|
+
|
|
19
|
+
var exec = (cmd, options = {}) => {
|
|
20
|
+
try {
|
|
21
|
+
const result = child_process.execSync(cmd, options);
|
|
22
|
+
return { status: true, error: null, stdout: result.toString(), stderr: "" };
|
|
23
|
+
} catch (error) {
|
|
24
|
+
return { status: false, error, stdout: "", stderr: "" };
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var pm2Dir = path2__default.default.join(process.cwd(), "./@karinjs/config/pm2.json");
|
|
28
|
+
var start = () => {
|
|
29
|
+
if (!fs2__default.default.existsSync(pm2Dir)) {
|
|
30
|
+
console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
|
|
31
|
+
console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
console.log("[pm2] \u542F\u52A8\u4E2D...");
|
|
35
|
+
const { error } = exec(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
|
|
36
|
+
if (error) {
|
|
37
|
+
console.log("[pm2] \u542F\u52A8\u5931\u8D25");
|
|
38
|
+
console.log(error);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
console.log("[pm2] \u542F\u52A8\u6210\u529F");
|
|
42
|
+
console.log("[pm2] \u91CD\u542F\u670D\u52A1: pnpm rs");
|
|
43
|
+
console.log("[pm2] \u67E5\u770B\u65E5\u5FD7: pnpm log");
|
|
44
|
+
console.log("[pm2] \u505C\u6B62\u670D\u52A1: pnpm stop");
|
|
45
|
+
console.log("[pm2] \u67E5\u770B\u76D1\u63A7: pm2 monit");
|
|
46
|
+
console.log("[pm2] \u67E5\u770B\u5217\u8868: pm2 list");
|
|
47
|
+
process.exit(0);
|
|
48
|
+
};
|
|
49
|
+
var log = () => {
|
|
50
|
+
if (!fs2__default.default.existsSync(pm2Dir)) {
|
|
51
|
+
console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
|
|
52
|
+
console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
const data = JSON.parse(fs2__default.default.readFileSync(pm2Dir, "utf-8"));
|
|
56
|
+
try {
|
|
57
|
+
const prefix = process.platform === "win32" ? "pm2.cmd" : "pm2";
|
|
58
|
+
child_process.spawn(prefix, ["logs", data.name, "--lines", data.lines || 1e3], { stdio: "inherit", shell: true });
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error("[pm2] \u53D1\u751F\u672A\u77E5\u9519\u8BEF: \u8BF7\u68C0\u67E5pm2\u662F\u5426\u5B89\u88C5 \u3010npm install -g pm2\u3011");
|
|
61
|
+
console.error(error);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var stop = () => {
|
|
66
|
+
if (!fs2__default.default.existsSync(pm2Dir)) {
|
|
67
|
+
console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
|
|
68
|
+
console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
const data = JSON.parse(fs2__default.default.readFileSync(pm2Dir, "utf-8"));
|
|
72
|
+
exec(`pm2 stop ${data.name}`, { cwd: process.cwd() });
|
|
73
|
+
console.log("[pm2] \u505C\u6B62\u6210\u529F");
|
|
74
|
+
process.exit(0);
|
|
75
|
+
};
|
|
76
|
+
var restart = () => {
|
|
77
|
+
if (!fs2__default.default.existsSync(pm2Dir)) {
|
|
78
|
+
console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
|
|
79
|
+
console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var pm2 = {
|
|
84
|
+
start,
|
|
85
|
+
log,
|
|
86
|
+
stop,
|
|
87
|
+
restart
|
|
88
|
+
};
|
|
89
|
+
var dir = process.env.INIT_CWD || process.cwd();
|
|
90
|
+
var pkgDir = url.fileURLToPath(new url.URL("../..", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
91
|
+
var createDir = () => {
|
|
92
|
+
const list = [
|
|
93
|
+
path2__default.default.join(dir, "logs"),
|
|
94
|
+
path2__default.default.join(dir, "plugins", "karin-plugin-example"),
|
|
95
|
+
path2__default.default.join(dir, "@karinjs", "config"),
|
|
96
|
+
path2__default.default.join(dir, "@karinjs", "data"),
|
|
97
|
+
path2__default.default.join(dir, "@karinjs", "temp", "console"),
|
|
98
|
+
path2__default.default.join(dir, "@karinjs", "temp", "html"),
|
|
99
|
+
path2__default.default.join(dir, "@karinjs", "resource")
|
|
100
|
+
];
|
|
101
|
+
list.forEach((item) => {
|
|
102
|
+
if (!fs2__default.default.existsSync(item)) fs2__default.default.mkdirSync(item, { recursive: true });
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
var createPnpmFile = (dir2) => {
|
|
106
|
+
const pnpmfile = path2__default.default.join(dir2, ".pnpmfile.cjs");
|
|
107
|
+
if (fs2__default.default.existsSync(pnpmfile)) return;
|
|
108
|
+
const content = [
|
|
109
|
+
"// \u6E05\u7A7A\u5BF9\u7B49\u4F9D\u8D56\u4E2D\u7684node-karin",
|
|
110
|
+
"function readPackage (pkg, context) {",
|
|
111
|
+
" if (pkg?.['peerDependencies']?.['node-karin'] && pkg['peerDependencies']['node-karin'] !== 'file:./lib') {",
|
|
112
|
+
" delete pkg['peerDependencies']['node-karin']",
|
|
113
|
+
" }",
|
|
114
|
+
" return pkg",
|
|
115
|
+
"}",
|
|
116
|
+
"module.exports = {",
|
|
117
|
+
" hooks: {",
|
|
118
|
+
" readPackage",
|
|
119
|
+
" },",
|
|
120
|
+
"}"
|
|
121
|
+
].join("\n");
|
|
122
|
+
fs2__default.default.writeFileSync(pnpmfile, content);
|
|
123
|
+
};
|
|
124
|
+
var shouldSkipNpmrc = () => {
|
|
125
|
+
const { stdout } = exec("npm config get registry");
|
|
126
|
+
if (stdout.includes("registry.npmjs.org")) return true;
|
|
127
|
+
const { stdout: proxy } = exec("npm config get proxy");
|
|
128
|
+
return !!proxy;
|
|
129
|
+
};
|
|
130
|
+
var createOrUpdateNpmrc = (dir2) => {
|
|
131
|
+
const list = [
|
|
132
|
+
"node_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/sqlite3",
|
|
133
|
+
"better_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/better-sqlite3",
|
|
134
|
+
"sass_binary_site=https://registry.npmmirror.com/-/binary/node-sass",
|
|
135
|
+
"sharp_binary_host=https://registry.npmmirror.com/-/binary/sharp",
|
|
136
|
+
"sharp_libvips_binary_host=https://registry.npmmirror.com/-/binary/sharp-libvips",
|
|
137
|
+
"canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas",
|
|
138
|
+
"# 19\u4EE5\u4E0B\u7248\u672C",
|
|
139
|
+
"puppeteer_download_host=https://registry.npmmirror.com/mirrors",
|
|
140
|
+
"# 20\u4EE5\u4E0A\u7248\u672C",
|
|
141
|
+
"PUPPETEER_DOWNLOAD_BASE_URL = https://registry.npmmirror.com/binaries/chrome-for-testing"
|
|
142
|
+
];
|
|
143
|
+
const npmrc = path2__default.default.join(dir2, ".npmrc");
|
|
144
|
+
if (!fs2__default.default.existsSync(npmrc)) {
|
|
145
|
+
fs2__default.default.writeFileSync(npmrc, list.join("\n"));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const data = fs2__default.default.readFileSync(npmrc, "utf-8");
|
|
149
|
+
const newEntries = list.filter((item) => {
|
|
150
|
+
const key = item.split("=")[0];
|
|
151
|
+
return !data.includes(key);
|
|
152
|
+
});
|
|
153
|
+
if (newEntries.length > 0) {
|
|
154
|
+
fs2__default.default.appendFileSync(npmrc, "\n" + newEntries.join("\n"));
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
var createOrUpdateEnv = (dir2) => {
|
|
158
|
+
const envData = [
|
|
159
|
+
"# \u662F\u5426\u542F\u7528HTTP",
|
|
160
|
+
"HTTP_ENABLE=true",
|
|
161
|
+
"# HTTP\u76D1\u542C\u7AEF\u53E3",
|
|
162
|
+
"HTTP_PORT=7777",
|
|
163
|
+
"# HTTP\u76D1\u542C\u5730\u5740",
|
|
164
|
+
"HTTP_HOST=0.0.0.0",
|
|
165
|
+
"# HTTP\u9274\u6743\u79D8\u94A5 \u4EC5\u7528\u4E8Ekarin\u81EA\u8EABApi",
|
|
166
|
+
"HTTP_AUTH_KEY=default",
|
|
167
|
+
"# ws_server\u9274\u6743\u79D8\u94A5",
|
|
168
|
+
"WS_SERVER_AUTH_KEY=",
|
|
169
|
+
"\n",
|
|
170
|
+
"# \u662F\u5426\u542F\u7528Redis \u5173\u95ED\u540E\u5C06\u4F7F\u7528\u5185\u90E8\u865A\u62DFRedis",
|
|
171
|
+
"REDIS_ENABLE=true",
|
|
172
|
+
"# \u91CD\u542F\u662F\u5426\u8C03\u7528pm2 \u5982\u679C\u4E0D\u8C03\u7528\u5219\u4F1A\u76F4\u63A5\u5173\u673A \u6B64\u914D\u7F6E\u9002\u5408\u6709\u8FDB\u7A0B\u5B88\u62A4\u7684\u7A0B\u5E8F",
|
|
173
|
+
"PM2_RESTART=true",
|
|
174
|
+
"\n",
|
|
175
|
+
"# \u65E5\u5FD7\u7B49\u7EA7",
|
|
176
|
+
"LOG_LEVEL=info",
|
|
177
|
+
"# \u65E5\u5FD7\u4FDD\u7559\u5929\u6570",
|
|
178
|
+
"LOG_DAYS_TO_KEEP=7",
|
|
179
|
+
"# \u65E5\u5FD7\u6587\u4EF6\u6700\u5927\u5927\u5C0F \u5982\u679C\u6B64\u9879\u5927\u4E8E0\u5219\u542F\u7528\u65E5\u5FD7\u5206\u5272",
|
|
180
|
+
"LOG_MAX_LOG_SIZE=0",
|
|
181
|
+
"# logger.fnc\u989C\u8272",
|
|
182
|
+
'LOG_FNC_COLOR="#E1D919"',
|
|
183
|
+
"\n",
|
|
184
|
+
"# ffmpeg",
|
|
185
|
+
"FFMPEG_PATH=",
|
|
186
|
+
"# ffprobe",
|
|
187
|
+
"FFPROBE_PATH=",
|
|
188
|
+
"# ffplay",
|
|
189
|
+
"FFPLAY_PATH=",
|
|
190
|
+
"\n",
|
|
191
|
+
"# \u8FD9\u91CC\u8BF7\u52FF\u4FEE\u6539",
|
|
192
|
+
"RUNTIME=node"
|
|
193
|
+
];
|
|
194
|
+
const env = path2__default.default.join(dir2, ".env");
|
|
195
|
+
if (!fs2__default.default.existsSync(env)) {
|
|
196
|
+
fs2__default.default.writeFileSync(env, envData.join("\n"));
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const value = fs2__default.default.readFileSync(env, "utf-8");
|
|
200
|
+
const newEntries = envData.filter((item) => {
|
|
201
|
+
if (item.includes("#")) return false;
|
|
202
|
+
const key = item.split("=")[0];
|
|
203
|
+
return !value.includes(key);
|
|
204
|
+
});
|
|
205
|
+
if (newEntries.length > 0) {
|
|
206
|
+
fs2__default.default.appendFileSync(env, "\n" + newEntries.join("\n"));
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
var createOrUpdateEnvDev = (dir2) => {
|
|
210
|
+
const envDevData = [
|
|
211
|
+
"# \u662F\u5426\u4E3A\u5F00\u53D1\u73AF\u5883",
|
|
212
|
+
"NODE_ENV=development",
|
|
213
|
+
"# \u8FD0\u884C\u5668",
|
|
214
|
+
"RUNTIME=tsx"
|
|
215
|
+
];
|
|
216
|
+
const envDev = path2__default.default.join(dir2, ".env.dev");
|
|
217
|
+
if (!fs2__default.default.existsSync(envDev)) {
|
|
218
|
+
fs2__default.default.writeFileSync(envDev, envDevData.join("\n"));
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const value = fs2__default.default.readFileSync(envDev, "utf-8");
|
|
222
|
+
const newEntries = envDevData.filter((item) => {
|
|
223
|
+
if (item.includes("#")) return false;
|
|
224
|
+
const key = item.split("=")[0];
|
|
225
|
+
return !value.includes(key);
|
|
226
|
+
});
|
|
227
|
+
if (newEntries.length > 0) {
|
|
228
|
+
fs2__default.default.appendFileSync(envDev, "\n" + newEntries.join("\n"));
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
var createWorkspace = (dir2) => {
|
|
232
|
+
const workspace = path2__default.default.join(dir2, "pnpm-workspace.yaml");
|
|
233
|
+
if (fs2__default.default.existsSync(workspace)) return;
|
|
234
|
+
const content = "packages:\n - 'plugins/**'\n";
|
|
235
|
+
fs2__default.default.writeFileSync(workspace, content);
|
|
236
|
+
};
|
|
237
|
+
var createOtherFile = async () => {
|
|
238
|
+
createPnpmFile(dir);
|
|
239
|
+
createWorkspace(dir);
|
|
240
|
+
if (!shouldSkipNpmrc()) {
|
|
241
|
+
createOrUpdateNpmrc(dir);
|
|
242
|
+
}
|
|
243
|
+
createOrUpdateEnv(dir);
|
|
244
|
+
createOrUpdateEnvDev(dir);
|
|
245
|
+
};
|
|
246
|
+
var createConfig = () => {
|
|
247
|
+
const defCfg = path2__default.default.join(pkgDir, "default", "config");
|
|
248
|
+
const files = fs2__default.default.readdirSync(defCfg);
|
|
249
|
+
files.forEach((file) => {
|
|
250
|
+
if (!file.endsWith(".json")) return;
|
|
251
|
+
const filePath = path2__default.default.join(defCfg, file);
|
|
252
|
+
const targetPath = path2__default.default.join(dir, "@karinjs", "config");
|
|
253
|
+
const targetFile = path2__default.default.join(targetPath, file);
|
|
254
|
+
if (!fs2__default.default.existsSync(targetFile)) {
|
|
255
|
+
fs2__default.default.copyFileSync(filePath, targetFile);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const defData = fs2__default.default.readFileSync(filePath, "utf-8");
|
|
259
|
+
const targetData = fs2__default.default.readFileSync(targetFile, "utf-8");
|
|
260
|
+
const mergedData = { ...JSON.parse(defData), ...JSON.parse(targetData) };
|
|
261
|
+
fs2__default.default.writeFileSync(targetFile, JSON.stringify(mergedData, null, 2));
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
var modifyPackageJson = () => {
|
|
265
|
+
const pkg = fs2__default.default.readFileSync(path2__default.default.join(dir, "package.json"), "utf-8");
|
|
266
|
+
const pkgData = JSON.parse(pkg);
|
|
267
|
+
if (pkgData.type === "module") return pkgData;
|
|
268
|
+
pkgData.type = "module";
|
|
269
|
+
fs2__default.default.writeFileSync(path2__default.default.join(dir, "package.json"), JSON.stringify(pkgData, null, 2));
|
|
270
|
+
return pkgData;
|
|
271
|
+
};
|
|
272
|
+
var init = async () => {
|
|
273
|
+
createDir();
|
|
274
|
+
await createOtherFile();
|
|
275
|
+
createConfig();
|
|
276
|
+
modifyPackageJson();
|
|
277
|
+
process.exit(0);
|
|
278
|
+
};
|
|
279
|
+
var start2 = async (env = ".env") => {
|
|
280
|
+
const dir2 = process.cwd();
|
|
281
|
+
const list = env === ".env" ? [".env"] : [".env", env];
|
|
282
|
+
list.forEach((item) => {
|
|
283
|
+
if (!fs2__default.default.existsSync(`${dir2}/${item}`)) {
|
|
284
|
+
if (env === ".env") {
|
|
285
|
+
console.error(`\u672A\u627E\u5230${item}\u6587\u4EF6\uFF0C\u8BF7\u4F7F\u7528 pnpm init \u8FDB\u884C\u521D\u59CB\u5316\u9879\u76EE`);
|
|
286
|
+
} else {
|
|
287
|
+
console.error(`\u672A\u627E\u5230${item}\u6587\u4EF6\uFF0C\u8BF7\u5C06\u5176\u653E\u7F6E\u5728\u9879\u76EE\u6839\u76EE\u5F55`);
|
|
288
|
+
}
|
|
289
|
+
process.exit(1);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
const path3 = list.map((item) => `${dir2}/${item}`);
|
|
293
|
+
dotenv__default.default.config({ path: path3, override: true });
|
|
294
|
+
const index = "../root.js";
|
|
295
|
+
const { karinMain } = await import(index);
|
|
296
|
+
const child = child_process.fork(karinMain);
|
|
297
|
+
child.on("message", (message) => {
|
|
298
|
+
if (message === "restart") {
|
|
299
|
+
child.kill();
|
|
300
|
+
child.removeAllListeners();
|
|
301
|
+
start2(env);
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
child.on("exit", (code) => process.exit(code));
|
|
305
|
+
};
|
|
306
|
+
var checkGitInstalled = () => {
|
|
307
|
+
try {
|
|
308
|
+
child_process.execSync("git --version");
|
|
309
|
+
return true;
|
|
310
|
+
} catch {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
var updateDependencies = async (packagePath) => {
|
|
315
|
+
try {
|
|
316
|
+
const packageJson = JSON.parse(fs2.readFileSync(packagePath, "utf-8"));
|
|
317
|
+
const dependencies = packageJson.dependencies || {};
|
|
318
|
+
const packagesToUpdate = [];
|
|
319
|
+
for (const [pkg, version] of Object.entries(dependencies)) {
|
|
320
|
+
if (pkg.startsWith("@types/")) {
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
const latestVersion = child_process.execSync(`pnpm view ${pkg} version`, { encoding: "utf-8" }).trim();
|
|
325
|
+
const currentVersion = version.replace(/[\^~]/g, "");
|
|
326
|
+
if (latestVersion !== currentVersion) {
|
|
327
|
+
console.log(`\u53D1\u73B0\u65B0\u7248\u672C ${pkg}: ${currentVersion} -> ${latestVersion}`);
|
|
328
|
+
packagesToUpdate.push(`${pkg}@latest`);
|
|
329
|
+
} else {
|
|
330
|
+
console.log(`${pkg} \u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C`);
|
|
331
|
+
}
|
|
332
|
+
} catch (error) {
|
|
333
|
+
console.error(`\u68C0\u67E5 ${pkg} \u7248\u672C\u5931\u8D25:`, error);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (packagesToUpdate.length > 0) {
|
|
337
|
+
console.log("\n\u5F00\u59CB\u66F4\u65B0\u4EE5\u4E0B\u5305:\n", packagesToUpdate.join("\n"));
|
|
338
|
+
try {
|
|
339
|
+
child_process.execSync(`pnpm update ${packagesToUpdate.join(" ")}`, {
|
|
340
|
+
stdio: "inherit"
|
|
341
|
+
});
|
|
342
|
+
console.log("\n\u6240\u6709\u5305\u66F4\u65B0\u5B8C\u6210");
|
|
343
|
+
} catch (error) {
|
|
344
|
+
console.error("\u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
|
|
345
|
+
}
|
|
346
|
+
} else {
|
|
347
|
+
console.log("\n\u6240\u6709\u5305\u90FD\u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C");
|
|
348
|
+
}
|
|
349
|
+
} catch (error) {
|
|
350
|
+
console.error("\u66F4\u65B0\u4F9D\u8D56\u5931\u8D25:", error);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
var updatePlugins = async (pluginsPath) => {
|
|
354
|
+
if (!checkGitInstalled()) {
|
|
355
|
+
console.error("\u8BF7\u5148\u5B89\u88C5git");
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (!fs2.existsSync(pluginsPath)) {
|
|
359
|
+
console.error("plugins\u76EE\u5F55\u4E0D\u5B58\u5728");
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const isDirectory = (await promises.stat(pluginsPath)).isDirectory();
|
|
363
|
+
if (!isDirectory) {
|
|
364
|
+
console.error("plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
const dirs = await promises.readdir(pluginsPath);
|
|
368
|
+
for (const dir2 of dirs) {
|
|
369
|
+
const pluginPath = path2.join(pluginsPath, dir2);
|
|
370
|
+
const gitPath = path2.join(pluginPath, ".git");
|
|
371
|
+
const packageJsonPath = path2.join(pluginPath, "package.json");
|
|
372
|
+
if (!dir2.startsWith("karin-plugin-") || !(await promises.stat(pluginPath)).isDirectory()) {
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
if (!fs2.existsSync(gitPath)) {
|
|
376
|
+
console.log(`${dir2} \u4E0D\u662Fgit\u4ED3\u5E93\uFF0C\u8DF3\u8FC7`);
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
try {
|
|
380
|
+
const packageJson = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
|
|
381
|
+
if (!packageJson.karin) {
|
|
382
|
+
console.log(`${dir2} \u7684package.json\u4E2D\u6CA1\u6709karin\u5B57\u6BB5\uFF0C\u8DF3\u8FC7`);
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
console.log(`\u6B63\u5728\u66F4\u65B0 ${dir2}...`);
|
|
386
|
+
child_process.execSync("git pull", { cwd: pluginPath, stdio: "inherit" });
|
|
387
|
+
} catch (error) {
|
|
388
|
+
console.error(`\u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
var updateAll = async () => {
|
|
393
|
+
try {
|
|
394
|
+
await Promise.all([updateDependencies("./package.json"), updatePlugins("./plugins")]);
|
|
395
|
+
} finally {
|
|
396
|
+
process.exit(0);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
commander.program.version(process.env.npm_package_version, "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
|
|
400
|
+
commander.program.command(".").description("\u524D\u53F0\u542F\u52A8").action(start2);
|
|
401
|
+
commander.program.command("start").description("\u524D\u53F0\u542F\u52A8").action(start2);
|
|
402
|
+
commander.program.command("pm2").description("\u540E\u53F0\u8FD0\u884C").action(pm2.start);
|
|
403
|
+
commander.program.command("stop").description("\u505C\u6B62\u540E\u53F0\u8FD0\u884C").action(pm2.stop);
|
|
404
|
+
commander.program.command("rs").description("\u91CD\u542Fpm2\u670D\u52A1").action(pm2.restart);
|
|
405
|
+
commander.program.command("log").description("\u67E5\u770B\u65E5\u5FD7").action(pm2.log);
|
|
406
|
+
commander.program.command("up").description("\u66F4\u65B0\u63D2\u4EF6").action(updateAll);
|
|
407
|
+
commander.program.command("init").description("\u521D\u59CB\u5316\u9879\u76EE").action(init);
|
|
408
|
+
commander.program.parse(process.argv);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|