node-karin 0.6.15 → 0.6.17
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/init.js +29 -0
- package/lib/cli/log.d.ts +2 -0
- package/lib/cli/log.js +12 -0
- package/lib/cli/postinstall.d.ts +2 -0
- package/lib/cli/postinstall.js +25 -0
- package/lib/utils/init.d.ts +48 -0
- package/lib/utils/init.js +205 -0
- package/package.json +11 -10
- package/lib/tools/init.js +0 -65
- /package/lib/{tools → cli}/init.d.ts +0 -0
package/lib/cli/init.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { select } from '@inquirer/prompts'
|
|
3
|
+
import { KarinInit } from '../utils/init.js'
|
|
4
|
+
async function main () {
|
|
5
|
+
/** 捕获错误 打印日志 */
|
|
6
|
+
process.on('uncaughtException', err => console.error(err))
|
|
7
|
+
process.on('unhandledRejection', err => console.error(err))
|
|
8
|
+
const init = new KarinInit()
|
|
9
|
+
init.init()
|
|
10
|
+
const prompt = await select({
|
|
11
|
+
message: '请选择npm源 中国大陆服务器一定要更换!!!',
|
|
12
|
+
choices: [
|
|
13
|
+
{ name: '淘宝源(推荐)', value: 'https://registry.npmmirror.com' },
|
|
14
|
+
{ name: '官方源', value: 'https://registry.npmjs.org' },
|
|
15
|
+
],
|
|
16
|
+
})
|
|
17
|
+
/** 结果 */
|
|
18
|
+
await init.changeRegistry(prompt)
|
|
19
|
+
const pkg = await select({
|
|
20
|
+
message: '请选择包管理器 如果不知道怎么选 请选pnpm',
|
|
21
|
+
choices: [
|
|
22
|
+
{ name: 'pnpm', value: 'pnpm' },
|
|
23
|
+
{ name: 'yarn', value: 'yarn' },
|
|
24
|
+
],
|
|
25
|
+
})
|
|
26
|
+
/** 结果 */
|
|
27
|
+
await init.install(pkg)
|
|
28
|
+
}
|
|
29
|
+
main().then(() => process.exit(0)).catch(() => process.exit(0))
|
package/lib/cli/log.d.ts
ADDED
package/lib/cli/log.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import yaml from 'yaml'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import { spawn } from 'child_process'
|
|
6
|
+
const cwd = process.cwd()
|
|
7
|
+
const _path = path.resolve(cwd + '/config/config/pm2.yaml')
|
|
8
|
+
const data = yaml.parse(fs.readFileSync(_path, 'utf8'))
|
|
9
|
+
const name = data.apps[0].name
|
|
10
|
+
const lines = data.lines || 1000
|
|
11
|
+
const cmd = process.platform === 'win32' ? 'pm2.cmd' : 'pm2'
|
|
12
|
+
spawn(cmd, ['logs', '--lines', lines, name], { stdio: 'inherit', shell: true, cwd })
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import { KarinInit } from '../utils/init.js'
|
|
4
|
+
async function main () {
|
|
5
|
+
/** 捕获错误 打印日志 */
|
|
6
|
+
process.on('uncaughtException', err => console.error(err))
|
|
7
|
+
process.on('unhandledRejection', err => console.error(err))
|
|
8
|
+
/** 在src目录说明为开发环境 不执行任何初始化操作 */
|
|
9
|
+
if (fs.existsSync('./src')) { return }
|
|
10
|
+
const init = new KarinInit()
|
|
11
|
+
init.init()
|
|
12
|
+
/** 判断锁文件 优先度: pnpm > yarn > cnpm > npm */
|
|
13
|
+
let pkg
|
|
14
|
+
if (fs.existsSync('pnpm-lock.yaml')) {
|
|
15
|
+
pkg = 'pnpm'
|
|
16
|
+
} else if (fs.existsSync('yarn.lock')) {
|
|
17
|
+
pkg = 'yarn'
|
|
18
|
+
} else if (fs.existsSync('cnpm-lock.yaml')) {
|
|
19
|
+
pkg = 'cnpm'
|
|
20
|
+
} else {
|
|
21
|
+
pkg = 'npm'
|
|
22
|
+
}
|
|
23
|
+
await init.install(pkg)
|
|
24
|
+
}
|
|
25
|
+
main().then(() => process.exit(0)).catch(() => process.exit(0))
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export declare class KarinInit {
|
|
3
|
+
/**
|
|
4
|
+
* 基础目录
|
|
5
|
+
*/
|
|
6
|
+
baseDir: string[];
|
|
7
|
+
constructor();
|
|
8
|
+
init(): void;
|
|
9
|
+
/**
|
|
10
|
+
* 递归创建目录
|
|
11
|
+
* @param dirname - 路径
|
|
12
|
+
*/
|
|
13
|
+
mkdir(dirname: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 解析json
|
|
16
|
+
*/
|
|
17
|
+
readJson(file: string): any;
|
|
18
|
+
/**
|
|
19
|
+
* 获取插件列表
|
|
20
|
+
*/
|
|
21
|
+
getPlugins(): string[];
|
|
22
|
+
/**
|
|
23
|
+
* 从npm包内复制默认配置出来
|
|
24
|
+
*/
|
|
25
|
+
copyFile(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* 修改package.json以支持运行
|
|
28
|
+
*/
|
|
29
|
+
modifyPackage(): void;
|
|
30
|
+
/**
|
|
31
|
+
* 更换镜像源为淘宝源
|
|
32
|
+
*/
|
|
33
|
+
changeRegistry(host: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* 安装pnpm或者yarn
|
|
36
|
+
* @param type - 包管理器名称
|
|
37
|
+
*/
|
|
38
|
+
install(type: 'pnpm' | 'yarn' | 'cnpm' | 'npm'): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* 执行命令
|
|
41
|
+
* @param cmd - 命令
|
|
42
|
+
*/
|
|
43
|
+
shell(cmd: string): Promise<unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* 获取当前的包管理器
|
|
46
|
+
*/
|
|
47
|
+
getRegistry(): 'pnpm' | 'cnpm' | 'yarn' | 'npm';
|
|
48
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import { exec } from 'child_process'
|
|
5
|
+
import { karinDir } from '../core/dir.js'
|
|
6
|
+
export class KarinInit {
|
|
7
|
+
/**
|
|
8
|
+
* 基础目录
|
|
9
|
+
*/
|
|
10
|
+
baseDir
|
|
11
|
+
constructor () {
|
|
12
|
+
this.baseDir = [
|
|
13
|
+
'./lib',
|
|
14
|
+
'./config/config',
|
|
15
|
+
'./config/defSet',
|
|
16
|
+
'./config/view',
|
|
17
|
+
'./config/plugin',
|
|
18
|
+
'./temp/input',
|
|
19
|
+
'./temp/html',
|
|
20
|
+
'./plugins/karin-plugin-example',
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
init () {
|
|
25
|
+
this.baseDir.forEach(dir => this.mkdir(dir))
|
|
26
|
+
/** 非src源代码环境才创建 */
|
|
27
|
+
if (!fs.existsSync('./src')) {
|
|
28
|
+
this.copyFile()
|
|
29
|
+
this.modifyPackage()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 递归创建目录
|
|
35
|
+
* @param dirname - 路径
|
|
36
|
+
*/
|
|
37
|
+
mkdir (dirname) {
|
|
38
|
+
if (fs.existsSync(dirname)) { return true }
|
|
39
|
+
if (this.mkdir(path.dirname(dirname))) { fs.mkdirSync(dirname) }
|
|
40
|
+
return true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 解析json
|
|
45
|
+
*/
|
|
46
|
+
readJson (file) {
|
|
47
|
+
return JSON.parse(fs.readFileSync(file, 'utf-8'))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 获取插件列表
|
|
52
|
+
*/
|
|
53
|
+
getPlugins () {
|
|
54
|
+
const pluginsDir = './plugins'
|
|
55
|
+
const plugins = fs.readdirSync(pluginsDir)
|
|
56
|
+
return plugins.filter(dir => dir.startsWith('karin-plugin-'))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 从npm包内复制默认配置出来
|
|
61
|
+
*/
|
|
62
|
+
async copyFile () {
|
|
63
|
+
/** 配置 */
|
|
64
|
+
const list = ['config/defSet', 'config/view']
|
|
65
|
+
list.forEach(dir => {
|
|
66
|
+
const pkgDir = path.join(karinDir, dir)
|
|
67
|
+
const projDir = path.join(process.cwd(), dir)
|
|
68
|
+
/** 清空projDir目录下的文件 保留目录 */
|
|
69
|
+
if (fs.existsSync(projDir)) { fs.rmdirSync(projDir, { recursive: true }) }
|
|
70
|
+
/** 读取pkgDir目录下的所有文件 复制到projDir下 */
|
|
71
|
+
const files = fs.readdirSync(pkgDir).filter(file => file.endsWith('.yaml'))
|
|
72
|
+
files.forEach(file => {
|
|
73
|
+
const destPath = path.join(projDir, file)
|
|
74
|
+
const srcPath = path.join(pkgDir, file)
|
|
75
|
+
fs.copyFileSync(srcPath, destPath)
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
/** 创建pnpm工作区配置 */
|
|
79
|
+
fs.copyFileSync(path.join(karinDir, 'pnpm-workspace.yaml'), './pnpm-workspace.yaml')
|
|
80
|
+
/** 为每个插件包创建统一存储的文件夹 */
|
|
81
|
+
const plugins = this.getPlugins()
|
|
82
|
+
const DataList = [
|
|
83
|
+
'data',
|
|
84
|
+
'temp',
|
|
85
|
+
'resources',
|
|
86
|
+
'temp/html',
|
|
87
|
+
'config/plugin',
|
|
88
|
+
]
|
|
89
|
+
DataList.forEach(_path => {
|
|
90
|
+
_path = path.join(process.cwd(), _path)
|
|
91
|
+
plugins.forEach(plugin => this.mkdir(path.join(_path, plugin)))
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 修改package.json以支持运行
|
|
97
|
+
*/
|
|
98
|
+
modifyPackage () {
|
|
99
|
+
const pkg = this.readJson(path.join(karinDir, 'package.json'))
|
|
100
|
+
const projPkg = this.readJson('./package.json')
|
|
101
|
+
delete pkg.bin
|
|
102
|
+
pkg.main = './node_modules/node-karin/lib/index.js'
|
|
103
|
+
pkg.dependencies['node-karin'] = 'latest'
|
|
104
|
+
pkg.dependencies['kritor-proto'] = 'latest'
|
|
105
|
+
pkg.dependencies = { ...projPkg.dependencies, ...pkg.dependencies }
|
|
106
|
+
pkg.devDependencies = { ...projPkg.devDependencies, ...pkg.devDependencies }
|
|
107
|
+
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 更换镜像源为淘宝源
|
|
112
|
+
*/
|
|
113
|
+
async changeRegistry (host) {
|
|
114
|
+
const cmd = `npm config set registry ${host}`
|
|
115
|
+
// 检查当前镜像源是否为淘宝源
|
|
116
|
+
const registry = await this.shell('npm config get registry')
|
|
117
|
+
if (registry === host) {
|
|
118
|
+
console.log(`当前npm源已经是 ${host} ~`)
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
if (!await this.shell(cmd)) {
|
|
122
|
+
console.log('更换npm源失败,请手动更换npm源!')
|
|
123
|
+
console.log(`可尝试手动执行 【 npm config set registry ${host} 】 更换镜像源~`)
|
|
124
|
+
} else {
|
|
125
|
+
console.log('更换npm源成功~')
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 安装pnpm或者yarn
|
|
131
|
+
* @param type - 包管理器名称
|
|
132
|
+
*/
|
|
133
|
+
async install (type) {
|
|
134
|
+
/** 检查是否已经安装对应的包管理器 */
|
|
135
|
+
if (!this.shell(`${type} -v`)) {
|
|
136
|
+
console.log(`检测到未安装${type},开始安装...`)
|
|
137
|
+
if (!await this.shell(`npm install -g ${type}`)) {
|
|
138
|
+
console.log(`${type}安装失败,请手动安装${type}!`)
|
|
139
|
+
console.log(`可尝试手动执行 【 npm install -g ${type} 】 安装${type}~`)
|
|
140
|
+
return
|
|
141
|
+
} else {
|
|
142
|
+
console.log(`${type}安装完成~`)
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
console.log('检测到已安装pnpm,开始安装依赖...')
|
|
146
|
+
}
|
|
147
|
+
/** 安装依赖 */
|
|
148
|
+
if (!this.shell(`${type} install -P`)) {
|
|
149
|
+
console.log('安装依赖失败,请手动安装依赖!')
|
|
150
|
+
console.log(`可尝试手动执行 【 ${type} install -P 】 安装依赖~`)
|
|
151
|
+
console.log('如中国大陆用户安装失败,请尝试执行换源 【 npm config set registry https://registry.npmmirror.com 】后再安装依赖~')
|
|
152
|
+
} else {
|
|
153
|
+
console.log('依赖安装完成~')
|
|
154
|
+
}
|
|
155
|
+
/** 检查安装pm2 */
|
|
156
|
+
if (!this.shell('pm2 -v')) {
|
|
157
|
+
console.log('检测到未安装pm2,开始安装pm2...')
|
|
158
|
+
if (!this.shell(`${type} install -g pm2`)) {
|
|
159
|
+
console.log('安装pm2失败,请手动安装pm2!')
|
|
160
|
+
console.log('可尝试手动执行 【 npm install -g pm2 】 安装pm2~')
|
|
161
|
+
} else {
|
|
162
|
+
console.log('pm2安装完成~')
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
console.log('检测到已安装pm2~')
|
|
166
|
+
}
|
|
167
|
+
console.log('依赖环境初始化完成~')
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 执行命令
|
|
172
|
+
* @param cmd - 命令
|
|
173
|
+
*/
|
|
174
|
+
shell (cmd) {
|
|
175
|
+
return new Promise(resolve => {
|
|
176
|
+
exec(cmd, { env: process.env, cwd: process.cwd() }, (err, stdout, stderr) => {
|
|
177
|
+
if (stdout) { return resolve(stdout.trim()) }
|
|
178
|
+
if (err) {
|
|
179
|
+
console.error(err)
|
|
180
|
+
return resolve(false)
|
|
181
|
+
}
|
|
182
|
+
if (stderr) {
|
|
183
|
+
console.error(stderr)
|
|
184
|
+
return resolve(false)
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
})
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 获取当前的包管理器
|
|
192
|
+
*/
|
|
193
|
+
getRegistry () {
|
|
194
|
+
const { npm_config_user_agent: agent, npm_config_userconfig: userconfig } = process.env
|
|
195
|
+
if (agent && agent.includes('pnpm')) {
|
|
196
|
+
return 'pnpm'
|
|
197
|
+
} else if (userconfig && userconfig.includes('cnpm')) {
|
|
198
|
+
return 'cnpm'
|
|
199
|
+
} else if (agent && agent.includes('yarn')) {
|
|
200
|
+
return 'yarn'
|
|
201
|
+
} else {
|
|
202
|
+
return 'npm'
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-karin",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.17",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "基于 Kritor 进行开发的nodejs机器人框架",
|
|
6
6
|
"homepage": "https://github.com/KarinJS/Karin",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"main": "./lib/index.js",
|
|
18
18
|
"types": "./lib/index.d.ts",
|
|
19
19
|
"bin": {
|
|
20
|
-
"init": "./lib/
|
|
20
|
+
"init": "./lib/cli/init.js",
|
|
21
|
+
"log": "./lib/cli/log.js"
|
|
21
22
|
},
|
|
22
23
|
"files": [
|
|
23
24
|
"/lib/**/*.js",
|
|
@@ -38,32 +39,32 @@
|
|
|
38
39
|
"app": "node .",
|
|
39
40
|
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json && npm run cp && npm run fix",
|
|
40
41
|
"cp": "cp ./lib/modules.d.ts ./modules.d.ts && cp ./lib/modules.js ./modules.js",
|
|
42
|
+
"debug": "node . --dev",
|
|
41
43
|
"delete": "pm2 delete ./config/config/pm2.yaml",
|
|
42
44
|
"dev": "tsx ./lib/index.js --dev",
|
|
43
|
-
"debug": "tsx watch ./lib/index.js --dev",
|
|
44
45
|
"fix": "eslint lib/**/*.js --fix",
|
|
45
46
|
"fix:all": "eslint lib/**/*.js --fix && eslint lib/**/*.ts --fix",
|
|
46
|
-
"
|
|
47
|
-
"init
|
|
48
|
-
"
|
|
49
|
-
"log": "node lib/
|
|
47
|
+
"hook": "node lib/cli/hook.js",
|
|
48
|
+
"init": "node lib/cli/install.js",
|
|
49
|
+
"postinstall": "node lib/cli/postinstall.js",
|
|
50
|
+
"log": "node lib/cli/log.js",
|
|
50
51
|
"monit": "pm2 monit",
|
|
51
52
|
"pub": "npm publish --access public",
|
|
52
53
|
"restart": "pm2 restart ./config/config/pm2.yaml",
|
|
53
54
|
"sort:pack": "npx sort-package-json",
|
|
54
55
|
"start": "pm2 start ./config/config/pm2.yaml && pm2 monit",
|
|
55
|
-
"stop": "pm2 delete ./config/config/pm2.yaml"
|
|
56
|
-
"uninstall": "node lib/tools/uninstall.js"
|
|
56
|
+
"stop": "pm2 delete ./config/config/pm2.yaml"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@grpc/grpc-js": "1.10.10",
|
|
60
60
|
"@grpc/proto-loader": "0.7.13",
|
|
61
|
+
"@inquirer/prompts": "5.1.2",
|
|
61
62
|
"art-template": "4.13.2",
|
|
62
63
|
"axios": "1.7.2",
|
|
63
64
|
"chalk": "5.3.0",
|
|
64
65
|
"chokidar": "3.6.0",
|
|
65
66
|
"express": "4.19.2",
|
|
66
|
-
"kritor-proto": "
|
|
67
|
+
"kritor-proto": "latest",
|
|
67
68
|
"level": "8.0.1",
|
|
68
69
|
"lodash": "4.17.21",
|
|
69
70
|
"log4js": "6.9.1",
|
package/lib/tools/init.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from 'fs'
|
|
3
|
-
import path from 'path'
|
|
4
|
-
import { karinDir } from '../core/dir.js'
|
|
5
|
-
import { execSync } from 'child_process'
|
|
6
|
-
const pathList = ['./plugins', './config/config', './lib']
|
|
7
|
-
// 创建目录
|
|
8
|
-
pathList.forEach(dir => mkdir(dir))
|
|
9
|
-
function mkdir (dirname) {
|
|
10
|
-
if (fs.existsSync(dirname)) { return true }
|
|
11
|
-
if (mkdir(path.dirname(dirname))) { fs.mkdirSync(dirname) }
|
|
12
|
-
return true
|
|
13
|
-
}
|
|
14
|
-
// 创建 lib 目录并导出 node-karin 模块
|
|
15
|
-
fs.writeFileSync('./lib/index.js', `export * from 'node-karin'`)
|
|
16
|
-
// 删除指定目录并重新创建
|
|
17
|
-
const delList = ['./config/defSet', './config/view']
|
|
18
|
-
delList.forEach(dir => {
|
|
19
|
-
if (fs.existsSync(dir)) { fs.rmdirSync(dir, { recursive: true }) }
|
|
20
|
-
mkdir(dir)
|
|
21
|
-
const root = path.join(karinDir, dir.replace('.', ''))
|
|
22
|
-
const files = fs.readdirSync(root).filter(file => file.endsWith('.yaml'))
|
|
23
|
-
files.forEach(file => {
|
|
24
|
-
const destPath = path.join(dir, file)
|
|
25
|
-
const srcPath = path.join(root, file)
|
|
26
|
-
if (!fs.existsSync(destPath)) { fs.copyFileSync(srcPath, destPath) }
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
// 修改 package.json 为 ESM 模块
|
|
30
|
-
const pack = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
|
|
31
|
-
const npmPack = JSON.parse(fs.readFileSync(path.join(karinDir, 'package.json'), 'utf-8'))
|
|
32
|
-
npmPack.main = './node_modules/node-karin/lib/index.js'
|
|
33
|
-
delete npmPack.bin
|
|
34
|
-
delete npmPack.types
|
|
35
|
-
npmPack.dependencies['node-karin'] = pack.dependencies['node-karin']
|
|
36
|
-
fs.writeFileSync('./package.json', JSON.stringify(npmPack, null, 2))
|
|
37
|
-
// 复制 pnpm-workspace.yaml 到根目录
|
|
38
|
-
fs.copyFileSync(path.join(karinDir, 'pnpm-workspace.yaml'), './pnpm-workspace.yaml')
|
|
39
|
-
// 检查是否安装 pnpm 并安装依赖
|
|
40
|
-
console.log('检查是否安装 pnpm...')
|
|
41
|
-
try {
|
|
42
|
-
const isPnpm = execSync('pnpm -v', { env: process.env }).toString().trim()
|
|
43
|
-
if (isPnpm) {
|
|
44
|
-
console.log('检查到 pnpm,开始安装依赖...')
|
|
45
|
-
} else {
|
|
46
|
-
installPnpm()
|
|
47
|
-
}
|
|
48
|
-
} catch {
|
|
49
|
-
installPnpm()
|
|
50
|
-
}
|
|
51
|
-
// 安装依赖
|
|
52
|
-
try {
|
|
53
|
-
execSync('pnpm install -P', { env: process.env, stdio: 'inherit' })
|
|
54
|
-
console.log('依赖安装完成~')
|
|
55
|
-
} catch {
|
|
56
|
-
console.log('安装依赖失败,请手动安装依赖!')
|
|
57
|
-
console.log('可尝试手动执行 【 pnpm install -P 】 安装依赖~')
|
|
58
|
-
console.log('如中国大陆用户安装失败,请尝试执行换源 【 npm config set registry https://registry.npmmirror.com 】后再安装依赖~')
|
|
59
|
-
}
|
|
60
|
-
console.log('初始化完成~,请通过 【 node . 】 启动程序~')
|
|
61
|
-
function installPnpm () {
|
|
62
|
-
console.log('未检查到 pnpm,开始安装 pnpm...')
|
|
63
|
-
execSync('npm --registry=https://registry.npmmirror.com install pnpm -g', { env: process.env, stdio: 'inherit' })
|
|
64
|
-
console.log('pnpm 安装完成,开始安装依赖...')
|
|
65
|
-
}
|
|
File without changes
|