50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Emit packages/bare-os-booter/lib/bare-module-manifest.data.mjs from
|
|
* bare-module-manifest.json so Pear's module graph always ships the manifest
|
|
* (readFileSync(pear://…) is unreliable; bare-fs coerces URLs through fileURLToPath).
|
|
*
|
|
* node scripts/generate-bare-module-manifest-data.mjs
|
|
*
|
|
* Invoked automatically at the end of sync-bare-module-manifest-from-catalog.mjs.
|
|
*/
|
|
import { readFile, writeFile } from 'node:fs/promises'
|
|
import { dirname, join } from 'node:path'
|
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
const root = join(__dirname, '..')
|
|
const manifestPath = join(
|
|
root,
|
|
'packages/bare-os-booter/lib/bare-module-manifest.json'
|
|
)
|
|
const dataPath = join(
|
|
root,
|
|
'packages/bare-os-booter/lib/bare-module-manifest.data.mjs'
|
|
)
|
|
|
|
const banner =
|
|
'/**\n' +
|
|
' * Auto-generated from bare-module-manifest.json — do not edit by hand.\n' +
|
|
' * Regenerate: `npm run sync:bare-manifest` or\n' +
|
|
' * `node scripts/generate-bare-module-manifest-data.mjs`.\n' +
|
|
' */\n'
|
|
|
|
export async function generateBareModuleManifestData(opts = {}) {
|
|
const src = opts.manifestPath ?? manifestPath
|
|
const dst = opts.dataPath ?? dataPath
|
|
const raw = await readFile(src, 'utf8')
|
|
const manifest = JSON.parse(raw)
|
|
const body = `${banner}export default ${JSON.stringify(manifest, null, 2)}\n`
|
|
await writeFile(dst, body, 'utf8')
|
|
}
|
|
|
|
const ranAsCli =
|
|
process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href
|
|
if (ranAsCli) {
|
|
generateBareModuleManifestData().catch((e) => {
|
|
console.error(e)
|
|
process.exit(1)
|
|
})
|
|
}
|