update download app show me

This commit is contained in:
2025-03-30 20:23:45 +08:00
parent be6d7091c3
commit aadd8266b1
8 changed files with 132 additions and 30 deletions

View File

@@ -9,6 +9,30 @@ import inquirer from 'inquirer';
import { packLib, unpackLib } from './publish.ts';
import chalk from 'chalk';
import { installDeps } from '@/uitls/npm.ts';
/**
* 获取package.json 中的 basename, version, user, appKey
* @returns
*/
export const getPackageJson = () => {
const filePath = path.join(process.cwd(), 'package.json');
if (!fs.existsSync(filePath)) {
return null;
}
try {
const packageJson = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
const basename = packageJson.basename || '';
const version = packageJson.version || '';
const userAppArry = basename.split('/');
if (userAppArry.length !== 2) {
console.error(chalk.red('basename is error, 请输入正确的路径, packages.json中basename例如 root/appKey'));
return null;
}
const [user, appKey] = userAppArry;
return { basename, version, pkg: packageJson, user, appKey };
} catch (error) {
return null;
}
};
const command = new Command('deploy')
.description('把前端文件传到服务器')
.argument('<filePath>', 'Path to the file to be uploaded, filepath or directory') // 定义文件路径参数
@@ -16,11 +40,19 @@ const command = new Command('deploy')
.option('-k, --key <key>', 'key')
.option('-y, --yes <yes>', 'yes')
.option('-o, --org <org>', 'org')
.option('-u, --update', 'load current app. set current version in product')
.option('-s, --showBackend', 'show backend url')
.option('-u, --update', 'load current app. set current version in product。 redis 缓存更新')
.option('-s, --showBackend', 'show backend url, 部署的后端应用显示执行的cli命令')
.action(async (filePath, options) => {
try {
let { version, key, yes, update, org, showBackend } = options;
// 获取当前目录是否存在package.json, 如果有从package.json 获取 version 和basename
const pkgInfo = getPackageJson();
if (!version && pkgInfo?.version) {
version = pkgInfo?.version || '';
}
if (!key && pkgInfo?.appKey) {
key = pkgInfo?.appKey || '';
}
if (!version || !key) {
const answers = await inquirer.prompt([
{