feat: expose port from buildDevStandalone

Co-authored-by: Valentin Palkovic <valentin@chromatic.com>
This commit is contained in:
Katerina Skroumpelou 2023-01-12 12:26:12 +02:00
parent 60a40e9430
commit ae927e4da8
3 changed files with 24 additions and 22 deletions

View File

@ -106,8 +106,8 @@ function commandBuilder(
return standaloneOptions;
}),
switchMap((standaloneOptions) => runInstance(standaloneOptions)),
map(() => {
return { success: true };
map((port: number) => {
return { success: true, info: { port } };
})
);
}
@ -132,10 +132,10 @@ async function setup(options: StorybookBuilderOptions, context: BuilderContext)
};
}
function runInstance(options: StandaloneOptions) {
return new Observable<void>((observer) => {
return new Observable<number>((observer) => {
// This Observable intentionally never complete, leaving the process running ;)
buildDevStandalone(options as any).then(
() => observer.next(),
({ port }) => observer.next(port),
(error) => observer.error(buildStandaloneErrorHandler(error))
);
});

View File

@ -28,7 +28,9 @@ import { updateCheck } from './utils/update-check';
import { getServerPort, getServerChannelUrl } from './utils/server-address';
import { getManagerBuilder, getPreviewBuilder } from './utils/get-builders';
export async function buildDevStandalone(options: CLIOptions & LoadOptions & BuilderOptions) {
export async function buildDevStandalone(
options: CLIOptions & LoadOptions & BuilderOptions
): Promise<{ port: number }> {
const { packageJson, versionUpdates, releaseNotes } = options;
const { version } = packageJson;
@ -156,21 +158,21 @@ export async function buildDevStandalone(options: CLIOptions & LoadOptions & Bui
// eslint-disable-next-line no-console
console.log(problems.map((p) => p.stack));
process.exit(problems.length > 0 ? 1 : 0);
return;
} else {
const name =
frameworkName.split('@storybook/').length > 1
? frameworkName.split('@storybook/')[1]
: frameworkName;
outputStartupInformation({
updateInfo: versionCheck,
version,
name,
address,
networkAddress,
managerTotalTime,
previewTotalTime,
});
}
const name =
frameworkName.split('@storybook/').length > 1
? frameworkName.split('@storybook/')[1]
: frameworkName;
outputStartupInformation({
updateInfo: versionCheck,
version,
name,
address,
networkAddress,
managerTotalTime,
previewTotalTime,
});
return { port };
}

View File

@ -61,7 +61,7 @@ async function getErrorLevel({ cliOptions, presetOptions }: TelemetryOptions): P
export async function withTelemetry(
eventType: EventType,
options: TelemetryOptions,
run: () => Promise<void>
run: () => Promise<any>
) {
if (!options.cliOptions.disableTelemetry)
telemetry('boot', { eventType }, { stripMetadata: true });