node-karin 0.11.13 → 0.11.14

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 (43) hide show
  1. package/config/view/config.yaml +5 -5
  2. package/lib/adapter/index.js +2 -2
  3. package/lib/cli/index.js +229 -232
  4. package/lib/cli/init.js +14 -14
  5. package/lib/cli/karin.js +15 -15
  6. package/lib/cli/start.js +8 -0
  7. package/lib/core/index.js +10 -10
  8. package/lib/core/init/init.js +1 -0
  9. package/lib/core/process/process.js +1 -1
  10. package/lib/core/server/server.js +13 -1
  11. package/lib/db/index.js +2 -2
  12. package/lib/db/level/level.js +0 -1
  13. package/lib/db/redis/redis_level.d.ts +2 -0
  14. package/lib/db/redis/redis_level.js +12 -11
  15. package/lib/event/index.js +5 -5
  16. package/lib/modules/art-template.js +1 -1
  17. package/lib/modules/axios.js +2 -2
  18. package/lib/modules/chalk.js +2 -2
  19. package/lib/modules/chokidar.js +2 -2
  20. package/lib/modules/commander.js +2 -2
  21. package/lib/modules/express.js +3 -3
  22. package/lib/modules/level.js +2 -2
  23. package/lib/modules/lodash.js +1 -1
  24. package/lib/modules/log4js.js +2 -2
  25. package/lib/modules/moment.js +1 -1
  26. package/lib/modules/node-schedule.js +2 -2
  27. package/lib/modules/redis.js +2 -2
  28. package/lib/modules/ws.js +3 -3
  29. package/lib/modules/yaml.js +2 -2
  30. package/lib/render/app.js +82 -81
  31. package/lib/render/base.js +54 -54
  32. package/lib/render/client.js +144 -142
  33. package/lib/render/client_even.js +140 -137
  34. package/lib/render/http.js +40 -41
  35. package/lib/render/index.js +6 -6
  36. package/lib/render/server.js +93 -88
  37. package/lib/render/wormhole.js +153 -151
  38. package/lib/types/index.js +13 -13
  39. package/lib/types/type/global.d.ts +2 -0
  40. package/lib/utils/index.js +11 -11
  41. package/package.json +6 -3
  42. package/lib/cli/dev.js +0 -3
  43. /package/lib/cli/{dev.d.ts → start.d.ts} +0 -0
@@ -103,13 +103,13 @@ view:
103
103
  comment: 主人列表 主权限
104
104
  path: master
105
105
  type: array
106
- arrayType: number
106
+ arrayType: string
107
107
 
108
108
  - key: 管理员列表
109
109
  comment: 管理员列表 子权限
110
110
  path: admin
111
111
  type: array
112
- arrayType: number
112
+ arrayType: string
113
113
 
114
114
  - key: 黑名单
115
115
  comment: 黑名单相关
@@ -119,7 +119,7 @@ view:
119
119
  - key: 黑名单用户
120
120
  path: BlackList.users
121
121
  type: array
122
- arrayType: number
122
+ arrayType: string
123
123
  associated:
124
124
  - file: App
125
125
  path: BlackList.users
@@ -127,7 +127,7 @@ view:
127
127
  - key: 黑名单群聊
128
128
  path: BlackList.groups
129
129
  type: array
130
- arrayType: number
130
+ arrayType: string
131
131
  associated:
132
132
  - file: App
133
133
  path: BlackList.groups
@@ -136,7 +136,7 @@ view:
136
136
  comment: 设置后不会打印该群的消息日志
137
137
  path: BlackList.GroupMsgLog
138
138
  type: array
139
- arrayType: number
139
+ arrayType: string
140
140
  associated:
141
141
  - file: App
142
142
  path: BlackList.GroupMsgLog
