diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 7e4b5b0312c002c15d2cd938de30347201c4e243..e912130b0b9ee0c0afe4f724aa2ab5e3c1417463 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -6,7 +6,8 @@ 并且此项目遵循 [Semantic Versioning](https://semver.org/lang/zh-CN/). ## [Unreleased] - +### Added +- 新增 compute-pkg 指令 ## [0.3.10] - 2024-01-04 ### Added diff --git a/packages/cli/src/commands/compute-pkg/compute-pkg.ts b/packages/cli/src/commands/compute-pkg/compute-pkg.ts new file mode 100644 index 0000000000000000000000000000000000000000..6bd6b17c5b073f3df43ba37048c396519c4a4cd2 --- /dev/null +++ b/packages/cli/src/commands/compute-pkg/compute-pkg.ts @@ -0,0 +1,33 @@ +import { Command } from 'commander'; +import { computePkg } from '@ibiz-template/cli-core'; +import { ICommand } from '../../interface'; + +/** + * 运行模板编译 + * + * @author ShineKOT + * @date 2024-03-26 10:57:19 + * @export + * @class ComputePkgCommand + * @implements {ICommand} + */ +export class ComputePkgCommand implements ICommand { + load(program: Command): void { + program + .command('compute-pkg') + .description('计算指定模型的插件列表') + .option('-m, --model ', '模型目录') + .option('--app [app-code-name]', '应用名称') + .action(this.action.bind(this)); + } + + async action(options: { model: string; app: string }): Promise { + if (!options.model) { + throw new Error(`未配置模型目录 -m 或 --model`); + } + if (!options.app) { + throw new Error(`未配置应用名称 --app`); + } + computePkg(options); + } +} diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 0d53e12c7ee8b2292d782ca6cc4dc9cb3065bdeb..a7bf69958db7d39ad6a4068193902121cc8e33bd 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -3,11 +3,13 @@ import { Command } from 'commander'; import { BuildModuleCommand } from './build/build'; import { DownloadPkgCommand } from './download-pkg/download-pkg'; +import { ComputePkgCommand } from './compute-pkg/compute-pkg'; export class CommandLoader { public static load(program: Command): void { new BuildModuleCommand().load(program); new DownloadPkgCommand().load(program); + new ComputePkgCommand().load(program); this.handleInvalidCommand(program); } diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 0feb35dcf1779d6b68280d4a541532cc7cdb1390..06ab39bcc8cdcb5e18e0602015d9bcc3524a0e7e 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -6,6 +6,8 @@ 并且此项目遵循 [Semantic Versioning](https://semver.org/lang/zh-CN/). ## [Unreleased] +### Added +- 新增computePkg,将指定模型的应用插件列表输出到**ibiz-download-pkg.config.ts** ## [0.3.9] - 2024-01-04 diff --git a/packages/core/src/compute-pkg/compute-pkg.ts b/packages/core/src/compute-pkg/compute-pkg.ts new file mode 100644 index 0000000000000000000000000000000000000000..6bec94e7306a55b70c717897a9cbdb7c6e71667a --- /dev/null +++ b/packages/core/src/compute-pkg/compute-pkg.ts @@ -0,0 +1,40 @@ +/* eslint-disable no-await-in-loop */ +import { existsSync, readFileSync, writeFileSync } from 'fs-extra'; +import { resolve, normalize } from 'path'; +import { + DEFAULT_APP_FILE, + DEFAULT_APP_FOLDER, + DEFAULT_OUT_FILE, +} from './constant'; +import { IPulginRef } from './interface'; +import { template } from './template'; + +export async function computePkg(options: { + model: string; + app: string; +}): Promise { + const { model, app } = options; + const modelFolderPath = normalize(resolve(model)); + const sourcePath = resolve( + modelFolderPath, + DEFAULT_APP_FOLDER, + app, + DEFAULT_APP_FILE, + ); + if (!existsSync(sourcePath)) { + throw new Error(`模型目录[${sourcePath}]不存在,请检查!`); + } + const content = readFileSync(sourcePath, 'utf-8'); + const pulginRepos: string[] = []; + const appConfig = JSON.parse(content); + const pluginRefs: IPulginRef[] = appConfig.getAllPSAppPFPluginRefs; + if (pluginRefs && pluginRefs.length > 0) { + pluginRefs.forEach(plugin => { + if (plugin.rTObjectRepo && !pulginRepos.includes(plugin.rTObjectRepo)) { + pulginRepos.push(plugin.rTObjectRepo); + } + }); + } + const outFile = template(pulginRepos); + writeFileSync(`./${DEFAULT_OUT_FILE}`, outFile); +} diff --git a/packages/core/src/compute-pkg/constant/index.ts b/packages/core/src/compute-pkg/constant/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..4d49cb32e370176b488cb39fc0244d9c86d0f998 --- /dev/null +++ b/packages/core/src/compute-pkg/constant/index.ts @@ -0,0 +1,3 @@ +export const DEFAULT_APP_FOLDER = 'PSSYSAPPS'; +export const DEFAULT_APP_FILE = 'PSSYSAPP.json'; +export const DEFAULT_OUT_FILE = 'ibiz-download-pkg.config.ts'; diff --git a/packages/core/src/compute-pkg/index.ts b/packages/core/src/compute-pkg/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..9da50383afbfe76136845e026ffa211c50ed696f --- /dev/null +++ b/packages/core/src/compute-pkg/index.ts @@ -0,0 +1,3 @@ +export * from './interface'; +export * from './constant'; +export { computePkg } from './compute-pkg'; diff --git a/packages/core/src/compute-pkg/interface/i-pulgin-ref.ts b/packages/core/src/compute-pkg/interface/i-pulgin-ref.ts new file mode 100644 index 0000000000000000000000000000000000000000..b4ff239bfa306aa748739b10689754822dd31a42 --- /dev/null +++ b/packages/core/src/compute-pkg/interface/i-pulgin-ref.ts @@ -0,0 +1,33 @@ +/** + * 插件引用 + */ +export interface IPulginRef { + /** + * 名称 + */ + name: string; + /** + * 插件代码标识 + */ + pluginCode: string; + /** + * 插件类型 + */ + pluginType: string; + /** + * 运行时插件名称 + */ + rTObjectName: string; + /** + * 运行时插件仓库配置 + */ + rTObjectRepo: string; + /** + * 插件引用模式 + */ + refMode: string; + /** + * 是否为远程运行时插件 + */ + runtimeObject: boolean; +} diff --git a/packages/core/src/compute-pkg/interface/index.ts b/packages/core/src/compute-pkg/interface/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..d2c3b780993683cb36597876b895edd288f5e361 --- /dev/null +++ b/packages/core/src/compute-pkg/interface/index.ts @@ -0,0 +1 @@ +export * from './i-pulgin-ref'; diff --git a/packages/core/src/compute-pkg/template/index.ts b/packages/core/src/compute-pkg/template/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..da6be3f6754e9a8de825053e700b74f797742c9e --- /dev/null +++ b/packages/core/src/compute-pkg/template/index.ts @@ -0,0 +1,15 @@ +export function template(pulginRepos: string[]): string { + return `// eslint-disable-next-line import/no-extraneous-dependencies +import { defineDownloadPkgConfig } from '@ibiz-template/cli'; +import { pkgConfig } from './src/download-pkg.config'; + +export default defineDownloadPkgConfig({ + clean: true, + registry: 'http://172.16.240.221:8081/repository/ibizsys/', + outDir: './public/plugins', + // 依赖包填写示例 + dependencies: [ + ...pkgConfig,${pulginRepos.map(p => `\n '${p}'`)} + ], +});`; +} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index bf0b1139de0b00c1991d1fce73e3c6a4b8ad9f16..8056cffc818aa34f0180706bccd237dd6402b090 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -4,3 +4,4 @@ export * from './interface'; export * from './util'; export { defineConfig } from './define-config'; export * from './download-pkg'; +export * from './compute-pkg';