hoppscotch-backend-git/scripts/build-hoppscotch-data.ts
2026-07-24 14:21:10 +02:00

58 lines
1.4 KiB
TypeScript

import { cp, mkdir, rm } from 'node:fs/promises';
import { join } from 'node:path';
const root = join(import.meta.dirname, '..'),
upstreamData = join(
root,
'hoppscotch-upstream/packages/hoppscotch-data',
),
cacheData = join(root, '.cache/hoppscotch-data'),
built = Bun.file(join(cacheData, 'dist/hoppscotch-data.js'));
if(await built.exists()) {
console.log('@hoppscotch/data already built in .cache');
process.exit(0);
}
console.log('Building @hoppscotch/data in .cache (submodule left untouched)…');
await rm(cacheData, {
recursive: true,
force: true,
});
await mkdir(join(root, '.cache'), { recursive: true });
await cp(upstreamData, cacheData, {
recursive: true,
filter: (src) => !src.includes('node_modules') && !src.includes('/dist'),
});
const install = Bun.spawn(
['bun', 'install', '--ignore-scripts'],
{
cwd: cacheData,
stdout: 'inherit',
stderr: 'inherit',
},
);
if(await install.exited !== 0)
process.exit(1);
const buildCode = Bun.spawn(
['bun', 'run', 'build:code'],
{
cwd: cacheData,
stdout: 'inherit',
stderr: 'inherit',
},
);
if(await buildCode.exited !== 0)
process.exit(1);
const decl = Bun.spawn(
['bunx', 'tsc', '--project', 'tsconfig.decl.json'],
{
cwd: cacheData,
stdout: 'inherit',
stderr: 'inherit',
},
);
process.exit(await decl.exited);