node-karin 1.15.5 → 1.16.1

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.
Files changed (89) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/adapter-BqlH3u3X.mjs +218 -0
  3. package/dist/app-DdMQbBEY.mjs +4109 -0
  4. package/dist/cache-CPcPeo6N.mjs +163 -0
  5. package/dist/chunk-NzVPYdc1.mjs +21 -0
  6. package/dist/cli/index.cjs +10900 -1
  7. package/dist/cli/index.d.ts +1 -1
  8. package/dist/cli/index.mjs +10770 -10224
  9. package/dist/file-ZGuqNDd-.mjs +15987 -0
  10. package/dist/file-dGy9of8-.mjs +268 -0
  11. package/dist/fsSync-Cf5MWILk.mjs +65 -0
  12. package/dist/index.d.ts +12235 -12738
  13. package/dist/index.mjs +2054 -25247
  14. package/dist/internal-DupfycKE.mjs +597 -0
  15. package/dist/kv-DZp4UIxg.mjs +192 -0
  16. package/dist/module/art-template.d.ts +2 -13
  17. package/dist/module/art-template.mjs +3 -1
  18. package/dist/module/axios.d.ts +3 -2
  19. package/dist/module/axios.mjs +5 -2
  20. package/dist/module/chalk.d.ts +3 -2
  21. package/dist/module/chalk.mjs +5 -2
  22. package/dist/module/chokidar.d.ts +3 -2
  23. package/dist/module/chokidar.mjs +5 -2
  24. package/dist/module/express.d.ts +2 -1
  25. package/dist/module/express.mjs +3 -1
  26. package/dist/module/lodash.d.ts +2 -1
  27. package/dist/module/lodash.mjs +3 -1
  28. package/dist/module/log4js.d.ts +3 -2
  29. package/dist/module/log4js.mjs +5 -2
  30. package/dist/module/moment.d.ts +2 -1
  31. package/dist/module/moment.mjs +3 -1
  32. package/dist/module/node-schedule.d.ts +3 -2
  33. package/dist/module/node-schedule.mjs +5 -2
  34. package/dist/module/redis.d.ts +3 -2
  35. package/dist/module/redis.mjs +5 -2
  36. package/dist/module/sqlite3.d.ts +3 -2
  37. package/dist/module/sqlite3.mjs +5 -2
  38. package/dist/module/ws.d.ts +3 -2
  39. package/dist/module/ws.mjs +5 -2
  40. package/dist/module/yaml.d.ts +3 -2
  41. package/dist/module/yaml.mjs +5 -2
  42. package/dist/queue-CnKedaZA.mjs +70 -0
  43. package/dist/redis-aLJ7wbJH.mjs +1556 -0
  44. package/dist/render-DPqueDZr.mjs +170 -0
  45. package/dist/root.d.ts +46 -46
  46. package/dist/root.mjs +136 -93
  47. package/dist/router-zPSN9-tY.mjs +124 -0
  48. package/dist/server-DT64D-m-.mjs +38 -0
  49. package/dist/snapka-BTlnZOyI.mjs +450 -0
  50. package/dist/sqlite-Dcj9jlW9.mjs +307 -0
  51. package/dist/start/app.d.ts +1 -1
  52. package/dist/start/app.mjs +14 -7
  53. package/dist/start/index.d.ts +1 -1
  54. package/dist/start/index.mjs +325 -656
  55. package/dist/template-Djk6y0uC.mjs +133 -0
  56. package/dist/terminalManager-Lxa8Sm06.mjs +783 -0
  57. package/dist/uptime-C121X_rq.mjs +210 -0
  58. package/dist/web/{CompressaPRO-GX.woff2.br → CompressaPRO-GX.woff2} +0 -0
  59. package/dist/web/assets/css/style-CBB8wM_W.css +14880 -0
  60. package/dist/web/assets/js/entry-Blf4Trpx.js +258540 -0
  61. package/dist/web/{googleapis.woff2.br → googleapis.woff2} +0 -0
  62. package/dist/web/index.html +2 -15
  63. package/dist/web/karin.png +0 -0
  64. package/dist/web/sha256.min.js +9 -0
  65. package/dist/ws-BLDoC2gV.mjs +80 -0
  66. package/dist/ws-CcoWd3Ar.mjs +106 -0
  67. package/package.json +7 -7
  68. package/dist/global.d.d.ts +0 -68
  69. package/dist/types-hAhbXJDZ.d.ts +0 -109
  70. package/dist/web/assets/css/components-ep7vm38G.css +0 -1
  71. package/dist/web/assets/css/index-Dadvd9mn.css.br +0 -0
  72. package/dist/web/assets/css/vendor-editor-CFbL2ovg.css.br +0 -0
  73. package/dist/web/assets/css/vendor-others-ZgkIHsf0.css +0 -1
  74. package/dist/web/assets/js/components-CU2xw4lY.js.br +0 -0
  75. package/dist/web/assets/js/entry-Dvb7eYLE.js.br +0 -0
  76. package/dist/web/assets/js/hooks-CRfhs4ON.js.br +0 -0
  77. package/dist/web/assets/js/page-404.tsx-DYMd_RI_.js +0 -1
  78. package/dist/web/assets/js/page-dashboard-CG60V_Z-.js.br +0 -0
  79. package/dist/web/assets/js/page-loading.tsx-wY8a9me3.js.br +0 -0
  80. package/dist/web/assets/js/page-login.tsx-B54ZOEZB.js.br +0 -0
  81. package/dist/web/assets/js/utils-C9nWTSuo.js +0 -2
  82. package/dist/web/assets/js/vendor-editor-BmqYP7lh.js.br +0 -0
  83. package/dist/web/assets/js/vendor-heroui-ClBCy2zk.js.br +0 -0
  84. package/dist/web/assets/js/vendor-others-6GiMrjd4.js.br +0 -0
  85. package/dist/web/assets/js/vendor-react-Dc9jdQiK.js.br +0 -0
  86. package/dist/web/assets/js/vendor-ui-utils-D0xkboLL.js.br +0 -0
  87. package/dist/web/assets/js/vendor-visual-saF8KLH_.js.br +0 -0
  88. package/dist/web/karin.png.br +0 -0
  89. package/dist/web/sha256.min.js.br +0 -0
