| 1 | #!/usr/bin/env node |
| 2 | |
| 3 | import { readFileSync } from "fs"; |
| 4 | import { parseConfigYaml } from "./load/unroll.js"; |
| 5 | import { validateConfigYaml } from "./validation.js"; |
| 6 | |
| 7 | async function main() { |
| 8 | const filePath = process.argv[2]; |
| 9 | if (!filePath) { |
| 10 | console.error("Please provide a YAML file path"); |
| 11 | process.exit(1); |
| 12 | } |
| 13 | |
| 14 | try { |
| 15 | // Read and parse the YAML file |
| 16 | const fileContents = readFileSync(filePath, "utf-8"); |
| 17 | const parsedYaml = parseConfigYaml(fileContents); |
| 18 | |
| 19 | // Validate the config |
| 20 | const validationErrors = validateConfigYaml(parsedYaml); |
| 21 | |
| 22 | if (validationErrors.length === 0) { |
| 23 | console.log("✅ Config file is valid!"); |
| 24 | process.exit(0); |
| 25 | } else { |
| 26 | console.error("❌ Config file validation failed:"); |
| 27 | validationErrors.forEach((error) => { |
| 28 | console.error(`- ${error.message}`); |
| 29 | }); |
| 30 | process.exit(1); |
| 31 | } |
| 32 | } catch (error: any) { |
| 33 | console.error("Error processing file:", error.message); |
| 34 | process.exit(1); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | main().catch(console.error); |