fix(deploy): set default version to 1.0.0 and generate key using nanoid; remove confirmation prompt
This commit is contained in:
@@ -4,13 +4,15 @@ import path from 'path';
|
||||
import fs from 'fs';
|
||||
import FormData from 'form-data';
|
||||
import { getBaseURL, query, storage } from '@/module/query.ts';
|
||||
import { input, confirm } from '@inquirer/prompts';
|
||||
import { confirm } from '@inquirer/prompts';
|
||||
import chalk from 'chalk';
|
||||
import { upload } from '@/module/download/upload.ts';
|
||||
import { getBufferHash, getHash } from '@/uitls/hash.ts';
|
||||
import { getHash } from '@/uitls/hash.ts';
|
||||
import { queryAppVersion } from '@/query/app-manager/query-app.ts';
|
||||
import { logger } from '@/module/logger.ts';
|
||||
import { getUsername } from './login.ts';
|
||||
import { customAlphabet } from 'nanoid';
|
||||
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 8);
|
||||
/**
|
||||
* 获取package.json 中的 basename, version, user, appKey
|
||||
* @returns
|
||||
@@ -23,7 +25,7 @@ export const getPackageJson = (opts?: { version?: string; appKey?: string }) =>
|
||||
try {
|
||||
const packageJson = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
||||
const basename = packageJson.basename || '';
|
||||
const version = packageJson.version || '';
|
||||
const version = packageJson.version || '1.0.0';
|
||||
const app = packageJson.app;
|
||||
const userAppArry = basename.split('/');
|
||||
if (userAppArry.length <= 2 && !opts?.appKey) {
|
||||
@@ -41,7 +43,7 @@ const command = new Command('deploy')
|
||||
.argument('<filePath>', 'Path to the file to be uploaded, filepath or directory') // 定义文件路径参数
|
||||
.option('-v, --version <version>', 'verbose')
|
||||
.option('-k, --key <key>', 'key')
|
||||
.option('-y, --yes <yes>', 'yes')
|
||||
.option('-y, --yes <yes>', 'yes 已经去除')
|
||||
.option('-o, --org <org>', 'org')
|
||||
.option('-u, --update', 'load current app. set current version in product。 redis 缓存更新')
|
||||
.option('-s, --showBackend', 'show backend url, 部署的后端应用,显示执行的cli命令')
|
||||
@@ -49,25 +51,21 @@ const command = new Command('deploy')
|
||||
.option('--dir, --directory <directory>', '上传的prefix路径,默认为空,例如设置为static,则会上传到/${username}/resources/${key}/${version}/static/路径下')
|
||||
.action(async (filePath, options) => {
|
||||
try {
|
||||
let { version, key, yes, update, org, showBackend } = options;
|
||||
let { version, key, update, org, showBackend } = options;
|
||||
const dot = !!options.dot;
|
||||
const pkgInfo = getPackageJson({ version, appKey: key });
|
||||
if (!version && pkgInfo?.version) {
|
||||
version = pkgInfo?.version || '';
|
||||
version = pkgInfo?.version || '1.0.0';
|
||||
}
|
||||
if (!key && pkgInfo?.appKey) {
|
||||
key = pkgInfo?.appKey || '';
|
||||
}
|
||||
logger.debug('start deploy');
|
||||
if (!version) {
|
||||
version = await input({
|
||||
message: 'Enter your version:',
|
||||
});
|
||||
version = '1.0.0';
|
||||
}
|
||||
if (!key) {
|
||||
key = await input({
|
||||
message: 'Enter your key:',
|
||||
});
|
||||
key = nanoid(8);
|
||||
}
|
||||
const pwd = process.cwd();
|
||||
const directory = path.join(pwd, filePath);
|
||||
@@ -99,15 +97,6 @@ const command = new Command('deploy')
|
||||
}
|
||||
logger.debug('upload Files', _relativeFiles);
|
||||
logger.debug('upload Files Key', key, version);
|
||||
if (!yes) {
|
||||
// 确认是否上传
|
||||
const confirmed = await confirm({
|
||||
message: 'Do you want to upload these files?',
|
||||
});
|
||||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
let username = '';
|
||||
if (pkgInfo?.user) {
|
||||
username = pkgInfo.user;
|
||||
|
||||
Reference in New Issue
Block a user