node-karin 0.0.3
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/LICENSE +674 -0
- package/README.md +57 -0
- package/config/defSet/App.yaml +37 -0
- package/config/defSet/config.yaml +43 -0
- package/config/defSet/group.yaml +18 -0
- package/config/defSet/pm2.yaml +21 -0
- package/config/defSet/redis.yaml +18 -0
- package/config/defSet/server.yaml +42 -0
- package/config/view/App.yaml +74 -0
- package/config/view/config.yaml +100 -0
- package/config/view/group.yaml +62 -0
- package/config/view/pm2.yaml +41 -0
- package/config/view/redis.yaml +25 -0
- package/config/view/server.yaml +93 -0
- package/lib/adapter/onebot/onebot11.d.ts +430 -0
- package/lib/adapter/onebot/onebot11.js +1302 -0
- package/lib/core/init.d.ts +0 -0
- package/lib/core/init.js +4 -0
- package/lib/core/karin.d.ts +72 -0
- package/lib/core/karin.js +51 -0
- package/lib/core/listener.d.ts +121 -0
- package/lib/core/listener.js +188 -0
- package/lib/core/plugin.app.d.ts +15 -0
- package/lib/core/plugin.app.js +18 -0
- package/lib/core/plugin.d.ts +182 -0
- package/lib/core/plugin.js +138 -0
- package/lib/core/plugin.loader.d.ts +149 -0
- package/lib/core/plugin.loader.js +462 -0
- package/lib/core/server.d.ts +26 -0
- package/lib/core/server.js +213 -0
- package/lib/db/level.d.ts +20 -0
- package/lib/db/level.js +38 -0
- package/lib/db/redis.d.ts +41 -0
- package/lib/db/redis.js +137 -0
- package/lib/db/redis_level.d.ts +113 -0
- package/lib/db/redis_level.js +290 -0
- package/lib/event/event.d.ts +138 -0
- package/lib/event/event.handler.d.ts +29 -0
- package/lib/event/event.handler.js +142 -0
- package/lib/event/event.js +120 -0
- package/lib/event/message.d.ts +102 -0
- package/lib/event/message.handler.d.ts +25 -0
- package/lib/event/message.handler.js +240 -0
- package/lib/event/message.js +70 -0
- package/lib/event/notice.d.ts +49 -0
- package/lib/event/notice.js +15 -0
- package/lib/event/request.d.ts +49 -0
- package/lib/event/request.js +15 -0
- package/lib/event/review.handler.d.ts +54 -0
- package/lib/event/review.handler.js +382 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.js +40 -0
- package/lib/renderer/app.d.ts +53 -0
- package/lib/renderer/app.js +93 -0
- package/lib/renderer/base.d.ts +30 -0
- package/lib/renderer/base.js +71 -0
- package/lib/renderer/client.d.ts +30 -0
- package/lib/renderer/client.js +159 -0
- package/lib/renderer/http.d.ts +19 -0
- package/lib/renderer/http.js +51 -0
- package/lib/renderer/server.d.ts +42 -0
- package/lib/renderer/server.js +112 -0
- package/lib/renderer/wormhole.d.ts +1 -0
- package/lib/renderer/wormhole.js +154 -0
- package/lib/types/adapter.d.ts +575 -0
- package/lib/types/adapter.js +1 -0
- package/lib/types/config.d.ts +327 -0
- package/lib/types/config.js +1 -0
- package/lib/types/element.d.ts +576 -0
- package/lib/types/element.js +1 -0
- package/lib/types/index.d.ts +8 -0
- package/lib/types/index.js +8 -0
- package/lib/types/logger.d.ts +109 -0
- package/lib/types/logger.js +1 -0
- package/lib/types/onebots11.d.ts +1371 -0
- package/lib/types/onebots11.js +1 -0
- package/lib/types/plugin.d.ts +282 -0
- package/lib/types/plugin.js +1 -0
- package/lib/types/render.d.ts +111 -0
- package/lib/types/render.js +1 -0
- package/lib/types/reply.d.ts +40 -0
- package/lib/types/reply.js +1 -0
- package/lib/types/types.d.ts +898 -0
- package/lib/types/types.js +1 -0
- package/lib/utils/YamlEditor.d.ts +62 -0
- package/lib/utils/YamlEditor.js +208 -0
- package/lib/utils/button.d.ts +49 -0
- package/lib/utils/button.js +79 -0
- package/lib/utils/common.d.ts +123 -0
- package/lib/utils/common.js +413 -0
- package/lib/utils/config.d.ts +72 -0
- package/lib/utils/config.js +254 -0
- package/lib/utils/exec.d.ts +22 -0
- package/lib/utils/exec.js +36 -0
- package/lib/utils/ffmpeg.d.ts +12 -0
- package/lib/utils/ffmpeg.js +25 -0
- package/lib/utils/handler.d.ts +76 -0
- package/lib/utils/handler.js +102 -0
- package/lib/utils/logger.d.ts +3 -0
- package/lib/utils/logger.js +104 -0
- package/lib/utils/segment.d.ts +276 -0
- package/lib/utils/segment.js +448 -0
- package/lib/utils/update.d.ts +69 -0
- package/lib/utils/update.js +151 -0
- package/lib/utils/updateVersion.d.ts +33 -0
- package/lib/utils/updateVersion.js +145 -0
- package/package.json +92 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
dir: string;
|
|
4
|
+
/**
|
|
5
|
+
* 获取插件列表 拥有packageon才会被识别
|
|
6
|
+
* @returns {string[]}
|
|
7
|
+
*/
|
|
8
|
+
getPlugins(): string[];
|
|
9
|
+
/**
|
|
10
|
+
* 更新框架或插件
|
|
11
|
+
* @param path - 插件相对路径
|
|
12
|
+
* @param cmd - 更新命令 默认git pull
|
|
13
|
+
* @param time - 超时时间 默认120s
|
|
14
|
+
*/
|
|
15
|
+
update(path: string, cmd?: string, time?: number): Promise<{
|
|
16
|
+
status: string;
|
|
17
|
+
data: string;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* 获取指定仓库最后一次提交时间日期
|
|
21
|
+
* @param path - 插件相对路径
|
|
22
|
+
*/
|
|
23
|
+
getTime(path: string): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* 获取指定仓库最后一次提交哈希值
|
|
26
|
+
* @param {string} path - 插件相对路径
|
|
27
|
+
* @param {boolean} [short] - 是否获取短哈希 默认true
|
|
28
|
+
* @returns {Promise<string>}
|
|
29
|
+
*/
|
|
30
|
+
getHash(path: string, short?: boolean): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* 获取指定仓库的提交记录
|
|
33
|
+
* @param {{
|
|
34
|
+
* path: string,
|
|
35
|
+
* count?: number,
|
|
36
|
+
* hash?: string
|
|
37
|
+
* }} options - 参数
|
|
38
|
+
* @param {string} options.path - 插件相对路径
|
|
39
|
+
* @param {number} [options.count] - 获取日志条数 默认1条
|
|
40
|
+
* @param {string} [options.hash] - 指定HEAD
|
|
41
|
+
* @returns {Promise<string>}
|
|
42
|
+
*/
|
|
43
|
+
getCommit(options: {
|
|
44
|
+
path: any;
|
|
45
|
+
count?: any;
|
|
46
|
+
hash?: any;
|
|
47
|
+
branch?: any;
|
|
48
|
+
}): Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* 检查插件是否有更新
|
|
51
|
+
* @param {string} path - 插件相对路径
|
|
52
|
+
* @param {number} [time] - 超时时间 默认120s
|
|
53
|
+
* @returns {Promise<{status: 'ok'|'failed', data: string|boolean}>}
|
|
54
|
+
*/
|
|
55
|
+
checkUpdate(path: fs.PathLike, time?: number): Promise<{
|
|
56
|
+
status: string;
|
|
57
|
+
data: string | undefined;
|
|
58
|
+
count?: undefined;
|
|
59
|
+
} | {
|
|
60
|
+
status: string;
|
|
61
|
+
data: boolean;
|
|
62
|
+
count?: undefined;
|
|
63
|
+
} | {
|
|
64
|
+
status: string;
|
|
65
|
+
data: string;
|
|
66
|
+
count: string | number;
|
|
67
|
+
}>;
|
|
68
|
+
};
|
|
69
|
+
export default _default;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import exec from './exec.js'
|
|
3
|
+
export default new (class Update {
|
|
4
|
+
dir
|
|
5
|
+
constructor () {
|
|
6
|
+
this.dir = './plugins'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 获取插件列表 拥有packageon才会被识别
|
|
11
|
+
* @returns {string[]}
|
|
12
|
+
*/
|
|
13
|
+
getPlugins () {
|
|
14
|
+
const list = []
|
|
15
|
+
const files = fs.readdirSync(this.dir, { withFileTypes: true })
|
|
16
|
+
/** 忽略非文件夹、非karin-plugin-开头的文件夹或/karin-adapter-开头的文件夹 */
|
|
17
|
+
files.forEach(file => {
|
|
18
|
+
if (!file.isDirectory()) { return }
|
|
19
|
+
if (!file.name.startsWith('karin-plugin-') && !file.name.startsWith('karin-adapter-')) { return }
|
|
20
|
+
if (!fs.existsSync(`${this.dir}/${file.name}/packageon`)) { return }
|
|
21
|
+
list.push(file.name)
|
|
22
|
+
})
|
|
23
|
+
return list
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 更新框架或插件
|
|
28
|
+
* @param path - 插件相对路径
|
|
29
|
+
* @param cmd - 更新命令 默认git pull
|
|
30
|
+
* @param time - 超时时间 默认120s
|
|
31
|
+
*/
|
|
32
|
+
async update (path, cmd = 'git pull', time = 120) {
|
|
33
|
+
/** 检查一下路径是否存在 */
|
|
34
|
+
if (!fs.existsSync(path)) { return { status: 'failed', data: '路径不存在' } }
|
|
35
|
+
/** 检查是否有.git文件夹 */
|
|
36
|
+
if (!fs.existsSync(`${path}/.git`)) { return { status: 'failed', data: '该路径不是一个git仓库' } }
|
|
37
|
+
/** 设置超时时间 */
|
|
38
|
+
const timer = setTimeout(() => {
|
|
39
|
+
return { status: 'failed', data: '执行超时' }
|
|
40
|
+
}, time * 1000)
|
|
41
|
+
const options = { env: process.env, cwd: path, encoding: 'utf-8' }
|
|
42
|
+
/** 记录当前短哈希 */
|
|
43
|
+
const hash = await this.getHash(path)
|
|
44
|
+
/** 执行更新 */
|
|
45
|
+
const { status, error } = await exec(cmd, true, options)
|
|
46
|
+
/** 执行成功 */
|
|
47
|
+
if (status === 'ok') {
|
|
48
|
+
clearTimeout(timer)
|
|
49
|
+
/** 再次获取短哈希 查看是否有更新 */
|
|
50
|
+
const newHash = await this.getHash(path)
|
|
51
|
+
if (hash === newHash) {
|
|
52
|
+
const time = await this.getTime(path)
|
|
53
|
+
return {
|
|
54
|
+
status: 'ok',
|
|
55
|
+
data: ['\n当前版本已是最新版本', `Hash: ${hash}`, `最后更新:${await this.getCommit({ path, count: 1 })}`, `最后提交时间:${time}`].join('\n'),
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const Commit = await this.getCommit({ path, hash })
|
|
59
|
+
return {
|
|
60
|
+
status: 'ok',
|
|
61
|
+
data: ['\n更新成功', `当前Hash: ${newHash}`, `更新日志:\n${Commit}`].join('\n'),
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const msg = ['\n更新失败', `当前Hash: ${hash}`, `错误信息:${error?.message?.toString() || error?.stack?.toString() || error?.toString()}`, '请解决错误后重试或执行【#强制更新】']
|
|
65
|
+
return { status: 'failed', data: msg.join('\n') }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 获取指定仓库最后一次提交时间日期
|
|
70
|
+
* @param path - 插件相对路径
|
|
71
|
+
*/
|
|
72
|
+
async getTime (path) {
|
|
73
|
+
const cmd = 'git log -1 --format=%cd --date=format:"%Y-%m-%d %H:%M:%S"'
|
|
74
|
+
const data = await exec(cmd, false, { cwd: path, encoding: 'utf-8' })
|
|
75
|
+
if (data.status === 'failed') { return '获取时间失败,请重试或更新Git~' }
|
|
76
|
+
return data.stdout.trim()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 获取指定仓库最后一次提交哈希值
|
|
81
|
+
* @param {string} path - 插件相对路径
|
|
82
|
+
* @param {boolean} [short] - 是否获取短哈希 默认true
|
|
83
|
+
* @returns {Promise<string>}
|
|
84
|
+
*/
|
|
85
|
+
async getHash (path, short = true) {
|
|
86
|
+
const cmd = short ? 'git rev-parse --short HEAD' : 'git rev-parse HEAD'
|
|
87
|
+
const data = await exec(cmd, false, { cwd: path, encoding: 'utf-8' })
|
|
88
|
+
if (data.status === 'failed') {
|
|
89
|
+
const text = data.error
|
|
90
|
+
throw new Error(text)
|
|
91
|
+
}
|
|
92
|
+
return data.stdout.trim()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 获取指定仓库的提交记录
|
|
97
|
+
* @param {{
|
|
98
|
+
* path: string,
|
|
99
|
+
* count?: number,
|
|
100
|
+
* hash?: string
|
|
101
|
+
* }} options - 参数
|
|
102
|
+
* @param {string} options.path - 插件相对路径
|
|
103
|
+
* @param {number} [options.count] - 获取日志条数 默认1条
|
|
104
|
+
* @param {string} [options.hash] - 指定HEAD
|
|
105
|
+
* @returns {Promise<string>}
|
|
106
|
+
*/
|
|
107
|
+
async getCommit (options) {
|
|
108
|
+
const { path, count = 1, hash, branch } = options
|
|
109
|
+
let cmd = `git log -${count} --format="[%ad]%s %n" --date="format:%m-%d %H:%M"`
|
|
110
|
+
/** 键入HEAD */
|
|
111
|
+
if (hash) { cmd = `git log ${hash}..HEAD --format="[%ad] %s %n" --date="format:%m-%d %H:%M"` }
|
|
112
|
+
/** 指定分支 */
|
|
113
|
+
if (branch) { cmd = `git log -${count} ${branch} --format="[%ad] %s %n" --date="format:%m-%d %H:%M"` }
|
|
114
|
+
const data = await exec(cmd, false, { cwd: path, encoding: 'utf-8' })
|
|
115
|
+
if (data.status === 'failed') {
|
|
116
|
+
const text = data.error
|
|
117
|
+
throw new Error(text)
|
|
118
|
+
}
|
|
119
|
+
return data.stdout.trim()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 检查插件是否有更新
|
|
124
|
+
* @param {string} path - 插件相对路径
|
|
125
|
+
* @param {number} [time] - 超时时间 默认120s
|
|
126
|
+
* @returns {Promise<{status: 'ok'|'failed', data: string|boolean}>}
|
|
127
|
+
*/
|
|
128
|
+
async checkUpdate (path, time = 120) {
|
|
129
|
+
/** 检查一下路径是否存在 */
|
|
130
|
+
if (!fs.existsSync(path)) { return { status: 'failed', data: '路径不存在' } }
|
|
131
|
+
/** 检查是否有.git文件夹 */
|
|
132
|
+
if (!fs.existsSync(`${path}/.git`)) { return { status: 'failed', data: '该路径不是一个git仓库' } }
|
|
133
|
+
/** 设置超时时间 */
|
|
134
|
+
const timer = setTimeout(() => {
|
|
135
|
+
return { status: 'failed', data: '执行超时' }
|
|
136
|
+
}, time * 1000)
|
|
137
|
+
const options = { env: process.env, cwd: path, encoding: 'utf-8' }
|
|
138
|
+
/** git fetch origin */
|
|
139
|
+
const { status, error } = await exec('git fetch origin', false, options)
|
|
140
|
+
if (status === 'failed') { return { status: 'failed', data: error?.message } }
|
|
141
|
+
/** git status -uno */
|
|
142
|
+
const { stdout } = await exec('git status -uno', false, options)
|
|
143
|
+
clearTimeout(timer)
|
|
144
|
+
/** 检查是否有更新 没更新直接返回 */
|
|
145
|
+
if (stdout.includes('Your branch is up to date with')) { return { status: 'ok', data: false } }
|
|
146
|
+
/** 获取落后几次更新 */
|
|
147
|
+
const count = stdout.match(/Your branch is behind '.*' by (\d+) commits/)?.[1] || 1
|
|
148
|
+
const data = await this.getCommit({ path, count, branch: 'origin' })
|
|
149
|
+
return { status: 'ok', data, count }
|
|
150
|
+
}
|
|
151
|
+
})()
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export default class Version {
|
|
2
|
+
path: string;
|
|
3
|
+
packageDir: string;
|
|
4
|
+
CHANGELOGDir: string;
|
|
5
|
+
packageJson: any;
|
|
6
|
+
version: string;
|
|
7
|
+
commitsMap: {
|
|
8
|
+
[key: string]: string[];
|
|
9
|
+
};
|
|
10
|
+
HEAD: string;
|
|
11
|
+
cmd: string;
|
|
12
|
+
stdout: string | string[];
|
|
13
|
+
url: string;
|
|
14
|
+
constructor(path: string);
|
|
15
|
+
init(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* 获取当前仓库最新的一个标签的HEAD
|
|
18
|
+
*/
|
|
19
|
+
gitTag(): Promise<false | undefined>;
|
|
20
|
+
/**
|
|
21
|
+
* 获取当前仓库的远程地址
|
|
22
|
+
*/
|
|
23
|
+
gitUrl(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* 更新版本号 tag
|
|
26
|
+
*/
|
|
27
|
+
updateVersion(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* 封装exce方法
|
|
30
|
+
* @param {string} cmd 执行的命令
|
|
31
|
+
*/
|
|
32
|
+
exce(cmd: string): Promise<string>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import { exec } from 'child_process'
|
|
3
|
+
export default class Version {
|
|
4
|
+
path
|
|
5
|
+
packageDir
|
|
6
|
+
CHANGELOGDir
|
|
7
|
+
packageJson
|
|
8
|
+
version
|
|
9
|
+
commitsMap
|
|
10
|
+
HEAD
|
|
11
|
+
cmd
|
|
12
|
+
stdout
|
|
13
|
+
url
|
|
14
|
+
constructor (path) {
|
|
15
|
+
this.cmd = ''
|
|
16
|
+
this.stdout = ''
|
|
17
|
+
this.url = ''
|
|
18
|
+
this.HEAD = ''
|
|
19
|
+
this.path = path
|
|
20
|
+
this.packageDir = this.path + '/packageon'
|
|
21
|
+
this.CHANGELOGDir = this.path + '/CHANGELOG.md'
|
|
22
|
+
this.packageJson = JSON.parse(fs.readFileSync(this.packageDir, 'utf-8'))
|
|
23
|
+
this.version = this.packageJson.version
|
|
24
|
+
this.commitsMap = {
|
|
25
|
+
release: ['### Releases'],
|
|
26
|
+
feat: ['### 新增功能'],
|
|
27
|
+
fix: ['### Bug修复'],
|
|
28
|
+
docs: ['### 文档更新'],
|
|
29
|
+
style: ['### 代码样式修改'],
|
|
30
|
+
refactor: ['### 代码重构'],
|
|
31
|
+
perf: ['### 性能优化'],
|
|
32
|
+
chore: ['### 构建工具相关'],
|
|
33
|
+
revert: ['### 回滚'],
|
|
34
|
+
others: ['### 其他提交'],
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async init () {
|
|
39
|
+
/** 获取仓库地址 */
|
|
40
|
+
await this.gitUrl()
|
|
41
|
+
/** 取tag对应的head */
|
|
42
|
+
await this.gitTag()
|
|
43
|
+
const HEAD = this.HEAD ? `${this.HEAD}..HEAD ` : ''
|
|
44
|
+
this.cmd = `git log ${HEAD}--pretty=format:"HEAD: %H=分割=sha: %h=分割=log: %s"`
|
|
45
|
+
this.stdout = (await this.exce(this.cmd))
|
|
46
|
+
if (!this.stdout) { throw new Error('commit为空...') }
|
|
47
|
+
this.stdout = this.stdout.trim().split('\n')
|
|
48
|
+
const reg = /(fix|feat|docs|style|refactor|perf|release|chore|revert)(:|:)/i
|
|
49
|
+
for (const commit of this.stdout) {
|
|
50
|
+
/** 拆分 */
|
|
51
|
+
const [HEAD, sha, log] = commit.split('=分割=').map(item => item.trim().replace(/^(HEAD|sha|log): /, ''))
|
|
52
|
+
/** 排除此项 */
|
|
53
|
+
if (log.startsWith('Merge branch')) { continue }
|
|
54
|
+
const match = log.match(reg)
|
|
55
|
+
const type = match ? match[1].toLowerCase() : 'others'
|
|
56
|
+
/** 拼接commit */
|
|
57
|
+
const info = `- ${log} ([${sha}](${this.url}/commit/${HEAD}))`
|
|
58
|
+
this.commitsMap[type].push(info)
|
|
59
|
+
}
|
|
60
|
+
/** 更新版本号 */
|
|
61
|
+
await this.updateVersion()
|
|
62
|
+
/** YYYY-MM-DD */
|
|
63
|
+
const date = new Date().toLocaleDateString().replace(/\//g, '-')
|
|
64
|
+
const text = [`## ${this.version} (${date})`]
|
|
65
|
+
for (const key in this.commitsMap) {
|
|
66
|
+
/** 排除空 */
|
|
67
|
+
if (this.commitsMap[key].length === 1) {
|
|
68
|
+
delete this.commitsMap[key]
|
|
69
|
+
continue
|
|
70
|
+
}
|
|
71
|
+
text.push(this.commitsMap[key].join('\n'))
|
|
72
|
+
}
|
|
73
|
+
/** 判断是否有CHANGELOG.md文件 */
|
|
74
|
+
if (fs.existsSync(this.CHANGELOGDir)) {
|
|
75
|
+
const oldText = fs.readFileSync(this.CHANGELOGDir, 'utf-8')
|
|
76
|
+
text.push(oldText)
|
|
77
|
+
}
|
|
78
|
+
fs.writeFileSync(this.CHANGELOGDir, text.join('\n\n'))
|
|
79
|
+
console.log('更新成功~')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 获取当前仓库最新的一个标签的HEAD
|
|
84
|
+
*/
|
|
85
|
+
async gitTag () {
|
|
86
|
+
const cmd = 'git tag'
|
|
87
|
+
const stdout = await this.exce(cmd)
|
|
88
|
+
if (!stdout) { return false }
|
|
89
|
+
const tags = stdout.trim().split('\n')
|
|
90
|
+
const lastTag = tags[tags.length - 1]
|
|
91
|
+
const cmd2 = `git rev-list -n 1 ${lastTag}`
|
|
92
|
+
const HEAD = await this.exce(cmd2)
|
|
93
|
+
this.HEAD = HEAD.trim()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 获取当前仓库的远程地址
|
|
98
|
+
*/
|
|
99
|
+
async gitUrl () {
|
|
100
|
+
const cmd = 'git remote -v'
|
|
101
|
+
const stdout = await this.exce(cmd)
|
|
102
|
+
let [url] = stdout.split('\n').map(item => item.split('\t')[1])
|
|
103
|
+
url = url.trim().split(' ')[0]
|
|
104
|
+
this.url = url
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 更新版本号 tag
|
|
109
|
+
*/
|
|
110
|
+
async updateVersion () {
|
|
111
|
+
/** 10进1 */
|
|
112
|
+
const versionArr = this.version.split('.').map((item) => parseInt(item))
|
|
113
|
+
if (versionArr[2] === 9) {
|
|
114
|
+
versionArr[1]++
|
|
115
|
+
versionArr[2] = 0
|
|
116
|
+
} else {
|
|
117
|
+
versionArr[2]++
|
|
118
|
+
}
|
|
119
|
+
this.version = versionArr.join('.')
|
|
120
|
+
this.packageJson.version = this.version
|
|
121
|
+
fs.writeFileSync(this.packageDir, JSON.stringify(this.packageJson, null, 2))
|
|
122
|
+
/** tag */
|
|
123
|
+
try {
|
|
124
|
+
await this.exce(`git tag v${this.version}`)
|
|
125
|
+
} catch (e) {
|
|
126
|
+
console.log('tag已存在')
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 封装exce方法
|
|
132
|
+
* @param {string} cmd 执行的命令
|
|
133
|
+
*/
|
|
134
|
+
exce (cmd) {
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
exec(cmd, { cwd: this.path }, (error, stdout) => {
|
|
137
|
+
if (error) {
|
|
138
|
+
reject(error)
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
resolve(stdout)
|
|
142
|
+
})
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-karin",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"private": false,
|
|
5
|
+
"homepage": "https://github.com/KarinJS/Karin#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/KarinJS/Karin/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/KarinJS/Karin.git"
|
|
12
|
+
},
|
|
13
|
+
"author": "Karin",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"imports": {
|
|
16
|
+
"#Karin": "./lib/index.js"
|
|
17
|
+
},
|
|
18
|
+
"main": "./lib/index.js",
|
|
19
|
+
"license": "GPL-3.0-only",
|
|
20
|
+
"files": [
|
|
21
|
+
"/lib/**/*.js",
|
|
22
|
+
"/lib/**/*.d.ts",
|
|
23
|
+
"/config/defSet/*.yaml",
|
|
24
|
+
"/config/view/*.yaml",
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"package.json",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"workspaces": [
|
|
30
|
+
"plugins/**"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"app": "node .",
|
|
34
|
+
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json && npm run fix",
|
|
35
|
+
"delete": "pm2 delete ./config/config/pm2.yaml",
|
|
36
|
+
"fix": "npx eslint lib/**/*.js --fix",
|
|
37
|
+
"init": "node lib/tools/install.js",
|
|
38
|
+
"init:dev": "node lib/tools/install.js",
|
|
39
|
+
"init:pack": "node lib/tools/install.js",
|
|
40
|
+
"js": "node .",
|
|
41
|
+
"js:dev": "node . --dev",
|
|
42
|
+
"log": "node lib/tools/pm2Log.js",
|
|
43
|
+
"monit": "pm2 monit",
|
|
44
|
+
"pub": "npm publish --access public",
|
|
45
|
+
"restart": "pm2 restart ./config/config/pm2.yaml",
|
|
46
|
+
"sort:pack": "npx sort-package-json",
|
|
47
|
+
"start": "pm2 start ./config/config/pm2.yaml && pm2 monit",
|
|
48
|
+
"stop": "pm2 delete ./config/config/pm2.yaml",
|
|
49
|
+
"ts": "tsx ./src/index.ts --dev",
|
|
50
|
+
"ts:dev": "tsx ./src/index.ts --dev",
|
|
51
|
+
"uninstall": "node lib/tools/uninstall.js",
|
|
52
|
+
"ver": "node lib/tools/updateVersion.js"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@grpc/grpc-js": "1.10.10",
|
|
56
|
+
"@grpc/proto-loader": "0.7.13",
|
|
57
|
+
"art-template": "4.13.2",
|
|
58
|
+
"axios": "1.7.2",
|
|
59
|
+
"chalk": "5.3.0",
|
|
60
|
+
"chokidar": "3.6.0",
|
|
61
|
+
"express": "4.19.2",
|
|
62
|
+
"kritor-proto": "^0.0.6",
|
|
63
|
+
"level": "8.0.1",
|
|
64
|
+
"lodash": "4.17.21",
|
|
65
|
+
"log4js": "6.9.1",
|
|
66
|
+
"moment": "2.30.1",
|
|
67
|
+
"node-schedule": "2.1.1",
|
|
68
|
+
"redis": "4.6.14",
|
|
69
|
+
"ws": "8.16.0",
|
|
70
|
+
"yaml": "2.4.1"
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"@types/express": "^4.17.21",
|
|
74
|
+
"@types/lodash": "^4.17.5",
|
|
75
|
+
"@types/node": "^20.14.8",
|
|
76
|
+
"@types/node-schedule": "^2.1.7",
|
|
77
|
+
"@types/ws": "8.5.10",
|
|
78
|
+
"eslint": "9.5.0",
|
|
79
|
+
"neostandard": "^0.7.2",
|
|
80
|
+
"sort-package-json": "^2.10.0",
|
|
81
|
+
"tsc-alias": "^1.8.10",
|
|
82
|
+
"tsx": "^4.15.7",
|
|
83
|
+
"typescript": "^4.9.5"
|
|
84
|
+
},
|
|
85
|
+
"engines": {
|
|
86
|
+
"node": ">=18"
|
|
87
|
+
},
|
|
88
|
+
"publishConfig": {
|
|
89
|
+
"access": "public",
|
|
90
|
+
"registry": "https://registry.npmjs.org"
|
|
91
|
+
}
|
|
92
|
+
}
|