From c2c6d4a7d39471aba608ba7f5071cb3cedaaa039 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Tue, 3 Mar 2026 00:40:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E8=87=B3=200.1.15=EF=BC=9B=E5=A2=9E=E5=BC=BA=20getSyn?= =?UTF-8?q?cList=20=E6=96=B9=E6=B3=95=E4=BB=A5=E6=94=AF=E6=8C=81=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E6=96=87=E4=BB=B6=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/command/sync/modules/base.ts | 7 +++++-- src/command/sync/sync.ts | 32 ++++++++++++++++++-------------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index ffab2a9..907a1aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/cli", - "version": "0.1.14", + "version": "0.1.15", "description": "envision 命令行工具", "type": "module", "basename": "/root/cli", diff --git a/src/command/sync/modules/base.ts b/src/command/sync/modules/base.ts index 44649f6..23f71d4 100644 --- a/src/command/sync/modules/base.ts +++ b/src/command/sync/modules/base.ts @@ -103,11 +103,14 @@ export class SyncBase { * @param opts.getFile 是否检测文件是否存在 * @returns */ - async getSyncList(opts?: { getFile?: boolean }): Promise { + async getSyncList(opts?: { getFile?: boolean, getLocalFile?: boolean }): Promise { const config = this.config!; let sync = config?.sync || {}; + const local = opts?.getLocalFile ?? true; const syncDirectory = await this.getSyncDirectoryList(); - sync = this.getMergeSync(sync, syncDirectory.sync); + if (local) { + sync = this.getMergeSync(sync, syncDirectory.sync); + } const syncKeys = Object.keys(sync); const baseURL = this.baseURL; const syncList = syncKeys.map((key) => { diff --git a/src/command/sync/sync.ts b/src/command/sync/sync.ts index 0778154..0912f17 100644 --- a/src/command/sync/sync.ts +++ b/src/command/sync/sync.ts @@ -172,11 +172,16 @@ const clone = new Command('clone') .option('-d --dir ', '配置目录') .option('-c --config ', '配置文件的名字', 'kevisual.json') .option('-i --link ', '克隆链接, 比 kevisual.json 优先级更高') + .option('-l --local', '值对sync的列表进行clone处理,只对sync列表处理') .description('检查目录') .action(async (opts) => { - const link = opts.link || ''; + let link = opts.link || ''; + const local = opts.local || false; const sync = new SyncBase({ dir: opts.dir, baseURL: baseURL, configFilename: opts.config }); if (link) { + if (!link.endsWith('.json')) { + link = link + (link.endsWith('/') ? '' : '/') + 'kevisual.json'; + } const res = await query.fetchText(link); if (res.code === 200) { fs.writeFileSync(sync.configPath, JSON.stringify(res.data, null, 2)); @@ -186,7 +191,7 @@ const clone = new Command('clone') } await sync.init() } - const syncList = await sync.getSyncList(); + const syncList = await sync.getSyncList({ getLocalFile: !local }); logger.debug(syncList); logger.info('检查目录\n'); const checkList = await sync.getCheckList(); @@ -211,24 +216,23 @@ const clone = new Command('clone') const matchList = matchObjectList .map((item2) => { const rp = sync.getRelativePath(item2.pathname); - if (!rp) return false; - if (rp.absolute.endsWith('gitignore.txt')) { - // 修改为 .gitignore - const newPath = rp.absolute.replace('gitignore.txt', '.gitignore'); - rp.absolute = newPath; - rp.relative = path.relative(sync.dir, newPath); - } else if (rp.absolute.endsWith('.dot')) { - const filename = path.basename(rp.absolute, '.dot'); - const newPath = path.join(path.dirname(rp.absolute), `.${filename}`); - rp.absolute = newPath; - rp.relative = path.relative(sync.dir, newPath); - } return { ...item2, relative: rp.relative, absolute: rp.absolute }; }) .filter((i) => i); for (const matchItem of matchList) { if (!matchItem) continue; + if (local) { + const some = syncList.some((syncItem) => { + if (syncItem.url === matchItem.url) { + return true; + } + return false; + }); + if (!some) { + continue; + } + } let needDownload = true; let hash = ''; await sync.getDir(matchItem.absolute, true);