node-karin 1.1.2 → 1.1.4
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 +14 -0
- package/dist/index.d.ts +13 -4
- package/dist/index.js +221 -155
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## [1.1.4](https://github.com/KarinJS/Karin/compare/core-v1.1.3...core-v1.1.4) (2025-01-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### 🐛 Bug Fixes
|
|
7
|
+
|
|
8
|
+
* 热更新`.env`未更新日志等级 ([b8b7c99](https://github.com/KarinJS/Karin/commit/b8b7c995cbd1fcd957e298f704fbafaa21b1a330))
|
|
9
|
+
|
|
10
|
+
## [1.1.3](https://github.com/KarinJS/Karin/compare/core-v1.1.2...core-v1.1.3) (2025-01-16)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### 🐛 Bug Fixes
|
|
14
|
+
|
|
15
|
+
* 热更新`.env` ([90c4eb8](https://github.com/KarinJS/Karin/commit/90c4eb86dbefd236b7a672a8c5a0c0a848964fff))
|
|
16
|
+
|
|
3
17
|
## [1.1.2](https://github.com/KarinJS/Karin/compare/core-v1.1.1...core-v1.1.2) (2025-01-16)
|
|
4
18
|
|
|
5
19
|
|
package/dist/index.d.ts
CHANGED
|
@@ -8957,6 +8957,8 @@ interface Config {
|
|
|
8957
8957
|
admin: string[];
|
|
8958
8958
|
/** 用户管理 */
|
|
8959
8959
|
user: {
|
|
8960
|
+
/** 是否启用用户事件 */
|
|
8961
|
+
enable: boolean;
|
|
8960
8962
|
/** 用户白名单 */
|
|
8961
8963
|
enable_list: string[];
|
|
8962
8964
|
/** 用户黑名单 */
|
|
@@ -9198,7 +9200,7 @@ type Groups = Record<string, {
|
|
|
9198
9200
|
}>;
|
|
9199
9201
|
|
|
9200
9202
|
/**
|
|
9201
|
-
* `
|
|
9203
|
+
* `privates.json` 类型
|
|
9202
9204
|
*/
|
|
9203
9205
|
type Privates = Record<string, {
|
|
9204
9206
|
/** 好友消息冷却时间,单位秒,0则无限制 */
|
|
@@ -9279,8 +9281,9 @@ declare const clearTemp: () => void;
|
|
|
9279
9281
|
/**
|
|
9280
9282
|
* 更新日志等级
|
|
9281
9283
|
* @param level 日志等级
|
|
9284
|
+
* @returns 返回更新后的日志等级
|
|
9282
9285
|
*/
|
|
9283
|
-
declare const updateLevel: (level?: string) =>
|
|
9286
|
+
declare const updateLevel: (level?: string) => string;
|
|
9284
9287
|
|
|
9285
9288
|
/**
|
|
9286
9289
|
* 获取群聊、频道配置
|
|
@@ -9530,6 +9533,11 @@ declare const getDirectCfg: (userId: string, selfId: string) => {
|
|
|
9530
9533
|
readonly key: string;
|
|
9531
9534
|
};
|
|
9532
9535
|
|
|
9536
|
+
/**
|
|
9537
|
+
* 监听.env文件变化并自动重新加载
|
|
9538
|
+
*/
|
|
9539
|
+
declare const watchEnv: () => Promise<void>;
|
|
9540
|
+
|
|
9533
9541
|
declare const index_admin: typeof admin;
|
|
9534
9542
|
declare const index_authKey: typeof authKey;
|
|
9535
9543
|
declare const index_clearTemp: typeof clearTemp;
|
|
@@ -9557,9 +9565,10 @@ declare const index_setStr: typeof setStr;
|
|
|
9557
9565
|
declare const index_setYaml: typeof setYaml;
|
|
9558
9566
|
declare const index_timeout: typeof timeout;
|
|
9559
9567
|
declare const index_updateLevel: typeof updateLevel;
|
|
9568
|
+
declare const index_watchEnv: typeof watchEnv;
|
|
9560
9569
|
declare const index_webSocketServerToken: typeof webSocketServerToken;
|
|
9561
9570
|
declare namespace index {
|
|
9562
|
-
export { adapter$1 as adapter, index_admin as admin, index_authKey as authKey, index_clearTemp as clearTemp, index_config as config, index_defaultConfig as defaultConfig, index_ffmpegPath as ffmpegPath, index_ffplayPath as ffplayPath, index_ffprobePath as ffprobePath, index_getDirectCfg as getDirectCfg, index_getFriendCfg as getFriendCfg, index_getGroupCfg as getGroupCfg, index_getGuildCfg as getGuildCfg, index_getYaml as getYaml, index_groups as groups, index_host as host, index_lint as lint, index_master as master, index_mergeData as mergeData, index_pkg as pkg, index_pm2 as pm2, index_port as port, index_privates as privates, index_redis as redis, render$1 as render, index_setStr as setStr, index_setYaml as setYaml, index_timeout as timeout, index_updateLevel as updateLevel, index_webSocketServerToken as webSocketServerToken };
|
|
9571
|
+
export { adapter$1 as adapter, index_admin as admin, index_authKey as authKey, index_clearTemp as clearTemp, index_config as config, index_defaultConfig as defaultConfig, index_ffmpegPath as ffmpegPath, index_ffplayPath as ffplayPath, index_ffprobePath as ffprobePath, index_getDirectCfg as getDirectCfg, index_getFriendCfg as getFriendCfg, index_getGroupCfg as getGroupCfg, index_getGuildCfg as getGuildCfg, index_getYaml as getYaml, index_groups as groups, index_host as host, index_lint as lint, index_master as master, index_mergeData as mergeData, index_pkg as pkg, index_pm2 as pm2, index_port as port, index_privates as privates, index_redis as redis, render$1 as render, index_setStr as setStr, index_setYaml as setYaml, index_timeout as timeout, index_updateLevel as updateLevel, index_watchEnv as watchEnv, index_webSocketServerToken as webSocketServerToken };
|
|
9563
9572
|
}
|
|
9564
9573
|
|
|
9565
9574
|
/** ws 服务 */
|
|
@@ -9684,7 +9693,7 @@ declare const contact: {
|
|
|
9684
9693
|
declare class AdapterConsole extends AdapterBase implements AdapterType {
|
|
9685
9694
|
constructor();
|
|
9686
9695
|
get selfId(): string;
|
|
9687
|
-
createEvent(data: Buffer): void
|
|
9696
|
+
createEvent(data: Buffer): Promise<void>;
|
|
9688
9697
|
sendMsg(contact: Contact, elements: Array<Elements>, retryCount?: number): Promise<SendMsgResults>;
|
|
9689
9698
|
getUrl(data: string | Buffer, ext: string): Promise<string>;
|
|
9690
9699
|
}
|
package/dist/index.js
CHANGED
|
@@ -492,9 +492,9 @@ var init_data = __esm({
|
|
|
492
492
|
stream2.on("end", () => resolve(Buffer.concat(chunks)));
|
|
493
493
|
stream2.on("error", (error) => reject(error));
|
|
494
494
|
});
|
|
495
|
-
readFile = async (
|
|
495
|
+
readFile = async (path17) => {
|
|
496
496
|
try {
|
|
497
|
-
const data = await fs5.promises.readFile(
|
|
497
|
+
const data = await fs5.promises.readFile(path17);
|
|
498
498
|
return data;
|
|
499
499
|
} catch (error) {
|
|
500
500
|
logger.error(error);
|
|
@@ -801,9 +801,11 @@ var init_config = __esm({
|
|
|
801
801
|
updateLevel = (level2) => {
|
|
802
802
|
if (level2) {
|
|
803
803
|
logger.level = level2;
|
|
804
|
-
return;
|
|
804
|
+
return level2;
|
|
805
805
|
}
|
|
806
|
-
|
|
806
|
+
const newLevel = process.env.LOG_LEVEL || "info";
|
|
807
|
+
logger.level = newLevel;
|
|
808
|
+
return newLevel;
|
|
807
809
|
};
|
|
808
810
|
watch(FILE, async (_, data) => {
|
|
809
811
|
cache3 = await lint(defaultConfig.config, data);
|
|
@@ -1147,10 +1149,10 @@ var init_yaml = __esm({
|
|
|
1147
1149
|
* 获取指定路径的值
|
|
1148
1150
|
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
1149
1151
|
*/
|
|
1150
|
-
get(
|
|
1152
|
+
get(path17) {
|
|
1151
1153
|
try {
|
|
1152
|
-
if (!
|
|
1153
|
-
return lodash.get(this.document.toJSON(),
|
|
1154
|
+
if (!path17) return this.document.toJSON();
|
|
1155
|
+
return lodash.get(this.document.toJSON(), path17);
|
|
1154
1156
|
} catch (error) {
|
|
1155
1157
|
logger.error(`[YamlEditor] \u83B7\u53D6\u6570\u636E\u65F6\u51FA\u9519\uFF1A${error}`);
|
|
1156
1158
|
return null;
|
|
@@ -1162,9 +1164,9 @@ var init_yaml = __esm({
|
|
|
1162
1164
|
* @param value - 要设置的值 允许的类型:`string`, `boolean`, `number`, `object`, `array`
|
|
1163
1165
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1164
1166
|
*/
|
|
1165
|
-
set(
|
|
1167
|
+
set(path17, value, isSplit = true) {
|
|
1166
1168
|
try {
|
|
1167
|
-
const _path = typeof
|
|
1169
|
+
const _path = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1168
1170
|
this.document.setIn(_path, value);
|
|
1169
1171
|
return true;
|
|
1170
1172
|
} catch (error) {
|
|
@@ -1178,11 +1180,11 @@ var init_yaml = __esm({
|
|
|
1178
1180
|
* @param value - 要添加的值
|
|
1179
1181
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1180
1182
|
*/
|
|
1181
|
-
add(
|
|
1183
|
+
add(path17, value, isSplit = true) {
|
|
1182
1184
|
try {
|
|
1183
|
-
const _path = typeof
|
|
1185
|
+
const _path = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1184
1186
|
this.document.addIn(_path, value);
|
|
1185
|
-
logger.debug(`[YamlEditor] \u5DF2\u5728 ${
|
|
1187
|
+
logger.debug(`[YamlEditor] \u5DF2\u5728 ${path17} \u6DFB\u52A0\u65B0\u7684\u503C`);
|
|
1186
1188
|
return true;
|
|
1187
1189
|
} catch (error) {
|
|
1188
1190
|
logger.error(`[YamlEditor] \u6DFB\u52A0\u6570\u636E\u65F6\u51FA\u9519\uFF1A${error}`);
|
|
@@ -1195,9 +1197,9 @@ var init_yaml = __esm({
|
|
|
1195
1197
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1196
1198
|
* @returns 是否删除成功
|
|
1197
1199
|
*/
|
|
1198
|
-
del(
|
|
1200
|
+
del(path17, isSplit = true) {
|
|
1199
1201
|
try {
|
|
1200
|
-
const _path = typeof
|
|
1202
|
+
const _path = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1201
1203
|
this.document.deleteIn(_path);
|
|
1202
1204
|
return true;
|
|
1203
1205
|
} catch (error) {
|
|
@@ -1212,9 +1214,9 @@ var init_yaml = __esm({
|
|
|
1212
1214
|
* @param prepend - 如果为 true,则添加到数组的开头,否则添加到末尾
|
|
1213
1215
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1214
1216
|
*/
|
|
1215
|
-
append(
|
|
1217
|
+
append(path17, value, prepend = false, isSplit = true) {
|
|
1216
1218
|
try {
|
|
1217
|
-
const _path = typeof
|
|
1219
|
+
const _path = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1218
1220
|
let current = this.document.getIn(_path);
|
|
1219
1221
|
if (!current) {
|
|
1220
1222
|
current = new YAML.YAMLSeq();
|
|
@@ -1225,7 +1227,7 @@ var init_yaml = __esm({
|
|
|
1225
1227
|
} else {
|
|
1226
1228
|
prepend ? current.items.unshift(value) : current.add(value);
|
|
1227
1229
|
}
|
|
1228
|
-
logger.debug(`[YamlEditor] \u5DF2\u5411 ${
|
|
1230
|
+
logger.debug(`[YamlEditor] \u5DF2\u5411 ${path17} \u6570\u7EC4${prepend ? "\u5F00\u5934" : "\u672B\u5C3E"}\u6DFB\u52A0\u65B0\u5143\u7D20\uFF1A${value}`);
|
|
1229
1231
|
return true;
|
|
1230
1232
|
} catch (error) {
|
|
1231
1233
|
logger.error(`[YamlEditor] \u5411\u6570\u7EC4\u6DFB\u52A0\u5143\u7D20\u65F6\u51FA\u9519\uFF1A${error}`);
|
|
@@ -1238,9 +1240,9 @@ var init_yaml = __esm({
|
|
|
1238
1240
|
* @param value - 要删除的值
|
|
1239
1241
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1240
1242
|
*/
|
|
1241
|
-
remove(
|
|
1243
|
+
remove(path17, value, isSplit = true) {
|
|
1242
1244
|
try {
|
|
1243
|
-
const _path = typeof
|
|
1245
|
+
const _path = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1244
1246
|
const current = this.document.getIn(_path);
|
|
1245
1247
|
if (!current) {
|
|
1246
1248
|
logger.error("[YamlEditor] \u6307\u5B9A\u7684\u8DEF\u5F84\u4E0D\u5B58\u5728");
|
|
@@ -1256,7 +1258,7 @@ var init_yaml = __esm({
|
|
|
1256
1258
|
return false;
|
|
1257
1259
|
}
|
|
1258
1260
|
current.items.splice(index4, 1);
|
|
1259
|
-
logger.debug(`[YamlEditor] \u5DF2\u4ECE ${
|
|
1261
|
+
logger.debug(`[YamlEditor] \u5DF2\u4ECE ${path17} \u6570\u7EC4\u5220\u9664\u5143\u7D20\uFF1A${value}`);
|
|
1260
1262
|
return true;
|
|
1261
1263
|
} catch (error) {
|
|
1262
1264
|
logger.error(`[YamlEditor] \u4ECE\u6570\u7EC4\u5220\u9664\u5143\u7D20\u65F6\u51FA\u9519\uFF1A${error}`);
|
|
@@ -1268,9 +1270,9 @@ var init_yaml = __esm({
|
|
|
1268
1270
|
* @param path - 路径,用点号分隔
|
|
1269
1271
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1270
1272
|
*/
|
|
1271
|
-
has(
|
|
1273
|
+
has(path17, isSplit = true) {
|
|
1272
1274
|
try {
|
|
1273
|
-
const _path = typeof
|
|
1275
|
+
const _path = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1274
1276
|
return this.document.hasIn(_path);
|
|
1275
1277
|
} catch (error) {
|
|
1276
1278
|
logger.error(`[YamlEditor] \u68C0\u67E5\u8DEF\u5F84\u662F\u5426\u5B58\u5728\u65F6\u51FA\u9519\uFF1A${error}`);
|
|
@@ -1283,9 +1285,9 @@ var init_yaml = __esm({
|
|
|
1283
1285
|
* @param value - 要查询的值
|
|
1284
1286
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1285
1287
|
*/
|
|
1286
|
-
hasval(
|
|
1288
|
+
hasval(path17, value, isSplit = true) {
|
|
1287
1289
|
try {
|
|
1288
|
-
const _path = typeof
|
|
1290
|
+
const _path = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1289
1291
|
const current = this.document.getIn(_path);
|
|
1290
1292
|
if (!current) return false;
|
|
1291
1293
|
if (current instanceof YAML.YAMLSeq) {
|
|
@@ -1296,7 +1298,7 @@ var init_yaml = __esm({
|
|
|
1296
1298
|
return lodash.isEqual(current, value);
|
|
1297
1299
|
}
|
|
1298
1300
|
} catch (error) {
|
|
1299
|
-
logger.error(`[YamlEditor] \u68C0\u67E5\u8DEF\u5F84 ${
|
|
1301
|
+
logger.error(`[YamlEditor] \u68C0\u67E5\u8DEF\u5F84 ${path17} \u662F\u5426\u5305\u542B\u503C\u65F6\u51FA\u9519\uFF1A${error}`);
|
|
1300
1302
|
return false;
|
|
1301
1303
|
}
|
|
1302
1304
|
}
|
|
@@ -1306,8 +1308,8 @@ var init_yaml = __esm({
|
|
|
1306
1308
|
* @param value - 要查询的值
|
|
1307
1309
|
* @deprecated 请使用 `hasval` 代替
|
|
1308
1310
|
*/
|
|
1309
|
-
hasVal(
|
|
1310
|
-
return this.hasval(
|
|
1311
|
+
hasVal(path17, value) {
|
|
1312
|
+
return this.hasval(path17, value);
|
|
1311
1313
|
}
|
|
1312
1314
|
/**
|
|
1313
1315
|
* 向根节点新增元素,如果根节点不是数组,则将其转换为数组再新增元素
|
|
@@ -1352,9 +1354,9 @@ var init_yaml = __esm({
|
|
|
1352
1354
|
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
1353
1355
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1354
1356
|
*/
|
|
1355
|
-
getpair(
|
|
1356
|
-
if (!
|
|
1357
|
-
const keys = typeof
|
|
1357
|
+
getpair(path17, isSplit = true) {
|
|
1358
|
+
if (!path17) throw new Error("path is required");
|
|
1359
|
+
const keys = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1358
1360
|
let pair = this.document.contents;
|
|
1359
1361
|
keys.forEach((key) => {
|
|
1360
1362
|
if (isMap(pair)) {
|
|
@@ -1374,10 +1376,10 @@ var init_yaml = __esm({
|
|
|
1374
1376
|
* @param prepend - 如果为 true,则添加注释到开头,否则添加到同一行的末尾
|
|
1375
1377
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1376
1378
|
*/
|
|
1377
|
-
comment(
|
|
1378
|
-
if (!
|
|
1379
|
-
const pair = this.getpair(
|
|
1380
|
-
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${
|
|
1379
|
+
comment(path17, comment2, prepend = true, isSplit = true) {
|
|
1380
|
+
if (!path17) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
|
|
1381
|
+
const pair = this.getpair(path17, isSplit);
|
|
1382
|
+
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path17}`);
|
|
1381
1383
|
comment2 = ` ${comment2}`;
|
|
1382
1384
|
if (prepend) {
|
|
1383
1385
|
pair.key.commentBefore = comment2;
|
|
@@ -1391,10 +1393,10 @@ var init_yaml = __esm({
|
|
|
1391
1393
|
* @param type - 要删除的注释类型,`before` 为注释前,`after` 为注释后,`all` 为全部
|
|
1392
1394
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1393
1395
|
*/
|
|
1394
|
-
uncomment(
|
|
1395
|
-
if (!
|
|
1396
|
-
const pair = this.getpair(
|
|
1397
|
-
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${
|
|
1396
|
+
uncomment(path17, type = "all", isSplit = true) {
|
|
1397
|
+
if (!path17) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
|
|
1398
|
+
const pair = this.getpair(path17, isSplit);
|
|
1399
|
+
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path17}`);
|
|
1398
1400
|
if (type === "all") {
|
|
1399
1401
|
delete pair.key.comment;
|
|
1400
1402
|
delete pair.key.commentBefore;
|
|
@@ -1410,10 +1412,10 @@ var init_yaml = __esm({
|
|
|
1410
1412
|
* @param type - 要检查的注释类型,`before` 为注释前,`after` 为注释后
|
|
1411
1413
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1412
1414
|
*/
|
|
1413
|
-
hascomment(
|
|
1414
|
-
if (!
|
|
1415
|
-
const pair = this.getpair(
|
|
1416
|
-
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${
|
|
1415
|
+
hascomment(path17, type, isSplit = true) {
|
|
1416
|
+
if (!path17) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
|
|
1417
|
+
const pair = this.getpair(path17, isSplit);
|
|
1418
|
+
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path17}`);
|
|
1417
1419
|
if (type === "before") {
|
|
1418
1420
|
return !!pair.key.commentBefore;
|
|
1419
1421
|
} else if (type === "after") {
|
|
@@ -1426,10 +1428,10 @@ var init_yaml = __esm({
|
|
|
1426
1428
|
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
1427
1429
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1428
1430
|
*/
|
|
1429
|
-
getcomment(
|
|
1430
|
-
if (!
|
|
1431
|
-
const pair = this.getpair(
|
|
1432
|
-
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${
|
|
1431
|
+
getcomment(path17, isSplit = true) {
|
|
1432
|
+
if (!path17) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
|
|
1433
|
+
const pair = this.getpair(path17, isSplit);
|
|
1434
|
+
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path17}`);
|
|
1433
1435
|
return pair.key.commentBefore || pair.key.comment;
|
|
1434
1436
|
}
|
|
1435
1437
|
/**
|
|
@@ -1441,11 +1443,11 @@ var init_yaml = __esm({
|
|
|
1441
1443
|
logger.debug("[YamlEditor] \u6587\u4EF6\u5DF2\u4FDD\u5B58");
|
|
1442
1444
|
}
|
|
1443
1445
|
};
|
|
1444
|
-
read = (
|
|
1445
|
-
const data = YAML.parse(fs8.readFileSync(
|
|
1446
|
+
read = (path17) => {
|
|
1447
|
+
const data = YAML.parse(fs8.readFileSync(path17, "utf-8"));
|
|
1446
1448
|
read.save = (options) => {
|
|
1447
1449
|
try {
|
|
1448
|
-
save(
|
|
1450
|
+
save(path17, data, typeof options === "string" ? JSON.parse(options) : options);
|
|
1449
1451
|
return true;
|
|
1450
1452
|
} catch (error) {
|
|
1451
1453
|
logger.error("[YamlEditor] \u4FDD\u5B58\u6587\u4EF6\u65F6\u51FA\u9519");
|
|
@@ -1455,23 +1457,23 @@ var init_yaml = __esm({
|
|
|
1455
1457
|
};
|
|
1456
1458
|
return data;
|
|
1457
1459
|
};
|
|
1458
|
-
write = (
|
|
1460
|
+
write = (path17, value) => {
|
|
1459
1461
|
try {
|
|
1460
|
-
fs8.writeFileSync(
|
|
1462
|
+
fs8.writeFileSync(path17, YAML.stringify(value));
|
|
1461
1463
|
return true;
|
|
1462
1464
|
} catch {
|
|
1463
1465
|
return false;
|
|
1464
1466
|
}
|
|
1465
1467
|
};
|
|
1466
|
-
save = (
|
|
1468
|
+
save = (path17, value, options) => {
|
|
1467
1469
|
if (!options) {
|
|
1468
|
-
fs8.writeFileSync(
|
|
1470
|
+
fs8.writeFileSync(path17, YAML.stringify(value));
|
|
1469
1471
|
return;
|
|
1470
1472
|
}
|
|
1471
1473
|
const editor = new YamlEditor(YAML.stringify(value));
|
|
1472
1474
|
const comment2 = typeof options === "string" ? JSON.parse(fs8.readFileSync(options, "utf8")) : options;
|
|
1473
1475
|
applyComments(editor, comment2);
|
|
1474
|
-
fs8.writeFileSync(
|
|
1476
|
+
fs8.writeFileSync(path17, editor.document.toString());
|
|
1475
1477
|
};
|
|
1476
1478
|
comment = (filePath, commentConfig) => {
|
|
1477
1479
|
const editor = new YamlEditor(filePath);
|
|
@@ -1770,6 +1772,31 @@ var init_privates = __esm({
|
|
|
1770
1772
|
}
|
|
1771
1773
|
});
|
|
1772
1774
|
|
|
1775
|
+
// src/utils/config/env.ts
|
|
1776
|
+
import path6 from "node:path";
|
|
1777
|
+
import dotenv from "dotenv";
|
|
1778
|
+
import chokidar2 from "chokidar";
|
|
1779
|
+
var watchEnv;
|
|
1780
|
+
var init_env2 = __esm({
|
|
1781
|
+
"src/utils/config/env.ts"() {
|
|
1782
|
+
"use strict";
|
|
1783
|
+
init_esm_shims();
|
|
1784
|
+
watchEnv = async () => {
|
|
1785
|
+
const targetPath = path6.join(process.cwd(), ".env");
|
|
1786
|
+
const watcher = chokidar2.watch(targetPath, { persistent: true, ignoreInitial: true });
|
|
1787
|
+
const runtime = process.env.RUNTIME;
|
|
1788
|
+
watcher.on("change", async () => {
|
|
1789
|
+
logger.info("[\u914D\u7F6E\u6587\u4EF6\u53D8\u52A8] .env");
|
|
1790
|
+
dotenv.config({ path: targetPath, override: true });
|
|
1791
|
+
process.env.RUNTIME = runtime;
|
|
1792
|
+
const { updateLevel: updateLevel2 } = await init_config().then(() => config_exports);
|
|
1793
|
+
updateLevel2(process.env.LOG_LEVEL);
|
|
1794
|
+
});
|
|
1795
|
+
};
|
|
1796
|
+
watchEnv();
|
|
1797
|
+
}
|
|
1798
|
+
});
|
|
1799
|
+
|
|
1773
1800
|
// src/utils/config/index.ts
|
|
1774
1801
|
var config_exports2 = {};
|
|
1775
1802
|
__export(config_exports2, {
|
|
@@ -1802,6 +1829,7 @@ __export(config_exports2, {
|
|
|
1802
1829
|
setYaml: () => setYaml,
|
|
1803
1830
|
timeout: () => timeout,
|
|
1804
1831
|
updateLevel: () => updateLevel,
|
|
1832
|
+
watchEnv: () => watchEnv,
|
|
1805
1833
|
webSocketServerToken: () => webSocketServerToken
|
|
1806
1834
|
});
|
|
1807
1835
|
var init_config2 = __esm({
|
|
@@ -1816,6 +1844,7 @@ var init_config2 = __esm({
|
|
|
1816
1844
|
init_adapter();
|
|
1817
1845
|
init_default();
|
|
1818
1846
|
init_privates();
|
|
1847
|
+
init_env2();
|
|
1819
1848
|
}
|
|
1820
1849
|
});
|
|
1821
1850
|
|
|
@@ -1897,7 +1926,7 @@ var init_time = __esm({
|
|
|
1897
1926
|
// src/utils/fs/path.ts
|
|
1898
1927
|
import fs9 from "node:fs";
|
|
1899
1928
|
import lodash2 from "lodash";
|
|
1900
|
-
import
|
|
1929
|
+
import path7 from "node:path";
|
|
1901
1930
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
1902
1931
|
var filesByExt, splitPath, getRelPath, urlToPath, isSubPath;
|
|
1903
1932
|
var init_path = __esm({
|
|
@@ -1912,45 +1941,45 @@ var init_path = __esm({
|
|
|
1912
1941
|
if (!Array.isArray(ext)) ext = [ext];
|
|
1913
1942
|
files.forEach((v) => {
|
|
1914
1943
|
if (v.isDirectory()) return;
|
|
1915
|
-
if (ext.includes(
|
|
1944
|
+
if (ext.includes(path7.extname(v.name))) {
|
|
1916
1945
|
if (returnType === "name") {
|
|
1917
1946
|
list4.push(v.name);
|
|
1918
1947
|
} else if (returnType === "rel") {
|
|
1919
|
-
const file =
|
|
1920
|
-
list4.push(
|
|
1948
|
+
const file = path7.resolve(filePath, v.name);
|
|
1949
|
+
list4.push(path7.relative(process.cwd(), file));
|
|
1921
1950
|
} else if (returnType === "abs") {
|
|
1922
|
-
list4.push(
|
|
1951
|
+
list4.push(path7.resolve(filePath, v.name));
|
|
1923
1952
|
}
|
|
1924
1953
|
}
|
|
1925
1954
|
});
|
|
1926
1955
|
return list4;
|
|
1927
1956
|
};
|
|
1928
1957
|
splitPath = (filePath) => {
|
|
1929
|
-
const dirname =
|
|
1930
|
-
const basename =
|
|
1958
|
+
const dirname = path7.dirname(filePath).replace(sep, "");
|
|
1959
|
+
const basename = path7.basename(filePath);
|
|
1931
1960
|
return { dirname, basename };
|
|
1932
1961
|
};
|
|
1933
1962
|
getRelPath = (filePath) => filePath.replace(/\\+/g, "/").replace(/\.+\/+|\/+$/g, "");
|
|
1934
1963
|
urlToPath = (url) => {
|
|
1935
1964
|
const filePath = fileURLToPath2(url);
|
|
1936
|
-
const rel =
|
|
1937
|
-
const upLevelsCount = rel.split(
|
|
1965
|
+
const rel = path7.relative(path7.dirname(filePath), process.cwd());
|
|
1966
|
+
const upLevelsCount = rel.split(path7.sep).length;
|
|
1938
1967
|
return lodash2.repeat("../", upLevelsCount);
|
|
1939
1968
|
};
|
|
1940
1969
|
isSubPath = (root, target, isAbs = true) => {
|
|
1941
1970
|
if (isAbs) {
|
|
1942
|
-
root =
|
|
1943
|
-
target =
|
|
1971
|
+
root = path7.resolve(root);
|
|
1972
|
+
target = path7.resolve(target);
|
|
1944
1973
|
}
|
|
1945
|
-
const relative =
|
|
1946
|
-
return relative && !relative.startsWith("..") && !
|
|
1974
|
+
const relative = path7.relative(root, target);
|
|
1975
|
+
return relative && !relative.startsWith("..") && !path7.isAbsolute(relative);
|
|
1947
1976
|
};
|
|
1948
1977
|
}
|
|
1949
1978
|
});
|
|
1950
1979
|
|
|
1951
1980
|
// src/plugin/list.ts
|
|
1952
1981
|
import fs10 from "node:fs";
|
|
1953
|
-
import
|
|
1982
|
+
import path8 from "node:path";
|
|
1954
1983
|
var cache8, getPlugins, getPluginsInfo, createPkg, getAppInfo, getGitInfo, getNpmInfo, isNpmPlugin, filterApp, filterGit, filterPkg;
|
|
1955
1984
|
var init_list = __esm({
|
|
1956
1985
|
"src/plugin/list.ts"() {
|
|
@@ -2005,17 +2034,17 @@ var init_list = __esm({
|
|
|
2005
2034
|
await Promise.allSettled(list4.map(async (v) => {
|
|
2006
2035
|
const [type, name] = v.split(":");
|
|
2007
2036
|
if (type === "app") {
|
|
2008
|
-
const file =
|
|
2037
|
+
const file = path8.join(pluginDir, name);
|
|
2009
2038
|
await getAppInfo(info, file, name, ext);
|
|
2010
2039
|
return;
|
|
2011
2040
|
}
|
|
2012
2041
|
if (type === "git" || type === "root") {
|
|
2013
|
-
const file = type === "root" ? process.cwd() :
|
|
2042
|
+
const file = type === "root" ? process.cwd() : path8.join(pluginDir, name);
|
|
2014
2043
|
await getGitInfo(info, file, name, ext);
|
|
2015
2044
|
return;
|
|
2016
2045
|
}
|
|
2017
2046
|
if (type === "npm") {
|
|
2018
|
-
const file =
|
|
2047
|
+
const file = path8.join(process.cwd(), "node_modules", name);
|
|
2019
2048
|
await getNpmInfo(info, file, name);
|
|
2020
2049
|
}
|
|
2021
2050
|
}));
|
|
@@ -2030,7 +2059,7 @@ var init_list = __esm({
|
|
|
2030
2059
|
dir,
|
|
2031
2060
|
id: -1,
|
|
2032
2061
|
get pkgPath() {
|
|
2033
|
-
const file =
|
|
2062
|
+
const file = path8.join(this.dir, "package.json");
|
|
2034
2063
|
if (!fs10.existsSync(file)) return "";
|
|
2035
2064
|
return file;
|
|
2036
2065
|
},
|
|
@@ -2045,7 +2074,7 @@ var init_list = __esm({
|
|
|
2045
2074
|
info.push(createPkg("app", name, dir, apps, [dir]));
|
|
2046
2075
|
};
|
|
2047
2076
|
getGitInfo = async (info, dir, name, ext) => {
|
|
2048
|
-
const pkg3 = await requireFile(
|
|
2077
|
+
const pkg3 = await requireFile(path8.join(dir, "package.json"));
|
|
2049
2078
|
if (!pkg3 || !pkg3.karin) {
|
|
2050
2079
|
info.push(createPkg("git", name, dir, [], []));
|
|
2051
2080
|
return;
|
|
@@ -2066,7 +2095,7 @@ var init_list = __esm({
|
|
|
2066
2095
|
pushApps(pkg3.karin.apps);
|
|
2067
2096
|
}
|
|
2068
2097
|
await Promise.allSettled(files.map(async (app2) => {
|
|
2069
|
-
const appPath =
|
|
2098
|
+
const appPath = path8.join(dir, app2);
|
|
2070
2099
|
if (!fs10.existsSync(appPath)) return;
|
|
2071
2100
|
apps.push(...filesByExt(appPath, ext, "abs"));
|
|
2072
2101
|
allApps.push(appPath);
|
|
@@ -2078,7 +2107,7 @@ var init_list = __esm({
|
|
|
2078
2107
|
const ext = ".js";
|
|
2079
2108
|
const apps = [];
|
|
2080
2109
|
const allApps = [];
|
|
2081
|
-
const pkg3 = await requireFile(
|
|
2110
|
+
const pkg3 = await requireFile(path8.join(dir, "package.json"));
|
|
2082
2111
|
if (!((_b = (_a = pkg3.karin) == null ? void 0 : _a.apps) == null ? void 0 : _b.length)) {
|
|
2083
2112
|
info.push(createPkg("npm", name, dir, [], []));
|
|
2084
2113
|
return;
|
|
@@ -2090,7 +2119,7 @@ var init_list = __esm({
|
|
|
2090
2119
|
files.push(...pkg3.karin.apps);
|
|
2091
2120
|
}
|
|
2092
2121
|
await Promise.allSettled(files.map(async (app2) => {
|
|
2093
|
-
const appPath =
|
|
2122
|
+
const appPath = path8.join(dir, app2);
|
|
2094
2123
|
if (!fs10.existsSync(appPath)) return;
|
|
2095
2124
|
apps.push(...filesByExt(appPath, ext, "abs"));
|
|
2096
2125
|
allApps.push(appPath);
|
|
@@ -2099,7 +2128,7 @@ var init_list = __esm({
|
|
|
2099
2128
|
};
|
|
2100
2129
|
isNpmPlugin = async (name) => {
|
|
2101
2130
|
try {
|
|
2102
|
-
const file =
|
|
2131
|
+
const file = path8.join(process.cwd(), "node_modules", name, "package.json");
|
|
2103
2132
|
const pkg3 = await requireFile(file);
|
|
2104
2133
|
return !!pkg3.karin;
|
|
2105
2134
|
} catch {
|
|
@@ -2120,12 +2149,12 @@ var init_list = __esm({
|
|
|
2120
2149
|
await Promise.all(files.map(async (v) => {
|
|
2121
2150
|
if (!v.isDirectory()) return;
|
|
2122
2151
|
if (!v.name.startsWith("karin-plugin-")) return;
|
|
2123
|
-
if (!fs10.existsSync(
|
|
2152
|
+
if (!fs10.existsSync(path8.join(pluginDir, v.name, "package.json"))) return;
|
|
2124
2153
|
list4.push(`git:${v.name}`);
|
|
2125
2154
|
}));
|
|
2126
2155
|
};
|
|
2127
2156
|
filterPkg = async (list4) => {
|
|
2128
|
-
const karinPkg = await requireFile(
|
|
2157
|
+
const karinPkg = await requireFile(path8.join(karinDir, "package.json"));
|
|
2129
2158
|
const exclude = [...Object.keys(karinPkg.dependencies || {}), ...Object.keys(karinPkg.devDependencies || {})];
|
|
2130
2159
|
const pkg3 = await requireFile("./package.json");
|
|
2131
2160
|
const dependencies = Object.keys(pkg3.dependencies || {}).filter((name) => !exclude.includes(name) && !name.startsWith("@types"));
|
|
@@ -2194,36 +2223,36 @@ var init_json = __esm({
|
|
|
2194
2223
|
"src/utils/fs/json.ts"() {
|
|
2195
2224
|
"use strict";
|
|
2196
2225
|
init_esm_shims();
|
|
2197
|
-
readJsonSync = (
|
|
2226
|
+
readJsonSync = (path17, isThrow = false) => {
|
|
2198
2227
|
try {
|
|
2199
|
-
const data = fs12.readFileSync(
|
|
2228
|
+
const data = fs12.readFileSync(path17, "utf8");
|
|
2200
2229
|
return JSON.parse(data);
|
|
2201
2230
|
} catch (error) {
|
|
2202
2231
|
if (isThrow) throw error;
|
|
2203
2232
|
return null;
|
|
2204
2233
|
}
|
|
2205
2234
|
};
|
|
2206
|
-
writeJsonSync = (
|
|
2235
|
+
writeJsonSync = (path17, data, isThrow = false) => {
|
|
2207
2236
|
try {
|
|
2208
|
-
fs12.writeFileSync(
|
|
2237
|
+
fs12.writeFileSync(path17, JSON.stringify(data, null, 2));
|
|
2209
2238
|
return true;
|
|
2210
2239
|
} catch (error) {
|
|
2211
2240
|
if (isThrow) throw error;
|
|
2212
2241
|
return false;
|
|
2213
2242
|
}
|
|
2214
2243
|
};
|
|
2215
|
-
readJson = async (
|
|
2244
|
+
readJson = async (path17, isThrow = false) => {
|
|
2216
2245
|
try {
|
|
2217
|
-
const data = await fs12.promises.readFile(
|
|
2246
|
+
const data = await fs12.promises.readFile(path17, "utf8");
|
|
2218
2247
|
return JSON.parse(data);
|
|
2219
2248
|
} catch (error) {
|
|
2220
2249
|
if (isThrow) throw error;
|
|
2221
2250
|
return null;
|
|
2222
2251
|
}
|
|
2223
2252
|
};
|
|
2224
|
-
writeJson = async (
|
|
2253
|
+
writeJson = async (path17, data, isThrow = false) => {
|
|
2225
2254
|
try {
|
|
2226
|
-
await fs12.promises.writeFile(
|
|
2255
|
+
await fs12.promises.writeFile(path17, JSON.stringify(data, null, 2));
|
|
2227
2256
|
return true;
|
|
2228
2257
|
} catch (error) {
|
|
2229
2258
|
if (isThrow) throw error;
|
|
@@ -2274,7 +2303,7 @@ var init_cache = __esm({
|
|
|
2274
2303
|
});
|
|
2275
2304
|
|
|
2276
2305
|
// src/utils/fs/pkg.ts
|
|
2277
|
-
import
|
|
2306
|
+
import path9 from "node:path";
|
|
2278
2307
|
import { existsSync as existsSync3 } from "node:fs";
|
|
2279
2308
|
import { createRequire } from "module";
|
|
2280
2309
|
var pkgRoot, getPluginInfo, isPlugin;
|
|
@@ -2294,15 +2323,15 @@ var init_pkg = __esm({
|
|
|
2294
2323
|
dir = __require.resolve(name);
|
|
2295
2324
|
}
|
|
2296
2325
|
try {
|
|
2297
|
-
if (existsSync3(
|
|
2298
|
-
return
|
|
2326
|
+
if (existsSync3(path9.join(dir, "package.json"))) {
|
|
2327
|
+
return path9.resolve(dir);
|
|
2299
2328
|
}
|
|
2300
2329
|
while (true) {
|
|
2301
|
-
dir =
|
|
2302
|
-
if (existsSync3(
|
|
2303
|
-
return
|
|
2330
|
+
dir = path9.dirname(dir);
|
|
2331
|
+
if (existsSync3(path9.join(dir, "package.json"))) {
|
|
2332
|
+
return path9.resolve(dir);
|
|
2304
2333
|
}
|
|
2305
|
-
if (dir ===
|
|
2334
|
+
if (dir === path9.dirname(dir)) {
|
|
2306
2335
|
throw new Error(`[common] \u672A\u627E\u5230\u5305${name}\u7684\u6839\u76EE\u5F55`);
|
|
2307
2336
|
}
|
|
2308
2337
|
}
|
|
@@ -2718,7 +2747,7 @@ __export(common_exports, {
|
|
|
2718
2747
|
writeYaml: () => write
|
|
2719
2748
|
});
|
|
2720
2749
|
import fs13 from "node:fs";
|
|
2721
|
-
import
|
|
2750
|
+
import path10 from "node:path";
|
|
2722
2751
|
import Axios, { AxiosError as AxiosError2 } from "axios";
|
|
2723
2752
|
var sleep, axios3, uptime2, formatTime2, updateYaml, getNpmPlugins, getPlugins2, getGitPlugins, mergeImage, getAbsPath, getImageSize, generateLayout, buildFilterComplex;
|
|
2724
2753
|
var init_common = __esm({
|
|
@@ -2790,13 +2819,13 @@ var init_common = __esm({
|
|
|
2790
2819
|
getGitPlugins = async (isPack = false) => getPlugins("git", isPack);
|
|
2791
2820
|
mergeImage = async (images, perRow = 3) => {
|
|
2792
2821
|
if (images.length < 2) throw Error("\u56FE\u7247\u6570\u91CF\u5FC5\u987B\u5927\u4E8E1");
|
|
2793
|
-
const root =
|
|
2794
|
-
const rootTemp =
|
|
2822
|
+
const root = path10.join(tempPath, "mergeImage");
|
|
2823
|
+
const rootTemp = path10.join(root, Date.now().toString());
|
|
2795
2824
|
fs13.mkdirSync(rootTemp, { recursive: true });
|
|
2796
2825
|
const files = getAbsPath(images, rootTemp);
|
|
2797
2826
|
const filterComplex = await buildFilterComplex(files, perRow);
|
|
2798
2827
|
const inputImages = files.map((file) => `-i "${file}"`).join(" ");
|
|
2799
|
-
const output =
|
|
2828
|
+
const output = path10.join(rootTemp, "output.png");
|
|
2800
2829
|
const ffmpegCmd = `${inputImages} -filter_complex "${filterComplex}" -map "[out]" ${output}`;
|
|
2801
2830
|
const result = await ffmpeg(ffmpegCmd);
|
|
2802
2831
|
if (!result.status) {
|
|
@@ -2815,13 +2844,13 @@ var init_common = __esm({
|
|
|
2815
2844
|
if (image2.startsWith("base64://")) {
|
|
2816
2845
|
const base642 = image2.replace(/^base64:\/\//, "");
|
|
2817
2846
|
const buffer2 = Buffer.from(base642, "base64");
|
|
2818
|
-
const file2 =
|
|
2847
|
+
const file2 = path10.join(root, `${index4}.png`);
|
|
2819
2848
|
fs13.writeFileSync(file2, buffer2);
|
|
2820
2849
|
files.push(file2);
|
|
2821
2850
|
return;
|
|
2822
2851
|
}
|
|
2823
2852
|
if (!fs13.existsSync(image2)) throw Error(`\u56FE\u7247\u8DEF\u5F84\u4E0D\u5B58\u5728: ${image2}`);
|
|
2824
|
-
const file =
|
|
2853
|
+
const file = path10.join(root, path10.basename(image2));
|
|
2825
2854
|
fs13.copyFileSync(image2, file);
|
|
2826
2855
|
files.push(file);
|
|
2827
2856
|
});
|
|
@@ -2871,8 +2900,8 @@ var init_level = __esm({
|
|
|
2871
2900
|
LevelDB = class extends Level {
|
|
2872
2901
|
id;
|
|
2873
2902
|
get;
|
|
2874
|
-
constructor(
|
|
2875
|
-
super(
|
|
2903
|
+
constructor(path17) {
|
|
2904
|
+
super(path17, { valueEncoding: "json" });
|
|
2876
2905
|
this.id = "Level";
|
|
2877
2906
|
this.get = super.get.bind(this);
|
|
2878
2907
|
}
|
|
@@ -3961,8 +3990,8 @@ var init_tools2 = __esm({
|
|
|
3961
3990
|
});
|
|
3962
3991
|
|
|
3963
3992
|
// src/plugin/watcher.ts
|
|
3964
|
-
import
|
|
3965
|
-
import
|
|
3993
|
+
import chokidar3 from "chokidar";
|
|
3994
|
+
import path11 from "node:path";
|
|
3966
3995
|
var WatcherPlugin;
|
|
3967
3996
|
var init_watcher = __esm({
|
|
3968
3997
|
"src/plugin/watcher.ts"() {
|
|
@@ -4001,12 +4030,12 @@ var init_watcher = __esm({
|
|
|
4001
4030
|
* 开始监听
|
|
4002
4031
|
*/
|
|
4003
4032
|
startWatch() {
|
|
4004
|
-
this.watcher =
|
|
4033
|
+
this.watcher = chokidar3.watch(Array.from(this.watchDirs), {
|
|
4005
4034
|
ignoreInitial: true,
|
|
4006
4035
|
ignored: /(^|[/\\])\../
|
|
4007
4036
|
});
|
|
4008
4037
|
this.watcher.on("add", (file) => this.handleFileChange(file, "add")).on("change", (file) => this.handleFileChange(file, "change")).on("unlink", (file) => this.handleFileChange(file, "unlink"));
|
|
4009
|
-
const relativePaths = Array.from(this.watchDirs).map((dir) =>
|
|
4038
|
+
const relativePaths = Array.from(this.watchDirs).map((dir) => path11.relative(process.cwd(), dir).replace(/\\/g, "/"));
|
|
4010
4039
|
logger.debug("\n[hmr] \u5F00\u59CB\u76D1\u542C\u6587\u4EF6\u5939:\n", relativePaths.join("\n"));
|
|
4011
4040
|
}
|
|
4012
4041
|
/**
|
|
@@ -4025,17 +4054,17 @@ var init_watcher = __esm({
|
|
|
4025
4054
|
* @param action 操作类型
|
|
4026
4055
|
*/
|
|
4027
4056
|
async handleFileChange(file, action) {
|
|
4028
|
-
const ext =
|
|
4057
|
+
const ext = path11.extname(file);
|
|
4029
4058
|
const exts = isTsx() ? [".ts", ".js"] : [".js"];
|
|
4030
4059
|
if (!exts.includes(ext)) return;
|
|
4031
|
-
const absPath2 =
|
|
4060
|
+
const absPath2 = path11.resolve(file);
|
|
4032
4061
|
const pkg3 = this.findPkgByFile(absPath2);
|
|
4033
4062
|
if (!pkg3) return;
|
|
4034
|
-
const relativePath =
|
|
4063
|
+
const relativePath = path11.relative(process.cwd(), file).replace(/\\/g, "/");
|
|
4035
4064
|
logger.debug(`[hmr][${pkg3.name}] \u6587\u4EF6${action}: ${relativePath}`);
|
|
4036
4065
|
if (action === "unlink") {
|
|
4037
4066
|
this.unloadPlugin(absPath2);
|
|
4038
|
-
logger.info(`[hmr][${pkg3.name}] \u5DF2\u5378\u8F7D: ${
|
|
4067
|
+
logger.info(`[hmr][${pkg3.name}] \u5DF2\u5378\u8F7D: ${path11.basename(file)}`);
|
|
4039
4068
|
return;
|
|
4040
4069
|
}
|
|
4041
4070
|
if (action === "change") {
|
|
@@ -4046,7 +4075,7 @@ var init_watcher = __esm({
|
|
|
4046
4075
|
this.loader.cachePlugin(result, pkg3, absPath2);
|
|
4047
4076
|
this.loader.sort();
|
|
4048
4077
|
const actionText = action === "add" ? "\u65B0\u589E\u63D2\u4EF6" : "\u91CD\u8F7D\u5B8C\u6210";
|
|
4049
|
-
logger.info(`[hmr][${pkg3.name}] ${actionText}: ${
|
|
4078
|
+
logger.info(`[hmr][${pkg3.name}] ${actionText}: ${path11.basename(file)}`);
|
|
4050
4079
|
} catch (error) {
|
|
4051
4080
|
logger.error(`[hmr][${pkg3.name}] \u52A0\u8F7D\u5931\u8D25:`, error);
|
|
4052
4081
|
}
|
|
@@ -4087,7 +4116,7 @@ __export(loader_exports, {
|
|
|
4087
4116
|
});
|
|
4088
4117
|
import fs14 from "node:fs";
|
|
4089
4118
|
import lodash5 from "lodash";
|
|
4090
|
-
import
|
|
4119
|
+
import path12 from "node:path";
|
|
4091
4120
|
import util2 from "node:util";
|
|
4092
4121
|
import schedule from "node-schedule";
|
|
4093
4122
|
var seq, LoaderPlugin;
|
|
@@ -4139,13 +4168,13 @@ var init_loader = __esm({
|
|
|
4139
4168
|
});
|
|
4140
4169
|
if (pkg3.type !== "app") {
|
|
4141
4170
|
if (isTsx() && ((_c = (_b = pkg3 == null ? void 0 : pkg3.pkgData) == null ? void 0 : _b.karin) == null ? void 0 : _c.main)) {
|
|
4142
|
-
const file =
|
|
4171
|
+
const file = path12.join(pkg3.dir, pkg3.pkgData.karin.main);
|
|
4143
4172
|
if (fs14.existsSync(file)) {
|
|
4144
4173
|
entryPromises.push(this.loaderMain(pkg3.name, file));
|
|
4145
4174
|
}
|
|
4146
4175
|
}
|
|
4147
4176
|
if ((_d = pkg3 == null ? void 0 : pkg3.pkgData) == null ? void 0 : _d.main) {
|
|
4148
|
-
const file =
|
|
4177
|
+
const file = path12.join(pkg3.dir, pkg3.pkgData.main);
|
|
4149
4178
|
if (fs14.existsSync(file)) {
|
|
4150
4179
|
entryPromises.push(this.loaderMain(pkg3.name, file));
|
|
4151
4180
|
}
|
|
@@ -4153,7 +4182,7 @@ var init_loader = __esm({
|
|
|
4153
4182
|
}
|
|
4154
4183
|
if (pkg3.type !== "app" && ((_f = (_e = pkg3 == null ? void 0 : pkg3.pkgData) == null ? void 0 : _e.karin) == null ? void 0 : _f.static)) {
|
|
4155
4184
|
const list5 = Array.isArray(pkg3.pkgData.karin.static) ? pkg3.pkgData.karin.static : [pkg3.pkgData.karin.static];
|
|
4156
|
-
cache9.static.push(...list5.map((file) =>
|
|
4185
|
+
cache9.static.push(...list5.map((file) => path12.resolve(pkg3.dir, file)));
|
|
4157
4186
|
}
|
|
4158
4187
|
}));
|
|
4159
4188
|
await Promise.all([...allPromises, ...entryPromises]);
|
|
@@ -4193,10 +4222,10 @@ var init_loader = __esm({
|
|
|
4193
4222
|
return {
|
|
4194
4223
|
absPath: app2,
|
|
4195
4224
|
get dirname() {
|
|
4196
|
-
return
|
|
4225
|
+
return path12.dirname(this.absPath);
|
|
4197
4226
|
},
|
|
4198
4227
|
get basename() {
|
|
4199
|
-
return
|
|
4228
|
+
return path12.basename(this.absPath);
|
|
4200
4229
|
},
|
|
4201
4230
|
type,
|
|
4202
4231
|
method,
|
|
@@ -4511,7 +4540,7 @@ var init_middleware = __esm({
|
|
|
4511
4540
|
});
|
|
4512
4541
|
|
|
4513
4542
|
// src/server/app.ts
|
|
4514
|
-
import
|
|
4543
|
+
import path13 from "node:path";
|
|
4515
4544
|
import express from "express";
|
|
4516
4545
|
import { createServer } from "node:http";
|
|
4517
4546
|
var app, server, listen;
|
|
@@ -4525,8 +4554,8 @@ var init_app = __esm({
|
|
|
4525
4554
|
app = express();
|
|
4526
4555
|
server = createServer(app);
|
|
4527
4556
|
app.use(authMiddleware);
|
|
4528
|
-
app.use("/web", express.static(
|
|
4529
|
-
app.use("/web/*", express.static(
|
|
4557
|
+
app.use("/web", express.static(path13.join(process.cwd(), "web")));
|
|
4558
|
+
app.use("/web/*", express.static(path13.join(process.cwd(), "web")));
|
|
4530
4559
|
app.use("/api/v1", router);
|
|
4531
4560
|
listen = (port2, host2) => {
|
|
4532
4561
|
server.listen(port2, host2, () => {
|
|
@@ -4611,7 +4640,7 @@ var init_ip = __esm({
|
|
|
4611
4640
|
|
|
4612
4641
|
// src/server/api/console.ts
|
|
4613
4642
|
import { promises as fs15 } from "node:fs";
|
|
4614
|
-
import
|
|
4643
|
+
import path14 from "node:path";
|
|
4615
4644
|
var ALLOWED_TYPES, MAX_FILE_SIZE, consoleRouter;
|
|
4616
4645
|
var init_console = __esm({
|
|
4617
4646
|
async "src/server/api/console.ts"() {
|
|
@@ -4648,7 +4677,7 @@ var init_console = __esm({
|
|
|
4648
4677
|
if (url.includes("..") || url.includes("~") || !url.match(/^[a-zA-Z0-9-_.]+$/)) {
|
|
4649
4678
|
return createForbiddenResponse(res, "\u975E\u6CD5\u8BF7\u6C42");
|
|
4650
4679
|
}
|
|
4651
|
-
const ext =
|
|
4680
|
+
const ext = path14.extname(url).toLowerCase();
|
|
4652
4681
|
if (!ALLOWED_TYPES[ext]) {
|
|
4653
4682
|
return createBadRequestResponse(res, "\u4E0D\u652F\u6301\u7684\u6587\u4EF6\u7C7B\u578B");
|
|
4654
4683
|
}
|
|
@@ -4666,7 +4695,7 @@ var init_console = __esm({
|
|
|
4666
4695
|
return createForbiddenResponse(res, "\u65E0\u6548\u7684 token");
|
|
4667
4696
|
}
|
|
4668
4697
|
}
|
|
4669
|
-
const file =
|
|
4698
|
+
const file = path14.join(consolePath, url);
|
|
4670
4699
|
try {
|
|
4671
4700
|
if (!file.startsWith(consolePath)) {
|
|
4672
4701
|
return createForbiddenResponse(res, "\u975E\u6CD5\u8BF7\u6C42");
|
|
@@ -5825,16 +5854,27 @@ var init_handler2 = __esm({
|
|
|
5825
5854
|
return true;
|
|
5826
5855
|
};
|
|
5827
5856
|
privateFilterEvent = (ctx3, config2, friend, cd) => {
|
|
5828
|
-
var _a, _b, _c, _d, _e, _f;
|
|
5857
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
5858
|
+
if (ctx3.isFriend) {
|
|
5859
|
+
if (!((_a = config2 == null ? void 0 : config2.user) == null ? void 0 : _a.enable)) {
|
|
5860
|
+
log(ctx3.userId, `\u5F53\u524D\u597D\u53CB\u4E8B\u4EF6\u672A\u542F\u7528: ${ctx3.eventId}`);
|
|
5861
|
+
return false;
|
|
5862
|
+
}
|
|
5863
|
+
} else {
|
|
5864
|
+
if (!((_b = config2 == null ? void 0 : config2.directs) == null ? void 0 : _b.enable)) {
|
|
5865
|
+
log(ctx3.userId, `\u5F53\u524D\u9891\u9053\u79C1\u4FE1\u4E8B\u4EF6\u672A\u542F\u7528: ${ctx3.eventId}`);
|
|
5866
|
+
return false;
|
|
5867
|
+
}
|
|
5868
|
+
}
|
|
5829
5869
|
if (!cd) {
|
|
5830
5870
|
log(ctx3.userId, `\u5F53\u524D\u5904\u4E8ECD\u4E2D: ${ctx3.eventId}`);
|
|
5831
5871
|
return false;
|
|
5832
5872
|
}
|
|
5833
|
-
if (((
|
|
5873
|
+
if (((_d = (_c = config2 == null ? void 0 : config2.user) == null ? void 0 : _c.enable_list) == null ? void 0 : _d.length) && !((_e = config2 == null ? void 0 : config2.user) == null ? void 0 : _e.enable_list.includes(ctx3.userId))) {
|
|
5834
5874
|
log(ctx3.userId, `\u7528\u6237\u672A\u5904\u4E8E\u767D\u540D\u5355: ${ctx3.eventId}`);
|
|
5835
5875
|
return false;
|
|
5836
5876
|
}
|
|
5837
|
-
if (((
|
|
5877
|
+
if (((_g = (_f = config2 == null ? void 0 : config2.user) == null ? void 0 : _f.disable_list) == null ? void 0 : _g.length) && ((_h = config2 == null ? void 0 : config2.user) == null ? void 0 : _h.disable_list.includes(ctx3.userId))) {
|
|
5838
5878
|
log(ctx3.userId, `\u7528\u6237\u5904\u4E8E\u9ED1\u540D\u5355: ${ctx3.eventId}`);
|
|
5839
5879
|
return false;
|
|
5840
5880
|
}
|
|
@@ -5877,63 +5917,74 @@ var init_handler2 = __esm({
|
|
|
5877
5917
|
return mode();
|
|
5878
5918
|
};
|
|
5879
5919
|
groupFilterEvent = (ctx3, config2, group, cd) => {
|
|
5880
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
|
|
5920
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D;
|
|
5921
|
+
if (ctx3.isGroup) {
|
|
5922
|
+
if (!((_a = config2 == null ? void 0 : config2.group) == null ? void 0 : _a.enable)) {
|
|
5923
|
+
log(ctx3.groupId, `\u5F53\u524D\u7FA4\u4E8B\u4EF6\u672A\u542F\u7528: ${ctx3.eventId}`);
|
|
5924
|
+
return false;
|
|
5925
|
+
}
|
|
5926
|
+
} else if (ctx3.isGuild) {
|
|
5927
|
+
if (!((_b = config2 == null ? void 0 : config2.guilds) == null ? void 0 : _b.enable)) {
|
|
5928
|
+
log(ctx3.guildId, `\u5F53\u524D\u9891\u9053\u4E8B\u4EF6\u672A\u542F\u7528: ${ctx3.eventId}`);
|
|
5929
|
+
return false;
|
|
5930
|
+
}
|
|
5931
|
+
}
|
|
5881
5932
|
if (!cd) {
|
|
5882
5933
|
log(ctx3.userId, `\u5F53\u524D\u5904\u4E8ECD\u4E2D: ${ctx3.eventId}`);
|
|
5883
5934
|
return false;
|
|
5884
5935
|
}
|
|
5885
|
-
if ((
|
|
5886
|
-
if (!((
|
|
5936
|
+
if ((_d = (_c = config2 == null ? void 0 : config2.user) == null ? void 0 : _c.enable_list) == null ? void 0 : _d.length) {
|
|
5937
|
+
if (!((_e = config2 == null ? void 0 : config2.user) == null ? void 0 : _e.enable_list.includes(ctx3.userId))) {
|
|
5887
5938
|
log(ctx3.userId, `\u7528\u6237\u672A\u5904\u4E8E\u767D\u540D\u5355: ${ctx3.eventId}`);
|
|
5888
5939
|
return false;
|
|
5889
5940
|
}
|
|
5890
5941
|
}
|
|
5891
|
-
if ((
|
|
5892
|
-
if ((
|
|
5942
|
+
if ((_g = (_f = config2 == null ? void 0 : config2.user) == null ? void 0 : _f.disable_list) == null ? void 0 : _g.length) {
|
|
5943
|
+
if ((_h = config2 == null ? void 0 : config2.user) == null ? void 0 : _h.disable_list.includes(ctx3.userId)) {
|
|
5893
5944
|
log(ctx3.userId, `\u7528\u6237\u5904\u4E8E\u9ED1\u540D\u5355: ${ctx3.eventId}`);
|
|
5894
5945
|
return false;
|
|
5895
5946
|
}
|
|
5896
5947
|
}
|
|
5897
5948
|
if (ctx3.isGroup) {
|
|
5898
|
-
if (((
|
|
5949
|
+
if (((_j = (_i = config2 == null ? void 0 : config2.group) == null ? void 0 : _i.enable_list) == null ? void 0 : _j.length) && !((_k = config2 == null ? void 0 : config2.group) == null ? void 0 : _k.enable_list.includes(ctx3.groupId))) {
|
|
5899
5950
|
log(ctx3.groupId, `\u7FA4\u672A\u5904\u4E8E\u767D\u540D\u5355: ${ctx3.eventId}`);
|
|
5900
5951
|
return false;
|
|
5901
5952
|
}
|
|
5902
|
-
if (((
|
|
5953
|
+
if (((_m = (_l = config2 == null ? void 0 : config2.group) == null ? void 0 : _l.disable_list) == null ? void 0 : _m.length) && ((_n = config2 == null ? void 0 : config2.group) == null ? void 0 : _n.disable_list.includes(ctx3.groupId))) {
|
|
5903
5954
|
log(ctx3.groupId, `\u7FA4\u5904\u4E8E\u9ED1\u540D\u5355: ${ctx3.eventId}`);
|
|
5904
5955
|
return false;
|
|
5905
5956
|
}
|
|
5906
|
-
if (((
|
|
5957
|
+
if (((_o = group.memberEnable) == null ? void 0 : _o.length) && !group.memberEnable.includes(ctx3.userId)) {
|
|
5907
5958
|
log(ctx3.userId, `\u7528\u6237\u672A\u5904\u4E8E\u7FA4\u6210\u5458\u767D\u540D\u5355: ${ctx3.eventId}`);
|
|
5908
5959
|
return false;
|
|
5909
5960
|
}
|
|
5910
|
-
if (((
|
|
5961
|
+
if (((_p = group.memberDisable) == null ? void 0 : _p.length) && group.memberDisable.includes(ctx3.userId)) {
|
|
5911
5962
|
log(ctx3.userId, `\u7528\u6237\u5904\u4E8E\u7FA4\u6210\u5458\u9ED1\u540D\u5355: ${ctx3.eventId}`);
|
|
5912
5963
|
return false;
|
|
5913
5964
|
}
|
|
5914
5965
|
}
|
|
5915
5966
|
if (ctx3.isGuild) {
|
|
5916
|
-
if (((
|
|
5967
|
+
if (((_r = (_q = config2 == null ? void 0 : config2.guilds) == null ? void 0 : _q.enable_list) == null ? void 0 : _r.length) && !((_s = config2 == null ? void 0 : config2.guilds) == null ? void 0 : _s.enable_list.includes(ctx3.guildId))) {
|
|
5917
5968
|
log(ctx3.guildId, `\u9891\u9053\u672A\u5904\u4E8E\u767D\u540D\u5355: ${ctx3.eventId}`);
|
|
5918
5969
|
return false;
|
|
5919
5970
|
}
|
|
5920
|
-
if (((
|
|
5971
|
+
if (((_u = (_t = config2 == null ? void 0 : config2.guilds) == null ? void 0 : _t.disable_list) == null ? void 0 : _u.length) && ((_v = config2 == null ? void 0 : config2.guilds) == null ? void 0 : _v.disable_list.includes(ctx3.guildId))) {
|
|
5921
5972
|
log(ctx3.guildId, `\u9891\u9053\u5904\u4E8E\u9ED1\u540D\u5355: ${ctx3.eventId}`);
|
|
5922
5973
|
return false;
|
|
5923
5974
|
}
|
|
5924
|
-
if (((
|
|
5975
|
+
if (((_x = (_w = config2 == null ? void 0 : config2.channels) == null ? void 0 : _w.enable_list) == null ? void 0 : _x.length) && !((_y = config2 == null ? void 0 : config2.channels) == null ? void 0 : _y.enable_list.includes(ctx3.channelId))) {
|
|
5925
5976
|
log(ctx3.channelId, `\u5B50\u9891\u9053\u672A\u5904\u4E8E\u767D\u540D\u5355: ${ctx3.eventId}`);
|
|
5926
5977
|
return false;
|
|
5927
5978
|
}
|
|
5928
|
-
if (((
|
|
5979
|
+
if (((_A = (_z = config2 == null ? void 0 : config2.channels) == null ? void 0 : _z.disable_list) == null ? void 0 : _A.length) && ((_B = config2 == null ? void 0 : config2.channels) == null ? void 0 : _B.disable_list.includes(ctx3.channelId))) {
|
|
5929
5980
|
log(ctx3.channelId, `\u5B50\u9891\u9053\u5904\u4E8E\u9ED1\u540D\u5355: ${ctx3.eventId}`);
|
|
5930
5981
|
return false;
|
|
5931
5982
|
}
|
|
5932
|
-
if (((
|
|
5983
|
+
if (((_C = group.memberEnable) == null ? void 0 : _C.length) && !group.memberEnable.includes(ctx3.userId)) {
|
|
5933
5984
|
log(ctx3.userId, `\u7528\u6237\u672A\u5904\u4E8E\u9891\u9053\u6210\u5458\u767D\u540D\u5355: ${ctx3.eventId}`);
|
|
5934
5985
|
return false;
|
|
5935
5986
|
}
|
|
5936
|
-
if (((
|
|
5987
|
+
if (((_D = group.memberDisable) == null ? void 0 : _D.length) && group.memberDisable.includes(ctx3.userId)) {
|
|
5937
5988
|
log(ctx3.userId, `\u7528\u6237\u5904\u4E8E\u9891\u9053\u6210\u5458\u9ED1\u540D\u5355: ${ctx3.eventId}`);
|
|
5938
5989
|
return false;
|
|
5939
5990
|
}
|
|
@@ -8447,7 +8498,7 @@ var init_event = __esm({
|
|
|
8447
8498
|
|
|
8448
8499
|
// src/adapter/input/index.ts
|
|
8449
8500
|
import fs16 from "node:fs";
|
|
8450
|
-
import
|
|
8501
|
+
import path15 from "node:path";
|
|
8451
8502
|
var index2, botID, AdapterConsole, adapter2;
|
|
8452
8503
|
var init_input = __esm({
|
|
8453
8504
|
async "src/adapter/input/index.ts"() {
|
|
@@ -8467,7 +8518,10 @@ var init_input = __esm({
|
|
|
8467
8518
|
AdapterConsole = class extends AdapterBase {
|
|
8468
8519
|
constructor() {
|
|
8469
8520
|
super();
|
|
8470
|
-
listeners.on(
|
|
8521
|
+
listeners.on(
|
|
8522
|
+
"karin:adapter:open",
|
|
8523
|
+
() => process.stdin.on("data", (data) => this.createEvent(data))
|
|
8524
|
+
);
|
|
8471
8525
|
listeners.on("karin:adapter:close", () => process.stdin.removeAllListeners("data"));
|
|
8472
8526
|
this.adapter.name = "@karinjs/console";
|
|
8473
8527
|
this.adapter.communication = "other";
|
|
@@ -8484,10 +8538,22 @@ var init_input = __esm({
|
|
|
8484
8538
|
get selfId() {
|
|
8485
8539
|
return this.account.selfId;
|
|
8486
8540
|
}
|
|
8487
|
-
createEvent(data) {
|
|
8541
|
+
async createEvent(data) {
|
|
8488
8542
|
const text2 = data.toString().trim();
|
|
8489
8543
|
const seq2 = Math.floor(Math.random() * 1e9);
|
|
8490
8544
|
const time2 = Date.now();
|
|
8545
|
+
if (text2.startsWith("log")) {
|
|
8546
|
+
const level2 = text2.replace(/^log/, "").trim();
|
|
8547
|
+
if (level2) {
|
|
8548
|
+
const list4 = ["trace", "debug", "info", "warn", "error", "fatal"];
|
|
8549
|
+
if (list4.includes(level2)) {
|
|
8550
|
+
const { updateLevel: updateLevel2 } = await init_config().then(() => config_exports);
|
|
8551
|
+
updateLevel2(level2);
|
|
8552
|
+
logger.info(`\u65E5\u5FD7\u7B49\u7EA7\u5DF2\u66F4\u65B0\u4E3A: ${level2}`);
|
|
8553
|
+
return;
|
|
8554
|
+
}
|
|
8555
|
+
}
|
|
8556
|
+
}
|
|
8491
8557
|
if (text2.startsWith("group")) {
|
|
8492
8558
|
const contact4 = contactGroup("10010");
|
|
8493
8559
|
createGroupMessage({
|
|
@@ -8557,7 +8623,7 @@ var init_input = __esm({
|
|
|
8557
8623
|
async getUrl(data, ext) {
|
|
8558
8624
|
const cfg = adapter();
|
|
8559
8625
|
const name = (++index2).toString();
|
|
8560
|
-
const file =
|
|
8626
|
+
const file = path15.join(consolePath, `${name}${ext}`);
|
|
8561
8627
|
await fs16.promises.writeFile(file, await buffer(data));
|
|
8562
8628
|
if (cfg.console.isLocal) {
|
|
8563
8629
|
return `http://127.0.0.1:${process.env.HTTP_PORT}/console/${name}${ext}`;
|
|
@@ -8702,8 +8768,8 @@ var init_cache2 = __esm({
|
|
|
8702
8768
|
|
|
8703
8769
|
// src/adapter/render/admin/template.ts
|
|
8704
8770
|
import fs17 from "node:fs";
|
|
8705
|
-
import
|
|
8706
|
-
import
|
|
8771
|
+
import path16 from "node:path";
|
|
8772
|
+
import chokidar4 from "chokidar";
|
|
8707
8773
|
import template from "art-template";
|
|
8708
8774
|
var cache11, watcherCache, renderTpl, getCacheData, getOutputPath, watch2;
|
|
8709
8775
|
var init_template = __esm({
|
|
@@ -8719,7 +8785,7 @@ var init_template = __esm({
|
|
|
8719
8785
|
if (options.file.startsWith("http")) {
|
|
8720
8786
|
throw TypeError("\u4ED6\u55B5\u7684 \u4E0D\u4F1A\u771F\u7684\u6709\u7B28\u6BD4\u4F20\u4E2Ahttp\u6765\u5F53\u505A\u6A21\u677F\u5427...");
|
|
8721
8787
|
}
|
|
8722
|
-
const file =
|
|
8788
|
+
const file = path16.resolve(options.file);
|
|
8723
8789
|
const tplData = getCacheData(file);
|
|
8724
8790
|
const renderData = template.render(tplData, options.data);
|
|
8725
8791
|
const outputPath = getOutputPath(options.file, renderData, options.name);
|
|
@@ -8746,10 +8812,10 @@ var init_template = __esm({
|
|
|
8746
8812
|
return tplData;
|
|
8747
8813
|
};
|
|
8748
8814
|
getOutputPath = (file, data, name) => {
|
|
8749
|
-
const extname =
|
|
8750
|
-
const basename =
|
|
8751
|
-
const fileDir =
|
|
8752
|
-
const filePath =
|
|
8815
|
+
const extname = path16.extname(file);
|
|
8816
|
+
const basename = path16.basename(file, extname);
|
|
8817
|
+
const fileDir = path16.join(htmlPath, name || "render");
|
|
8818
|
+
const filePath = path16.join(fileDir, `${basename}-${Date.now()}${extname}`);
|
|
8753
8819
|
existToMkdirSync(fileDir);
|
|
8754
8820
|
fs17.writeFileSync(filePath, data);
|
|
8755
8821
|
return filePath;
|
|
@@ -8757,7 +8823,7 @@ var init_template = __esm({
|
|
|
8757
8823
|
watch2 = async (file, data) => {
|
|
8758
8824
|
cache11.set(file, data);
|
|
8759
8825
|
if (watcherCache.has(file)) return;
|
|
8760
|
-
const watcher =
|
|
8826
|
+
const watcher = chokidar4.watch(file);
|
|
8761
8827
|
watcherCache.set(file, watcher);
|
|
8762
8828
|
watcher.on("change", () => {
|
|
8763
8829
|
cache11.set(file, fs17.readFileSync(file, "utf-8"));
|
|
@@ -10201,11 +10267,11 @@ var checkGitPluginUpdate = async (filePath, time2 = 120) => {
|
|
|
10201
10267
|
}
|
|
10202
10268
|
};
|
|
10203
10269
|
var getCommit = async (options) => {
|
|
10204
|
-
const { path:
|
|
10270
|
+
const { path: path17, count: count3 = 1, hash, branch } = options;
|
|
10205
10271
|
let cmd = `git log -${count3} --format="[%ad]%s %n" --date="format:%m-%d %H:%M"`;
|
|
10206
10272
|
if (hash) cmd = `git log ${hash}..HEAD --format="[%ad] %s %n" --date="format:%m-%d %H:%M"`;
|
|
10207
10273
|
if (branch) cmd = `git log -${count3} ${branch} --format="[%ad] %s %n" --date="format:%m-%d %H:%M"`;
|
|
10208
|
-
const { stdout, error } = await exec(cmd, { cwd:
|
|
10274
|
+
const { stdout, error } = await exec(cmd, { cwd: path17 });
|
|
10209
10275
|
if (error) {
|
|
10210
10276
|
throw error;
|
|
10211
10277
|
}
|