#!/usr/bin/env node import { readFile, stat } from 'node:fs/promises' import { basename } from 'node:path' const FORBIDDEN = [ 'guanghubingshuo.com', ] const REQUIRED = [ 'guanghulab.com/fifth-domain/bingshuo/hololake-platform', 'GLS-SYS-ARCH-001', ] const targets = process.argv.slice(2) if (targets.length === 0) { console.error('Usage: pnpm verify:internal-package [...]') process.exit(2) } async function collectFiles(target) { const info = await stat(target) if (info.isFile()) return [target] const { readdir } = await import('node:fs/promises') const entries = await readdir(target, { withFileTypes: true }) return (await Promise.all(entries.map((entry) => collectFiles(`${target}/${entry.name}`), ))).flat() } const matches = new Map(REQUIRED.map((needle) => [needle, false])) for (const target of targets) { for (const file of await collectFiles(target)) { const contents = await readFile(file) const text = contents.toString('latin1') for (const forbidden of FORBIDDEN) { if (text.includes(forbidden)) { console.error(`Forbidden private route found in ${file}: ${forbidden}`) process.exit(1) } } for (const required of REQUIRED) { if (text.includes(required)) matches.set(required, true) } } } const missing = [...matches].filter(([, found]) => !found).map(([needle]) => needle) if (missing.length > 0) { console.error(`Required public architecture markers missing from ${targets.map((target) => basename(target)).join(', ')}: ${missing.join(', ')}`) process.exit(1) } console.log(`Internal package content verified: ${targets.map((target) => basename(target)).join(', ')}`)