fix: deploy -d filename or directory

This commit is contained in:
熊潇 2025-02-20 21:35:17 +08:00
parent 2d496917ab
commit ce84ab4902
2 changed files with 25 additions and 18 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@kevisual/envision-cli", "name": "@kevisual/envision-cli",
"version": "0.0.18", "version": "0.0.19",
"description": "envision command tools", "description": "envision command tools",
"main": "dist/index.js", "main": "dist/index.js",
"type": "module", "type": "module",

View File

@ -12,7 +12,7 @@ import { installDeps } from '@/uitls/npm.ts';
const command = new Command('deploy') const command = new Command('deploy')
.description('把前端文件传到服务器') .description('把前端文件传到服务器')
.argument('<filePath>', 'Path to the file to be uploaded') // 定义文件路径参数 .argument('<filePath>', 'Path to the file to be uploaded, filepath or directory') // 定义文件路径参数
.option('-v, --version <version>', 'verbose') .option('-v, --version <version>', 'verbose')
.option('-k, --key <key>', 'key') .option('-k, --key <key>', 'key')
.option('-y, --yes <yes>', 'yes') .option('-y, --yes <yes>', 'yes')
@ -40,23 +40,30 @@ const command = new Command('deploy')
} }
const pwd = process.cwd(); const pwd = process.cwd();
const directory = path.join(pwd, filePath); const directory = path.join(pwd, filePath);
const gPath = path.join(directory, '**/*'); // 获取directory如果是文件夹获取文件夹下所有文件如果是文件获取文件
const files = await glob(gPath, { cwd: pwd, ignore: ['node_modules/**/*'], onlyFiles: true }); const stat = fs.statSync(directory);
const _relativeFiles = files.map((file) => path.relative(directory, file)); let _relativeFiles = [];
console.log('upload Files', _relativeFiles); if (stat.isDirectory()) {
console.log('upload Files Key', key, version); const gPath = path.join(directory, '**/*');
if (!yes) { const files = await glob(gPath, { cwd: pwd, ignore: ['node_modules/**/*'], onlyFiles: true });
// 确认是否上传 _relativeFiles = files.map((file) => path.relative(directory, file));
const confirm = await inquirer.prompt([ console.log('upload Files', _relativeFiles);
{ console.log('upload Files Key', key, version);
type: 'confirm', if (!yes) {
name: 'confirm', // 确认是否上传
message: 'Do you want to upload these files?', const confirm = await inquirer.prompt([
}, {
]); type: 'confirm',
if (!confirm.confirm) { name: 'confirm',
return; 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 }); const res = await uploadFiles(_relativeFiles, directory, { key, version });