update: 优化部署

This commit is contained in:
熊潇 2025-06-18 22:42:39 +08:00
parent c021beb576
commit b239dae9e3
5 changed files with 32 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@kevisual/cli", "name": "@kevisual/cli",
"version": "0.0.56-beta.4", "version": "0.0.56",
"description": "envision command tools", "description": "envision command tools",
"main": "dist/app.mjs", "main": "dist/app.mjs",
"type": "module", "type": "module",

View File

@ -91,7 +91,7 @@ const command = new Command('deploy')
if (stat.isDirectory()) { if (stat.isDirectory()) {
isDirectory = true; isDirectory = true;
const gPath = path.join(directory, '**/*'); const gPath = path.join(directory, '**/*');
const files = await glob(gPath, { cwd: pwd, ignore: ['node_modules/**/*'], onlyFiles: true, dot }); const files = await glob(gPath, { cwd: pwd, ignore: ['node_modules/**/*', '.git/**/*', '.DS_Store'], onlyFiles: true, dot });
_relativeFiles = files.map((file) => path.relative(directory, file)); _relativeFiles = files.map((file) => path.relative(directory, file));
} else if (stat.isFile()) { } else if (stat.isFile()) {
const filename = path.basename(directory); const filename = path.basename(directory);

View File

@ -349,11 +349,26 @@ const deployLoadFn = async (id: string, fileKey: string, force = false, install
// devDependencies: [Object], // devDependencies: [Object],
// dependencies: [Object] // dependencies: [Object]
// }, // },
let appKey = '';
let version = '';
if (id && id.includes('/')) {
const [a, b] = id.split('/');
if (a) {
appKey = b || '1.0.0';
version = a;
id = '';
} else {
console.error(chalk.red('id format error, please use "version/appKey" format'));
return;
}
}
const res = await query.post({ const res = await query.post({
path: 'micro-app', path: 'micro-app',
key: 'deploy', key: 'deploy',
data: { data: {
id: id, id: id,
version: version,
appKey: appKey,
key: fileKey, key: fileKey,
force: force, force: force,
install: !!install, install: !!install,

View File

@ -20,7 +20,7 @@ const syncUpload = new Command('upload')
.option('-d --dir <dir>', '配置目录') .option('-d --dir <dir>', '配置目录')
.option('-c --config <config>', '配置文件的名字', 'kevisual.json') .option('-c --config <config>', '配置文件的名字', 'kevisual.json')
.option('-f --file <file>', '操作的对应的文件名') .option('-f --file <file>', '操作的对应的文件名')
.description('上传项目') .description('上传项目, 上传需要和registry的地址同步。')
.action(async (opts) => { .action(async (opts) => {
console.log('上传项目'); console.log('上传项目');
const sync = new SyncBase({ dir: opts.dir, baseURL: baseURL, configFilename: opts.config }); const sync = new SyncBase({ dir: opts.dir, baseURL: baseURL, configFilename: opts.config });
@ -32,6 +32,8 @@ const syncUpload = new Command('upload')
...sync.config.metadata, ...sync.config.metadata,
}; };
const filepath = sync.getRelativePath(opts.file); const filepath = sync.getRelativePath(opts.file);
const newInfos = [];
for (const item of syncList) { for (const item of syncList) {
if (!item.auth || !item.exist) { if (!item.auth || !item.exist) {
nodonwArr.push(item); nodonwArr.push(item);
@ -54,15 +56,22 @@ const syncUpload = new Command('upload')
}); });
if (res.code === 200) { if (res.code === 200) {
if (res.data?.isNew) { if (res.data?.isNew) {
logger.info('上传成功', item.key, chalk.green(item.url), chalk.green('文件上传')); newInfos.push(['上传成功', item.key, chalk.green(item.url), chalk.green('文件上传')]);
} else if (res.data?.isNewMeta) { } else if (res.data?.isNewMeta) {
logger.info('上传成功', item.key, chalk.green(item.url), chalk.green('元数据更新')); newInfos.push(['上传成功', item.key, chalk.green(item.url), chalk.green('元数据更新')]);
} else { } else {
// 文件未更新
logger.info('上传成功', item.key, chalk.green(item.url), chalk.blue('文件未更新')); logger.info('上传成功', item.key, chalk.green(item.url), chalk.blue('文件未更新'));
} }
} }
logger.debug(res); logger.debug(res);
} }
if (newInfos.length) {
logger.info('上传成功的文件\n');
newInfos.forEach((item) => {
logger.info(...item);
});
}
if (nodonwArr.length && !filepath) { if (nodonwArr.length && !filepath) {
logger.warn('以下文件未上传\n', nodonwArr.map((item) => item.key).join(',')); logger.warn('以下文件未上传\n', nodonwArr.map((item) => item.key).join(','));
} }

View File

@ -31,11 +31,12 @@ type Options = {
hash?: string; hash?: string;
[key: string]: any; [key: string]: any;
}; };
export const fetchLink = async (url: string, opts?: Options) => { export const fetchLink = async (url: string = '', opts?: Options) => {
const token = process.env.KEVISUAL_TOKEN || storage.getItem('token'); const token = process.env.KEVISUAL_TOKEN || storage.getItem('token');
const fetchURL = new URL(url); const fetchURL = new URL(url);
const check = opts?.check ?? false; const check = opts?.check ?? false;
const setToken = opts?.setToken ?? true; const isKevisual = !!url.includes('kevisual');
const setToken = opts?.setToken ?? isKevisual;
if (check) { if (check) {
if (!url.startsWith(baseURL)) { if (!url.startsWith(baseURL)) {
throw new Error('url must start with ' + baseURL); throw new Error('url must start with ' + baseURL);