diff --git a/package.json b/package.json index fe2ea7f..47ece92 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/command/app/micro-app/index.ts b/src/command/app/micro-app/index.ts index 592832b..239ca72 100644 --- a/src/command/app/micro-app/index.ts +++ b/src/command/app/micro-app/index.ts @@ -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) { @@ -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({ diff --git a/src/command/ls-token.ts b/src/command/ls-token.ts index 0a85186..2024a5c 100644 --- a/src/command/ls-token.ts +++ b/src/command/ls-token.ts @@ -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); diff --git a/src/uitls/file.ts b/src/uitls/file.ts index 171158f..26e6b33 100644 --- a/src/uitls/file.ts +++ b/src/uitls/file.ts @@ -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;