mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-22 05:02:18 +08:00
24 lines
715 B
TypeScript
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;
|
|
}
|