fix: fix sync add config file name

This commit is contained in:
熊潇 2025-05-13 02:10:18 +08:00
parent 785bd7b004
commit f26bc59e29
3 changed files with 47 additions and 7 deletions

View File

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

View File

@ -4,6 +4,7 @@ import { Config, SyncList, SyncConfigType, SyncConfig } from './type.ts';
import { fileIsExist } from '@/uitls/file.ts';
import { getHash } from '@/uitls/hash.ts';
import glob from 'fast-glob';
import { logger } from '@/module/logger.ts';
export type SyncOptions = {
dir?: string;
@ -50,6 +51,12 @@ export class SyncBase {
if (syncType === 'sync') return true;
return syncType === type;
}
/**
*
* @param opts
* @param opts.getFile
* @returns
*/
async getSyncList(opts?: { getFile?: boolean }): Promise<SyncList[]> {
const config = this.config!;
let sync = config?.sync || {};
@ -110,7 +117,7 @@ export class SyncBase {
let obj: Record<string, string> = {};
const keys: string[] = [];
for (let item of syncDirectory) {
const { registry, ignore = [], files, replace = {} } = item;
const { registry, ignore = [], files = [], replace = {} } = item;
const cwd = this.#dir;
const glob_files = await glob(files, {
ignore,
@ -119,9 +126,14 @@ export class SyncBase {
dot: true,
absolute: true,
});
const registyURL = registry || config.registry;
if (!registyURL) {
logger.error('请配置 registry', item);
continue;
}
for (let file of glob_files) {
const key = path.relative(cwd, file);
const _registryURL = new URL(registry);
const _registryURL = new URL(registyURL);
const replaceKeys = Object.keys(replace);
let newKey = key;
for (let replaceKey of replaceKeys) {
@ -137,6 +149,11 @@ export class SyncBase {
}
return { sync: obj, keys };
}
/**
*
* @param syncList
* @returns
*/
async getSyncListFile(syncList: SyncList[]) {
let syncListFile: SyncList[] = [];
for (let item of syncList) {

View File

@ -16,10 +16,11 @@ const command = new Command('sync')
const syncUpload = new Command('upload')
.option('-d --dir <dir>', '配置目录')
.option('-s --share <share>', '共享设置')
.option('-c --config <config>', '配置文件的名字', 'kevisual.json')
.description('上传项目')
.action(async (opts) => {
console.log('上传项目');
const sync = new SyncBase({ baseURL: baseURL });
const sync = new SyncBase({ dir: opts.dir, baseURL: baseURL, configFilename: opts.config });
const syncList = await sync.getSyncList({ getFile: true });
logger.debug(syncList);
const nodonwArr: (typeof syncList)[number][] = [];
@ -48,7 +49,13 @@ const syncUpload = new Command('upload')
meta,
});
if (res.code === 200) {
logger.info('上传成功', item.key, chalk.green(item.url));
if (res.data?.isNew) {
logger.info('上传成功', item.key, chalk.green(item.url), chalk.green('文件上传'));
} else if (res.data?.isNewMeta) {
logger.info('上传成功', item.key, chalk.green(item.url), chalk.green('元数据更新'));
} else {
logger.info('上传成功', item.key, chalk.green(item.url), chalk.blue('文件未更新'));
}
}
logger.debug(res);
}
@ -58,9 +65,10 @@ const syncUpload = new Command('upload')
});
const syncDownload = new Command('download')
.option('-d --dir <dir>', '配置目录')
.option('-c --config <config>', '配置文件的名字', 'kevisual.json')
.description('下载项目')
.action(async () => {
const sync = new SyncBase({ baseURL: baseURL });
.action(async (opts) => {
const sync = new SyncBase({ dir: opts.dir, baseURL: baseURL, configFilename: opts.config });
const syncList = await sync.getSyncList();
logger.debug(syncList);
const nodonwArr: (typeof syncList)[number][] = [];
@ -85,7 +93,22 @@ const syncDownload = new Command('download')
logger.warn('以下文件未下载', nodonwArr.map((item) => item.key).join(','));
}
});
const syncList = new Command('list')
.option('-d --dir <dir>', '配置目录')
.option('-c --config <config>', '配置文件的名字', 'kevisual.json')
.description('列出同步列表')
.action(async (opts) => {
const sync = new SyncBase({ dir: opts.dir, baseURL: baseURL, configFilename: opts.config });
const syncList = await sync.getSyncList();
logger.debug(syncList);
logger.info('同步列表\n');
syncList.forEach((item) => {
logger.info(chalk.blue(item.key), chalk.gray(item.type), chalk.green(item.url));
});
});
command.addCommand(syncUpload);
command.addCommand(syncDownload);
command.addCommand(syncList);
app.addCommand(command);