Files
ipal-kit/scripts/legacy-site-check.mjs
T
Radosław SmolińskiandClaude Fable 5.2 3d5106bc4a IAPL rename: readEnv exported, the MCP server name left as it was, legacy:site needs a database
- readEnv / legacyEnvName exported from the root and /env (a project's own code reads IAPL_* with the IPAL_* fallback);
  the name constants hold the IAPL_ spelling — changelog and env.md say so
- createMcpRoute: the default serverName stays 'ipal-site' (clients see it); the scripted step had changed it
- legacy:site: the builds read the database; the script and PROGRAMISTA say which

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-25 17:47:11 +01:00

122 lines
6.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* pnpm legacy:site — a site written for the last release BEFORE the rename to IAPL works on this build, unedited.
*
* The reference site as it was at a tag (default v1.16.7: `ipalKit()`, `ipal-tokens`, `ipal-doctor.json`, `ipal-*`
* skills, the old pointer block) is unpacked next to the plugin and installed against the plugin built from this
* tree. Nothing in it is changed. Then:
* 1. the old commands run: `ipal-tokens --check`, `ipal-doctor` (no error; the warnings are printed);
* 2. `payload generate:importmap` leaves the committed import map byte for byte as it was;
* 3. `tsc --noEmit`: the old names still type-check;
* 4. a production build with webpack and one with Turbopack.
*
* Needs: the plugin built (`pnpm build`; --skip-plugin-build when dist is current), the tag in the local repository.
* The builds read the database (static params), so DATABASE_URI must point at a reachable local MongoDB — an empty
* one is enough (default mongodb://127.0.0.1:27017/example-studiopl_dev, the reference site's local database).
* Options: --tag=v1.16.7 · --only=webpack|turbopack · --skip-build (steps 1–3 only) · --keep (leave the folder).
* The folder (.legacy-site-<tag>, git-ignored) is removed at the end unless --keep.
*/
import { spawnSync } from 'node:child_process'
import { existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const args = process.argv.slice(2)
const opt = (name, fallback) => args.find((a) => a.startsWith(`--${name}=`))?.slice(name.length + 3) ?? fallback
const tag = opt('tag', 'v1.16.7')
const only = opt('only')
const bundlers = ['webpack', 'turbopack'].filter((b) => !only || b === only)
const site = path.join(root, `.legacy-site-${tag.replace(/[^\w.-]/g, '_')}`)
const env = {
...process.env,
DATABASE_URI: process.env.DATABASE_URI ?? 'mongodb://127.0.0.1:27017/example-studiopl_dev',
NEXT_PUBLIC_SERVER_URL: process.env.NEXT_PUBLIC_SERVER_URL ?? 'http://localhost:3000',
NEXT_TELEMETRY_DISABLED: '1',
PAYLOAD_SECRET: process.env.PAYLOAD_SECRET ?? 'legacy-site-check-secret-0123456789abcdef',
}
const results = []
const sh = (label, command, commandArgs, { capture = false, cwd = site, allowFail = false } = {}) => {
console.log(`\n[legacy:site] ${label}`)
const res = spawnSync(command, commandArgs, { cwd, encoding: 'utf8', env, maxBuffer: 256 * 1024 * 1024, stdio: capture ? ['ignore', 'pipe', 'inherit'] : 'inherit' })
if (res.status !== 0 && !allowFail) {
console.error(`\n[legacy:site] ✗ FAILED: ${label}`)
finish(1)
}
return res
}
const finish = (code) => {
if (!args.includes('--keep')) {rmSync(site, { force: true, recursive: true })}
for (const line of results) {console.log(`[legacy:site] ${line}`)}
process.exit(code)
}
if (spawnSync('git', ['rev-parse', '--verify', '--quiet', `${tag}^{commit}`], { cwd: root }).status !== 0) {
console.error(`[legacy:site] tag ${tag} is not in this repository (git fetch --tags)`)
process.exit(2)
}
if (!args.includes('--skip-plugin-build')) {sh('build the plugin', 'pnpm', ['build'], { cwd: root })}
if (!existsSync(path.join(root, 'dist/index.js'))) {
console.error('[legacy:site] dist/ is missing — run pnpm build')
process.exit(2)
}
rmSync(site, { force: true, recursive: true })
mkdirSync(site, { recursive: true })
// reference/ of the tag, unpacked as a direct child of the plugin root: its "file:.." dependency is this tree.
const archive = spawnSync('sh', ['-c', `git archive ${tag} reference | tar -x --strip-components=1 -C "${site}"`], { cwd: root, stdio: 'inherit' })
if (archive.status !== 0) {finish(1)}
const config = readFileSync(path.join(site, 'src/payload.config.ts'), 'utf8')
if (!/\bipalKit\s*\(/.test(config)) {
console.error(`[legacy:site] ${tag}: the reference site does not call ipalKit() — pick a tag from before 1.17.0`)
finish(2)
}
sh('install the old site against this build', 'pnpm', ['install', '--ignore-workspace', '--no-frozen-lockfile'])
const installed = JSON.parse(readFileSync(path.join(site, 'node_modules/@intecion/ipal-kit/package.json'), 'utf8')).version
results.push(`site of ${tag}, plugin ${installed} from this tree`)
sh('old command: ipal-tokens --check', 'pnpm', ['exec', 'ipal-tokens', '--check'])
results.push('ipal-tokens --check: ok')
const doctor = sh('old command: ipal-doctor (static, offline)', 'pnpm', ['exec', 'ipal-doctor', '.', '--offline', '--json'], { allowFail: true, capture: true })
let report
try {
report = JSON.parse(doctor.stdout)
} catch {
console.error(doctor.stdout)
console.error('[legacy:site] ✗ ipal-doctor did not print JSON')
finish(1)
}
const open = report.findings.filter((f) => !f.silenced)
const count = (severity) => open.filter((f) => f.severity === severity)
for (const f of open.filter((x) => x.severity !== 'info')) {console.log(` ${f.severity}: ${f.rule} — ${f.message}`)}
results.push(`ipal-doctor: ${count('error').length} error(s), ${count('warning').length} warning(s) [${[...new Set(count('warning').map((f) => f.rule))].join(', ')}], ${count('info').length} info [${[...new Set(count('info').map((f) => f.rule))].join(', ')}]`)
if (count('error').length) {
console.error('[legacy:site] ✗ the doctor reports an error on a site that had none')
finish(1)
}
const mapFile = path.join(site, 'src/app/(payload)/admin/importMap.js')
const mapBefore = readFileSync(mapFile, 'utf8')
sh('payload generate:importmap', 'pnpm', ['generate:importmap'])
if (readFileSync(mapFile, 'utf8') !== mapBefore) {
console.error('[legacy:site] ✗ the generated import map differs from the one the old site has committed')
finish(1)
}
results.push('import map: unchanged')
sh('tsc --noEmit (old names against the new types)', 'pnpm', ['typecheck'])
results.push('typecheck: ok')
if (!args.includes('--skip-build')) {
for (const bundler of bundlers) {
rmSync(path.join(site, '.next'), { force: true, recursive: true })
sh(`production build, ${bundler}`, 'pnpm', ['exec', 'cross-env', 'NODE_OPTIONS=--max-old-space-size=3072', 'next', 'build', ...(bundler === 'webpack' ? ['--webpack'] : [])])
results.push(`build (${bundler}): ok`)
}
}
console.log('\n[legacy:site] ✓ the old site works on this build')
finish(0)