node-karin 0.1.0 → 0.1.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/core/dir.d.ts +1 -0
- package/lib/core/dir.js +4 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/tools/init.d.ts +2 -0
- package/lib/tools/init.js +31 -0
- package/lib/utils/config.js +8 -3
- package/package.json +4 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const karinDir: string;
|
package/lib/core/dir.js
ADDED
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import { karinDir } from '../core/dir.js'
|
|
5
|
+
const pathList = ['./plugins', './config/config']
|
|
6
|
+
for (const dir of pathList) { mkdir(dir) }
|
|
7
|
+
function mkdir (dirname) {
|
|
8
|
+
if (fs.existsSync(dirname)) { return true }
|
|
9
|
+
/** 递归自调用 */
|
|
10
|
+
if (mkdir(path.dirname(dirname))) { fs.mkdirSync(dirname) }
|
|
11
|
+
return true
|
|
12
|
+
}
|
|
13
|
+
// 删除这两个文件夹
|
|
14
|
+
const delList = ['./config/defSet', './config/view']
|
|
15
|
+
for (const dir of delList) {
|
|
16
|
+
if (fs.existsSync(dir)) { fs.rmdirSync(dir, { recursive: true }) }
|
|
17
|
+
// 复制整个文件夹过去
|
|
18
|
+
fs.copyFileSync(`${karinDir}${dir.replace('.', '')}`, dir)
|
|
19
|
+
}
|
|
20
|
+
// 判断是否为第一次使用
|
|
21
|
+
if (!fs.existsSync('./index.js') && !fs.existsSync('./plugins')) {
|
|
22
|
+
// 创建一个index.js文件 以供初次开箱使用,写入默认配置
|
|
23
|
+
fs.writeFileSync('./index.js', `import { Bot } from 'node-karin'
|
|
24
|
+
console.log(Bot.name + '开始初始化~')
|
|
25
|
+
`)
|
|
26
|
+
}
|
|
27
|
+
// 修改package.json为esm模块
|
|
28
|
+
const pack = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
|
|
29
|
+
pack.type = 'module'
|
|
30
|
+
fs.writeFileSync('./package.json', JSON.stringify(pack, null, 2))
|
|
31
|
+
console.log('初始化完成~,请通过 node index 启动程序~')
|
package/lib/utils/config.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import Yaml from 'yaml'
|
|
3
3
|
import chokidar from 'chokidar'
|
|
4
|
+
import { karinDir } from '../core/dir.js'
|
|
4
5
|
/** 配置文件 */
|
|
5
6
|
export default new (class Cfg {
|
|
6
7
|
dir
|
|
@@ -11,8 +12,8 @@ export default new (class Cfg {
|
|
|
11
12
|
review
|
|
12
13
|
loggger
|
|
13
14
|
constructor () {
|
|
14
|
-
this.dir =
|
|
15
|
-
this._path =
|
|
15
|
+
this.dir = karinDir
|
|
16
|
+
this._path = process.cwd() + '/config'
|
|
16
17
|
this._pathDef = this.dir + '/config/defSet'
|
|
17
18
|
/** 缓存 */
|
|
18
19
|
this.change = new Map()
|
|
@@ -25,6 +26,8 @@ export default new (class Cfg {
|
|
|
25
26
|
|
|
26
27
|
/** 初始化配置 */
|
|
27
28
|
async initCfg () {
|
|
29
|
+
if (!fs.existsSync(this._path)) { fs.mkdirSync(this._path) }
|
|
30
|
+
this._path = process.cwd() + '/config/config'
|
|
28
31
|
if (!fs.existsSync(this._path)) { fs.mkdirSync(this._path) }
|
|
29
32
|
const files = fs.readdirSync(this._pathDef).filter(file => file.endsWith('.yaml'))
|
|
30
33
|
for (const file of files) {
|
|
@@ -33,6 +36,8 @@ export default new (class Cfg {
|
|
|
33
36
|
if (!fs.existsSync(path)) { fs.copyFileSync(pathDef, path) }
|
|
34
37
|
}
|
|
35
38
|
// 创建插件文件夹文件夹
|
|
39
|
+
if (!fs.existsSync('./plugins')) { fs.mkdirSync('./plugins') }
|
|
40
|
+
if (!fs.existsSync('./plugins/karin-plugin-example')) { fs.mkdirSync('./plugins/karin-plugin-example') }
|
|
36
41
|
const plugins = this.getPlugins()
|
|
37
42
|
this.dirPath('data', plugins)
|
|
38
43
|
this.dirPath('temp', plugins)
|
|
@@ -44,7 +49,7 @@ export default new (class Cfg {
|
|
|
44
49
|
getPlugins () {
|
|
45
50
|
const files = fs.readdirSync('./plugins', { withFileTypes: true })
|
|
46
51
|
// 过滤掉非karin-plugin-开头或karin-adapter-开头的文件夹
|
|
47
|
-
return files.filter(file => file.isDirectory() && (file.name.startsWith('karin-plugin-')
|
|
52
|
+
return files.filter(file => file.isDirectory() && (file.name.startsWith('karin-plugin-'))).map(dir => dir.name)
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-karin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"homepage": "https://github.com/KarinJS/Karin#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
"#Karin": "./lib/index.js"
|
|
18
18
|
},
|
|
19
19
|
"main": "./lib/index.js",
|
|
20
|
+
"bin": {
|
|
21
|
+
"init": "./lib/tools/init.js"
|
|
22
|
+
},
|
|
20
23
|
"files": [
|
|
21
24
|
"/lib/**/*.js",
|
|
22
25
|
"/lib/**/*.d.ts",
|