77 lines
2.2 KiB
JavaScript
77 lines
2.2 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* CI: kernel TUI artifact + booter embedded source match a fresh concat,
|
|
* and lib/tui/src + lib/sdk/src stay free of import/export/require.
|
|
*/
|
|
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
import process from 'node:process'
|
|
import { fileURLToPath } from 'node:url'
|
|
import {
|
|
concatTuiSdkSource,
|
|
tuiSdkDataModule,
|
|
tuiSdkPaths
|
|
} from './lib/tui-sdk-bundle.mjs'
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
const FORBIDDEN = /\b(import|export|require)\s*[\s('"`]/
|
|
|
|
function walkJs(dir, out) {
|
|
if (!fs.existsSync(dir)) return
|
|
for (const ent of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
const p = path.join(dir, ent.name)
|
|
if (ent.isDirectory()) walkJs(p, out)
|
|
else if (ent.isFile() && ent.name.endsWith('.js')) out.push(p)
|
|
}
|
|
}
|
|
|
|
function main() {
|
|
const p = tuiSdkPaths(root)
|
|
const { source } = concatTuiSdkSource(root)
|
|
const kernel = fs.existsSync(p.kernelOut)
|
|
? fs.readFileSync(p.kernelOut, 'utf8')
|
|
: ''
|
|
if (kernel.trim() !== source.trim()) {
|
|
console.error(
|
|
'verify-tui-concat: kernel/lib/bare-os/tui.js is stale. Run: node scripts/bundle-tui-sdk.mjs'
|
|
)
|
|
process.exit(1)
|
|
}
|
|
const seeder = fs.existsSync(p.seederOut)
|
|
? fs.readFileSync(p.seederOut, 'utf8')
|
|
: ''
|
|
if (seeder.trim() !== source.trim()) {
|
|
console.error(
|
|
'verify-tui-concat: seeder kernel/lib/bare-os/tui.js is stale. Run: node scripts/bundle-tui-sdk.mjs'
|
|
)
|
|
process.exit(1)
|
|
}
|
|
const wantData = tuiSdkDataModule(source)
|
|
const gotData = fs.existsSync(p.dataOut)
|
|
? fs.readFileSync(p.dataOut, 'utf8')
|
|
: ''
|
|
if (gotData !== wantData) {
|
|
console.error(
|
|
'verify-tui-concat: bare-os-tui-sdk.data.mjs is stale. Run: node scripts/bundle-tui-sdk.mjs'
|
|
)
|
|
process.exit(1)
|
|
}
|
|
|
|
const srcFiles = []
|
|
walkJs(path.join(root, 'lib', 'tui', 'src'), srcFiles)
|
|
walkJs(path.join(root, 'lib', 'sdk', 'src'), srcFiles)
|
|
for (const abs of srcFiles) {
|
|
const txt = fs.readFileSync(abs, 'utf8')
|
|
if (FORBIDDEN.test(txt)) {
|
|
console.error(
|
|
'verify-tui-concat: import/export/require in',
|
|
path.relative(root, abs)
|
|
)
|
|
process.exit(1)
|
|
}
|
|
}
|
|
console.log('verify-tui-concat: OK')
|
|
}
|
|
|
|
main()
|