Skip to content

Commit

Permalink
Merge pull request #23144 from storybookjs/fix/init-after-dev
Browse files Browse the repository at this point in the history
CLI: Fix storybook dev after storybook init via subprocess
  • Loading branch information
shilman committed Jun 20, 2023
2 parents 5b30336 + 39820ec commit c739d02
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions code/lib/cli/src/initiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { JsPackageManagerFactory, useNpmWarning } from './js-package-manager';
import type { NpmOptions } from './NpmOptions';
import type { CommandOptions } from './generators/types';
import { HandledError } from './HandledError';
import { dev } from './dev';

const logger = console;

Expand Down Expand Up @@ -348,34 +347,19 @@ async function doInitiate(options: CommandOptions, pkg: PackageJson): Promise<vo
if (shouldRunDev) {
logger.log('\nRunning Storybook');

switch (projectType) {
case ProjectType.ANGULAR: {
try {
// for angular specifically, we have to run the `ng` command, and to stream the output
// it has to be a sync command.
packageManager.runPackageCommandSync(
`ng run ${installResult.projectName}:storybook`,
['--quiet'],
undefined,
'inherit'
);
} catch (e) {
if (e.message.includes('Command failed with exit code 129')) {
// catch ctrl + c error
} else {
throw e;
}
}
break;
}

default: {
await dev({
...options,
port: 6006,
open: true,
quiet: true,
});
try {
// instead of calling 'dev' automatically, we spawn a subprocess so that it gets
// executed directly in the user's project directory. This avoid potential issues
// with packages running in npxs' node_modules
packageManager.runPackageCommandSync(storybookCommand, ['--quiet'], undefined, 'inherit');
} catch (e) {
const isCtrlC =
e.message.includes('Command failed with exit code 129') &&
e.message.includes('CTRL+C') &&
e.message.includes('SIGINT');
if (!isCtrlC) {
// only throw if it's not ctrl + c
throw e;
}
}
}
Expand Down

0 comments on commit c739d02

Please sign in to comment.