Skip to content

Commit

Permalink
CLI: check for storybook before running upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed May 23, 2022
1 parent 2c48845 commit fd6fc5d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/cli/src/upgrade.ts
Expand Up @@ -9,6 +9,7 @@ import {
} from './js-package-manager';
import { commandLog } from './helpers';
import { automigrate } from './automigrate';
import { isStorybookInstalled } from './detect';

type Package = {
package: string;
Expand Down Expand Up @@ -152,6 +153,14 @@ export const upgrade = async ({
...options
}: UpgradeOptions) => {
const packageManager = JsPackageManagerFactory.getPackageManager(useNpm);
const packageJson = packageManager.retrievePackageJson();

if (!isStorybookInstalled(packageJson)) {
commandLog(
`There's no Storybook installed in the current directory: ${process.cwd()}\nAre you running the command in the correct directory?\n`
);
process.exit(0);
}

commandLog(`Checking for latest versions of '@storybook/*' packages`);
if (!options.disableTelemetry) {
Expand All @@ -162,7 +171,7 @@ export const upgrade = async ({
if (!dryRun) flags.push('--upgrade');
flags.push('--target');
flags.push(prerelease ? 'greatest' : 'latest');
flags = addExtraFlags(EXTRA_FLAGS, flags, packageManager.retrievePackageJson());
flags = addExtraFlags(EXTRA_FLAGS, flags, packageJson);
const check = spawnSync('npx', ['npm-check-updates@latest', '/storybook/', ...flags], {
stdio: 'pipe',
}).output.toString();
Expand Down

0 comments on commit fd6fc5d

Please sign in to comment.