node-karin 1.9.0 → 1.9.2
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/CHANGELOG.md +15 -0
- package/README.md +95 -0
- package/dist/cli/index.cjs +1 -1
- package/dist/cli/index.mjs +29 -13
- package/dist/index.d.ts +83 -2
- package/dist/index.mjs +19 -5
- package/package.json +2 -2
package/dist/cli/index.mjs
CHANGED
|
@@ -223,20 +223,36 @@ const stop = async () => {
|
|
|
223
223
|
};
|
|
224
224
|
const restart = async (force) => {
|
|
225
225
|
rotateLogs();
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
226
|
+
try {
|
|
227
|
+
const forceRestart = () => {
|
|
228
|
+
const appName2 = readPm2Config()?.apps?.[0]?.name || "karin";
|
|
229
|
+
execSync(`pm2 delete ${appName2}`, { cwd: process.cwd() });
|
|
230
|
+
execSync(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
|
|
231
|
+
console.log("[pm2] 重启成功");
|
|
232
|
+
};
|
|
233
|
+
console.log("[pm2] 重启中...");
|
|
234
|
+
if (!fs.existsSync(pm2Dir)) {
|
|
235
|
+
console.log(`[pm2] 配置文件不存在 请检查 ${pm2Dir} 是否存在`);
|
|
236
|
+
console.log("[pm2] 如果是新项目,请先前台启动生成配置文件: pnpm app");
|
|
237
|
+
process.exit(1);
|
|
238
|
+
}
|
|
239
|
+
if (force) {
|
|
240
|
+
forceRestart();
|
|
241
|
+
process.exit(0);
|
|
242
|
+
}
|
|
243
|
+
const appName = readPm2Config()?.apps?.[0]?.name || "karin";
|
|
244
|
+
if (!appName) ;
|
|
245
|
+
execSync(`pm2 restart ${appName}`, { cwd: process.cwd() });
|
|
246
|
+
console.log("[pm2] 重启成功");
|
|
247
|
+
process.exit(0);
|
|
248
|
+
} catch (error2) {
|
|
249
|
+
console.log("[pm2] 尝试直接重启失败 尝试删除服务并重新启动");
|
|
250
|
+
const appName = readPm2Config()?.apps?.[0]?.name || "karin";
|
|
251
|
+
execSync(`pm2 delete ${appName}`, { cwd: process.cwd() });
|
|
252
|
+
execSync(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
|
|
253
|
+
console.log("[pm2] 重启成功");
|
|
254
|
+
process.exit(0);
|
|
235
255
|
}
|
|
236
|
-
execSync(`pm2 delete ${appName}`, { cwd: process.cwd() });
|
|
237
|
-
execSync(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
|
|
238
|
-
console.log("[pm2] 重启成功");
|
|
239
|
-
process.exit(0);
|
|
240
256
|
};
|
|
241
257
|
const pm2 = {
|
|
242
258
|
start: start$1,
|
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ import { exec as exec$1, ExecException } from 'child_process';
|
|
|
16
16
|
export { ExecException } from 'child_process';
|
|
17
17
|
import { RedisClientOptions, RedisClientType } from 'redis';
|
|
18
18
|
import * as http from 'http';
|
|
19
|
-
import { KarinPluginType } from '@karinjs/plugins-list';
|
|
20
19
|
import { WebSocket } from 'ws';
|
|
21
20
|
|
|
22
21
|
declare const debug: {
|
|
@@ -7730,6 +7729,88 @@ interface SandboxSendApi {
|
|
|
7730
7729
|
init: SandBoxAccountInfo;
|
|
7731
7730
|
}
|
|
7732
7731
|
|
|
7732
|
+
/**
|
|
7733
|
+
* TODO: 后续改为自动化
|
|
7734
|
+
*/
|
|
7735
|
+
/**
|
|
7736
|
+
* 插件基础类型
|
|
7737
|
+
*/
|
|
7738
|
+
interface KarinPluginBase {
|
|
7739
|
+
/** 插件包名 */
|
|
7740
|
+
name: string;
|
|
7741
|
+
/**
|
|
7742
|
+
* 插件类型
|
|
7743
|
+
* - npm: npm 插件
|
|
7744
|
+
* - git: git 插件
|
|
7745
|
+
* - app: 单应用插件
|
|
7746
|
+
*/
|
|
7747
|
+
type: 'npm' | 'git' | 'app';
|
|
7748
|
+
/** 插件描述 限制 50 长度 */
|
|
7749
|
+
description: string;
|
|
7750
|
+
/** 插件提交到仓库时间 */
|
|
7751
|
+
time: string;
|
|
7752
|
+
/** 插件主页 */
|
|
7753
|
+
home: string;
|
|
7754
|
+
/** 插件许可证 */
|
|
7755
|
+
license: {
|
|
7756
|
+
/** 许可证名称 */
|
|
7757
|
+
name: string;
|
|
7758
|
+
/** 许可证地址 */
|
|
7759
|
+
url: string;
|
|
7760
|
+
};
|
|
7761
|
+
/** 插件作者 */
|
|
7762
|
+
author: {
|
|
7763
|
+
/** 名字 */
|
|
7764
|
+
name: string;
|
|
7765
|
+
/** 主页 */
|
|
7766
|
+
home: string;
|
|
7767
|
+
/** 头像 仅支持url 如果是github、gitee无需填写 */
|
|
7768
|
+
avatar?: string;
|
|
7769
|
+
}[];
|
|
7770
|
+
/** 插件仓库 */
|
|
7771
|
+
repo: {
|
|
7772
|
+
/** 仓库类型 */
|
|
7773
|
+
type: 'github' | 'gitee' | 'gitcode' | 'gitlab' | 'npm';
|
|
7774
|
+
/** 仓库地址 */
|
|
7775
|
+
url: string;
|
|
7776
|
+
/** 默认分支 npm类型为空字符串 */
|
|
7777
|
+
branch: string;
|
|
7778
|
+
}[];
|
|
7779
|
+
}
|
|
7780
|
+
/**
|
|
7781
|
+
* npm 插件类型
|
|
7782
|
+
*/
|
|
7783
|
+
interface KarinNpmPlugin extends KarinPluginBase {
|
|
7784
|
+
type: 'npm';
|
|
7785
|
+
/** 允许pnpm在安装期间执行脚本的包名列表 */
|
|
7786
|
+
allowBuild?: string[];
|
|
7787
|
+
}
|
|
7788
|
+
/**
|
|
7789
|
+
* git 插件类型
|
|
7790
|
+
*/
|
|
7791
|
+
interface KarinGitPlugin extends KarinPluginBase {
|
|
7792
|
+
type: 'git';
|
|
7793
|
+
}
|
|
7794
|
+
/**
|
|
7795
|
+
* 单应用插件类型
|
|
7796
|
+
*/
|
|
7797
|
+
interface KarinAppPlugin extends KarinPluginBase {
|
|
7798
|
+
type: 'app';
|
|
7799
|
+
/** app文件直链 */
|
|
7800
|
+
files: {
|
|
7801
|
+
/** app插件名称 */
|
|
7802
|
+
name: string;
|
|
7803
|
+
/** 文件直链 */
|
|
7804
|
+
url: string;
|
|
7805
|
+
/** 描述 */
|
|
7806
|
+
description?: string;
|
|
7807
|
+
}[];
|
|
7808
|
+
}
|
|
7809
|
+
/**
|
|
7810
|
+
* 插件市场类型每个插件的类型
|
|
7811
|
+
*/
|
|
7812
|
+
type KarinPluginType = KarinNpmPlugin | KarinGitPlugin | KarinAppPlugin;
|
|
7813
|
+
|
|
7733
7814
|
/**
|
|
7734
7815
|
* 基类
|
|
7735
7816
|
*/
|
|
@@ -10103,7 +10184,7 @@ declare const downloadFile: <T extends boolean = false>(fileUrl: string, savePat
|
|
|
10103
10184
|
* @param savePath 保存路径
|
|
10104
10185
|
* @param param axios参数
|
|
10105
10186
|
*/
|
|
10106
|
-
declare const downFile: (fileUrl: string, savePath: string, param?: AxiosRequestConfig) => Promise<boolean
|
|
10187
|
+
declare const downFile: (fileUrl: string, savePath: string, param?: AxiosRequestConfig) => Promise<DownloadFileResult<boolean>>;
|
|
10107
10188
|
/**
|
|
10108
10189
|
* 标准化文件路径 统一使用/分隔符
|
|
10109
10190
|
* @param file - 路径
|
package/dist/index.mjs
CHANGED
|
@@ -692,8 +692,16 @@ var init_logger = __esm({
|
|
|
692
692
|
process.stdout.write(`${prefixText} ${message2}
|
|
693
693
|
`);
|
|
694
694
|
}
|
|
695
|
-
state.fileWriter
|
|
695
|
+
if (state.fileWriter) {
|
|
696
|
+
try {
|
|
697
|
+
state.fileWriter.write(level, `[${timestamp}][${levelText}] ${message2}
|
|
698
|
+
`);
|
|
699
|
+
} catch (err) {
|
|
700
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
701
|
+
process.stdout.write(`${chalk2.red(`${state.config.prefix}[${timestamp}][ERROR]`)} \u6587\u4EF6\u5199\u5165\u5931\u8D25: ${errorMessage}
|
|
696
702
|
`);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
697
705
|
};
|
|
698
706
|
};
|
|
699
707
|
setupWriters();
|
|
@@ -1371,8 +1379,12 @@ var init_file2 = __esm({
|
|
|
1371
1379
|
createPluginDir = async (name, files) => {
|
|
1372
1380
|
if (!Array.isArray(files)) files = ["config", "data", "resources"];
|
|
1373
1381
|
if (files.length === 0) return;
|
|
1374
|
-
const
|
|
1375
|
-
|
|
1382
|
+
const isOrgPkg = name.startsWith("@") && name.includes("/");
|
|
1383
|
+
let pluginPath = isOrgPkg ? path5.join(karinPathBase, name.replace("/", "-")) : path5.join(karinPathBase, name);
|
|
1384
|
+
if (isOrgPkg && !fs6.existsSync(pluginPath)) {
|
|
1385
|
+
const [orgName, pkgName] = name.split("/");
|
|
1386
|
+
pluginPath = path5.join(karinPathBase, orgName, pkgName);
|
|
1387
|
+
}
|
|
1376
1388
|
await Promise.all(files.map((file) => {
|
|
1377
1389
|
const filePath = path5.join(pluginPath, file);
|
|
1378
1390
|
if (!fs6.existsSync(filePath)) return fs6.promises.mkdir(filePath, { recursive: true });
|
|
@@ -11191,7 +11203,7 @@ var init_restart = __esm({
|
|
|
11191
11203
|
}));
|
|
11192
11204
|
return { status: "success", data: "\u5DF2\u53D1\u9001\u91CD\u542F\u4FE1\u53F7" };
|
|
11193
11205
|
}
|
|
11194
|
-
if (process.env.PM2_RESTART
|
|
11206
|
+
if (process.env.PM2_RESTART !== "true") process.exit();
|
|
11195
11207
|
if (process.env.pm_id) {
|
|
11196
11208
|
const { error: error2 } = await exec("npx karin rs");
|
|
11197
11209
|
if (error2) return { status: "failed", data: error2 };
|
|
@@ -11213,12 +11225,14 @@ var init_restart = __esm({
|
|
|
11213
11225
|
process.exit(0);
|
|
11214
11226
|
}
|
|
11215
11227
|
if (process.env.RUNTIME === "pm2") {
|
|
11228
|
+
if (process.env.PM2_RESTART !== "true") process.exit();
|
|
11216
11229
|
await exec("npx karin rs");
|
|
11217
11230
|
return;
|
|
11218
11231
|
}
|
|
11219
11232
|
if (process.env.RUNTIME === "tsx") {
|
|
11220
11233
|
throw new Error("tsx \u4E0D\u652F\u6301\u91CD\u542F");
|
|
11221
11234
|
}
|
|
11235
|
+
if (process.env.PM2_RESTART !== "true") process.exit();
|
|
11222
11236
|
const { error } = await exec("npx karin pm2");
|
|
11223
11237
|
if (error) throw error;
|
|
11224
11238
|
};
|
|
@@ -19218,7 +19232,7 @@ var init_load = __esm({
|
|
|
19218
19232
|
} else if (Array.isArray(pkg2.pkgData.karin?.files)) {
|
|
19219
19233
|
files.push(...pkg2.pkgData.karin.files);
|
|
19220
19234
|
}
|
|
19221
|
-
await createPluginDir(pkg2.name
|
|
19235
|
+
await createPluginDir(pkg2.name, files);
|
|
19222
19236
|
debug("debug: createPluginDir", pkg2.name, files);
|
|
19223
19237
|
pkg2.apps.forEach((app4) => {
|
|
19224
19238
|
const promise = async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-karin",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"description": "Lightweight, efficient, concise, and stable robot framework.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
"app": "node dist/start/index.mjs",
|
|
145
145
|
"build": "pnpm build:main && pnpm build:module",
|
|
146
146
|
"build:dev": "pnpm build:main",
|
|
147
|
-
"build:main": "tsc && tsup
|
|
147
|
+
"build:main": "tsc && tsup",
|
|
148
148
|
"build:module": "tsc && tsup --config tsup.config.module.ts",
|
|
149
149
|
"build:types": "tsc && tsup --config tsup.config.types.ts",
|
|
150
150
|
"app:bun": "bun dist/start/index.mjs",
|