perf: 优化micro解压的-x参数
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "@kevisual/envision-cli", | ||||
|   "version": "0.0.29", | ||||
|   "version": "0.0.30", | ||||
|   "description": "envision command tools", | ||||
|   "main": "dist/index.js", | ||||
|   "type": "module", | ||||
|   | ||||
| @@ -8,6 +8,7 @@ import fs from 'fs'; | ||||
| import { Readable } from 'stream'; | ||||
| import * as tar from 'tar'; | ||||
| import path from 'path'; | ||||
| import { fileIsExist } from '@/uitls/file.ts'; | ||||
|  | ||||
| // Utility function to convert a web ReadableStream to a Node.js Readable stream | ||||
| function nodeReadableStreamFromWeb(webStream: ReadableStream<Uint8Array>) { | ||||
| @@ -74,6 +75,9 @@ const downloadAppCommand = new Command('download') | ||||
|           return; | ||||
|         } | ||||
|         const outputPath = options.output || filename; | ||||
|         if (!fileIsExist(outputPath)) { | ||||
|           fs.mkdirSync(path.dirname(outputPath), { recursive: true }); | ||||
|         } | ||||
|         const fileStream = fs.createWriteStream(outputPath); | ||||
|  | ||||
|         if (res.body) { | ||||
| @@ -84,6 +88,9 @@ const downloadAppCommand = new Command('download') | ||||
|             if (options.extract) { | ||||
|               console.log(chalk.green(`解压: ${outputPath}`)); | ||||
|               const extractPath = path.join(process.cwd(), options.extract || '.'); | ||||
|               if (!fileIsExist(extractPath)) { | ||||
|                 fs.mkdirSync(extractPath, { recursive: true }); | ||||
|               } | ||||
|               const fileInput = path.join(process.cwd(), outputPath); | ||||
|               tar | ||||
|                 .extract({ | ||||
|   | ||||
| @@ -131,6 +131,11 @@ const baseURL = new Command('baseURL') | ||||
|       setTokenList([]); | ||||
|       return; | ||||
|     } | ||||
|     if (!config.baseURL) { | ||||
|       config = getConfig(); | ||||
|       writeConfig({ ...config, baseURL: 'https://kevisual.xiongxiao.me' }); | ||||
|       config = getConfig(); | ||||
|     } | ||||
|     console.log('current baseURL:', config.baseURL); | ||||
|   }); | ||||
| app.addCommand(baseURL); | ||||
|   | ||||
| @@ -1,7 +1,11 @@ | ||||
| import fs from 'fs'; | ||||
| export const fileIsExist = (filePath: string) => { | ||||
| export const fileIsExist = (filePath: string, isFile = false) => { | ||||
|   try { | ||||
|     // 检查文件或者目录是否存在 | ||||
|     fs.accessSync(filePath, fs.constants.F_OK); | ||||
|     if (isFile) { | ||||
|       fs.accessSync(filePath, fs.constants.R_OK); | ||||
|     } | ||||
|     return true; | ||||
|   } catch (error) { | ||||
|     return false; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user