node-karin 0.6.4 → 0.6.5
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/tools/init.js +45 -15
- package/package.json +3 -2
- package/pnpm-workspace.yaml +2 -0
package/lib/tools/init.js
CHANGED
|
@@ -2,34 +2,64 @@
|
|
|
2
2
|
import fs from 'fs'
|
|
3
3
|
import path from 'path'
|
|
4
4
|
import { karinDir } from '../core/dir.js'
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { execSync } from 'child_process'
|
|
6
|
+
const pathList = ['./plugins', './config/config', './lib']
|
|
7
|
+
// 创建目录
|
|
8
|
+
pathList.forEach(dir => mkdir(dir))
|
|
7
9
|
function mkdir (dirname) {
|
|
8
10
|
if (fs.existsSync(dirname)) { return true }
|
|
9
|
-
/** 递归自调用 */
|
|
10
11
|
if (mkdir(path.dirname(dirname))) { fs.mkdirSync(dirname) }
|
|
11
12
|
return true
|
|
12
13
|
}
|
|
13
|
-
//
|
|
14
|
+
// 创建 lib 目录并导出 node-karin 模块
|
|
15
|
+
fs.writeFileSync('./lib/index.js', `export * from 'node-karin'`)
|
|
16
|
+
// 删除指定目录并重新创建
|
|
14
17
|
const delList = ['./config/defSet', './config/view']
|
|
15
|
-
|
|
18
|
+
delList.forEach(dir => {
|
|
16
19
|
if (fs.existsSync(dir)) { fs.rmdirSync(dir, { recursive: true }) }
|
|
17
20
|
mkdir(dir)
|
|
18
|
-
const root =
|
|
21
|
+
const root = path.join(karinDir, dir.replace('.', ''))
|
|
19
22
|
const files = fs.readdirSync(root).filter(file => file.endsWith('.yaml'))
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
if (!fs.existsSync(
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
// 修改package.json为
|
|
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 模块
|
|
27
30
|
const pack = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
|
|
28
|
-
|
|
29
|
-
const npmPack = JSON.parse(fs.readFileSync(`${karinDir}/package.json`, 'utf-8'))
|
|
31
|
+
const npmPack = JSON.parse(fs.readFileSync(path.join(karinDir, 'package.json'), 'utf-8'))
|
|
30
32
|
npmPack.main = './node_modules/node-karin/lib/index.js'
|
|
31
33
|
delete npmPack.bin
|
|
32
34
|
delete npmPack.types
|
|
33
35
|
npmPack.dependencies = pack.dependencies
|
|
34
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
|
+
}
|
|
35
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-karin",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "基于 Kritor 进行开发的nodejs机器人框架",
|
|
6
6
|
"homepage": "https://github.com/KarinJS/Karin",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"modules.d.ts",
|
|
29
29
|
"LICENSE",
|
|
30
30
|
"package.json",
|
|
31
|
-
"README.md"
|
|
31
|
+
"README.md",
|
|
32
|
+
"pnpm-workspace.yaml"
|
|
32
33
|
],
|
|
33
34
|
"workspaces": [
|
|
34
35
|
"plugins/**"
|