(argv: string[])
| 343 | } |
| 344 | |
| 345 | export const cli = (argv: string[]) => { |
| 346 | if (argv.includes("--help") || argv.includes("-h")) { |
| 347 | console.log(` |
| 348 | USAGE: |
| 349 | walkthroughgen generate <yaml-file> [options] |
| 350 | |
| 351 | OPTIONS: |
| 352 | --help, -h Show help |
| 353 | generate <yaml-file> Generate markdown from YAML file |
| 354 | `); |
| 355 | return; |
| 356 | } |
| 357 | |
| 358 | if (argv[0] === "generate") { |
| 359 | if (!argv[1]) { |
| 360 | console.error("Error: YAML file path is required for 'generate' command."); |
| 361 | console.log("Usage: walkthroughgen generate <yaml-file>"); |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | const yamlPath = argv[1]; |
| 366 | let yamlContent; |
| 367 | try { |
| 368 | yamlContent = fs.readFileSync(yamlPath, 'utf8'); |
| 369 | } catch (error: any) { |
| 370 | console.error(`Error: Could not read YAML file at '${yamlPath}'.`); |
| 371 | console.error(error.message); |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | let data: WalkthroughData; |
| 376 | try { |
| 377 | data = yaml.load(yamlContent) as WalkthroughData; |
| 378 | } catch (error: any) { |
| 379 | console.error(`Error: Could not parse YAML content from '${yamlPath}'.`); |
| 380 | console.error(error.message); |
| 381 | return; |
| 382 | } |
| 383 | |
| 384 | if (!data || typeof data.title !== 'string' || typeof data.text !== 'string') { |
| 385 | console.error(`Error: Invalid YAML structure in '${yamlPath}'. Missing required 'title' or 'text' fields.`); |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | // Track virtual file state for diff generation |
| 390 | const projectRoot = path.dirname(yamlPath); |
| 391 | const virtualFileState = new Map<string, string>(); |
| 392 | |
| 393 | // Process folders target first |
| 394 | if (data.targets) { |
| 395 | for (const target of data.targets) { |
| 396 | // Ensure target.folders is an object with a path property |
| 397 | if (target.folders && typeof target.folders === 'object' && target.folders.path) { |
| 398 | const currentFoldersTarget = target.folders; // Assign to a new const for type narrowing |
| 399 | const foldersBasePath = path.join(path.dirname(yamlPath), currentFoldersTarget.path); |
| 400 | console.log('Creating folders base path:', foldersBasePath); |
| 401 | fs.mkdirSync(foldersBasePath, { recursive: true }); |
| 402 |
no test coverage detected