node-karin 0.6.25 → 0.6.27
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/plugin.loader.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/utils/common.js +25 -8
- package/lib/utils/config.d.ts +1 -1
- package/lib/utils/config.js +8 -3
- package/package.json +1 -1
|
@@ -256,7 +256,7 @@ class PluginLoader {
|
|
|
256
256
|
async createdApp (dir, name, isOrderBy = false, isNpm = false) {
|
|
257
257
|
try {
|
|
258
258
|
const list = []
|
|
259
|
-
let path = `${this.dirPath}${isNpm ? 'node_modules
|
|
259
|
+
let path = `${this.dirPath}${isNpm ? 'node_modules' : 'plugins'}/${dir}/${name}`
|
|
260
260
|
if (isOrderBy) { path = path + `?${Date.now()}` }
|
|
261
261
|
const tmp = await import(path)
|
|
262
262
|
lodash.forEach(tmp, (App) => {
|
package/lib/index.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export declare const Cfg: {
|
|
|
37
37
|
review: boolean;
|
|
38
38
|
logger: import("log4js").Logger;
|
|
39
39
|
initCfg(): Promise<void>;
|
|
40
|
-
getPlugins(): string[]
|
|
40
|
+
getPlugins(): Promise<string[]>;
|
|
41
41
|
mkdir(dirname: string): boolean;
|
|
42
42
|
dirPath(_path: string, plugins: string[]): Promise<void>;
|
|
43
43
|
timeout(type?: "ws" | "grpc"): number;
|
package/lib/utils/common.js
CHANGED
|
@@ -406,21 +406,38 @@ export const common = new (class Common {
|
|
|
406
406
|
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'))
|
|
407
407
|
const dependencies = Object.keys(pkg.dependencies).filter((name) => !pkgdependencies.includes(name))
|
|
408
408
|
if (!showDetails) {
|
|
409
|
-
|
|
409
|
+
const list = []
|
|
410
|
+
// 检查pkg是否存在karin字段
|
|
411
|
+
const readPackageJson = async (name) => {
|
|
412
|
+
try {
|
|
413
|
+
const pkgPath = path.join(process.cwd(), 'node_modules', name, 'package.json')
|
|
414
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
415
|
+
if (pkg?.karin) { list.push(name) }
|
|
416
|
+
} catch { }
|
|
417
|
+
}
|
|
418
|
+
await Promise.all(dependencies.map(readPackageJson))
|
|
419
|
+
return list
|
|
410
420
|
} else {
|
|
411
421
|
const list = []
|
|
412
422
|
const readPackageJson = async (name) => {
|
|
413
423
|
try {
|
|
414
424
|
const pkgPath = path.join(process.cwd(), 'node_modules', name, 'package.json')
|
|
415
425
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
416
|
-
if (pkg?.karin
|
|
417
|
-
pkg
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
426
|
+
if (pkg?.karin) {
|
|
427
|
+
if (pkg?.main) {
|
|
428
|
+
const dir = `${name}/${path.dirname(pkg.main).replace(/\.\//, '')}`
|
|
429
|
+
list.push({ dir, name: path.basename(pkg.main) })
|
|
430
|
+
}
|
|
431
|
+
if (pkg?.karin?.apps?.length) {
|
|
432
|
+
pkg.karin.apps.forEach((app) => {
|
|
433
|
+
fs.readdirSync(`./node_modules/${name}/${app}`).forEach((name) => {
|
|
434
|
+
/** 忽略非js */
|
|
435
|
+
if (!name.endsWith('.js')) { return }
|
|
436
|
+
const dir = `${name}/${app}`
|
|
437
|
+
list.push({ dir, name })
|
|
438
|
+
})
|
|
422
439
|
})
|
|
423
|
-
}
|
|
440
|
+
}
|
|
424
441
|
}
|
|
425
442
|
} catch { }
|
|
426
443
|
}
|
package/lib/utils/config.d.ts
CHANGED
package/lib/utils/config.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import { karinDir } from '../core/dir.js'
|
|
3
3
|
import { fs, yaml as Yaml, chokidar } from '../modules.js'
|
|
4
|
+
import { common } from './common.js'
|
|
4
5
|
/**
|
|
5
6
|
* 配置文件
|
|
6
7
|
*/
|
|
@@ -57,7 +58,7 @@ export const config = new (class Cfg {
|
|
|
57
58
|
})
|
|
58
59
|
}
|
|
59
60
|
/** 为每个插件包创建统一存储的文件夹 */
|
|
60
|
-
const plugins = this.getPlugins()
|
|
61
|
+
const plugins = await this.getPlugins()
|
|
61
62
|
const DataList = [
|
|
62
63
|
'data',
|
|
63
64
|
'temp',
|
|
@@ -69,10 +70,14 @@ export const config = new (class Cfg {
|
|
|
69
70
|
this.logger = (await import('./logger.js')).default
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
getPlugins () {
|
|
73
|
+
async getPlugins () {
|
|
74
|
+
const list = []
|
|
73
75
|
const files = fs.readdirSync('./plugins', { withFileTypes: true })
|
|
74
76
|
// 过滤掉非karin-plugin-开头的文件夹
|
|
75
|
-
|
|
77
|
+
list.push(...files.filter(file => file.isDirectory() && (file.name.startsWith('karin-plugin-'))).map(dir => dir.name))
|
|
78
|
+
// 获取npm插件
|
|
79
|
+
list.push(...(await common.getNpmPlugins(false)))
|
|
80
|
+
return list
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
/**
|