-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaggregate-manifests.ts
More file actions
89 lines (76 loc) · 2.34 KB
/
Copy pathaggregate-manifests.ts
File metadata and controls
89 lines (76 loc) · 2.34 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
81
82
83
84
85
86
87
88
89
import { readFileSync, writeFileSync } from "fs";
import { glob } from "glob";
import yaml from "js-yaml";
import path from "path";
import { fileURLToPath } from "url";
interface ConfigRow {
label: string;
value: string;
}
interface ScenarioManifest {
app_type: string;
display_name: string;
grant: string;
description: string;
callout?: string;
extends?: string;
run_command?: string;
config_rows: ConfigRow[];
}
interface FrameworkManifest {
framework: string;
label: string;
lang: string;
lib: string;
docs_url: string;
scenarios: Record<string, ScenarioManifest>;
}
interface AggregatedScenario extends ScenarioManifest {
frameworks: string[];
}
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const SAMPLES = path.join(ROOT, "samples");
async function main() {
const manifestFiles = await glob("*/manifest.yaml", { cwd: SAMPLES });
if (manifestFiles.length === 0) {
console.error("No manifest.yaml files found in samples/");
process.exit(1);
}
const scenarios: Record<string, AggregatedScenario> = {};
const frameworks: Record<
string,
{ label: string; lang: string; lib: string; docs_url: string }
> = {};
for (const file of manifestFiles.sort()) {
const fullPath = path.join(SAMPLES, file);
const content = readFileSync(fullPath, "utf-8");
const manifest = yaml.load(content) as FrameworkManifest;
frameworks[manifest.framework] = {
label: manifest.label,
lang: manifest.lang,
lib: manifest.lib,
docs_url: manifest.docs_url,
};
for (const [scenarioId, scenario] of Object.entries(manifest.scenarios)) {
if (!scenarios[scenarioId]) {
scenarios[scenarioId] = {
...scenario,
frameworks: [manifest.framework],
};
} else {
scenarios[scenarioId].frameworks.push(manifest.framework);
}
}
}
const output = { frameworks, scenarios };
const yamlStr = yaml.dump(output, { lineWidth: 120, noRefs: true, quotingType: '"' });
const outputPath = path.join(ROOT, "snippet-manifest.yaml");
writeFileSync(
outputPath,
`# GENERATED — do not edit. Aggregated from per-framework manifest.yaml files.\n${yamlStr}`
);
console.log(
`Wrote ${outputPath} (${Object.keys(scenarios).length} scenarios, ${Object.keys(frameworks).length} frameworks)`
);
}
main();