@@ -0,0 +1,268 @@
1
+ import { karinPathBase } from "./root.mjs";
2
+ import path from "node:path";
3
+ import { promisify } from "node:util";
4
+ import fs from "node:fs";
5
+ import axios from "axios";
6
+ import { pipeline } from "node:stream";
7
+
8
+ //#region src/utils/fs/file.ts
9
+ /** promisify stream.pipeline */
10
+ const streamPipeline = promisify(pipeline);
11
+ /** 当前运行环境的路径标准协议前缀 */
12
+ const sep = path.sep === "/" ? /^file:\/\// : /^file:[/]{2,3}/;
13
+ /**
14
+ * 下载文件
15
+ * @param fileUrl 下载地址
16
+ * @param savePath 保存路径
17
+ * @param options 请求参数 基本是axios参数,额外拓展了returnBoolean
18
+ */
19
+ const downloadFile = async (fileUrl, savePath, options = {}) => {
20
+ try {
21
+ await fs.promises.mkdir(path.dirname(savePath), { recursive: true });
22
+ const response = await axios.get(fileUrl, {
23
+ ...options,
24
+ responseType: "stream"
25
+ });
26
+ await streamPipeline(response.data, fs.createWriteStream(savePath));
27
+ if (options.returnBoolean) return true;
28
+ return {
29
+ success: true,
30
+ data: response.data
31
+ };
32
+ } catch (error) {
33
+ if (options.returnBoolean) return false;
34
+ return {
35
+ success: false,
36
+ data: error
37
+ };
38
+ }
39
+ };
40
+ /**
41
+ * 下载保存文件
42
+ * @param fileUrl 下载地址
43
+ * @param savePath 保存路径
44
+ * @param param axios参数
45
+ */
46
+ const downFile = async (fileUrl, savePath, param = {}) => {
47
+ return downloadFile(fileUrl, savePath, {
48
+ ...param,
49
+ returnBoolean: true
50
+ });
51
+ };
52
+ /**
53
+ * 标准化文件路径 统一使用/分隔符
54
+ * @param file - 路径
55
+ * @param absPath - 返回绝对路径 默认为true
56
+ * @param prefix - 添加file://前缀 默认为false
57
+ * @returns 标准化后的路径
58
+ */
59
+ const absPath = (file, absPath = true, prefix = false) => {
60
+ file = file.replace(/\\/g, "/");
61
+ if (file.startsWith("file://")) file = file.replace(sep, "");
62
+ file = path.normalize(file);
63
+ if (absPath) file = path.resolve(file);
64
+ if (prefix) file = "file://" + file;
65
+ return file.replace(/\\/g, "/");
66
+ };
67
+ /**
68
+ * 为每个插件创建基本文件夹结构
69
+ * @param name 插件名称
70
+ * @param files 需要创建的文件夹列表
71
+ */
72
+ const createPluginDir = async (name, files) => {
73
+ if (!Array.isArray(files)) files = [
74
+ "config",
75
+ "data",
76
+ "resources"
77
+ ];
78
+ if (files.length === 0) return;
79
+ /** 如果是组织包,优先使用旧版兼容格式(@org-pkg-name) */
80
+ const isOrgPkg = name.startsWith("@") && name.includes("/");
81
+ let pluginPath = isOrgPkg ? path.join(karinPathBase, name.replace("/", "-")) : path.join(karinPathBase, name);
82
+ /** 如果是组织包且旧版兼容格式(@org-pkg-name)不存在,则使用新版组织包结构(@org/pkg-name) */
83
+ if (isOrgPkg && !fs.existsSync(pluginPath)) {
84
+ const [orgName, pkgName] = name.split("/");
85
+ pluginPath = path.join(karinPathBase, orgName, pkgName);
86
+ }
87
+ await Promise.all(files.map((file) => {
88
+ const filePath = path.join(pluginPath, file);
89
+ if (!fs.existsSync(filePath)) return fs.promises.mkdir(filePath, { recursive: true });
90
+ return Promise.resolve();
91
+ }));
92
+ };
93
+ /**
94
+ * 获取符合后缀的文件列表(仅包含文件名称)
95
+ * @param filePath 文件路径
96
+ * @param suffixs 需要复制的文件后缀 可带点
97
+ * @returns 符合条件的文件列表
98
+ */
99
+ const getFiles = (filePath, suffixs = []) => {
100
+ if (!fs.existsSync(filePath)) throw new Error(`路径不存在: ${filePath}`);
101
+ /** 读取默认配置文件列表,只保留文件,排除文件夹 */
102
+ let files = fs.readdirSync(filePath, { withFileTypes: true }).filter((file) => file.isFile()).map((file) => file.name);
103
+ if (suffixs.length) {
104
+ /** 统一后缀格式为 .suffix */
105
+ const normalizedSuffixs = suffixs.map((suffix) => suffix.startsWith(".") ? suffix : `.${suffix}`);
106
+ files = files.filter((file) => {
107
+ const suffix = path.extname(file);
108
+ return suffix && normalizedSuffixs.includes(suffix);
109
+ });
110
+ }
111
+ return files;
112
+ };
113
+ /**
114
+ * 复制文件 同步
115
+ * @param files 需要复制的文件列表
116
+ * @param defaulPath 模板配置文件路径
117
+ * @param userPath 用户配置文件路径
118
+ */
119
+ const copyFilesSync = (files, defaulPath, userPath) => {
120
+ files.forEach((file) => {
121
+ const defaulFile = path.join(defaulPath, file);
122
+ const userFile = path.join(userPath, file);
123
+ if (!fs.existsSync(userFile)) fs.copyFileSync(defaulFile, userFile);
124
+ });
125
+ };
126
+ /**
127
+ * 复制文件 异步
128
+ * @param files 需要复制的文件列表
129
+ * @param defaulPath 模板配置文件路径
130
+ * @param userPath 用户配置文件路径
131
+ */
132
+ const copyFiles = async (files, defaulPath, userPath) => {
133
+ await Promise.all(files.map(async (file) => {
134
+ const defaulFile = path.join(defaulPath, file);
135
+ const userFile = path.join(userPath, file);
136
+ if (!fs.existsSync(userFile)) await fs.promises.copyFile(defaulFile, userFile);
137
+ }));
138
+ };
139
+ /**
140
+ * 创建配置文件 同步
141
+ * @description 从模板配置文件复制到目标文件夹
142
+ * @param defaulPath 模板配置文件路径
143
+ * @param userPath 目标文件夹路径
144
+ * @param suffixs 需要复制的文件后缀 可带点
145
+ * @param isThrow 是否抛出异常 默认不抛出
146
+ * @returns 是否复制成功
147
+ * @example
148
+ * ```ts
149
+ * copyConfigSync('defaultPath', 'userPath')
150
+ * copyConfigSync('defaultPath', 'userPath', ['yaml'])
151
+ * copyConfigSync('defaultPath', 'userPath', ['.yaml', 'json'])
152
+ * copyConfigSync('defaultPath', 'userPath', [], true)
153
+ * ```
154
+ */
155
+ const copyConfigSync = (defaulPath, userPath, suffixs = [], isThrow = false) => {
156
+ try {
157
+ const files = getFiles(defaulPath, suffixs);
158
+ fs.mkdirSync(userPath, { recursive: true });
159
+ fs.mkdirSync(defaulPath, { recursive: true });
160
+ copyFilesSync(files, defaulPath, userPath);
161
+ return true;
162
+ } catch (error) {
163
+ if (isThrow) throw error;
164
+ return false;
165
+ }
166
+ };
167
+ /**
168
+ * 创建配置文件 异步
169
+ * @description 从模板配置文件复制到用户配置文件
170
+ * @param defaulPath 模板配置文件路径
171
+ * @param userPath 用户配置文件路径
172
+ * @param suffixs 需要复制的文件后缀 可带点
173
+ * @param isThrow 是否抛出异常 默认不抛出
174
+ * @returns 是否复制成功
175
+ * @example
176
+ * ```ts
177
+ * await copyConfig('defaultPath', 'userPath')
178
+ * await copyConfig('defaultPath', 'userPath', ['yaml'])
179
+ * await copyConfig('defaultPath', 'userPath', ['.yaml', 'json'])
180
+ * await copyConfig('defaultPath', 'userPath', [], true)
181
+ * ```
182
+ */
183
+ const copyConfig = async (defaulPath, userPath, suffixs = [], isThrow = false) => {
184
+ try {
185
+ const files = getFiles(defaulPath, suffixs);
186
+ await Promise.all([fs.promises.mkdir(userPath, { recursive: true }), fs.promises.mkdir(defaulPath, { recursive: true })]);
187
+ await copyFiles(files, defaulPath, userPath);
188
+ return true;
189
+ } catch (error) {
190
+ if (isThrow) throw error;
191
+ return false;
192
+ }
193
+ };
194
+ /**
195
+ * 递归获取目录下的所有文件
196
+ * @param dir 目录路径
197
+ * @param options 选项
198
+ * @returns 符合条件的文件路径列表
199
+ * @example
200
+ * ```ts
201
+ * getAllFilesSync('dir')
202
+ * getAllFilesSync('dir', { suffixs: ['yaml', '.json'] })
203
+ * getAllFilesSync('dir', { exclude: ['.yaml', 'json'] })
204
+ * getAllFilesSync('dir', { returnType: 'abs' })
205
+ * ```
206
+ */
207
+ const getAllFilesSync = (dir, options = {}) => {
208
+ const { suffixs = [], exclude = [], returnType = "rel" } = options;
209
+ const result = [];
210
+ const readDirRecursive = (currentDir, prefix = "") => {
211
+ const files = fs.readdirSync(currentDir, { withFileTypes: true });
212
+ for (const file of files) {
213
+ const relativePath = path.join(prefix, file.name);
214
+ const fullPath = path.join(currentDir, file.name);
215
+ if (file.isDirectory()) readDirRecursive(fullPath, relativePath);
216
+ else if (file.isFile()) {
217
+ const suffix = path.extname(file.name);
218
+ if (suffixs.length > 0) {
219
+ if (suffixs.map((s) => s.startsWith(".") ? s : `.${s}`).includes(suffix)) result.push(returnType === "abs" ? fullPath : relativePath);
220
+ } else if (exclude.length > 0) {
221
+ if (!exclude.map((s) => s.startsWith(".") ? s : `.${s}`).includes(suffix)) result.push(returnType === "abs" ? fullPath : relativePath);
222
+ } else result.push(returnType === "abs" ? fullPath : relativePath);
223
+ }
224
+ }
225
+ };
226
+ if (!fs.existsSync(dir)) throw new Error(`路径不存在: ${dir}`);
227
+ readDirRecursive(dir);
228
+ return result;
229
+ };
230
+ /**
231
+ * 递归获取目录下的所有文件(异步版本)
232
+ * @param dir 目录路径
233
+ * @param options 选项
234
+ * @returns 符合条件的文件路径列表
235
+ * @example
236
+ * ```ts
237
+ * await getFilesRecursive('dir')
238
+ * await getFilesRecursive('dir', { suffixs: ['yaml', '.json'] })
239
+ * await getFilesRecursive('dir', { exclude: ['.yaml', 'json'] })
240
+ * await getFilesRecursive('dir', { returnType: 'abs' })
241
+ * ```
242
+ */
243
+ const getAllFiles = async (dir, options = {}) => {
244
+ const { suffixs = [], exclude = [], returnType = "rel" } = options;
245
+ const result = [];
246
+ const readDirRecursive = async (currentDir, prefix = "") => {
247
+ const files = await fs.promises.readdir(currentDir, { withFileTypes: true });
248
+ await Promise.all(files.map(async (file) => {
249
+ const relativePath = path.join(prefix, file.name);
250
+ const fullPath = path.join(currentDir, file.name);
251
+ if (file.isDirectory()) await readDirRecursive(fullPath, relativePath);
252
+ else if (file.isFile()) {
253
+ const suffix = path.extname(file.name);
254
+ if (suffixs.length > 0) {
255
+ if (suffixs.map((s) => s.startsWith(".") ? s : `.${s}`).includes(suffix)) result.push(returnType === "abs" ? fullPath : relativePath);
256
+ } else if (exclude.length > 0) {
257
+ if (!exclude.map((s) => s.startsWith(".") ? s : `.${s}`).includes(suffix)) result.push(returnType === "abs" ? fullPath : relativePath);
258
+ } else result.push(returnType === "abs" ? fullPath : relativePath);
259
+ }
260
+ }));
261
+ };
262
+ if (!fs.existsSync(dir)) throw new Error(`路径不存在: ${dir}`);
263
+ await readDirRecursive(dir);
264
+ return result;
265
+ };
266
+
267
+ //#endregion
268
+ export { copyFilesSync as a, downloadFile as c, getFiles as d, sep as f, copyFiles as i, getAllFiles as l, copyConfig as n, createPluginDir as o, copyConfigSync as r, downFile as s, absPath as t, getAllFilesSync as u };
@@ -0,0 +1,65 @@
1
+ import fs from "node:fs";
2
+
3
+ //#region src/utils/fs/fsSync.ts
4
+ /**
5
+ * 检查目录是否存在
6
+ * @param file 文件路径
7
+ * @returns 返回布尔值
8
+ */
9
+ const existsSync$1 = (file) => {
10
+ return fs.existsSync(file);
11
+ };
12
+ /**
13
+ * 检查是否为目录
14
+ * @param file 文件路径
15
+ * @returns 返回布尔值
16
+ */
17
+ const isDirSync = (file) => {
18
+ try {
19
+ return fs.statSync(file).isDirectory();
20
+ } catch {
21
+ return false;
22
+ }
23
+ };
24
+ /**
25
+ * 检查是否为文件
26
+ * @param file 文件路径
27
+ * @returns 返回布尔值
28
+ */
29
+ const isFileSync = (file) => {
30
+ try {
31
+ return fs.statSync(file).isFile();
32
+ } catch {
33
+ return false;
34
+ }
35
+ };
36
+ /**
37
+ * 递归创建文件夹
38
+ * @param dirname 文件夹路径
39
+ * @returns 返回布尔值 是否创建成功
40
+ */
41
+ const mkdirSync = (dirname) => {
42
+ try {
43
+ fs.mkdirSync(dirname, { recursive: true });
44
+ return true;
45
+ } catch {
46
+ return false;
47
+ }
48
+ };
49
+ /**
50
+ * 检查目录是否存在 不存在则创建
51
+ * @param file 文件路径
52
+ * @returns 返回布尔值
53
+ */
54
+ const existToMkdirSync = (file) => {
55
+ try {
56
+ if (!fs.existsSync(file)) mkdirSync(file);
57
+ return true;
58
+ } catch {
59
+ return false;
60
+ }
61
+ };
62
+ const rmSync = fs.rmSync;
63
+
64
+ //#endregion
65
+ export { mkdirSync as a, isFileSync as i, existsSync$1 as n, rmSync as o, isDirSync as r, existToMkdirSync as t };