Refactor code structure for improved readability and maintainability

This commit is contained in:
xiongxiao
2026-03-15 04:22:35 +08:00
committed by cnb
parent 228635a3cc
commit 342b68abe3
4 changed files with 5075 additions and 79 deletions

View File

@@ -52,7 +52,7 @@
"@kevisual/router": "^0.1.1",
"@kevisual/types": "^0.0.12",
"@kevisual/use-config": "^1.0.30",
"@opencode-ai/plugin": "^1.2.24",
"@opencode-ai/plugin": "^1.2.26",
"@types/bun": "^1.3.10",
"@types/node": "^25.5.0",
"@types/send": "^1.2.1",
@@ -77,15 +77,15 @@
"access": "public"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.1008.0",
"@aws-sdk/client-s3": "^3.1009.0",
"@kevisual/js-filter": "^0.0.6",
"@kevisual/oss": "^0.0.20",
"@kevisual/video-tools": "^0.0.13",
"@opencode-ai/sdk": "^1.2.24",
"@opencode-ai/sdk": "^1.2.26",
"es-toolkit": "^1.45.1",
"eventemitter3": "^5.0.4",
"lowdb": "^7.0.1",
"lru-cache": "^11.2.6",
"lru-cache": "^11.2.7",
"pm2": "^6.0.14",
"unstorage": "^1.17.4",
"zod": "^4.3.6"

View File

