From 169827b211933de0bdfd72178a0286f94f203dd5 Mon Sep 17 00:00:00 2001 From: xion Date: Sun, 16 Feb 2025 03:10:50 +0800 Subject: [PATCH] feat: add loginType and deploy load sever --- package.json | 2 +- src/command/deploy.ts | 38 +++++++++++++++++++++++++++++++++++++- src/command/init.ts | 2 +- src/query/user/login.ts | 2 ++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b7b6d9a..03cf1f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/envision-cli", - "version": "0.0.14", + "version": "0.0.15", "description": "envision command tools", "main": "dist/index.js", "type": "module", diff --git a/src/command/deploy.ts b/src/command/deploy.ts index b666bf8..6dfea8f 100644 --- a/src/command/deploy.ts +++ b/src/command/deploy.ts @@ -16,9 +16,10 @@ const command = new Command('deploy') .option('-v, --version ', 'verbose') .option('-k, --key ', 'key') .option('-y, --yes ', 'yes') + .option('-u, --update', 'load current app. set current version in product') .action(async (filePath, options) => { try { - let { version, key, yes } = options; + let { version, key, yes, update } = options; if (!version || !key) { const answers = await inquirer.prompt([ { @@ -64,6 +65,15 @@ const command = new Command('deploy') res.data?.data?.files?.map?.((d) => { console.log('uploaded file', d?.name, d?.path); }); + const { id, data, ...rest } = res.data || {}; + if (id && !update) { + console.log(chalk.green('id: '), id); + console.log(chalk.green(`run to load: envision deploy-load ${id}`)); + } else if (id && update) { + deployLoadFn(id); + } else { + console.log('rest', JSON.stringify(rest, null, 2)); + } } else { console.error('File upload failed', res?.message); } @@ -125,6 +135,32 @@ const uploadFiles = async (files: string[], directory: string, { key, version }: }; app.addCommand(command); +const deployLoadFn = async (id: string) => { + if (!id) { + console.error(chalk.red('id is required')); + return; + } + const res = await query.post({ + path: 'app', + key: 'publish', + data: { + id: id, + }, + }); + if (res.code === 200) { + console.log('deploy-load success. current version:', res.data?.version); + } else { + console.error('deploy-load failed', res.message); + } +}; +const deployLoad = new Command('deploy-load') + .description('部署加载') + .argument('', 'id') + .action(async (id) => { + deployLoadFn(id); + }); +app.addCommand(deployLoad); + const local = new Command('local') .description('本地部署') .argument('', 'key') diff --git a/src/command/init.ts b/src/command/init.ts index 07e5000..39d6531 100644 --- a/src/command/init.ts +++ b/src/command/init.ts @@ -124,7 +124,7 @@ const mainApp = new Command('main') if (options.init) { await initMain(); return; - } else { + } else if (!options.start && !options.restart && !options.exit && !options.pm2) { console.warn(chalk.yellow('请使用 --init 初始化 main 应用')); } const runChild = () => { diff --git a/src/query/user/login.ts b/src/query/user/login.ts index 8943c93..7677079 100644 --- a/src/query/user/login.ts +++ b/src/query/user/login.ts @@ -7,6 +7,7 @@ export const queryLogin = async (username: string, password: string) => { payload: { username, password, + loginType: 'plugin', }, }); }; @@ -23,6 +24,7 @@ export const switchOrg = async (username) => { path: 'user', key: 'switchOrg', data: { + loginType: 'plugin', username, }, });