node-karin 0.1.0 → 0.1.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.
@@ -0,0 +1 @@
1
+ export declare const karinDir: string;
@@ -0,0 +1,4 @@
1
+ import path from 'path'
2
+ import { fileURLToPath } from 'url'
3
+ const filename = fileURLToPath(import.meta.url)
4
+ export const karinDir = path.resolve(filename, '../../../').replace(/\\/g, '/').replace(/\/$/, '')
@@ -203,7 +203,6 @@ export default new (class PluginLoader {
203
203
  })
204
204
  this.rule = lodash.orderBy(list, ['val'], ['asc']).map((v) => Number(v.key))
205
205
  logger.debug('rule排序完成...')
206
- logger.info(this.rule)
207
206
  }
208
207
 
209
208
  /**
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import './core/dir.js';
1
2
  import './core/init.js';
2
3
  import config from './utils/config.js';
3
4
  import logger from './utils/logger.js';
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // 基本模块
2
+ import './core/dir.js';
2
3
  import './core/init.js';
3
4
  import config from './utils/config.js';
4
5
  import logger from './utils/logger.js';
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,37 @@
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
+ mkdir(dir)
18
+ const root = `${karinDir}${dir.replace('.', '')}`
19
+ const files = fs.readdirSync(root).filter(file => file.endsWith('.yaml'))
20
+ for (const file of files) {
21
+ const path = `${dir}/${file}`
22
+ const pathDef = `${root}/${file}`
23
+ if (!fs.existsSync(path)) { fs.copyFileSync(pathDef, path) }
24
+ }
25
+ }
26
+ // 判断是否为第一次使用
27
+ if (!fs.existsSync('./index.js') && !fs.existsSync('./plugins')) {
28
+ // 创建一个index.js文件 以供初次开箱使用,写入默认配置
29
+ fs.writeFileSync('./index.js', `import { Bot } from 'node-karin'
30
+ console.log(Bot.name + '开始初始化~')
31
+ `)
32
+ }
33
+ // 修改package.json为esm模块
34
+ 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 启动程序~')
@@ -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 = process.cwd()
15
- this._path = this.dir + '/config/config'
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-') || file.name.startsWith('karin-adapter-'))).map(dir => dir.name)
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.0",
3
+ "version": "0.1.2",
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",