Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
52 lines
1.8 KiB
JavaScript
52 lines
1.8 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Generate Orval client into api/generated/.
|
|
*
|
|
* Monorepo: refresh OpenAPI from Nest when ../backend exists, then orval.
|
|
* Satellite (ghabilee-frontend): orval only from committed ./openapi.json.
|
|
*/
|
|
import { spawnSync } from 'node:child_process'
|
|
import { copyFileSync, existsSync } from 'node:fs'
|
|
import { dirname, join } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const frontendRoot = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
const backendOpenapi = join(frontendRoot, '../backend/openapi.json')
|
|
const localOpenapi = join(frontendRoot, 'openapi.json')
|
|
const backendDir = join(frontendRoot, '../backend')
|
|
|
|
function run(command, args, opts = {}) {
|
|
const result = spawnSync(command, args, {
|
|
stdio: 'inherit',
|
|
cwd: frontendRoot,
|
|
shell: process.platform === 'win32',
|
|
...opts,
|
|
})
|
|
if (result.status !== 0) {
|
|
process.exit(result.status ?? 1)
|
|
}
|
|
}
|
|
|
|
if (existsSync(backendDir) && existsSync(join(backendDir, 'package.json'))) {
|
|
console.log('==> Exporting OpenAPI from backend...')
|
|
run('pnpm', ['--dir', backendDir, 'generate:openapi'])
|
|
if (!existsSync(backendOpenapi)) {
|
|
console.error(`Missing ${backendOpenapi} after export`)
|
|
process.exit(1)
|
|
}
|
|
copyFileSync(backendOpenapi, localOpenapi)
|
|
console.log('==> Copied backend/openapi.json → frontend/openapi.json')
|
|
} else if (!existsSync(localOpenapi)) {
|
|
console.error(
|
|
'No ../backend and no ./openapi.json — cannot generate API client.\n' +
|
|
'In the satellite repo, openapi.json must be committed; re-sync from the monorepo.',
|
|
)
|
|
process.exit(1)
|
|
} else {
|
|
console.log('==> No backend sibling — using committed ./openapi.json')
|
|
}
|
|
|
|
console.log('==> Running orval...')
|
|
run('pnpm', ['exec', 'orval', '--config', 'orval.config.ts'])
|
|
console.log('✓ api/generated updated')
|