-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # src/utils/common/common.ts # src/utils/config/config.ts
- Loading branch information
Showing
24 changed files
with
444 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import fs from 'fs' | ||
import { dirName } from 'karin/types' | ||
|
||
/** | ||
* 获取git插件列表 | ||
* @param isPack - 是否屏蔽不带package.json的插件,默认为false | ||
*/ | ||
export function getGitPlugins (isPack = false): Array<dirName> { | ||
const dir = './plugins' | ||
let list = fs.readdirSync(dir, { withFileTypes: true }) | ||
/** 忽略非文件夹、非 karin-plugin-开头的文件夹 */ | ||
list = list.filter(v => v.isDirectory() && v.name.startsWith('karin-plugin-')) | ||
if (isPack) list = list.filter(v => fs.existsSync(`${dir}/${v.name}/package.json`)) | ||
const arr: dirName[] = [] | ||
list.map(v => arr.push(v.name as dirName)) | ||
return arr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import { NpmInfo } from 'karin/utils' | ||
import { readJson } from './readJson' | ||
|
||
/** | ||
* 获取npm插件列表 | ||
* @param showDetails - 是否返回详细信息 | ||
* 默认只返回插件npm包名,为true时返回详细的{dir, name}[] | ||
*/ | ||
export async function getNpmPlugins<T extends boolean> (showDetails: T): Promise<T extends true ? NpmInfo[] : string[]> { | ||
/** 屏蔽的依赖包列表 */ | ||
const exclude = ['art-template', 'axios', 'chalk', 'chokidar', 'commander', 'express', 'level', 'lodash', 'log4js', 'moment', 'node-karin', 'node-schedule', 'redis', 'ws', 'yaml'] | ||
|
||
const pkg = readJson('./package.json') | ||
const dependencies = Object.keys(pkg.dependencies).filter((name) => !exclude.includes(name)) | ||
|
||
if (!showDetails) { | ||
const list: string[] = [] | ||
const readPackageJson = async (name: string) => { | ||
try { | ||
const pkgPath = path.join(process.cwd(), 'node_modules', name, 'package.json') | ||
const pkg = readJson(pkgPath) | ||
if (pkg?.karin) list.push(name) | ||
} catch (error: any) { | ||
logger.error(`[common] 解析 package.json 时出错:${error.stack || error.message || JSON.stringify(error)}`) | ||
} | ||
} | ||
|
||
await Promise.all(dependencies.map(readPackageJson)) | ||
return list as T extends true ? NpmInfo[] : string[] | ||
} | ||
|
||
const list: NpmInfo[] = [] | ||
/** 获取详细的npm信息 */ | ||
const readPackageJson = async (files: string) => { | ||
try { | ||
const root = path.join(process.cwd(), 'node_modules', files) | ||
const pkgPath = path.join(root, 'package.json') | ||
const pkg = readJson(pkgPath) | ||
if (!pkg?.karin) return | ||
|
||
if (pkg?.main) { | ||
list.push({ plugin: files, path: path.dirname(pkg.main), file: path.basename(pkg.main), isMain: true }) | ||
} | ||
|
||
if (pkg?.karin?.apps?.length) { | ||
pkg.karin.apps.forEach((app: string) => { | ||
if (!fs.existsSync(path.join(root, app))) { | ||
logger.error(`[common] npm插件${files}的app目录${app}不存在 已跳过`) | ||
return | ||
} | ||
|
||
fs.readdirSync(path.join(root, app)).forEach((filename: string) => { | ||
/** 忽略非js文件 npm包不考虑ts */ | ||
if (!filename.endsWith('.js')) return | ||
list.push({ plugin: files, path: app, file: filename, isMain: false }) | ||
}) | ||
}) | ||
} | ||
} catch (error: any) { | ||
logger.error(`[common] 获取npm插件列表时出错:${error.stack || error.message || JSON.stringify(error)}`) | ||
} | ||
} | ||
|
||
await Promise.all(dependencies.map(readPackageJson)) | ||
return list as T extends true ? NpmInfo[] : string[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import fs from 'fs' | ||
|
||
/** | ||
* - 解析json文件 | ||
* @param file - 文件路径 | ||
*/ | ||
export function readJson (file: string): any { | ||
return JSON.parse(fs.readFileSync(file, 'utf8')) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { logger } from 'karin/utils' | ||
import { logger } from 'karin/utils/core/logger' | ||
|
||
/** | ||
* 启动日志 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.