This commit is contained in:
2025-11-24 16:14:54 +08:00
parent 8db44dcb04
commit 5dc4dcfb58
4 changed files with 23 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@kevisual/code-center", "name": "@kevisual/code-center",
"version": "0.0.8", "version": "0.0.9",
"description": "code center", "description": "code center",
"type": "module", "type": "module",
"main": "index.js", "main": "index.js",
@@ -10,18 +10,21 @@
"type": "pm2-system-app", "type": "pm2-system-app",
"key": "code-center", "key": "code-center",
"entry": "./app.js", "entry": "./app.js",
"engine": "bun",
"runtime": [ "runtime": [
"client" "client"
] ],
"pm2Options": {
"interpreter": "bun"
}
}, },
"scripts": { "scripts": {
"test": "tsx test/**/*.ts", "test": "tsx test/**/*.ts",
"dev": "bun run --watch --hot src/index.ts", "dev": "bun run --watch --hot src/index.ts",
"dev:inspect": "bun run --watch --hot --inspect src/index.ts", "dev:inspect": "bun run --watch --hot --inspect src/index.ts",
"cmd": "bun run src/run.ts ", "cmd": "bun run src/run.ts ",
"prebuild": "rimraf dist", "prebuild": "rimraf dist && rimraf pack-dist",
"build": "NODE_ENV=production bun bun.config.mjs", "build": "NODE_ENV=production bun bun.config.mjs",
"postbuild": "ev pack",
"deploy": "rsync -avz --delete ./pack-dist/ light:/root/kevisual/assistant-app/apps/root/code-center", "deploy": "rsync -avz --delete ./pack-dist/ light:/root/kevisual/assistant-app/apps/root/code-center",
"deploy:envision": "rsync -avz --delete ./pack-dist/ envision:~/kevisual/assistant-app/apps/root/code-center", "deploy:envision": "rsync -avz --delete ./pack-dist/ envision:~/kevisual/assistant-app/apps/root/code-center",
"clean": "rm -rf dist", "clean": "rm -rf dist",

View File

@@ -18,7 +18,7 @@ app
.define(async (ctx) => { .define(async (ctx) => {
const tokenUser = ctx.state.tokenUser; const tokenUser = ctx.state.tokenUser;
const data = ctx.query?.data; const data = ctx.query?.data;
const { id, key, force, install, appKey: postAppKey, version: postVersion = '1.0.0' } = data; const { id, force, install, appKey: postAppKey, version: postVersion = '1.0.0' } = data;
if (!id && !postAppKey) { if (!id && !postAppKey) {
ctx.throw(400, 'Invalid id or postAppKey'); ctx.throw(400, 'Invalid id or postAppKey');
} }
@@ -46,20 +46,21 @@ app
ctx.throw(400, `Invalid appKey , no found app with key: ${postAppKey} and version: ${postVersion}`); ctx.throw(400, `Invalid appKey , no found app with key: ${postAppKey} and version: ${postVersion}`);
} }
} }
const { key: appKey, version } = microApp; const { version } = microApp;
const check = await appPathCheck({ key: key }); const appKey = username + '/' + microApp.key;
const check = await appPathCheck({ appKey });
let appType: string; let appType: string;
if (check) { if (check) {
if (!force) { if (!force) {
ctx.throw(400, 'App already exists, please remove it first'); ctx.throw(400, 'App already exists, please remove it first');
} else { } else {
const app = manager.getAppShowInfo(key); const app = manager.getAppShowInfo(appKey);
appType = app?.type; appType = app?.type;
await manager.removeApp(key); await manager.removeApp(appKey);
} }
} }
const installAppData = await installApp({ username, appKey, version, key, needInstallDeps: !!install }); const installAppData = await installApp({ appKey, version, needInstallDeps: !!install });
await manager.add(installAppData.showAppInfo); await manager.add(installAppData.showAppInfo);
ctx.body = installAppData; ctx.body = installAppData;
if (appType === 'system-app') { if (appType === 'system-app') {

View File

@@ -9,13 +9,10 @@ import path from 'path';
import { appsPath } from '../lib/index.ts'; import { appsPath } from '../lib/index.ts';
import { installAppFromKey } from './manager.ts'; import { installAppFromKey } from './manager.ts';
export type InstallAppOpts = { export type InstallAppOpts = {
path?: string;
key?: string;
needInstallDeps?: boolean; needInstallDeps?: boolean;
// minio中 // minio中
appKey?: string; appKey?: string;
version?: string; version?: string;
username?: string;
}; };
/** /**
* 检测路径是否存在 * 检测路径是否存在
@@ -23,16 +20,16 @@ export type InstallAppOpts = {
* @returns * @returns
*/ */
export const appPathCheck = async (opts: InstallAppOpts) => { export const appPathCheck = async (opts: InstallAppOpts) => {
const { key } = opts; const { appKey } = opts;
const directory = path.join(appsPath, key); const directory = path.join(appsPath, appKey);
if (fileIsExist(directory)) { if (fileIsExist(directory)) {
return true; return true;
} }
return false; return false;
}; };
export const installApp = async (opts: InstallAppOpts) => { export const installApp = async (opts: InstallAppOpts) => {
const { key, needInstallDeps, appKey, version, username } = opts; const { needInstallDeps, appKey, version } = opts;
const prefix = `${username}/${appKey}/${version}`; const prefix = `${appKey}/${version}`;
const pkgPrefix = prefix + '/package.json'; const pkgPrefix = prefix + '/package.json';
const stat = await getFileStat(pkgPrefix); const stat = await getFileStat(pkgPrefix);
if (!stat) { if (!stat) {
@@ -44,7 +41,7 @@ export const installApp = async (opts: InstallAppOpts) => {
}); });
for (const file of fileList) { for (const file of fileList) {
const { name } = file as MinioFile; const { name } = file as MinioFile;
const outputPath = path.join(appsPath, key, name.replace(prefix, '')); const outputPath = path.join(appsPath, appKey, name.replace(prefix, ''));
const dir = path.dirname(outputPath); const dir = path.dirname(outputPath);
if (!fileIsExist(dir)) { if (!fileIsExist(dir)) {
fs.mkdirSync(dir, { recursive: true }); fs.mkdirSync(dir, { recursive: true });
@@ -58,7 +55,7 @@ export const installApp = async (opts: InstallAppOpts) => {
writeStream.on('error', reject); writeStream.on('error', reject);
}); });
} }
const directory = path.join(appsPath, key); const directory = path.join(appsPath, appKey);
if (!fileIsExist(directory)) { if (!fileIsExist(directory)) {
fs.mkdirSync(directory, { recursive: true }); fs.mkdirSync(directory, { recursive: true });
} }
@@ -69,7 +66,7 @@ export const installApp = async (opts: InstallAppOpts) => {
console.log('installDeps error, [need manual install deps]', e); console.log('installDeps error, [need manual install deps]', e);
} }
} }
return installAppFromKey(key); return installAppFromKey(appKey);
}; };
export const checkPnpm = () => { export const checkPnpm = () => {

View File

@@ -32,6 +32,8 @@ export const installAppFromKey = async (key: string) => {
// //
entry: app?.entry || '', entry: app?.entry || '',
path: directory, path: directory,
engine: app?.engine,
pm2Options: app?.pm2Options || {},
origin: app, origin: app,
}; };
app.key = key; app.key = key;