Skip to content

Commit

Permalink
✨ feat(scripts): 添加配置更新脚本功能
Browse files Browse the repository at this point in the history
- 新增 updateConfig.ts 和 updateConfig.js 配置更新脚本
- 实现遍历配置模式的功能【traverseSchema】
- 支持递归处理嵌套配置项
- 添加配置生成和更新的自动化流程
- 包含错误处理和日志输出机制
  • Loading branch information
littleCareless committed Dec 11, 2024
1 parent 480f7d0 commit 96fa854
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
38 changes: 38 additions & 0 deletions scripts/updateConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ConfigSchema_1 = require("../src/config/ConfigSchema");
const ConfigGenerator_1 = require("../src/config/ConfigGenerator");
async function updateAllConfigs() {
async function traverseSchema(schema, path = "") {
for (const [key, value] of Object.entries(schema)) {
const currentPath = path ? `${path}.${key}` : key;
if ((0, ConfigSchema_1.isConfigValue)(value)) {
const config = {
key: currentPath,
type: value.type,
default: value.default,
description: value.description,
...(value.enum && { enum: value.enum }),
...(value.enumDescriptions && {
enumDescriptions: value.enumDescriptions,
}),
...(value.isSpecial && { isSpecial: value.isSpecial }),
};
await ConfigGenerator_1.ConfigGenerator.addConfig(config);
console.log(`Updated config: ${currentPath}`);
}
else if (value && typeof value === "object") {
await traverseSchema(value, currentPath);
}
}
}
try {
await traverseSchema(ConfigSchema_1.CONFIG_SCHEMA);
console.log("All configurations updated successfully!");
}
catch (error) {
console.error("Error updating configurations:", error);
process.exit(1);
}
}
updateAllConfigs();
45 changes: 45 additions & 0 deletions scripts/updateConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { CONFIG_SCHEMA, isConfigValue } from "../src/config/ConfigSchema";
import {
ConfigGenerator,
ConfigDefinition,
} from "../src/config/ConfigGenerator";

async function updateAllConfigs() {
async function traverseSchema(
schema: Record<string, any>,
path: string = ""
) {
for (const [key, value] of Object.entries(schema)) {
const currentPath = path ? `${path}.${key}` : key;

if (isConfigValue(value)) {
const config: ConfigDefinition = {
key: currentPath,
type: value.type,
default: value.default,
description: value.description,
...(value.enum && { enum: value.enum }),
...(value.enumDescriptions && {
enumDescriptions: value.enumDescriptions,
}),
...(value.isSpecial && { isSpecial: value.isSpecial }),
};

await ConfigGenerator.addConfig(config);
console.log(`Updated config: ${currentPath}`);
} else if (value && typeof value === "object") {
await traverseSchema(value, currentPath);
}
}
}

try {
await traverseSchema(CONFIG_SCHEMA);
console.log("All configurations updated successfully!");
} catch (error) {
console.error("Error updating configurations:", error);
process.exit(1);
}
}

updateAllConfigs();

0 comments on commit 96fa854

Please sign in to comment.