@@ -1,2 +1,2 @@
1
- export * from './input/index.js'
2
- export * from './onebot/11/index.js'
1
+ export * from './input/index.js';
2
+ export * from './onebot/11/index.js';
package/lib/cli/index.js CHANGED
@@ -1,282 +1,279 @@
1
- import fs from 'fs'
2
- import path from 'path'
3
- import yaml from 'yaml'
4
- import axios from 'axios'
5
- import { fileURLToPath } from 'url'
6
- import { exec as execCmd, spawn } from 'child_process'
7
- import { KarinCfgInit } from '../core/init/config.js'
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import yaml from 'yaml';
4
+ import axios from 'axios';
5
+ import { fileURLToPath } from 'url';
6
+ import { exec as execCmd, spawn } from 'child_process';
7
+ import { KarinCfgInit } from '../core/init/config.js';
8
8
  export class KarinCli {
9
- child
10
- filename
11
- karinDir
12
- file
13
- constructor () {
14
- process.env.karin_app_start_count = '0'
15
- process.env.karin_app_watch = 'no'
16
- /** 当前文件绝对路径 */
17
- this.filename = fileURLToPath(import.meta.url)
18
- /** karin目录 */
19
- this.karinDir = path.join(path.dirname(this.filename), '../..')
20
- /** 入口文件(注意后缀) */
21
- this.file = path.join(path.dirname(this.filename), '../index.js')
22
- this.child = null
23
- }
24
-
25
- /**
9
+ child;
10
+ filename;
11
+ karinDir;
12
+ file;
13
+ constructor() {
14
+ process.env.karin_app_start_count = '0';
15
+ process.env.karin_app_watch = 'no';
16
+ /** 当前文件绝对路径 */
17
+ this.filename = fileURLToPath(import.meta.url);
18
+ /** karin目录 */
19
+ this.karinDir = path.join(path.dirname(this.filename), '../..');
20
+ /** 入口文件(注意后缀) */
21
+ this.file = path.join(path.dirname(this.filename), '../index.js');
22
+ this.child = null;
23
+ process.env.karin_app_version = this.pkg(true).version;
24
+ }
25
+ /**
26
26
  * 获取pkg
27
27
  * @param isNpm - 是否是npm包
28
28
  */
29
- pkg (isNpm) {
30
- const filePath = isNpm ? path.join(this.karinDir, 'package.json') : path.join(process.cwd(), 'package.json')
31
- const data = JSON.parse(fs.readFileSync(filePath, 'utf-8'))
32
- return data
33
- }
34
-
35
- /**
29
+ pkg(isNpm) {
30
+ const filePath = isNpm ? path.join(this.karinDir, 'package.json') : path.join(process.cwd(), 'package.json');
31
+ const data = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
32
+ return data;
33
+ }
34
+ /**
36
35
  * 获取配置文件路径
37
36
  * @param name - 配置文件名
38
37
  */
39
- getConfigPath (name) {
40
- const filePath = `./config/config/${name}.yaml`
41
- if (!fs.existsSync(filePath)) { return `${this.karinDir}/config/config/${name}.yaml` }
42
- return filePath
43
- }
44
-
45
- /**
38
+ getConfigPath(name) {
39
+ const filePath = `./config/config/${name}.yaml`;
40
+ if (!fs.existsSync(filePath))
41
+ return `${this.karinDir}/config/config/${name}.yaml`;
42
+ return filePath;
43
+ }
44
+ /**
46
45
  * 获取pm2配置
47
46
  * @param name - 配置文件名
48
47
  */
49
- getConfigData (name) {
50
- const _path = this.getConfigPath(name)
51
- const data = yaml.parse(fs.readFileSync(_path, 'utf-8'))
52
- return data
53
- }
54
-
55
- /**
48
+ getConfigData(name) {
49
+ const _path = this.getConfigPath(name);
50
+ const data = yaml.parse(fs.readFileSync(_path, 'utf-8'));
51
+ return data;
52
+ }
53
+ /**
56
54
  * 启动
57
55
  * @param mode - 模式
58
56
  * @param lang - 语言环境
59
57
  * @param runner - 运行器
60
58
  */
