feat: 更新版本号至 0.1.15;增强 getSyncList 方法以支持本地文件选项

This commit is contained in:
2026-03-03 00:40:30 +08:00
parent 57bf884360
commit c2c6d4a7d3
3 changed files with 24 additions and 17 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@kevisual/cli", "name": "@kevisual/cli",
"version": "0.1.14", "version": "0.1.15",
"description": "envision 命令行工具", "description": "envision 命令行工具",
"type": "module", "type": "module",
"basename": "/root/cli", "basename": "/root/cli",

View File

@@ -103,11 +103,14 @@ export class SyncBase {
* @param opts.getFile 是否检测文件是否存在 * @param opts.getFile 是否检测文件是否存在
* @returns * @returns
*/ */
async getSyncList(opts?: { getFile?: boolean }): Promise<SyncList[]> { async getSyncList(opts?: { getFile?: boolean, getLocalFile?: boolean }): Promise<SyncList[]> {
const config = this.config!; const config = this.config!;
let sync = config?.sync || {}; let sync = config?.sync || {};
const local = opts?.getLocalFile ?? true;
const syncDirectory = await this.getSyncDirectoryList(); 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 syncKeys = Object.keys(sync);
const baseURL = this.baseURL; const baseURL = this.baseURL;
const syncList = syncKeys.map((key) => { const syncList = syncKeys.map((key) => {

View File

@@ -172,11 +172,16 @@ const clone = new Command('clone')
.option('-d --dir <dir>', '配置目录') .option('-d --dir <dir>', '配置目录')
.option('-c --config <config>', '配置文件的名字', 'kevisual.json') .option('-c --config <config>', '配置文件的名字', 'kevisual.json')
.option('-i --link <link>', '克隆链接, 比 kevisual.json 优先级更高') .option('-i --link <link>', '克隆链接, 比 kevisual.json 优先级更高')
.option('-l --local', '值对sync的列表进行clone处理只对sync列表处理')
.description('检查目录') .description('检查目录')
.action(async (opts) => { .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 }); const sync = new SyncBase({ dir: opts.dir, baseURL: baseURL, configFilename: opts.config });
if (link) { if (link) {
if (!link.endsWith('.json')) {
link = link + (link.endsWith('/') ? '' : '/') + 'kevisual.json';
}
const res = await query.fetchText(link); const res = await query.fetchText(link);
if (res.code === 200) { if (res.code === 200) {
fs.writeFileSync(sync.configPath, JSON.stringify(res.data, null, 2)); fs.writeFileSync(sync.configPath, JSON.stringify(res.data, null, 2));
@@ -186,7 +191,7 @@ const clone = new Command('clone')
} }
await sync.init() await sync.init()
} }
const syncList = await sync.getSyncList(); const syncList = await sync.getSyncList({ getLocalFile: !local });
logger.debug(syncList); logger.debug(syncList);
logger.info('检查目录\n'); logger.info('检查目录\n');
const checkList = await sync.getCheckList(); const checkList = await sync.getCheckList();
@@ -211,24 +216,23 @@ const clone = new Command('clone')
const matchList = matchObjectList const matchList = matchObjectList
.map((item2) => { .map((item2) => {
const rp = sync.getRelativePath(item2.pathname); const rp = sync.getRelativePath(item2.pathname);
if (!rp) return false; 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 }; return { ...item2, relative: rp.relative, absolute: rp.absolute };
}) })
.filter((i) => i); .filter((i) => i);
for (const matchItem of matchList) { for (const matchItem of matchList) {
if (!matchItem) continue; 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 needDownload = true;
let hash = ''; let hash = '';
await sync.getDir(matchItem.absolute, true); await sync.getDir(matchItem.absolute, true);