| #!/usr/bin/env node |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import { spawnSync } from "node:child_process"; |
| import { mkdirSync, writeFileSync, existsSync } from "node:fs"; |
| import { dirname, join, resolve } from "node:path"; |
| import { fileURLToPath } from "node:url"; |
|
|
| const scriptDir = dirname(fileURLToPath(import.meta.url)); |
| const websiteDir = resolve(scriptDir, ".."); |
| const extractScript = join(scriptDir, "extract-skills.py"); |
| const outputFile = join(websiteDir, "src", "data", "skills.json"); |
|
|
| function writeEmptyFallback(reason) { |
| mkdirSync(dirname(outputFile), { recursive: true }); |
| writeFileSync(outputFile, "[]\n"); |
| console.warn( |
| `[prebuild] extract-skills.py skipped (${reason}); wrote empty skills.json. ` + |
| `Install python3 + pyyaml locally for a populated Skills Hub page.`, |
| ); |
| } |
|
|
| if (!existsSync(extractScript)) { |
| writeEmptyFallback("extract script missing"); |
| process.exit(0); |
| } |
|
|
| const result = spawnSync("python3", [extractScript], { |
| stdio: "inherit", |
| cwd: websiteDir, |
| }); |
|
|
| if (result.error && result.error.code === "ENOENT") { |
| writeEmptyFallback("python3 not found"); |
| process.exit(0); |
| } |
|
|
| if (result.status !== 0) { |
| writeEmptyFallback(`extract-skills.py exited with status ${result.status}`); |
| process.exit(0); |
| } |
|
|