@@ -1,6 +1,6 @@
{
"name": "@kevisual/cli",
"version": "0.1.24",
"version": "0.1.25",
"description": "envision 命令行工具",
"type": "module",
"basename": "/root/cli",
@@ -47,13 +47,13 @@
"@kevisual/context": "^0.0.8",
"@kevisual/router": "^0.1.1",
"@kevisual/use-config": "^1.0.30",
"@opencode-ai/sdk": "^1.2.24",
"@opencode-ai/sdk": "^1.2.26",
"@types/busboy": "^1.5.4",
"busboy": "^1.6.0",
"eventemitter3": "^5.0.4",
"jose": "^6.2.1",
"lowdb": "^7.0.1",
"lru-cache": "^11.2.6",
"lru-cache": "^11.2.7",
"micromatch": "^4.0.8",
"nanoid": "^5.1.6",
"pm2": "latest",
@@ -62,7 +62,7 @@
},
"devDependencies": {
"@kevisual/api": "^0.0.64",
"@kevisual/cnb": "^0.0.45",
"@kevisual/cnb": "^0.0.46",
"@kevisual/dts": "^0.0.4",
"@kevisual/load": "^0.0.6",
"@kevisual/logger": "^0.0.4",

4982
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -14,11 +14,79 @@ const parseIfJson = (str: string) => {
return {};
}
};
const publishRegistry = (options: { execPath: string, registry: string, tag?: string, config: any, env: any }) => {
const packageJson = path.resolve(options.execPath, 'package.json');
let cmd = '';
const config = options.config || {};
const execPath = options.execPath;
const registry = options.registry;
const setEnv = options.env || {};
switch (registry) {
case 'npm':
cmd = 'npm publish -s --registry https://registry.npmjs.org';
break;
case 'cnb':
cmd = 'npm publish -s --registry https://npm.cnb.cool/kevisual/registry/-/packages/';
break;
default:
cmd = 'npm publish -s --registry https://registry.npmjs.org';
break;
}
if (fileIsExist(packageJson)) {
const keys = Object.keys(config).filter((key) => key.includes('NPM_TOKEN'));
const tokenEnv = keys.reduce((prev, key) => {
return {
...prev,
[key]: config[key],
};
}, {});
const pkg = fs.readFileSync(packageJson, 'utf-8');
const pkgJson = parseIfJson(pkg);
const version = pkgJson?.version as string;
if (version && options?.tag) {
let tag = String(version).split('-')[1] || '';
if (tag) {
if (tag.includes('.')) {
tag = tag.split('.')[0];
}
cmd = `${cmd} --tag ${tag}`;
}
}
console.log(chalk.green(cmd));
const child = spawn(cmd, {
shell: true,
cwd: execPath,
env: {
...process.env, // 保留当前环境变量
...tokenEnv,
...setEnv,
},
});
child.stdout.on('data', (data) => {
console.log(chalk.green(`${data}`));
});
child.stderr.on('data', (data) => {
// 过滤掉 'npm notice' 或者其他信息
if (data.toString().includes('npm notice')) {
console.log(chalk.yellow(`notice: ${data}`));
} else {
console.error(`stderr: ${data}`);
}
});
child.on('close', (code) => {
// console.log(`child process exited with code ${code}`);
});
} else {
console.error(chalk.red('package.json not found'));
}
}
const command = new Command('npm').description('npm command show publish and set .npmrc').action(async (options) => { });
const publish = new Command('publish')
.argument('[registry]')
.option('-p --proxy', 'proxy')
.option('-t, --tag', 'tag')
.option('-u, --update', 'update new version')
.description('publish npm')
.action(async (registry, options) => {
if (!registry) {
@@ -26,8 +94,8 @@ const publish = new Command('publish')
message: 'Select the registry to publish',
choices: [
{
name: 'me',
value: 'me',
name: 'all',
value: 'all',
},
{
name: 'npm',
@@ -41,7 +109,6 @@ const publish = new Command('publish')
});
}
const config = getConfig();
let cmd = '';
const execPath = process.cwd();
let setEnv = {};
const proxyEnv = {
@@ -55,70 +122,15 @@ const publish = new Command('publish')
...proxyEnv,
};
}
if (registry) {
const packageJson = path.resolve(execPath, 'package.json');
switch (registry) {
case 'me':
cmd = 'npm publish -s --registry https://npm.xiongxiao.me';
break;
case 'npm':
cmd = 'npm publish -s --registry https://registry.npmjs.org';
break;
case 'cnb':
cmd = 'npm publish -s --registry https://npm.cnb.cool/kevisual/registry/-/packages/';
break;
default:
cmd = 'npm publish -s --registry https://npm.xiongxiao.me';
break;
}
if (fileIsExist(packageJson)) {
const keys = Object.keys(config).filter((key) => key.includes('NPM_TOKEN'));
const tokenEnv = keys.reduce((prev, key) => {
return {
...prev,
[key]: config[key],
};
}, {});
const pkg = fs.readFileSync(packageJson, 'utf-8');
const pkgJson = parseIfJson(pkg);
const version = pkgJson?.version as string;
if (version && options?.tag) {
let tag = String(version).split('-')[1] || '';
if (tag) {
if (tag.includes('.')) {
tag = tag.split('.')[0];
}
cmd = `${cmd} --tag ${tag}`;
}
}
console.log(chalk.green(cmd));
if (options?.update) {
patchFunc({ directory: execPath });
}
const child = spawn(cmd, {
shell: true,
cwd: execPath,
env: {
...process.env, // 保留当前环境变量
...tokenEnv,
...setEnv,
},
});
child.stdout.on('data', (data) => {
console.log(chalk.green(`${data}`));
});
child.stderr.on('data', (data) => {
// 过滤掉 'npm notice' 或者其他信息
if (data.toString().includes('npm notice')) {
console.log(chalk.yellow(`notice: ${data}`));
} else {
console.error(`stderr: ${data}`);
}
});
child.on('close', (code) => {
// console.log(`child process exited with code ${code}`);
});
} else {
console.error(chalk.red('package.json not found'));
}
if (registry === 'all') {
publishRegistry({ execPath, registry: 'npm', config, env: setEnv });
publishRegistry({ execPath, registry: 'cnb', config, env: setEnv });
} else {
publishRegistry({ execPath, registry, tag: options?.tag, config, env: setEnv });
}
});
@@ -142,8 +154,7 @@ const npmrc = new Command('set')
const config = getConfig();
const npmrcContent =
config?.npmrc ||
`//npm.xiongxiao.me/:_authToken=\${ME_NPM_TOKEN}
//npm.cnb.cool/kevisual/registry/-/packages/:_authToken=\${CNB_API_KEY}
`/npm.cnb.cool/kevisual/registry/-/packages/:_authToken=\${CNB_API_KEY}
//registry.npmjs.org/:_authToken=\${NPM_TOKEN}
`;
const execPath = process.cwd();
@@ -210,9 +221,8 @@ const install = new Command('install')
});
command.addCommand(install);
// npm patch
const patch = new Command('patch').description('npm patch 发布补丁版本').action(async () => {
const cwd = process.cwd();
const patchFunc = (opts?: { directory?: string }) => {
const cwd = opts?.directory || process.cwd();
const packageJson = path.resolve(cwd, 'package.json');
if (fileIsExist(packageJson)) {
const pkg = fs.readFileSync(packageJson, 'utf-8');
@@ -229,6 +239,10 @@ const patch = new Command('patch').description('npm patch 发布补丁版本').a
}
}
}
}
// npm patch
const patch = new Command('patch').description('npm patch 发布补丁版本').action(async () => {
patchFunc();
});
command.addCommand(patch);