|
1 | | -import type { BmalphConfig, UpstreamVersions } from "./config.js"; |
| 1 | +import type { BmalphConfig, BmadConfig, UpstreamVersions } from "./config.js"; |
2 | 2 | import type { BmalphState } from "./state.js"; |
3 | 3 | import { PLATFORM_IDS, type PlatformId } from "../platform/types.js"; |
4 | 4 | import { |
@@ -95,6 +95,115 @@ export function validateConfig(data: unknown): BmalphConfig { |
95 | 95 | }; |
96 | 96 | } |
97 | 97 |
|
| 98 | +export function validateBmadConfig(data: unknown): BmadConfig { |
| 99 | + assertObject(data, "bmadConfig"); |
| 100 | + |
| 101 | + let platform: string | undefined; |
| 102 | + if (data.platform !== undefined) { |
| 103 | + if (typeof data.platform !== "string") { |
| 104 | + throw new Error("bmadConfig.platform must be a string"); |
| 105 | + } |
| 106 | + platform = data.platform; |
| 107 | + } |
| 108 | + |
| 109 | + let project_name: string | undefined; |
| 110 | + if (data.project_name !== undefined) { |
| 111 | + if (typeof data.project_name !== "string") { |
| 112 | + throw new Error("bmadConfig.project_name must be a string"); |
| 113 | + } |
| 114 | + project_name = data.project_name; |
| 115 | + } |
| 116 | + |
| 117 | + let output_folder: string | undefined; |
| 118 | + if (data.output_folder !== undefined) { |
| 119 | + if (typeof data.output_folder !== "string") { |
| 120 | + throw new Error("bmadConfig.output_folder must be a string"); |
| 121 | + } |
| 122 | + output_folder = data.output_folder; |
| 123 | + } |
| 124 | + |
| 125 | + let user_name: string | undefined; |
| 126 | + if (data.user_name !== undefined) { |
| 127 | + if (typeof data.user_name !== "string") { |
| 128 | + throw new Error("bmadConfig.user_name must be a string"); |
| 129 | + } |
| 130 | + user_name = data.user_name; |
| 131 | + } |
| 132 | + |
| 133 | + let communication_language: string | undefined; |
| 134 | + if (data.communication_language !== undefined) { |
| 135 | + if (typeof data.communication_language !== "string") { |
| 136 | + throw new Error("bmadConfig.communication_language must be a string"); |
| 137 | + } |
| 138 | + communication_language = data.communication_language; |
| 139 | + } |
| 140 | + |
| 141 | + let document_output_language: string | undefined; |
| 142 | + if (data.document_output_language !== undefined) { |
| 143 | + if (typeof data.document_output_language !== "string") { |
| 144 | + throw new Error("bmadConfig.document_output_language must be a string"); |
| 145 | + } |
| 146 | + document_output_language = data.document_output_language; |
| 147 | + } |
| 148 | + |
| 149 | + let user_skill_level: string | undefined; |
| 150 | + if (data.user_skill_level !== undefined) { |
| 151 | + if (typeof data.user_skill_level !== "string") { |
| 152 | + throw new Error("bmadConfig.user_skill_level must be a string"); |
| 153 | + } |
| 154 | + user_skill_level = data.user_skill_level; |
| 155 | + } |
| 156 | + |
| 157 | + let planning_artifacts: string | undefined; |
| 158 | + if (data.planning_artifacts !== undefined) { |
| 159 | + if (typeof data.planning_artifacts !== "string") { |
| 160 | + throw new Error("bmadConfig.planning_artifacts must be a string"); |
| 161 | + } |
| 162 | + planning_artifacts = data.planning_artifacts; |
| 163 | + } |
| 164 | + |
| 165 | + let implementation_artifacts: string | undefined; |
| 166 | + if (data.implementation_artifacts !== undefined) { |
| 167 | + if (typeof data.implementation_artifacts !== "string") { |
| 168 | + throw new Error("bmadConfig.implementation_artifacts must be a string"); |
| 169 | + } |
| 170 | + implementation_artifacts = data.implementation_artifacts; |
| 171 | + } |
| 172 | + |
| 173 | + let project_knowledge: string | undefined; |
| 174 | + if (data.project_knowledge !== undefined) { |
| 175 | + if (typeof data.project_knowledge !== "string") { |
| 176 | + throw new Error("bmadConfig.project_knowledge must be a string"); |
| 177 | + } |
| 178 | + project_knowledge = data.project_knowledge; |
| 179 | + } |
| 180 | + |
| 181 | + let modules: string[] | undefined; |
| 182 | + if (data.modules !== undefined) { |
| 183 | + if ( |
| 184 | + !Array.isArray(data.modules) || |
| 185 | + !data.modules.every((m: unknown) => typeof m === "string") |
| 186 | + ) { |
| 187 | + throw new Error("bmadConfig.modules must be an array of strings"); |
| 188 | + } |
| 189 | + modules = data.modules; |
| 190 | + } |
| 191 | + |
| 192 | + return { |
| 193 | + platform, |
| 194 | + project_name, |
| 195 | + output_folder, |
| 196 | + user_name, |
| 197 | + communication_language, |
| 198 | + document_output_language, |
| 199 | + user_skill_level, |
| 200 | + planning_artifacts, |
| 201 | + implementation_artifacts, |
| 202 | + project_knowledge, |
| 203 | + modules, |
| 204 | + }; |
| 205 | +} |
| 206 | + |
98 | 207 | export function validateState(data: unknown): BmalphState { |
99 | 208 | assertObject(data, "state"); |
100 | 209 |
|
|
0 commit comments