* Generate samples/cookbook data from cookbook.yml
()
| 1401 | * Generate samples/cookbook data from cookbook.yml |
| 1402 | */ |
| 1403 | function generateSamplesData() { |
| 1404 | const cookbookYamlPath = path.join(COOKBOOK_DIR, "cookbook.yml"); |
| 1405 | |
| 1406 | if (!fs.existsSync(cookbookYamlPath)) { |
| 1407 | console.warn( |
| 1408 | "Warning: cookbook/cookbook.yml not found, skipping samples generation" |
| 1409 | ); |
| 1410 | return { |
| 1411 | cookbooks: [], |
| 1412 | totalRecipes: 0, |
| 1413 | totalCookbooks: 0, |
| 1414 | filters: { languages: [], tags: [] }, |
| 1415 | }; |
| 1416 | } |
| 1417 | |
| 1418 | const cookbookManifest = parseYamlFile(cookbookYamlPath); |
| 1419 | if (!cookbookManifest || !cookbookManifest.cookbooks) { |
| 1420 | console.warn("Warning: Invalid cookbook.yml format"); |
| 1421 | return { |
| 1422 | cookbooks: [], |
| 1423 | totalRecipes: 0, |
| 1424 | totalCookbooks: 0, |
| 1425 | filters: { languages: [], tags: [] }, |
| 1426 | }; |
| 1427 | } |
| 1428 | |
| 1429 | const allLanguages = new Set(); |
| 1430 | const allTags = new Set(); |
| 1431 | let totalRecipes = 0; |
| 1432 | |
| 1433 | // First pass: collect all known language IDs across cookbooks |
| 1434 | cookbookManifest.cookbooks.forEach((cookbook) => { |
| 1435 | cookbook.languages.forEach((lang) => allLanguages.add(lang.id)); |
| 1436 | }); |
| 1437 | |
| 1438 | const cookbooks = cookbookManifest.cookbooks.map((cookbook) => { |
| 1439 | |
| 1440 | // Process recipes and add file paths |
| 1441 | const recipes = cookbook.recipes.map((recipe) => { |
| 1442 | // Collect tags |
| 1443 | if (recipe.tags) { |
| 1444 | recipe.tags.forEach((tag) => allTags.add(tag)); |
| 1445 | } |
| 1446 | |
| 1447 | totalRecipes++; |
| 1448 | |
| 1449 | // External recipes link to an external URL — skip local file resolution |
| 1450 | if (recipe.external) { |
| 1451 | if (recipe.url) { |
| 1452 | try { |
| 1453 | new URL(recipe.url); |
| 1454 | } catch { |
| 1455 | console.warn(`Warning: Invalid URL for external recipe "${recipe.id}": ${recipe.url}`); |
| 1456 | } |
| 1457 | } else { |
| 1458 | console.warn(`Warning: External recipe "${recipe.id}" is missing a url`); |
| 1459 | } |
| 1460 |