-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 新增 updateConfig.ts 和 updateConfig.js 配置更新脚本 - 实现遍历配置模式的功能【traverseSchema】 - 支持递归处理嵌套配置项 - 添加配置生成和更新的自动化流程 - 包含错误处理和日志输出机制
- Loading branch information
1 parent
480f7d0
commit 96fa854
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |