feat: add loginType and deploy load sever

This commit is contained in:
熊潇 2025-02-16 03:10:50 +08:00
parent b631ff4a09
commit 169827b211
4 changed files with 41 additions and 3 deletions

View File

@ -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",

View File

@ -16,9 +16,10 @@ const command = new Command('deploy')
.option('-v, --version <version>', 'verbose')
.option('-k, --key <key>', 'key')
.option('-y, --yes <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>', 'id')
.action(async (id) => {
deployLoadFn(id);
});
app.addCommand(deployLoad);
const local = new Command('local')
.description('本地部署')
.argument('<key>', 'key')

View File

@ -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 = () => {

View File

@ -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,
},
});