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

@@ -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) {