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",
"version": "0.0.8",
"version": "0.0.9",
"description": "code center",
"type": "module",
"main": "index.js",
@@ -10,18 +10,21 @@
"type": "pm2-system-app",
"key": "code-center",
"entry": "./app.js",
"engine": "bun",
"runtime": [
"client"
]
],
"pm2Options": {
"interpreter": "bun"
}
},
"scripts": {
"test": "tsx test/**/*.ts",
"dev": "bun run --watch --hot src/index.ts",
"dev:inspect": "bun run --watch --hot --inspect src/index.ts",
"cmd": "bun run src/run.ts ",
"prebuild": "rimraf dist",
"prebuild": "rimraf dist && rimraf pack-dist",
"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:envision": "rsync -avz --delete ./pack-dist/ envision:~/kevisual/assistant-app/apps/root/code-center",
"clean": "rm -rf dist",

View File

@@ -18,7 +18,7 @@ app
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
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) {
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}`);
}
}
const { key: appKey, version } = microApp;
const check = await appPathCheck({ key: key });
const { version } = microApp;
const appKey = username + '/' + microApp.key;
const check = await appPathCheck({ appKey });
let appType: string;
if (check) {
if (!force) {
ctx.throw(400, 'App already exists, please remove it first');
} else {
const app = manager.getAppShowInfo(key);
const app = manager.getAppShowInfo(appKey);
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);
ctx.body = installAppData;
if (appType === 'system-app') {

View File

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

View File

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