MCPcopy Create free account
hub / github.com/apache/camel-website / fetchCatalogAndSchema

Function fetchCatalogAndSchema

scripts/generate-offline-bundle.js:20–75  ·  view source on GitHub ↗
(version)

Source from the content-addressed store, hash-verified

18];
19
20function fetchCatalogAndSchema(version) {
21 const branch = `camel-${version}.x`;
22 const catalogDir = path.join(PUBLIC_DIR, 'catalog');
23
24 console.log(`\nFetching catalog and YAML DSL schema from ${CAMEL_REPO}@${branch}...`);
25
26 // fetch YAML DSL canonical schema
27 const schemaDir = path.join(catalogDir, 'schema');
28 fs.mkdirSync(schemaDir, { recursive: true });
29 try {
30 const schema = execFileSync('gh', [
31 'api', `repos/${CAMEL_REPO}/contents/${YAML_SCHEMA_PATH}?ref=${branch}`,
32 '--jq', '.content'
33 ], { encoding: 'utf8' });
34 fs.writeFileSync(
35 path.join(schemaDir, 'camelYamlDsl-canonical.json'),
36 Buffer.from(schema.trim(), 'base64').toString('utf8')
37 );
38 console.log(' Fetched schema/camelYamlDsl-canonical.json');
39 } catch (error) {
40 console.warn(` Could not fetch YAML DSL schema: ${error.message}`);
41 }
42
43 // fetch catalog JSON files for each category
44 for (const dir of CATALOG_DIRS) {
45 const targetDir = path.join(catalogDir, dir);
46 fs.mkdirSync(targetDir, { recursive: true });
47 try {
48 const files = execFileSync('gh', [
49 'api', `repos/${CAMEL_REPO}/contents/${CATALOG_BASE}/${dir}?ref=${branch}`,
50 '--jq', '.[].name'
51 ], { encoding: 'utf8' }).trim().split('\n').filter(f => f.endsWith('.json'));
52
53 console.log(` Fetching catalog/${dir}/ (${files.length} files)...`);
54
55 for (const file of files) {
56 try {
57 const content = execFileSync('gh', [
58 'api', `repos/${CAMEL_REPO}/contents/${CATALOG_BASE}/${dir}/${file}?ref=${branch}`,
59 '--jq', '.content'
60 ], { encoding: 'utf8' });
61 fs.writeFileSync(
62 path.join(targetDir, file),
63 Buffer.from(content.trim(), 'base64').toString('utf8')
64 );
65 } catch {
66 // skip individual file failures silently
67 }
68 }
69 } catch (error) {
70 console.warn(` Could not fetch catalog/${dir}: ${error.message}`);
71 }
72 }
73
74 return fs.existsSync(catalogDir);
75}
76
77function main() {

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected