update change cli
This commit is contained in:
@@ -152,10 +152,10 @@ export class SyncBase {
|
||||
async getSyncDirectoryList() {
|
||||
const config = this.config;
|
||||
const syncDirectory = config?.syncDirectory || [];
|
||||
let obj: Record<string, string> = {};
|
||||
let obj: Record<string, any> = {};
|
||||
const keys: string[] = [];
|
||||
for (let item of syncDirectory) {
|
||||
const { registry, ignore = [], files = [], replace = {} } = item;
|
||||
const { registry, ignore = [], files = [], replace = {}, meta } = item;
|
||||
const cwd = this.#dir;
|
||||
const glob_files = await glob(files, {
|
||||
ignore: this.getIngore(ignore),
|
||||
@@ -182,7 +182,10 @@ export class SyncBase {
|
||||
const pathname = path.join(_registryURL.pathname, newKey);
|
||||
_registryURL.pathname = pathname;
|
||||
keys.push(key);
|
||||
obj[key] = _registryURL.toString();
|
||||
obj[key] = { url: _registryURL.toString() };
|
||||
if (meta) {
|
||||
obj[key] = { ...obj[key], meta };
|
||||
}
|
||||
}
|
||||
}
|
||||
return { sync: obj, keys };
|
||||
|
||||
@@ -2,6 +2,7 @@ export type SyncConfigType = 'sync' | 'download' | 'upload' | 'none';
|
||||
export type SyncConfig = {
|
||||
type?: SyncConfigType; // 是否可以同步
|
||||
url: string; // 文件具体的 url 的地址
|
||||
meta?: Record<string, any>; // 元数据
|
||||
};
|
||||
export type SyncDirectory = {
|
||||
/**
|
||||
@@ -15,6 +16,7 @@ export type SyncDirectory = {
|
||||
registry?: string;
|
||||
files?: string[];
|
||||
replace?: Record<string, string>;
|
||||
meta?: Record<string, any>;
|
||||
};
|
||||
export interface Config {
|
||||
name?: string; // 项目名称
|
||||
|
||||
@@ -6,7 +6,7 @@ import fs from 'node:fs';
|
||||
import { upload } from '@/module/download/upload.ts';
|
||||
import { logger } from '@/module/logger.ts';
|
||||
import { chalk } from '@/module/chalk.ts';
|
||||
import path, { relative } from 'node:path';
|
||||
import path from 'node:path';
|
||||
import { fileIsExist } from '@/uitls/file.ts';
|
||||
|
||||
const command = new Command('sync')
|
||||
@@ -18,7 +18,6 @@ const command = new Command('sync')
|
||||
|
||||
const syncUpload = new Command('upload')
|
||||
.option('-d --dir <dir>', '配置目录')
|
||||
.option('-s --share <share>', '共享设置')
|
||||
.option('-c --config <config>', '配置文件的名字', 'kevisual.json')
|
||||
.option('-f --file <file>', '操作的对应的文件名')
|
||||
.description('上传项目')
|
||||
@@ -32,9 +31,6 @@ const syncUpload = new Command('upload')
|
||||
const meta: Record<string, string> = {
|
||||
...sync.config.metadata,
|
||||
};
|
||||
if (opts.share) {
|
||||
meta.share = opts.share;
|
||||
}
|
||||
const filepath = sync.getRelativePath(opts.file);
|
||||
for (const item of syncList) {
|
||||
if (!item.auth || !item.exist) {
|
||||
@@ -54,7 +50,7 @@ const syncUpload = new Command('upload')
|
||||
url: item.url,
|
||||
needHash: true,
|
||||
hash: item.hash,
|
||||
meta,
|
||||
meta: item.meta ?? meta,
|
||||
});
|
||||
if (res.code === 200) {
|
||||
if (res.data?.isNew) {
|
||||
@@ -109,6 +105,7 @@ const syncDownload = new Command('download')
|
||||
const syncList = new Command('list')
|
||||
.option('-d --dir <dir>', '配置目录')
|
||||
.option('-c --config <config>', '配置文件的名字', 'kevisual.json')
|
||||
.option('-a --all', '显示所有的文件')
|
||||
.description('列出同步列表')
|
||||
.action(async (opts) => {
|
||||
const sync = new SyncBase({ dir: opts.dir, baseURL: baseURL, configFilename: opts.config });
|
||||
@@ -116,14 +113,16 @@ const syncList = new Command('list')
|
||||
logger.debug(syncList);
|
||||
logger.info('同步列表\n');
|
||||
syncList.forEach((item) => {
|
||||
logger.info(chalk.blue(item.key), chalk.gray(item.type), chalk.green(item.url));
|
||||
if (opts.all) {
|
||||
logger.info(item);
|
||||
} else logger.info(chalk.blue(item.key), chalk.gray(item.type), chalk.green(item.url));
|
||||
});
|
||||
});
|
||||
const syncCreateList = new Command('create')
|
||||
.option('-d --dir <dir>', '配置目录')
|
||||
.option('-c --config <config>', '配置文件的名字', 'kevisual.json')
|
||||
.option('-o --output <output>', '输出文件')
|
||||
.description('创建文件')
|
||||
.description('创建文件, 获取远程的目录列表,然后创建新的配置文件')
|
||||
.action(async (opts) => {
|
||||
const sync = new SyncBase({ dir: opts.dir, baseURL: baseURL, configFilename: opts.config });
|
||||
const syncList = await sync.getSyncList();
|
||||
|
||||
Reference in New Issue
Block a user