node-karin 0.6.1 → 0.6.2

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 CHANGED
@@ -1 +1,4 @@
1
+ /**
2
+ * - 获取当前npm包的根目录
3
+ */
1
4
  export declare const karinDir: string;
package/lib/core/dir.js CHANGED
@@ -1,4 +1,7 @@
1
1
  import path from 'path'
2
2
  import { fileURLToPath } from 'url'
3
3
  const filename = fileURLToPath(import.meta.url)
4
+ /**
5
+ * - 获取当前npm包的根目录
6
+ */
4
7
  export const karinDir = path.resolve(filename, '../../../').replace(/\\/g, '/').replace(/\/$/, '')
package/lib/index.d.ts CHANGED
@@ -37,7 +37,7 @@ export declare const Cfg: {
37
37
  logger: import("log4js").Logger;
38
38
  initCfg(): Promise<void>;
39
39
  getPlugins(): string[];
40
- checkPath(path: string): void;
40
+ mkdir(dirname: string): boolean;
41
41
  dirPath(name: string, plugins: string[]): Promise<void>;
42
42
  timeout(type?: "ws" | "grpc"): number;
43
43
  readonly redis: import("./types/index.js").Redis;
package/lib/tools/init.js CHANGED
@@ -23,15 +23,13 @@ for (const dir of delList) {
23
23
  if (!fs.existsSync(path)) { fs.copyFileSync(pathDef, path) }
24
24
  }
25
25
  }
26
- // 判断是否为第一次使用
27
- if (!fs.existsSync('./index.js')) {
28
- // 创建一个index.js文件 以供初次开箱使用,写入默认配置
29
- fs.writeFileSync('./index.js', `import { Bot } from 'node-karin'
30
- console.log(Bot.name + '开始初始化~')
31
- `)
32
- }
33
26
  // 修改package.json为esm模块
34
27
  const pack = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
35
- pack.type = 'module'
36
- fs.writeFileSync('./package.json', JSON.stringify(pack, null, 2))
37
- console.log('初始化完成~,请通过 node index 启动程序~')
28
+ // 解析包内的package.json文件
29
+ const npmPack = JSON.parse(fs.readFileSync(`${karinDir}/package.json`, 'utf-8'))
30
+ npmPack.main = './node_modules/node-karin/lib/index.js'
31
+ delete npmPack.bin
32
+ delete npmPack.types
33
+ npmPack.dependencies = pack.dependencies
34
+ fs.writeFileSync('./package.json', JSON.stringify(npmPack, null, 2))
35
+ console.log('初始化完成~,请通过 【 node . 】 启动程序~')
@@ -15,9 +15,10 @@ export declare const config: {
15
15
  initCfg(): Promise<void>;
16
16
  getPlugins(): string[];
17
17
  /**
18
- * 检查路径是否存在 不存在则创建
18
+ * 递归创建目录
19
+ * @param dirname - 要创建的文件夹路径
19
20
  */
20
- checkPath(path: string): void;
21
+ mkdir(dirname: string): boolean;
21
22
  /**
22
23
  * 为每一个插件建立对应的文件夹
23
24
  */
@@ -1,3 +1,4 @@
1
+ import path from 'path'
1
2
  import { karinDir } from '../core/dir.js'
2
3
  import { fs, yaml as Yaml, chokidar } from '../modules.js'
3
4
  /**
@@ -33,7 +34,7 @@ export const config = new (class Cfg {
33
34
  './plugins',
34
35
  './plugins/karin-plugin-example',
35
36
  ]
36
- list.forEach(path => this.checkPath(path))
37
+ list.forEach(path => this.mkdir(path))
37
38
  if (this.npmCfgDir !== (this._path + '/defSet').replace(/\\/g, '/')) {
38
39
  const files = fs.readdirSync(this.npmCfgDir).filter(file => file.endsWith('.yaml'))
39
40
  files.forEach(file => {
@@ -58,10 +59,14 @@ export const config = new (class Cfg {
58
59
  }
59
60
 
60
61
  /**
61
- * 检查路径是否存在 不存在则创建
62
+ * 递归创建目录
63
+ * @param dirname - 要创建的文件夹路径
62
64
  */
63
- checkPath (path) {
64
- if (!fs.existsSync(path)) { fs.mkdirSync(path) }
65
+ mkdir (dirname) {
66
+ if (fs.existsSync(dirname)) { return true }
67
+ /** 递归自调用 */
68
+ if (this.mkdir(path.dirname(dirname))) { fs.mkdirSync(dirname) }
69
+ return true
65
70
  }
66
71
 
67
72
  /**
@@ -69,10 +74,10 @@ export const config = new (class Cfg {
69
74
  */
70
75
  async dirPath (name, plugins) {
71
76
  name = `./${name}`
72
- this.checkPath(name)
77
+ this.mkdir(name)
73
78
  for (const plugin of plugins) {
74
79
  const path = `${name}/${plugin}`
75
- this.checkPath(path)
80
+ this.mkdir(path)
76
81
  }
77
82
  }
78
83
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "private": false,
5
5
  "description": "基于 Kritor 进行开发的nodejs机器人框架",
6
6
  "homepage": "https://github.com/KarinJS/Karin",
@@ -14,9 +14,6 @@
14
14
  "license": "GPL-3.0-only",
15
15
  "author": "Karin",
16
16
  "type": "module",
17
- "imports": {
18
- "#Karin": "./lib/index.js"
19
- },
20
17
  "main": "./lib/index.js",
21
18
  "types": "./lib/index.d.ts",
22
19
  "bin": {