node-karin 0.8.0 → 0.8.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.
- package/lib/cli/karin.js +70 -4
- package/lib/utils/init.js +1 -1
- package/package.json +1 -1
- package/lib/cli/up.d.ts +0 -2
- package/lib/cli/up.js +0 -35
package/lib/cli/karin.js
CHANGED
|
@@ -6,6 +6,7 @@ import axios from 'axios'
|
|
|
6
6
|
import { fileURLToPath } from 'url'
|
|
7
7
|
import { program } from 'commander'
|
|
8
8
|
import { exec as execCmd, spawn } from 'child_process'
|
|
9
|
+
import { KarinInit } from '../utils/init.js'
|
|
9
10
|
class KarinCli {
|
|
10
11
|
child
|
|
11
12
|
filename
|
|
@@ -18,7 +19,7 @@ class KarinCli {
|
|
|
18
19
|
/** karin目录 */
|
|
19
20
|
this.karinDir = path.join(path.dirname(this.filename), '../..')
|
|
20
21
|
/** 入口文件(注意后缀) */
|
|
21
|
-
this.file = path.join(path.dirname(this.filename), '../index')
|
|
22
|
+
this.file = path.join(path.dirname(this.filename), '../index.js')
|
|
22
23
|
this.child = null
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -64,10 +65,10 @@ class KarinCli {
|
|
|
64
65
|
let cmd
|
|
65
66
|
switch (runner) {
|
|
66
67
|
case 'node' /* Runner.Node */:
|
|
67
|
-
cmd = [this.file
|
|
68
|
+
cmd = [this.file]
|
|
68
69
|
break
|
|
69
70
|
case 'tsx' /* Runner.Tsx */:
|
|
70
|
-
cmd = [this.file
|
|
71
|
+
cmd = [this.file]
|
|
71
72
|
break
|
|
72
73
|
case 'pm2' /* Runner.Pm2 */: {
|
|
73
74
|
this.pm2()
|
|
@@ -75,7 +76,7 @@ class KarinCli {
|
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
/** 启动 */
|
|
78
|
-
this.child = spawn(runner, cmd, { stdio: ['inherit', 'inherit', 'inherit', 'ipc'], cwd: process.cwd(), env: process.env })
|
|
79
|
+
this.child = spawn(runner, cmd, { stdio: ['inherit', 'inherit', 'inherit', 'ipc'], cwd: process.cwd(), env: process.env, shell: true })
|
|
79
80
|
/** 监听退出 */
|
|
80
81
|
this.child.once('exit', (code) => process.exit(code))
|
|
81
82
|
/** 监听子进程消息 */
|
|
@@ -166,6 +167,70 @@ class KarinCli {
|
|
|
166
167
|
spawn(cmd, ['logs', type, '--lines', lines], { stdio: 'inherit', shell: true, cwd: process.cwd() })
|
|
167
168
|
}
|
|
168
169
|
|
|
170
|
+
/**
|
|
171
|
+
* 更新依赖
|
|
172
|
+
*/
|
|
173
|
+
async update () {
|
|
174
|
+
/** 屏蔽的依赖包列表 */
|
|
175
|
+
const pkgdependencies = [
|
|
176
|
+
'@grpc/grpc-js',
|
|
177
|
+
'@grpc/proto-loader',
|
|
178
|
+
'art-template',
|
|
179
|
+
'axios',
|
|
180
|
+
'chalk',
|
|
181
|
+
'chokidar',
|
|
182
|
+
'express',
|
|
183
|
+
'kritor-proto',
|
|
184
|
+
'level',
|
|
185
|
+
'lodash',
|
|
186
|
+
'log4js',
|
|
187
|
+
'moment',
|
|
188
|
+
'node-schedule',
|
|
189
|
+
'redis',
|
|
190
|
+
'ws',
|
|
191
|
+
'yaml',
|
|
192
|
+
]
|
|
193
|
+
let cmd = ''
|
|
194
|
+
const list = Object.keys(this.pkg.dependencies).filter(key => !pkgdependencies.includes(key))
|
|
195
|
+
/** 获取包管理器 */
|
|
196
|
+
const pkg = new KarinInit().getRegistry()
|
|
197
|
+
switch (pkg) {
|
|
198
|
+
case 'pnpm': {
|
|
199
|
+
cmd = 'pnpm update'
|
|
200
|
+
break
|
|
201
|
+
}
|
|
202
|
+
case 'yarn': {
|
|
203
|
+
cmd = 'yarn upgrade'
|
|
204
|
+
break
|
|
205
|
+
}
|
|
206
|
+
case 'npm': {
|
|
207
|
+
cmd = 'npm update'
|
|
208
|
+
break
|
|
209
|
+
}
|
|
210
|
+
case 'cnpm': {
|
|
211
|
+
cmd = 'cnpm update'
|
|
212
|
+
break
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** 异步并发更新依赖 */
|
|
216
|
+
await Promise.all(list.map(async (item) => {
|
|
217
|
+
try {
|
|
218
|
+
const res = await this.exec(`${cmd} ${item}@latest`)
|
|
219
|
+
/** 已经是最新 */
|
|
220
|
+
if (res.includes('is up to date')) {
|
|
221
|
+
console.log(`[依赖更新] ${item} 已经是最新~`)
|
|
222
|
+
} else {
|
|
223
|
+
console.log(`[依赖更新] ${item} 更新完成~`)
|
|
224
|
+
}
|
|
225
|
+
} catch (error) {
|
|
226
|
+
console.error(`[依赖更新] ${item} 更新失败:`)
|
|
227
|
+
console.error(`error.stack: ${error.stack}`)
|
|
228
|
+
console.error(`error.message: ${error.message}`)
|
|
229
|
+
}
|
|
230
|
+
}))
|
|
231
|
+
console.log('所有依赖已更新完成~')
|
|
232
|
+
}
|
|
233
|
+
|
|
169
234
|
/**
|
|
170
235
|
* 封装exec
|
|
171
236
|
* @param cmd - 命令
|
|
@@ -205,4 +270,5 @@ program.command('rs').description('重启pm2服务').action(() => cli.restart())
|
|
|
205
270
|
program.command('dev').description('TypeScript开发模式').action(() => cli.start('dev' /* Mode.Dev */, 'ts' /* Lang.Ts */, 'tsx' /* Runner.Tsx */))
|
|
206
271
|
program.command('debug').description('JavaScript调试模式').action(() => cli.start('dev' /* Mode.Dev */, 'js' /* Lang.Js */, 'node' /* Runner.Node */))
|
|
207
272
|
program.command('log').description('查看日志').action(() => cli.log())
|
|
273
|
+
program.command('up').description('更新依赖').action(() => cli.update())
|
|
208
274
|
program.parse(process.argv)
|
package/lib/utils/init.js
CHANGED
|
@@ -65,7 +65,7 @@ export class KarinInit {
|
|
|
65
65
|
const pkgDir = path.join(karinDir, dir)
|
|
66
66
|
const projDir = path.join(process.cwd(), dir)
|
|
67
67
|
/** 清空projDir目录下的文件 保留目录 */
|
|
68
|
-
if (fs.existsSync(projDir)) { fs.
|
|
68
|
+
if (fs.existsSync(projDir)) { fs.rmSync(projDir, { recursive: true }) }
|
|
69
69
|
this.mkdir(projDir)
|
|
70
70
|
/** 读取pkgDir目录下的所有文件 复制到projDir下 */
|
|
71
71
|
const files = fs.readdirSync(pkgDir).filter(file => file.endsWith('.yaml'))
|
package/package.json
CHANGED
package/lib/cli/up.d.ts
DELETED
package/lib/cli/up.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { exec } from 'child_process'
|
|
3
|
-
import { KarinInit } from '../utils/init.js'
|
|
4
|
-
/** 获取包管理器 */
|
|
5
|
-
const pkg = new KarinInit().getRegistry()
|
|
6
|
-
let cmd = ''
|
|
7
|
-
/** 更新所有依赖到最新版本 */
|
|
8
|
-
switch (pkg) {
|
|
9
|
-
case 'pnpm': {
|
|
10
|
-
cmd = 'pnpm update --latest'
|
|
11
|
-
break
|
|
12
|
-
}
|
|
13
|
-
case 'yarn': {
|
|
14
|
-
cmd = 'yarn upgrade --latest'
|
|
15
|
-
break
|
|
16
|
-
}
|
|
17
|
-
case 'npm': {
|
|
18
|
-
cmd = 'npm update --latest'
|
|
19
|
-
break
|
|
20
|
-
}
|
|
21
|
-
case 'cnpm': {
|
|
22
|
-
cmd = 'cnpm update --latest'
|
|
23
|
-
break
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exec(cmd, (error, stdout, stderr) => {
|
|
27
|
-
if (error) {
|
|
28
|
-
console.error('[更新依赖] 发送错误:')
|
|
29
|
-
console.error(`error.stack: ${error.stack}`)
|
|
30
|
-
console.error(`error.message: ${error.message}`)
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
console.log(`[更新依赖] 更新完成: ${stdout}`)
|
|
34
|
-
console.log(`[更新依赖] 更新错误: ${stderr}`)
|
|
35
|
-
})
|