|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const { |
| 4 | + getInstallComponent, |
| 5 | + listInstallComponents, |
| 6 | + listInstallProfiles, |
| 7 | +} = require('./lib/install-manifests'); |
| 8 | + |
| 9 | +const FAMILY_ALIASES = Object.freeze({ |
| 10 | + baseline: 'baseline', |
| 11 | + baselines: 'baseline', |
| 12 | + language: 'language', |
| 13 | + languages: 'language', |
| 14 | + lang: 'language', |
| 15 | + framework: 'framework', |
| 16 | + frameworks: 'framework', |
| 17 | + capability: 'capability', |
| 18 | + capabilities: 'capability', |
| 19 | + agent: 'agent', |
| 20 | + agents: 'agent', |
| 21 | + skill: 'skill', |
| 22 | + skills: 'skill', |
| 23 | +}); |
| 24 | + |
| 25 | +function showHelp(exitCode = 0) { |
| 26 | + console.log(` |
| 27 | +Discover ECC install components and profiles |
| 28 | +
|
| 29 | +Usage: |
| 30 | + node scripts/catalog.js profiles [--json] |
| 31 | + node scripts/catalog.js components [--family <family>] [--target <target>] [--json] |
| 32 | + node scripts/catalog.js show <component-id> [--json] |
| 33 | +
|
| 34 | +Examples: |
| 35 | + node scripts/catalog.js profiles |
| 36 | + node scripts/catalog.js components --family language |
| 37 | + node scripts/catalog.js show framework:nextjs |
| 38 | +`); |
| 39 | + |
| 40 | + process.exit(exitCode); |
| 41 | +} |
| 42 | + |
| 43 | +function normalizeFamily(value) { |
| 44 | + if (!value) { |
| 45 | + return null; |
| 46 | + } |
| 47 | + |
| 48 | + const normalized = String(value).trim().toLowerCase(); |
| 49 | + return FAMILY_ALIASES[normalized] || normalized; |
| 50 | +} |
| 51 | + |
| 52 | +function parseArgs(argv) { |
| 53 | + const args = argv.slice(2); |
| 54 | + const parsed = { |
| 55 | + command: null, |
| 56 | + componentId: null, |
| 57 | + family: null, |
| 58 | + target: null, |
| 59 | + json: false, |
| 60 | + help: false, |
| 61 | + }; |
| 62 | + |
| 63 | + if (args.length === 0 || args[0] === '--help' || args[0] === '-h') { |
| 64 | + parsed.help = true; |
| 65 | + return parsed; |
| 66 | + } |
| 67 | + |
| 68 | + parsed.command = args[0]; |
| 69 | + |
| 70 | + for (let index = 1; index < args.length; index += 1) { |
| 71 | + const arg = args[index]; |
| 72 | + |
| 73 | + if (arg === '--help' || arg === '-h') { |
| 74 | + parsed.help = true; |
| 75 | + } else if (arg === '--json') { |
| 76 | + parsed.json = true; |
| 77 | + } else if (arg === '--family') { |
| 78 | + if (!args[index + 1]) { |
| 79 | + throw new Error('Missing value for --family'); |
| 80 | + } |
| 81 | + parsed.family = normalizeFamily(args[index + 1]); |
| 82 | + index += 1; |
| 83 | + } else if (arg === '--target') { |
| 84 | + if (!args[index + 1]) { |
| 85 | + throw new Error('Missing value for --target'); |
| 86 | + } |
| 87 | + parsed.target = args[index + 1]; |
| 88 | + index += 1; |
| 89 | + } else if (parsed.command === 'show' && !parsed.componentId) { |
| 90 | + parsed.componentId = arg; |
| 91 | + } else { |
| 92 | + throw new Error(`Unknown argument: ${arg}`); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + return parsed; |
| 97 | +} |
| 98 | + |
| 99 | +function printProfiles(profiles) { |
| 100 | + console.log('Install profiles:\n'); |
| 101 | + for (const profile of profiles) { |
| 102 | + console.log(`- ${profile.id} (${profile.moduleCount} modules)`); |
| 103 | + console.log(` ${profile.description}`); |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +function printComponents(components) { |
| 108 | + console.log('Install components:\n'); |
| 109 | + for (const component of components) { |
| 110 | + console.log(`- ${component.id} [${component.family}]`); |
| 111 | + console.log(` targets=${component.targets.join(', ')} modules=${component.moduleIds.join(', ')}`); |
| 112 | + console.log(` ${component.description}`); |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +function printComponent(component) { |
| 117 | + console.log(`Install component: ${component.id}\n`); |
| 118 | + console.log(`Family: ${component.family}`); |
| 119 | + console.log(`Targets: ${component.targets.join(', ')}`); |
| 120 | + console.log(`Modules: ${component.moduleIds.join(', ')}`); |
| 121 | + console.log(`Description: ${component.description}`); |
| 122 | + |
| 123 | + if (component.modules.length > 0) { |
| 124 | + console.log('\nResolved modules:'); |
| 125 | + for (const module of component.modules) { |
| 126 | + console.log(`- ${module.id} [${module.kind}]`); |
| 127 | + console.log( |
| 128 | + ` targets=${module.targets.join(', ')} default=${module.defaultInstall} cost=${module.cost} stability=${module.stability}` |
| 129 | + ); |
| 130 | + console.log(` ${module.description}`); |
| 131 | + } |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +function main() { |
| 136 | + try { |
| 137 | + const options = parseArgs(process.argv); |
| 138 | + |
| 139 | + if (options.help) { |
| 140 | + showHelp(0); |
| 141 | + } |
| 142 | + |
| 143 | + if (options.command === 'profiles') { |
| 144 | + const profiles = listInstallProfiles(); |
| 145 | + if (options.json) { |
| 146 | + console.log(JSON.stringify({ profiles }, null, 2)); |
| 147 | + } else { |
| 148 | + printProfiles(profiles); |
| 149 | + } |
| 150 | + return; |
| 151 | + } |
| 152 | + |
| 153 | + if (options.command === 'components') { |
| 154 | + const components = listInstallComponents({ |
| 155 | + family: options.family, |
| 156 | + target: options.target, |
| 157 | + }); |
| 158 | + if (options.json) { |
| 159 | + console.log(JSON.stringify({ components }, null, 2)); |
| 160 | + } else { |
| 161 | + printComponents(components); |
| 162 | + } |
| 163 | + return; |
| 164 | + } |
| 165 | + |
| 166 | + if (options.command === 'show') { |
| 167 | + if (!options.componentId) { |
| 168 | + throw new Error('Catalog show requires an install component ID'); |
| 169 | + } |
| 170 | + const component = getInstallComponent(options.componentId); |
| 171 | + if (options.json) { |
| 172 | + console.log(JSON.stringify(component, null, 2)); |
| 173 | + } else { |
| 174 | + printComponent(component); |
| 175 | + } |
| 176 | + return; |
| 177 | + } |
| 178 | + |
| 179 | + throw new Error(`Unknown catalog command: ${options.command}`); |
| 180 | + } catch (error) { |
| 181 | + console.error(`Error: ${error.message}`); |
| 182 | + process.exit(1); |
| 183 | + } |
| 184 | +} |
| 185 | + |
| 186 | +main(); |
0 commit comments