storybook/scripts/utils/serve-sandbox.ts
2022-08-12 15:06:36 +10:00

24 lines
715 B
TypeScript

import { AbortController } from 'node-abort-controller';
import path from 'path';
import { exec } from './exec';
const codeDir = path.resolve(__dirname, '../../code');
export async function serveSandbox(
directory: string,
{ dryRun, debug }: { dryRun?: boolean; debug?: boolean }
) {
const controller = new AbortController();
exec(
`yarn http-server ${directory} --port 8001`,
{ cwd: codeDir },
{ dryRun, debug, signal: controller.signal as AbortSignal }
).catch((err) => {
// If aborted, we want to make sure the rejection is handled.
if (!err.killed) throw err;
});
await exec('yarn wait-on http://localhost:8001', { cwd: codeDir }, { dryRun, debug });
return controller;
}