#!/usr/bin/env node /** * Create a writable Pear link for local stage/release on this host. * Writes packages//.pear-stage-link (gitignored). * * Usage: node scripts/bootstrap-pear-stage-link.mjs */ import { execSync } from 'node:child_process' import { writeFileSync } from 'node:fs' import path from 'node:path' const pkgDir = path.resolve(process.argv[2] ?? '') if (!pkgDir) { console.error('usage: bootstrap-pear-stage-link.mjs ') process.exit(1) } let out try { out = execSync('pear touch --json', { cwd: pkgDir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] }) } catch (err) { console.error(`pear touch failed: ${err.message}`) process.exit(1) } let link = null for (const line of out.trim().split('\n').filter(Boolean).reverse()) { try { const row = JSON.parse(line) link = row.data?.link ?? row.link ?? null if (link) break } catch { /* skip non-JSON lines (warnings) */ } } if (!link || !/^pear:\/\/[a-z0-9]+$/i.test(link)) { console.error('pear touch --json did not return a pear:// link') process.exit(1) } const dest = path.join(pkgDir, '.pear-stage-link') writeFileSync(dest, `${link}\n`, 'utf8') console.error(`Wrote ${dest}`) process.stdout.write(`${link}\n`)