feat: update ev cli
This commit is contained in:
		| @@ -21,3 +21,4 @@ export const app = new App({ | |||||||
|     httpsKey: httpsPem.key, |     httpsKey: httpsPem.key, | ||||||
|   }, |   }, | ||||||
| }); | }); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -93,7 +93,7 @@ const pageListCommand = new Command('page-list') | |||||||
|   .action(async (opts) => { |   .action(async (opts) => { | ||||||
|     const manager = new AssistantApp(assistantConfig); |     const manager = new AssistantApp(assistantConfig); | ||||||
|     await manager.loadConfig(); |     await manager.loadConfig(); | ||||||
|     const showInfos = manager.pageList(); |     const showInfos = await manager.pageList(); | ||||||
|     if (opts.all) { |     if (opts.all) { | ||||||
|       console.log('Installed Pages:', showInfos); |       console.log('Installed Pages:', showInfos); | ||||||
|     } else { |     } else { | ||||||
|   | |||||||
| @@ -1,3 +1,4 @@ | |||||||
|  | import { logger } from '@/module/logger.ts'; | ||||||
| import { program, Command, assistantConfig } from '@/program.ts'; | import { program, Command, assistantConfig } from '@/program.ts'; | ||||||
| import { AppDownload } from '@/services/app/index.ts'; | import { AppDownload } from '@/services/app/index.ts'; | ||||||
|  |  | ||||||
| @@ -17,9 +18,12 @@ const downloadCommand = new Command('download') | |||||||
|     const registry = options.registry || assistantConfig.getRegistry(); |     const registry = options.registry || assistantConfig.getRegistry(); | ||||||
|     // console.log('registry', registry); |     // console.log('registry', registry); | ||||||
|     const app = new AppDownload(assistantConfig); |     const app = new AppDownload(assistantConfig); | ||||||
|  |     let info = ''; | ||||||
|     if (id) { |     if (id) { | ||||||
|       await app.downloadApp({ id, type, registry, force, yes }); |       const msg = await app.downloadApp({ id, type, registry, force, yes }); | ||||||
|  |       info = String(msg); | ||||||
|     } |     } | ||||||
|  |     logger.debug(info); | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
| appManagerCommand.addCommand(downloadCommand); | appManagerCommand.addCommand(downloadCommand); | ||||||
| @@ -31,8 +35,11 @@ const deleteCommand = new Command('delete') | |||||||
|   .action(async (options) => { |   .action(async (options) => { | ||||||
|     const { id, type } = options; |     const { id, type } = options; | ||||||
|     const app = new AppDownload(assistantConfig); |     const app = new AppDownload(assistantConfig); | ||||||
|  |     let info = ''; | ||||||
|     if (id) { |     if (id) { | ||||||
|       await app.deleteApp({ id, type }); |       const msg = await app.deleteApp({ id, type }); | ||||||
|  |       info = String(msg); | ||||||
|     } |     } | ||||||
|  |     logger.debug(info); | ||||||
|   }); |   }); | ||||||
| appManagerCommand.addCommand(deleteCommand); | appManagerCommand.addCommand(deleteCommand); | ||||||
|   | |||||||
| @@ -22,8 +22,8 @@ export class AssistantApp extends Manager { | |||||||
|     this.pagesPath = pagesPath; |     this.pagesPath = pagesPath; | ||||||
|     this.config = config; |     this.config = config; | ||||||
|   } |   } | ||||||
|   pageList() { |   async pageList() { | ||||||
|     const pages = glob.sync('*/*/package.json', { |     const pages = await glob(['*/*/package.json'], { | ||||||
|       cwd: this.pagesPath, |       cwd: this.pagesPath, | ||||||
|       onlyFiles: true, |       onlyFiles: true, | ||||||
|     }); |     }); | ||||||
| @@ -35,9 +35,32 @@ export class AssistantApp extends Manager { | |||||||
|         user, |         user, | ||||||
|         app, |         app, | ||||||
|         version: content?.version, |         version: content?.version, | ||||||
|  |         title: content?.title || '', | ||||||
|  |         description: content?.description || '', | ||||||
|         content, |         content, | ||||||
|       }; |       }; | ||||||
|     }); |     }); | ||||||
|     return pagesParse; |     return pagesParse; | ||||||
|   } |   } | ||||||
|  |   async getPageAndAppList() { | ||||||
|  |     const root = this.config.configPath.configDir; | ||||||
|  |     const pages = await glob([root + '/apps/*/package.json', root + '/pages/*/*/package.json'], { | ||||||
|  |       cwd: root, | ||||||
|  |       onlyFiles: true, | ||||||
|  |     }); | ||||||
|  |     const pagesParse = pages.map((page) => { | ||||||
|  |       const relativePath = path.relative(root, page); | ||||||
|  |       const contentStr = fs.readFileSync(path.join(page), 'utf-8'); | ||||||
|  |       const content = parseIfJson(contentStr); | ||||||
|  |       if (!content.appType) { | ||||||
|  |         const isWeb = relativePath.startsWith('pages/'); | ||||||
|  |         content.appType = isWeb ? 'web' : 'app'; | ||||||
|  |       } | ||||||
|  |       return { | ||||||
|  |         ...content, | ||||||
|  |         filepath: relativePath, | ||||||
|  |       }; | ||||||
|  |     }); | ||||||
|  |     return pagesParse; | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| import { Logger } from '@kevisual/logger'; | import { Logger } from '@kevisual/logger'; | ||||||
| const level = process.env.LOG_LEVEL || 'info'; | const level = process.env.LOG_LEVEL || 'info'; | ||||||
| const logger = new Logger({ level: level as any }); | export const logger = new Logger({ level: level as any }); | ||||||
|  |  | ||||||
| export const console = { | export const console = { | ||||||
|   log: logger.info, |   log: logger.info, | ||||||
|   | |||||||
| @@ -11,3 +11,13 @@ app | |||||||
|     // |     // | ||||||
|   }) |   }) | ||||||
|   .addTo(app); |   .addTo(app); | ||||||
|  |  | ||||||
|  | app | ||||||
|  |   .route({ | ||||||
|  |     path: 'client', | ||||||
|  |     key: 'version', | ||||||
|  |   }) | ||||||
|  |   .define(async (ctx) => { | ||||||
|  |     ctx.body = 'v1.0.0'; | ||||||
|  |   }) | ||||||
|  |   .addTo(app); | ||||||
|   | |||||||
							
								
								
									
										27
									
								
								assistant/src/routes/shop-install/define.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								assistant/src/routes/shop-install/define.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | |||||||
