feat: add loginType and deploy load sever
This commit is contained in:
		| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "@kevisual/envision-cli", |   "name": "@kevisual/envision-cli", | ||||||
|   "version": "0.0.14", |   "version": "0.0.15", | ||||||
|   "description": "envision command tools", |   "description": "envision command tools", | ||||||
|   "main": "dist/index.js", |   "main": "dist/index.js", | ||||||
|   "type": "module", |   "type": "module", | ||||||
|   | |||||||
| @@ -16,9 +16,10 @@ const command = new Command('deploy') | |||||||
|   .option('-v, --version <version>', 'verbose') |   .option('-v, --version <version>', 'verbose') | ||||||
|   .option('-k, --key <key>', 'key') |   .option('-k, --key <key>', 'key') | ||||||
|   .option('-y, --yes <yes>', 'yes') |   .option('-y, --yes <yes>', 'yes') | ||||||
|  |   .option('-u, --update', 'load current app. set current version in product') | ||||||
|   .action(async (filePath, options) => { |   .action(async (filePath, options) => { | ||||||
|     try { |     try { | ||||||
|       let { version, key, yes } = options; |       let { version, key, yes, update } = options; | ||||||
|       if (!version || !key) { |       if (!version || !key) { | ||||||
|         const answers = await inquirer.prompt([ |         const answers = await inquirer.prompt([ | ||||||
|           { |           { | ||||||
| @@ -64,6 +65,15 @@ const command = new Command('deploy') | |||||||
|         res.data?.data?.files?.map?.((d) => { |         res.data?.data?.files?.map?.((d) => { | ||||||
|           console.log('uploaded file', d?.name, d?.path); |           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 { |       } else { | ||||||
|         console.error('File upload failed', res?.message); |         console.error('File upload failed', res?.message); | ||||||
|       } |       } | ||||||
| @@ -125,6 +135,32 @@ const uploadFiles = async (files: string[], directory: string, { key, version }: | |||||||
| }; | }; | ||||||
| app.addCommand(command); | 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') | const local = new Command('local') | ||||||
|   .description('本地部署') |   .description('本地部署') | ||||||
|   .argument('<key>', 'key') |   .argument('<key>', 'key') | ||||||
|   | |||||||
| @@ -124,7 +124,7 @@ const mainApp = new Command('main') | |||||||
|     if (options.init) { |     if (options.init) { | ||||||
|       await initMain(); |       await initMain(); | ||||||
|       return; |       return; | ||||||
|     } else { |     } else if (!options.start && !options.restart && !options.exit && !options.pm2) { | ||||||
|       console.warn(chalk.yellow('请使用 --init 初始化 main 应用')); |       console.warn(chalk.yellow('请使用 --init 初始化 main 应用')); | ||||||
|     } |     } | ||||||
|     const runChild = () => { |     const runChild = () => { | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ export const queryLogin = async (username: string, password: string) => { | |||||||
|     payload: { |     payload: { | ||||||
|       username, |       username, | ||||||
|       password, |       password, | ||||||
|  |       loginType: 'plugin', | ||||||
|     }, |     }, | ||||||
|   }); |   }); | ||||||
| }; | }; | ||||||
| @@ -23,6 +24,7 @@ export const switchOrg = async (username) => { | |||||||
|     path: 'user', |     path: 'user', | ||||||
|     key: 'switchOrg', |     key: 'switchOrg', | ||||||
|     data: { |     data: { | ||||||
|  |       loginType: 'plugin', | ||||||
|       username, |       username, | ||||||
|     }, |     }, | ||||||
|   }); |   }); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user