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