|  | import { QueryUtil } from '@kevisual/router/define'; | ||||||
|  |  | ||||||
|  | export const shopDefine = QueryUtil.create({ | ||||||
|  |   getRegistry: { | ||||||
|  |     path: 'shop', | ||||||
|  |     key: 'get-registry', | ||||||
|  |     description: '获取应用商店注册表信息', | ||||||
|  |   }, | ||||||
|  |  | ||||||
|  |   listInstalled: { | ||||||
|  |     path: 'shop', | ||||||
|  |     key: 'list-installed', | ||||||
|  |     description: '列出当前已安装的所有应用', | ||||||
|  |   }, | ||||||
|  |  | ||||||
|  |   install: { | ||||||
|  |     path: 'shop', | ||||||
|  |     key: 'install', | ||||||
|  |     description: '安装指定的应用,可以指定 id、type、force 和 yes 参数', | ||||||
|  |   }, | ||||||
|  |  | ||||||
|  |   uninstall: { | ||||||
|  |     path: 'shop', | ||||||
|  |     key: 'uninstall', | ||||||
|  |     description: '卸载指定的应用,可以指定 id 和 type 参数', | ||||||
|  |   }, | ||||||
|  | }); | ||||||
| @@ -1,64 +1,69 @@ | |||||||
| import { app } from '@/app.ts'; | import { app, assistantConfig } from '@/app.ts'; | ||||||
| // import { getInstallList, installApp, uninstallApp } from '@/modules/install.ts'; | import { AppDownload } from '@/services/app/index.ts'; | ||||||
| const getInstallList = async () => { | import { AssistantApp } from '@/module/assistant/index.ts'; | ||||||
|   return []; | import { shopDefine } from './define.ts'; | ||||||
| }; |  | ||||||
| const installApp = async (pkg: string) => { |  | ||||||
|   return { |  | ||||||
|     code: 200, |  | ||||||
|     message: 'success', |  | ||||||
|     data: { |  | ||||||
|       pkg, |  | ||||||
|     }, |  | ||||||
|   }; |  | ||||||
| }; |  | ||||||
| const uninstallApp = async (pkg: string) => { |  | ||||||
|   return { |  | ||||||
|     code: 200, |  | ||||||
|     message: 'success', |  | ||||||
|   }; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| app | app | ||||||
|   .route({ |   .route({ | ||||||
|     path: 'shop', |     ...shopDefine.get('getRegistry'), | ||||||
|     key: 'list-installed', |  | ||||||
|     middleware: ['auth'], |     middleware: ['auth'], | ||||||
|   }) |   }) | ||||||
|   .define(async (ctx) => { |   .define(async (ctx) => { | ||||||
|     // https://localhost:51015/client/router?path=shop&key=list-installed |     const registry = assistantConfig.getRegistry(); | ||||||
|     const list = await getInstallList(); |     assistantConfig.checkMounted(); | ||||||
|     ctx.body = list; |     ctx.body = registry; | ||||||
|   }) |   }) | ||||||
|   .addTo(app); |   .addTo(app); | ||||||
|  |  | ||||||
| app | app | ||||||
|   .route({ |   .route({ | ||||||
|     path: 'shop', |     ...shopDefine.get('listInstalled'), | ||||||
|     key: 'install', |     middleware: ['auth'], | ||||||
|  |   }) | ||||||
|  |   .define(async (ctx) => { | ||||||
|  |     const manager = new AssistantApp(assistantConfig); | ||||||
|  |     await manager.loadConfig(); | ||||||
|  |     const data = await manager.getPageAndAppList(); | ||||||
|  |     ctx.body = data; | ||||||
|  |   }) | ||||||
|  |   .addTo(app); | ||||||
|  |  | ||||||
|  | app | ||||||
|  |   .route({ | ||||||
|  |     ...shopDefine.get('install'), | ||||||
|     middleware: ['auth'], |     middleware: ['auth'], | ||||||
|   }) |   }) | ||||||
|   .define(async (ctx) => { |   .define(async (ctx) => { | ||||||
|     // https://localhost:51015/client/router?path=shop&key=install |     // https://localhost:51015/client/router?path=shop&key=install | ||||||
|     const { pkg } = ctx.query.data; |     const options = ctx.query?.data || {}; | ||||||
|     const res = await installApp(pkg); |     const { id, type, force, yes } = options; | ||||||
|     if (res.code !== 200) { |     assistantConfig.checkMounted(); | ||||||
|       ctx.throw(res.code, res.message); |     const registry = options.registry || assistantConfig.getRegistry(); | ||||||
|  |     // console.log('registry', registry); | ||||||
|  |     const app = new AppDownload(assistantConfig); | ||||||
|  |     let info = ''; | ||||||
|  |     if (id) { | ||||||
|  |       const msg = await app.downloadApp({ id, type, registry, force, yes }); | ||||||
|  |       info = String(msg); | ||||||
|     } |     } | ||||||
|     ctx.body = res; |     ctx.body = { info }; | ||||||
|   }) |   }) | ||||||
|   .addTo(app); |   .addTo(app); | ||||||
|  |  | ||||||
| app | app | ||||||
|   .route({ |   .route({ | ||||||
|     path: 'shop', |     ...shopDefine.get('uninstall'), | ||||||
|     key: 'uninstall', |  | ||||||
|     middleware: ['auth'], |     middleware: ['auth'], | ||||||
|   }) |   }) | ||||||
|   .define(async (ctx) => { |   .define(async (ctx) => { | ||||||
|     // https://localhost:51015/client/router?path=shop&key=uninstall |     // https://localhost:51015/client/router?path=shop&key=uninstall | ||||||
|     const { pkg } = ctx.query.data; |     const options = ctx.query?.data || {}; | ||||||
|     const res = await uninstallApp(pkg); |     const { id, type, yes } = options; | ||||||
|     ctx.body = res; |     const app = new AppDownload(assistantConfig); | ||||||
|  |     let info = ''; | ||||||
|  |     if (id) { | ||||||
|  |       const msg = await app.deleteApp({ id, type, yes }); | ||||||
|  |       info = String(msg); | ||||||
|  |     } | ||||||
|  |     ctx.body = { info }; | ||||||
|   }) |   }) | ||||||
|   .addTo(app); |   .addTo(app); | ||||||
|   | |||||||
| @@ -48,14 +48,19 @@ type DeleteAppOptions = { | |||||||
|   id: string; |   id: string; | ||||||
|   type?: appType; |   type?: appType; | ||||||
|   appName?: string; |   appName?: string; | ||||||
|  |   yes?: boolean; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| export class AppDownload { | export class AppDownload { | ||||||
|   config: AssistantConfig; |   config: AssistantConfig; | ||||||
|   constructor(config: AssistantConfig) { |   constructor(config: AssistantConfig) { | ||||||
|     this.config = config; |     this.config = config; | ||||||
|   } |   } | ||||||
|  |   async getRegistry() { | ||||||
|  |     return this.config.getRegistry(); | ||||||
|  |   } | ||||||
|   async downloadApp(opts: DownloadAppOptions) { |   async downloadApp(opts: DownloadAppOptions) { | ||||||
|     const { id, type = 'web', force } = opts; |     const { id, type = 'web', force, yes } = opts; | ||||||
|     const configDir = this.config.configDir; |     const configDir = this.config.configDir; | ||||||
|     this.config?.checkMounted(); |     this.config?.checkMounted(); | ||||||
|     const appsDir = this.config.configPath?.appsDir; |     const appsDir = this.config.configPath?.appsDir; | ||||||
| @@ -100,7 +105,7 @@ export class AppDownload { | |||||||
|     return confirm; |     return confirm; | ||||||
|   } |   } | ||||||
|   async deleteApp(opts: DeleteAppOptions) { |   async deleteApp(opts: DeleteAppOptions) { | ||||||
|     const { id, type = 'web' } = opts; |     const { id, type = 'web', yes = false } = opts; | ||||||
|     const appName = opts?.appName || id.split('/').pop(); |     const appName = opts?.appName || id.split('/').pop(); | ||||||
|     this.config?.checkMounted(); |     this.config?.checkMounted(); | ||||||
|     const appsDir = this.config.configPath?.appsDir; |     const appsDir = this.config.configPath?.appsDir; | ||||||
| @@ -119,10 +124,12 @@ export class AppDownload { | |||||||
|       deletePath = appPath; |       deletePath = appPath; | ||||||
|     } |     } | ||||||
|     if (deletePath && checkFileExists(deletePath)) { |     if (deletePath && checkFileExists(deletePath)) { | ||||||
|       const confirm = await this.confirm(`是否删除 ${deletePath} 应用?`); |       if (!yes) { | ||||||
|       if (!confirm) { |         const confirm = await this.confirm(`是否删除 ${deletePath} 应用?`); | ||||||
|         console.log('取消删除应用'); |         if (!confirm) { | ||||||
|         return; |           console.log('取消删除应用'); | ||||||
|  |           return; | ||||||
|  |         } | ||||||
|       } |       } | ||||||
|       fs.rmSync(deletePath, { recursive: true }); |       fs.rmSync(deletePath, { recursive: true }); | ||||||
|       isDelete = true; |       isDelete = true; | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ import { fileProxy, httpProxy, createApiProxy, wsProxy } from '@/module/assistan | |||||||
| import http from 'http'; | import http from 'http'; | ||||||
| import { LocalProxy } from './local-proxy.ts'; | import { LocalProxy } from './local-proxy.ts'; | ||||||
| import { assistantConfig, app } from '@/app.ts'; | import { assistantConfig, app } from '@/app.ts'; | ||||||
| import { log } from '@/module/logger.ts'; | import { log, logger } from '@/module/logger.ts'; | ||||||
| const localProxy = new LocalProxy({ | const localProxy = new LocalProxy({ | ||||||
|   assistantConfig, |   assistantConfig, | ||||||
| }); | }); | ||||||
| @@ -21,6 +21,7 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp | |||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   if (pathname.startsWith('/client')) { |   if (pathname.startsWith('/client')) { | ||||||
|  |     logger.info('url', { url: req.url }); | ||||||
|     console.debug('handle by router'); |     console.debug('handle by router'); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
| @@ -74,7 +75,7 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp | |||||||
|       indexPath: localProxyProxy.indexPath, |       indexPath: localProxyProxy.indexPath, | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
|   const creatCenterProxy = createApiProxy(_assistantConfig?.pageApi || 'https://kevisual.cn', ['/root']); |   const creatCenterProxy = createApiProxy(_assistantConfig?.pageApi || 'https://kevisual.cn', ['/root', '/' + _user]); | ||||||
|   const centerProxy = creatCenterProxy.find((item) => pathname.startsWith(item.path)); |   const centerProxy = creatCenterProxy.find((item) => pathname.startsWith(item.path)); | ||||||
|   if (centerProxy) { |   if (centerProxy) { | ||||||
|     return httpProxy(req, res, { |     return httpProxy(req, res, { | ||||||
|   | |||||||
							
								
								
									
										12
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								package.json
									
									
									
									
									
								
							| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "@kevisual/envision-cli", |   "name": "@kevisual/envision-cli", | ||||||
|   "version": "0.0.49", |   "version": "0.0.51", | ||||||
|   "description": "envision command tools", |   "description": "envision command tools", | ||||||
|   "main": "dist/app.mjs", |   "main": "dist/app.mjs", | ||||||
|   "type": "module", |   "type": "module", | ||||||
| @@ -39,20 +39,20 @@ | |||||||
|   "author": "abearxiong", |   "author": "abearxiong", | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "micromatch": "^4.0.8", |     "micromatch": "^4.0.8", | ||||||
|     "pm2": "^6.0.5" |     "pm2": "^6.0.6" | ||||||
|   }, |   }, | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|     "@kevisual/load": "^0.0.6", |     "@kevisual/load": "^0.0.6", | ||||||
|     "@kevisual/logger": "^0.0.3", |     "@kevisual/logger": "^0.0.3", | ||||||
|     "@kevisual/query": "0.0.17", |     "@kevisual/query": "0.0.18", | ||||||
|     "@kevisual/query-login": "0.0.5", |     "@kevisual/query-login": "0.0.5", | ||||||
|     "@types/bun": "^1.2.13", |     "@types/bun": "^1.2.13", | ||||||
|     "@types/crypto-js": "^4.2.2", |     "@types/crypto-js": "^4.2.2", | ||||||
|     "@types/jsonwebtoken": "^9.0.9", |     "@types/jsonwebtoken": "^9.0.9", | ||||||
|     "@types/micromatch": "^4.0.9", |     "@types/micromatch": "^4.0.9", | ||||||
|     "@types/node": "^22.15.17", |     "@types/node": "^22.15.18", | ||||||
|     "chalk": "^5.4.1", |     "chalk": "^5.4.1", | ||||||
|     "commander": "^13.1.0", |     "commander": "^14.0.0", | ||||||
|     "crypto-js": "^4.2.0", |     "crypto-js": "^4.2.0", | ||||||
|     "fast-glob": "^3.3.3", |     "fast-glob": "^3.3.3", | ||||||
|     "filesize": "^10.1.6", |     "filesize": "^10.1.6", | ||||||
| @@ -60,7 +60,7 @@ | |||||||
|     "ignore": "^7.0.4", |     "ignore": "^7.0.4", | ||||||
|     "inquirer": "^12.6.1", |     "inquirer": "^12.6.1", | ||||||
|     "jsonwebtoken": "^9.0.2", |     "jsonwebtoken": "^9.0.2", | ||||||
|     "rollup": "^4.40.2", |     "rollup": "^4.41.0", | ||||||
|     "rollup-plugin-dts": "^6.2.1", |     "rollup-plugin-dts": "^6.2.1", | ||||||
|     "tar": "^7.4.3", |     "tar": "^7.4.3", | ||||||
|     "zustand": "^5.0.4" |     "zustand": "^5.0.4" | ||||||
|   | |||||||
							
								
								
									
										806
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										806
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -7,11 +7,18 @@ import { getConfig } from '@/module/get-config.ts'; | |||||||
| import fs from 'fs'; | import fs from 'fs'; | ||||||
| import inquirer from 'inquirer'; | import inquirer from 'inquirer'; | ||||||
| import { checkPnpm } from '@/uitls/npm.ts'; | import { checkPnpm } from '@/uitls/npm.ts'; | ||||||
|  | const parseIfJson = (str: string) => { | ||||||
|  |   try { | ||||||
|  |     return JSON.parse(str); | ||||||
|  |   } catch (e) { | ||||||
|  |     return {}; | ||||||
|  |   } | ||||||
|  | }; | ||||||
| const command = new Command('npm').description('npm command show publish and set .npmrc').action(async (options) => {}); | const command = new Command('npm').description('npm command show publish and set .npmrc').action(async (options) => {}); | ||||||
| const publish = new Command('publish') | const publish = new Command('publish') | ||||||
|   .argument('[registry]') |   .argument('[registry]') | ||||||
|   .option('-p --proxy', 'proxy') |   .option('-p --proxy', 'proxy') | ||||||
|  |   .option('-t, --tag', 'tag') | ||||||
|   .description('publish npm') |   .description('publish npm') | ||||||
|   .action(async (registry, options) => { |   .action(async (registry, options) => { | ||||||
|     const answer = await inquirer.prompt([ |     const answer = await inquirer.prompt([ | ||||||
| @@ -53,15 +60,12 @@ const publish = new Command('publish') | |||||||
|       switch (registry) { |       switch (registry) { | ||||||
|         case 'me': |         case 'me': | ||||||
|           cmd = 'npm publish --registry https://npm.xiongxiao.me'; |           cmd = 'npm publish --registry https://npm.xiongxiao.me'; | ||||||
|           console.log(chalk.green(cmd)); |  | ||||||
|           break; |           break; | ||||||
|         case 'npm': |         case 'npm': | ||||||
|           cmd = 'npm publish --registry https://registry.npmjs.org'; |           cmd = 'npm publish --registry https://registry.npmjs.org'; | ||||||
|           console.log(chalk.green(cmd)); |  | ||||||
|           break; |           break; | ||||||
|         default: |         default: | ||||||
|           cmd = 'npm publish --registry https://npm.xiongxiao.me'; |           cmd = 'npm publish --registry https://npm.xiongxiao.me'; | ||||||
|           console.log(chalk.green(cmd)); |  | ||||||
|           break; |           break; | ||||||
|       } |       } | ||||||
|       if (fileIsExist(packageJson)) { |       if (fileIsExist(packageJson)) { | ||||||
| @@ -72,6 +76,20 @@ const publish = new Command('publish') | |||||||
|             [key]: config[key], |             [key]: config[key], | ||||||
|           }; |           }; | ||||||
|         }, {}); |         }, {}); | ||||||
|  |         const pkg = fs.readFileSync(packageJson, 'utf-8'); | ||||||
|  |         const pkgJson = parseIfJson(pkg); | ||||||
|  |         const version = pkgJson?.version as string; | ||||||
|  |         if (version && options?.tag) { | ||||||
|  |           let tag = String(version).split('-')[1] || ''; | ||||||
|  |           if (tag) { | ||||||
|  |             if (tag.includes('.')) { | ||||||
|  |               tag = tag.split('.')[0]; | ||||||
|  |             } | ||||||
|  |             cmd = `${cmd} --tag ${tag}`; | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |         console.log(chalk.green(cmd)); | ||||||
|  |  | ||||||
|         const child = spawn(cmd, { |         const child = spawn(cmd, { | ||||||
|           shell: true, |           shell: true, | ||||||
|           cwd: execPath, |           cwd: execPath, | ||||||
|   | |||||||
| @@ -94,6 +94,29 @@ const checkDelete = async (opts?: { force?: boolean; dir?: string; yes?: boolean | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
| }; | }; | ||||||
|  | export const rewritePkg = (packagePath: string, pkg: Package) => { | ||||||
|  |   const readJsonFile = (filePath: string) => { | ||||||
|  |     try { | ||||||
|  |       return JSON.parse(fs.readFileSync(filePath, 'utf-8')); | ||||||
|  |     } catch (error) { | ||||||
|  |       return {}; | ||||||
|  |     } | ||||||
|  |   }; | ||||||
|  |   try { | ||||||
|  |     const dirname = path.dirname(packagePath); | ||||||
|  |     if (!fs.existsSync(dirname)) { | ||||||
|  |       fs.mkdirSync(dirname, { recursive: true }); | ||||||
|  |     } | ||||||
|  |     const json = readJsonFile(packagePath); | ||||||
|  |     json.id = pkg?.id; | ||||||
|  |     json.appInfo = pkg; | ||||||
|  |  | ||||||
|  |     fs.writeFileSync(packagePath, JSON.stringify(json, null, 2)); | ||||||
|  |   } catch (error) { | ||||||
|  |     fs.writeFileSync(packagePath, JSON.stringify({ appInfo: pkg, id: pkg?.id }, null, 2)); | ||||||
|  |   } | ||||||
|  |   return pkg; | ||||||
|  | }; | ||||||
| type InstallAppOpts = { | type InstallAppOpts = { | ||||||
|   appDir?: string; |   appDir?: string; | ||||||
|   kevisualUrl?: string; |   kevisualUrl?: string; | ||||||
| @@ -118,7 +141,6 @@ export const installApp = async (app: Package, opts: InstallAppOpts = {}) => { | |||||||
|   try { |   try { | ||||||
|     let files = _app.data.files || []; |     let files = _app.data.files || []; | ||||||
|     const version = _app.version; |     const version = _app.version; | ||||||
|     let hasPackage = false; |  | ||||||
|     const user = _app.user; |     const user = _app.user; | ||||||
|     const key = _app.key; |     const key = _app.key; | ||||||
|     const downloadDirPath = appType === 'web' ? path.join(appDir, user, key) : path.join(appDir); |     const downloadDirPath = appType === 'web' ? path.join(appDir, user, key) : path.join(appDir); | ||||||
| @@ -128,9 +150,6 @@ export const installApp = async (app: Package, opts: InstallAppOpts = {}) => { | |||||||
|       .filter((file: any) => file?.path) |       .filter((file: any) => file?.path) | ||||||
|       .map((file: any) => { |       .map((file: any) => { | ||||||
|         const name = file?.name || ''; |         const name = file?.name || ''; | ||||||
|         if (name.startsWith('package.json')) { |  | ||||||
|           hasPackage = true; |  | ||||||
|         } |  | ||||||
|         const noVersionPath = file.path.replace(`/${version}`, ''); |         const noVersionPath = file.path.replace(`/${version}`, ''); | ||||||
|         let downloadPath = noVersionPath; |         let downloadPath = noVersionPath; | ||||||
|         let downloadUrl = ''; |         let downloadUrl = ''; | ||||||
| @@ -150,15 +169,7 @@ export const installApp = async (app: Package, opts: InstallAppOpts = {}) => { | |||||||
|       }); |       }); | ||||||
|     const downloadTasks: DownloadTask[] = downFiles as any; |     const downloadTasks: DownloadTask[] = downFiles as any; | ||||||
|     console.log('downloadTasks', downloadTasks); |     console.log('downloadTasks', downloadTasks); | ||||||
|     if (!hasPackage) { |  | ||||||
|       console.log('没有package.json文件, 生成一个'); |  | ||||||
|       const pkg = { ..._app }; |  | ||||||
|       if (pkg.data) { |  | ||||||
|         delete pkg.data.permission; |  | ||||||
|       } |  | ||||||
|       fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2)); |  | ||||||
|     } |  | ||||||
|     // return; |  | ||||||
|     for (const file of downloadTasks) { |     for (const file of downloadTasks) { | ||||||
|       const downloadPath = file.downloadPath; |       const downloadPath = file.downloadPath; | ||||||
|       const downloadUrl = file.downloadUrl; |       const downloadUrl = file.downloadUrl; | ||||||
| @@ -186,6 +197,7 @@ export const installApp = async (app: Package, opts: InstallAppOpts = {}) => { | |||||||
|     //   fs.writeFileSync(path.join(appDir, `${user}/${key}/index.html`), JSON.stringify(app, null, 2)); |     //   fs.writeFileSync(path.join(appDir, `${user}/${key}/index.html`), JSON.stringify(app, null, 2)); | ||||||
|     // } |     // } | ||||||
|     _app.data.files = files; |     _app.data.files = files; | ||||||
|  |     rewritePkg(packagePath, _app); | ||||||
|     return { |     return { | ||||||
|       code: 200, |       code: 200, | ||||||
|       data: _app, |       data: _app, | ||||||
|   | |||||||
 Submodule submodules/kevisual-query-login updated: 557cd99b20...0a0ffbdb23
									
								
							
		Reference in New Issue
	
	Block a user