storybook/scripts/tasks/run-registry.ts
2023-03-29 12:32:23 +02:00

35 lines
1.0 KiB
TypeScript

import detectFreePort from 'detect-port';
import { CODE_DIRECTORY } from '../utils/constants';
import { exec } from '../utils/exec';
import type { Task } from '../task';
export async function runRegistry({ dryRun, debug }: { dryRun?: boolean; debug?: boolean }) {
const controller = new AbortController();
exec(
'ts-node --swc --project=../scripts/tsconfig.json ../scripts/run-registry.ts --open',
{ cwd: CODE_DIRECTORY, env: { CI: 'true' } },
{ dryRun, debug, signal: controller.signal }
).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:6001', { cwd: CODE_DIRECTORY }, { dryRun, debug });
return controller;
}
const REGISTRY_PORT = 6001;
export const runRegistryTask: Task = {
description: 'Run the internal npm server',
service: true,
dependsOn: ['publish'],
async ready() {
return (await detectFreePort(REGISTRY_PORT)) !== REGISTRY_PORT;
},
async run(_, options) {
return runRegistry(options);
},
};