61
- start (mode, lang, runner) {
62
- process.env.karin_app_mode = mode
63
- process.env.karin_app_lang = lang
64
- process.env.karin_app_runner = runner
65
- let cmd
66
- switch (runner) {
67
- case 'node' /* Runner.Node */:
68
- cmd = [this.file]
69
- break
70
- case 'tsx' /* Runner.Tsx */:
71
- cmd = [this.file]
72
- break
73
- case 'pm2' /* Runner.Pm2 */: {
74
- this.pm2()
75
- return
76
- }
59
+ start(mode, lang, runner) {
60
+ process.env.karin_app_mode = mode;
61
+ process.env.karin_app_lang = lang;
62
+ process.env.karin_app_runner = runner;
63
+ let cmd;
64
+ switch (runner) {
65
+ case "node" /* Runner.Node */:
66
+ cmd = [this.file];
67
+ break;
68
+ case "tsx" /* Runner.Tsx */:
69
+ cmd = [this.file];
70
+ break;
71
+ case "pm2" /* Runner.Pm2 */: {
72
+ this.pm2();
73
+ return;
74
+ }
75
+ }
76
+ /** 启动 */
77
+ this.child = spawn(runner, cmd, { stdio: ['inherit', 'inherit', 'inherit', 'ipc'], cwd: process.cwd(), env: process.env, shell: runner === "tsx" /* Runner.Tsx */ });
78
+ /** 监听退出 */
79
+ this.child.once('exit', (code) => process.exit(code));
80
+ /** 监听子进程消息 */
81
+ this.child.on('message', (data) => {
82
+ /** pm2重启 */
83
+ if (data.env.pm_id)
84
+ return this.restart();
85
+ try {
86
+ /** 先结束进程 */
87
+ this.child.kill('SIGINT');
88
+ /** 停止监听 */
89
+ this.child.removeAllListeners();
90
+ /** 重启次数+1 */
91
+ const count = Number(process.env.karin_app_start_count) || 0;
92
+ process.env.karin_app_start_count = String(count + 1);
93
+ }
94
+ catch { }
95
+ return this.start(mode, lang, runner);
96
+ });
77
97
  }
78
- /** 启动 */
79
- this.child = spawn(runner, cmd, { stdio: ['inherit', 'inherit', 'inherit', 'ipc'], cwd: process.cwd(), env: process.env, shell: runner === 'tsx' /* Runner.Tsx */ })
80
- /** 监听退出 */
81
- this.child.once('exit', (code) => process.exit(code))
82
- /** 监听子进程消息 */
83
- this.child.on('message', (data) => {
84
- /** pm2重启 */
85
- if (data.env.pm_id) { return this.restart() }
86
- try {
87
- /** 先结束进程 */
88
- this.child.kill('SIGINT')
89
- /** 停止监听 */
90
- this.child.removeAllListeners()
91
- /** 重启次数+1 */
92
- const count = Number(process.env.karin_app_start_count) || 0
93
- process.env.karin_app_start_count = String(count + 1)
94
- } catch { }
95
- return this.start(mode, lang, runner)
96
- })
97
- }
98
-
99
- /**
98
+ /**
100
99
  * pm2重启
101
100
  */
102
- async restart () {
103
- const pm2Cfg = this.getConfigData('pm2')
104
- const serverCfg = this.getConfigData('server')
105
- /** 尝试获取pm2的进程id */
106
- const port = serverCfg?.http?.port || 7000
107
- const res = await this.Axios(`http://127.0.0.1:${port}/api/ping`, 1000)
108
- if (res) {
109
- await this.exec(`pm2 restart ${res.pm2_id}`)
110
- } else {
111
- await this.exec(`pm2 restart ${pm2Cfg?.apps[0]?.name || 'Karin'}`)
101
+ async restart() {
102
+ const pm2Cfg = this.getConfigData('pm2');
103
+ const serverCfg = this.getConfigData('server');
104
+ /** 尝试获取pm2的进程id */
105
+ const port = serverCfg?.http?.port || 7000;
106
+ const res = await this.Axios(`http://127.0.0.1:${port}/api/ping`, 1000);
107
+ if (res) {
108
+ await this.exec(`pm2 restart ${res.pm2_id}`);
109
+ }
110
+ else {
111
+ await this.exec(`pm2 restart ${pm2Cfg?.apps[0]?.name || 'Karin'}`);
112
+ }
113
+ console.log('pm2服务已重启');
114
+ process.exit(0);
112
115
  }
113
- console.log('pm2服务已重启')
114
- process.exit(0)
115
- }
116
-
117
- /**
116
+ /**
118
117
  * pm2启动
119
118
  */
120
- async pm2 () {
121
- console.log('pm2启动中...')
122
- const filePath = this.getConfigPath('pm2')
123
- const data = this.getConfigData('pm2')
124
- /** 修正入口文件路径 兼容0.6.28以前的版本 */
125
- if (!fs.existsSync('./src') && filePath === './config/config/pm2.yaml') {
126
- const script = './node_modules/node-karin/lib/index.js'
127
- if (data.apps[0].script !== script) {
128
- data.apps[0].script = script
129
- fs.writeFileSync(filePath, yaml.stringify(data))
130
- }
119
+ async pm2() {
120
+ console.log('pm2启动中...');
121
+ const filePath = this.getConfigPath('pm2');
122
+ const data = this.getConfigData('pm2');
123
+ /** 修正入口文件路径 兼容0.6.28以前的版本 */
124
+ if (!fs.existsSync('./src') && filePath === './config/config/pm2.yaml') {
125
+ const script = './node_modules/node-karin/lib/index.js';
126
+ if (data.apps[0].script !== script) {
127
+ data.apps[0].script = script;
128
+ fs.writeFileSync(filePath, yaml.stringify(data));
129
+ }
130
+ }
131
+ const cmd = `pm2 start ${filePath} --env ${JSON.stringify(process.env)}`;
132
+ await this.exec(cmd);
133
+ console.log('pm2服务已启动 可执行 【npx karin log】 查看日志');
134
+ process.exit(0);
131
135
  }
132
- const cmd = `pm2 start ${filePath} --env ${JSON.stringify(process.env)}`
133
- await this.exec(cmd)
134
- console.log('pm2服务已启动 可执行 【npx karin log】 查看日志')
135
- process.exit(0)
136
- }
137
-
138
- /**
136
+ /**
139
137
  * pm2结束进程
140
138
  */
141
- async stop () {
142
- console.log('pm2服务停止中...')
143
- const pm2Cfg = this.getConfigData('pm2')
144
- const serverCfg = this.getConfigData('server')
145
- const port = serverCfg?.http?.port || 7000
146
- const res = await this.Axios(`http://127.0.0.1:${port}/api/ping`, 1000)
147
- if (res) {
148
- await this.exec(`pm2 delete ${res.pm2_id}`)
149
- } else {
150
- await this.exec(`pm2 delete ${pm2Cfg?.apps[0]?.name || 'Karin'}`)
139
+ async stop() {
140
+ console.log('pm2服务停止中...');
141
+ const pm2Cfg = this.getConfigData('pm2');
142
+ const serverCfg = this.getConfigData('server');
143
+ const port = serverCfg?.http?.port || 7000;
144
+ const res = await this.Axios(`http://127.0.0.1:${port}/api/ping`, 1000);
145
+ if (res) {
146
+ await this.exec(`pm2 delete ${res.pm2_id}`);
147
+ }
148
+ else {
149
+ await this.exec(`pm2 delete ${pm2Cfg?.apps[0]?.name || 'Karin'}`);
150
+ }
151
+ console.log('pm2服务已停止');
152
+ process.exit(0);
151
153
  }
152
- console.log('pm2服务已停止')
153
- process.exit(0)
154
- }
155
-
156
- /**
154
+ /**
157
155
  * pm2查看日志
158
156
  */
159
- async log () {
160
- const pm2Cfg = this.getConfigData('pm2')
161
- const serverCfg = this.getConfigData('server')
162
- const port = serverCfg?.http?.port || 7000
163
- const res = await this.Axios(`http://127.0.0.1:${port}/api/ping`, 1000)
164
- const lines = pm2Cfg?.lines || 1000
165
- const cmd = process.platform === 'win32' ? 'pm2.cmd' : 'pm2'
166
- const type = res ? res.pm_id : pm2Cfg?.apps[0]?.name || 'Karin'
167
- spawn(cmd, ['logs', type, '--lines', lines], { stdio: 'inherit', shell: true, cwd: process.cwd() })
168
- }
169
-
170
- /**
157
+ async log() {
158
+ const pm2Cfg = this.getConfigData('pm2');
159
+ const serverCfg = this.getConfigData('server');
160
+ const port = serverCfg?.http?.port || 7000;
161
+ const res = await this.Axios(`http://127.0.0.1:${port}/api/ping`, 1000);
162
+ const lines = pm2Cfg?.lines || 1000;
163
+ const cmd = process.platform === 'win32' ? 'pm2.cmd' : 'pm2';
164
+ const type = res ? res.pm_id : pm2Cfg?.apps[0]?.name || 'Karin';
165
+ spawn(cmd, ['logs', type, '--lines', lines], { stdio: 'inherit', shell: true, cwd: process.cwd() });
166
+ }
167
+ /**
171
168
  * 更新依赖
172
169
  */
173
- async update () {
174
- /** 屏蔽的依赖包列表 */
175
- const pkgdependencies = [
176
- 'art-template',
177
- 'axios',
178
- 'chalk',
179
- 'chokidar',
180
- 'commander',
181
- 'express',
182
- 'level',
183
- 'lodash',
184
- 'log4js',
185
- 'moment',
186
- 'node-schedule',
187
- 'redis',
188
- 'ws',
189
- 'yaml',
190
- ]
191
- const list = Object.keys(this.pkg(false).dependencies).filter(key => !pkgdependencies.includes(key))
192
- /** 获取包管理器 */
193
- const pkg = new KarinCfgInit().getRegistry()
194
- const cmd = pkg === 'yarn' ? 'yarn upgrade' : `${pkg} update`
195
- /** 异步并发更新依赖 */
196
- await Promise.all(list.map(async (item) => {
197
- try {
198
- /** 检查是否已经是最新版本 */
199
- const local = await this.getLocalVersion(item, pkg)
200
- const remote = await this.getRemoteVersion(item, pkg)
201
- if (local === remote) {
202
- console.log(`[依赖更新] ${item} 已经是最新~`)
203
- return
204
- }
205
- console.log(`[依赖更新] ${item} 当前版本: ${local} 最新版本: ${remote}`)
206
- await this.exec(`${cmd} ${item}@latest`)
207
- console.log(`[依赖更新] ${item} 更新完成~`)
208
- } catch (error) {
209
- console.error(`[依赖更新] ${item} 更新失败:`)
210
- console.error(`error.stack: ${error.stack}`)
211
- console.error(`error.message: ${error.message}`)
212
- }
213
- }))
214
- console.log('所有依赖已更新完成~')
215
- }
216
-
217
- /**
170
+ async update() {
171
+ /** 屏蔽的依赖包列表 */
172
+ const pkgdependencies = [
173
+ 'art-template',
174
+ 'axios',
175
+ 'chalk',
176
+ 'chokidar',
177
+ 'commander',
178
+ 'express',
179
+ 'level',
180
+ 'lodash',
181
+ 'log4js',
182
+ 'moment',
183
+ 'node-schedule',
184
+ 'redis',
185
+ 'ws',
186
+ 'yaml',
187
+ ];
188
+ const list = Object.keys(this.pkg(false).dependencies).filter(key => !pkgdependencies.includes(key));
189
+ /** 获取包管理器 */
190
+ const pkg = new KarinCfgInit().getRegistry();
191
+ const cmd = pkg === 'yarn' ? 'yarn upgrade' : `${pkg} update`;
192
+ /** 异步并发更新依赖 */
193
+ await Promise.all(list.map(async (item) => {
194
+ try {
195
+ /** 检查是否已经是最新版本 */
196
+ const local = await this.getLocalVersion(item, pkg);
197
+ const remote = await this.getRemoteVersion(item, pkg);
198
+ if (local === remote) {
199
+ console.log(`[依赖更新] ${item} 已经是最新~`);
200
+ return;
201
+ }
202
+ console.log(`[依赖更新] ${item} 当前版本: ${local} 最新版本: ${remote}`);
203
+ await this.exec(`${cmd} ${item}@latest`);
204
+ console.log(`[依赖更新] ${item} 更新完成~`);
205
+ }
206
+ catch (error) {
207
+ console.error(`[依赖更新] ${item} 更新失败:`);
208
+ console.error(`error.stack: ${error.stack}`);
209
+ console.error(`error.message: ${error.message}`);
210
+ }
211
+ }));
212
+ console.log('所有依赖已更新完成~');
213
+ }
214
+ /**
218
215
  * 获取指定包的本地版本
219
216
  * @param name - 包名
220
217
  * @param pkg - 包管理器
221
218
  * @returns - 版本号
222
219
  */
223
- async getLocalVersion (name, pkg) {
224
- const cmd = pkg === 'yarn' ? `yarn list --pattern ${name}` : `${pkg} list ${name} --depth=0`
225
- const text = await this.exec(cmd)
226
- /** pnpm特殊处理 */
227
- if (pkg === 'pnpm') {
228
- const reg = new RegExp(`${name}\\s+([\\d.]+)`, 'gm')
229
- const res = reg.exec(text)
230
- return res?.[1] || '0.0.0'
220
+ async getLocalVersion(name, pkg) {
221
+ const cmd = pkg === 'yarn' ? `yarn list --pattern ${name}` : `${pkg} list ${name} --depth=0`;
222
+ const text = await this.exec(cmd);
223
+ /** pnpm特殊处理 */
224
+ if (pkg === 'pnpm') {
225
+ const reg = new RegExp(`${name}\\s+([\\d.]+)`, 'gm');
226
+ const res = reg.exec(text);
227
+ return res?.[1] || '0.0.0';
228
+ }
229
+ const reg = new RegExp(`${name}@(\\d+\\.\\d+\\.\\d+)`, 'gm');
230
+ const res = reg.exec(text);
231
+ return res?.[1] || '0.0.0';
231
232
  }
232
- const reg = new RegExp(`${name}@(\\d+\\.\\d+\\.\\d+)`, 'gm')
233
- const res = reg.exec(text)
234
- return res?.[1] || '0.0.0'
235
- }
236
-
237
- /**
233
+ /**
238
234
  * 获取指定包的最新版本
239
235
  * @param name - 包名
240
236
  * @param pkg - 包管理器
241
237
  */
242
- async getRemoteVersion (name, pkg) {
243
- const cmd = `${pkg} info ${name} version`
244
- const text = await this.exec(cmd)
245
- /** yarn特殊处理 */
246
- if (pkg === 'yarn') {
247
- const lines = text.split('\n').map(line => line.trim())
248
- const ver = lines.find(line => /^\d+\.\d+\.\d+$/.test(line))
249
- return ver || ''
238
+ async getRemoteVersion(name, pkg) {
239
+ const cmd = `${pkg} info ${name} version`;
240
+ const text = await this.exec(cmd);
241
+ /** yarn特殊处理 */
242
+ if (pkg === 'yarn') {
243
+ const lines = text.split('\n').map(line => line.trim());
244
+ const ver = lines.find(line => /^\d+\.\d+\.\d+$/.test(line));
245
+ return ver || '';
246
+ }
247
+ return text.trim();
250
248
  }
251
- return text.trim()
252
- }
253
-
254
- /**
249
+ /**
255
250
  * 封装exec
256
251
  * @param cmd - 命令
257
252
  */
258
- exec (cmd) {
259
- return new Promise((resolve, reject) => {
260
- execCmd(cmd, (error, stdout, stderr) => {
261
- if (stdout) { return resolve(stdout.trim()) }
262
- if (error) { return reject(error) }
263
- return reject(stderr)
264
- })
265
- })
266
- }
267
-
268
- /**
253
+ exec(cmd) {
254
+ return new Promise((resolve, reject) => {
255
+ execCmd(cmd, (error, stdout, stderr) => {
256
+ if (stdout)
257
+ return resolve(stdout.trim());
258
+ if (error)
259
+ return reject(error);
260
+ return reject(stderr);
261
+ });
262
+ });
263
+ }
264
+ /**
269
265
  * 封装axios 超时返回false
270
266
  * @param url - 请求地址
271
267
  * @param timeout - 超时时间
272
268
  * @returns - 请求结果
273
269
  */
274
- async Axios (url, timeout) {
275
- try {
276
- const res = await axios.get(url, { timeout })
277
- return res.data
278
- } catch {
279
- return false
270
+ async Axios(url, timeout) {
271
+ try {
272
+ const res = await axios.get(url, { timeout });
273
+ return res.data;
274
+ }
275
+ catch {
276
+ return false;
277
+ }
280
278
  }
281
- }
282
279
  }
package/lib/cli/init.js CHANGED
@@ -1,21 +1,21 @@
1
1
  #!/usr/bin/env node
2
- import { KarinCfgInit } from '../core/init/config.js'
2
+ import { KarinCfgInit } from '../core/init/config.js';
3
3
  /**
4
4
  * 休眠函数
5
5
  * @param ms 毫秒
6
6
  */
7
- function sleep (ms) {
8
- return new Promise(resolve => setTimeout(resolve, ms))
7
+ function sleep(ms) {
8
+ return new Promise(resolve => setTimeout(resolve, ms));
9
9
  }
10
- async function main () {
11
- /** 捕获错误 打印日志 */
12
- process.on('uncaughtException', err => console.error(err))
13
- process.on('unhandledRejection', err => console.error(err))
14
- const init = new KarinCfgInit()
15
- init.init()
16
- await sleep(1000)
17
- const pkg = init.getRegistry()
18
- /** 结果 */
19
- await init.install(pkg)
10
+ async function main() {
11
+ /** 捕获错误 打印日志 */
12
+ process.on('uncaughtException', err => console.error(err));
13
+ process.on('unhandledRejection', err => console.error(err));
14
+ const init = new KarinCfgInit();
15
+ init.init();
16
+ await sleep(1000);
17
+ const pkg = init.getRegistry();
18
+ /** 结果 */
19
+ await init.install(pkg);
20
20
  }
21
- main().then(() => process.exit(0)).catch(() => process.exit(0))
21
+ main().then(() => process.exit(0)).catch(() => process.exit(0));
package/lib/cli/karin.js CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env node
2
- import { program } from 'commander'
3
- import { KarinCli } from './index.js'
4
- const cli = new KarinCli()
5
- program.version(cli.pkg(true).version, '-v, --version', '显示版本号')
6
- program.command('.').description('启动karin').action(() => cli.start('prod' /* Mode.Prod */, 'js' /* Lang.Js */, 'node' /* Runner.Node */))
7
- program.command('start').description('启动karin').action(() => cli.start('prod' /* Mode.Prod */, 'js' /* Lang.Js */, 'node' /* Runner.Node */))
8
- program.command('pm2').description('后台运行karin').action(() => cli.start('prod' /* Mode.Prod */, 'js' /* Lang.Js */, 'pm2' /* Runner.Pm2 */))
9
- program.command('stop').description('停止后台运行').action(() => cli.stop())
10
- program.command('rs').description('重启pm2服务').action(() => cli.restart())
11
- program.command('dev').description('JavaScript开发模式').action(() => cli.start('dev' /* Mode.Dev */, 'js' /* Lang.Js */, 'node' /* Runner.Node */))
12
- program.command('ts').description('TypeScript开发模式').action(() => cli.start('dev' /* Mode.Dev */, 'ts' /* Lang.Ts */, 'tsx' /* Runner.Tsx */))
13
- program.command('log').description('查看日志').action(() => cli.log())
14
- program.command('up').description('更新依赖').action(() => cli.update())
15
- program.command('init').description('初始化karin').action(() => { import('./init.js') })
16
- program.parse(process.argv)
2
+ import { program } from 'commander';
3
+ import { KarinCli } from './index.js';
4
+ const cli = new KarinCli();
5
+ program.version(cli.pkg(true).version, '-v, --version', '显示版本号');
6
+ program.command('.').description('启动karin').action(() => cli.start("prod" /* Mode.Prod */, "js" /* Lang.Js */, "node" /* Runner.Node */));
7
+ program.command('start').description('启动karin').action(() => cli.start("prod" /* Mode.Prod */, "js" /* Lang.Js */, "node" /* Runner.Node */));
8
+ program.command('pm2').description('后台运行karin').action(() => cli.start("prod" /* Mode.Prod */, "js" /* Lang.Js */, "pm2" /* Runner.Pm2 */));
9
+ program.command('stop').description('停止后台运行').action(() => cli.stop());
10
+ program.command('rs').description('重启pm2服务').action(() => cli.restart());
11
+ program.command('dev').description('JavaScript开发模式').action(() => cli.start("dev" /* Mode.Dev */, "js" /* Lang.Js */, "node" /* Runner.Node */));
12
+ program.command('ts').description('TypeScript开发模式').action(() => cli.start("dev" /* Mode.Dev */, "ts" /* Lang.Ts */, "tsx" /* Runner.Tsx */));
13
+ program.command('log').description('查看日志').action(() => cli.log());
14
+ program.command('up').description('更新依赖').action(() => cli.update());
15
+ program.command('init').description('初始化karin').action(() => { import('./init.js'); });
16
+ program.parse(process.argv);
@@ -0,0 +1,8 @@
1
+ import { program } from 'commander';
2
+ import { KarinCli } from './index.js';
3
+ const karin = new KarinCli();
4
+ program.version(karin.pkg(true).version, '-v, --version', '显示版本号');
5
+ program.command('.').description('启动karin').action(() => karin.start("prod" /* Mode.Prod */, "js" /* Lang.Js */, "node" /* Runner.Node */));
6
+ program.command('start').description('启动karin').action(() => karin.start("prod" /* Mode.Prod */, "js" /* Lang.Js */, "node" /* Runner.Node */));
7
+ program.command('dev').description('dev开发模式').action(() => karin.start("dev" /* Mode.Dev */, "js" /* Lang.Js */, "node" /* Runner.Node */));
8
+ program.parse(process.argv);