51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
const fs = require('fs/promises')
|
|
const path = require('path')
|
|
const { spawn } = require('child_process')
|
|
|
|
const repoRoot = process.cwd()
|
|
const nextBin = path.join(repoRoot, 'node_modules', 'next', 'dist', 'bin', 'next')
|
|
const tscBin = path.join(repoRoot, 'node_modules', 'typescript', 'bin', 'tsc')
|
|
|
|
function run(command, args) {
|
|
return new Promise((resolve, reject) => {
|
|
const child = spawn(command, args, {
|
|
cwd: repoRoot,
|
|
stdio: 'inherit',
|
|
shell: false,
|
|
})
|
|
|
|
child.on('exit', (code) => {
|
|
if (code === 0) {
|
|
resolve()
|
|
return
|
|
}
|
|
|
|
reject(new Error(`${command} ${args.join(' ')} exited with code ${code}`))
|
|
})
|
|
})
|
|
}
|
|
|
|
async function ensureNextCacheLifeStub() {
|
|
const typesDir = path.join(repoRoot, '.next', 'types')
|
|
const cacheLifePath = path.join(typesDir, 'cache-life.d.ts')
|
|
|
|
await fs.mkdir(typesDir, { recursive: true })
|
|
|
|
try {
|
|
await fs.access(cacheLifePath)
|
|
} catch {
|
|
await fs.writeFile(cacheLifePath, '', 'utf8')
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
await run(process.execPath, [nextBin, 'typegen'])
|
|
await ensureNextCacheLifeStub()
|
|
await run(process.execPath, [tscBin, '--noEmit', '--incremental', 'false'])
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error)
|
|
process.exitCode = 1
|
|
})
|