This commit is contained in:
2025-06-19 00:07:18 +08:00
parent b239dae9e3
commit 3c0cb64478
3 changed files with 365 additions and 159 deletions

View File

@@ -17,7 +17,7 @@ import { logger } from '@/module/logger.ts';
* 获取package.json 中的 basename, version, user, appKey
* @returns
*/
export const getPackageJson = () => {
export const getPackageJson = (opts?: { version?: string; appKey?: string }) => {
const filePath = path.join(process.cwd(), 'package.json');
if (!fs.existsSync(filePath)) {
return null;
@@ -28,12 +28,12 @@ export const getPackageJson = () => {
const version = packageJson.version || '';
const app = packageJson.app as { key: string };
const userAppArry = basename.split('/');
if (userAppArry.length <= 2) {
if (userAppArry.length <= 2 && !opts?.appKey) {
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, app };
return { basename, version, pkg: packageJson, user, appKey: appKey || opts?.appKey, app };
} catch (error) {
return null;
}
@@ -56,7 +56,7 @@ const command = new Command('deploy')
const noCheck = !options.noCheck;
const dot = !!options.dot;
// 获取当前目录是否存在package.json, 如果有从package.json 获取 version 和basename
const pkgInfo = getPackageJson();
const pkgInfo = getPackageJson({ version, appKey: key });
if (!version && pkgInfo?.version) {
version = pkgInfo?.version || '';
}