-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdate-readme-cli.ts
More file actions
80 lines (71 loc) · 2.29 KB
/
update-readme-cli.ts
File metadata and controls
80 lines (71 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* CLI handler for update-readme
*
* This module orchestrates the full README update workflow:
* 1. Generate YAML index from workspace structure
* 2. Render README.md from the index
*/
import { realpathSync } from "fs";
import { dirname, resolve } from "path";
import { handleCli as generateIndexCli } from "./generate-readme-index-cli.ts";
import { handleCli as renderReadmeCli } from "./render-readme-cli.ts";
/**
* Result of CLI execution
*/
export interface CliResult {
/** Exit code (0 for success, non-zero for error) */
exitCode: number;
/** Error message if any */
error?: string;
}
/**
* CLI handler that updates README tables
*
* @param args - Command line arguments (typically process.argv.slice(2))
* @param rootDir - Root directory of the project (typically __dirname/../../../)
* @returns Promise resolving to CLI result with exit code
*/
export async function handleCli(
args: string[],
rootDir: string
): Promise<CliResult> {
console.log("📝 Updating README tables...\n");
try {
// Step 1: Generate index
const indexResult = generateIndexCli(args, rootDir);
if (indexResult.exitCode !== 0) {
return indexResult;
}
console.log("");
// Step 2: Render README
const renderResult = renderReadmeCli(rootDir);
if (renderResult.exitCode !== 0) {
return renderResult;
}
console.log("\n✅ README tables updated successfully!");
console.log(
"💡 Edit readme-metadata.yaml to customize labels and purposes"
);
return { exitCode: 0 };
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
console.error("❌ Error:", message);
return { exitCode: 1, error: message };
}
}
// Execute CLI if this module is run directly.
// istanbul ignore next - CLI entry point, difficult to test in Jest
if (process.argv[1]?.endsWith("update-readme-cli.ts")) {
// Derive rootDir from process.argv[1] (3 levels up: tools/generator/readme-generator)
const mainPath = realpathSync(process.argv[1]);
const rootDir = resolve(dirname(mainPath), "../../..");
const args = process.argv.slice(2);
handleCli(args, rootDir)
.then((result) => {
process.exit(result.exitCode);
})
.catch((err) => {
console.error("Unexpected error:", err);
process.exit(1);
});
}