From ce84ab49029ebceceaf25703165a176ae01bcc6f Mon Sep 17 00:00:00 2001 From: xion Date: Thu, 20 Feb 2025 21:35:17 +0800 Subject: [PATCH] fix: deploy -d filename or directory --- package.json | 2 +- src/command/deploy.ts | 41 ++++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 035bfe1..323f995 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/envision-cli", - "version": "0.0.18", + "version": "0.0.19", "description": "envision command tools", "main": "dist/index.js", "type": "module", diff --git a/src/command/deploy.ts b/src/command/deploy.ts index 6dfea8f..1b748d4 100644 --- a/src/command/deploy.ts +++ b/src/command/deploy.ts @@ -12,7 +12,7 @@ import { installDeps } from '@/uitls/npm.ts'; const command = new Command('deploy') .description('把前端文件传到服务器') - .argument('', 'Path to the file to be uploaded') // 定义文件路径参数 + .argument('', 'Path to the file to be uploaded, filepath or directory') // 定义文件路径参数 .option('-v, --version ', 'verbose') .option('-k, --key ', 'key') .option('-y, --yes ', 'yes') @@ -40,23 +40,30 @@ const command = new Command('deploy') } const pwd = process.cwd(); const directory = path.join(pwd, filePath); - const gPath = path.join(directory, '**/*'); - const files = await glob(gPath, { cwd: pwd, ignore: ['node_modules/**/*'], onlyFiles: true }); - const _relativeFiles = files.map((file) => path.relative(directory, file)); - console.log('upload Files', _relativeFiles); - console.log('upload Files Key', key, version); - if (!yes) { - // 确认是否上传 - const confirm = await inquirer.prompt([ - { - type: 'confirm', - name: 'confirm', - message: 'Do you want to upload these files?', - }, - ]); - if (!confirm.confirm) { - return; + // 获取directory,如果是文件夹,获取文件夹下所有文件,如果是文件,获取文件 + const stat = fs.statSync(directory); + let _relativeFiles = []; + if (stat.isDirectory()) { + const gPath = path.join(directory, '**/*'); + const files = await glob(gPath, { cwd: pwd, ignore: ['node_modules/**/*'], onlyFiles: true }); + _relativeFiles = files.map((file) => path.relative(directory, file)); + console.log('upload Files', _relativeFiles); + console.log('upload Files Key', key, version); + if (!yes) { + // 确认是否上传 + const confirm = await inquirer.prompt([ + { + type: 'confirm', + name: 'confirm', + message: 'Do you want to upload these files?', + }, + ]); + if (!confirm.confirm) { + return; + } } + } else if (stat.isFile()) { + _relativeFiles = [path.relative(pwd, directory)]; } const res = await uploadFiles(_relativeFiles, directory, { key, version });