Skip to content

Commit

Permalink
fix(storybook): check storybook is installed and not on v7 already
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Apr 19, 2023
1 parent 4446bf7 commit 6fde64f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as build from '@storybook/core-server';
import { CLIOptions } from '@storybook/types'; // TODO(katerina): Remove when Storybook 7
import 'dotenv/config';
import {
isStorybookV7,
storybookConfigExistsCheck,
storybookMajorVersion,
} from '../../utils/utilities';
import { CommonNxStorybookConfig } from '../../utils/models';
import {
Expand All @@ -18,7 +18,7 @@ export default async function buildStorybookExecutor(
context: ExecutorContext
) {
storybookConfigExistsCheck(options.configDir, context.projectName);
const storybook7 = isStorybookV7();
const storybook7 = storybookMajorVersion() === 7;
if (storybook7) {
const buildOptions: CLIOptions = options;
logger.info(`NX Storybook builder starting ...`);
Expand Down
4 changes: 2 additions & 2 deletions packages/storybook/src/executors/storybook/storybook.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ExecutorContext } from '@nx/devkit';
import * as build from '@storybook/core-server';
import 'dotenv/config';
import {
isStorybookV7,
storybookConfigExistsCheck,
storybookMajorVersion,
} from '../../utils/utilities';
import {
getStorybookFrameworkPath,
Expand All @@ -20,7 +20,7 @@ export default async function* storybookExecutor(
success: boolean;
info?: { port: number; baseUrl?: string };
}> {
const storybook7 = isStorybookV7();
const storybook7 = storybookMajorVersion() === 7;
storybookConfigExistsCheck(options.configDir, context.projectName);
if (storybook7) {
const buildOptions: CLIOptions = options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Tree } from '@nx/devkit';
import { output } from 'nx/src/utils/output';
import migrate7Generator from '../../generators/migrate-7/migrate-7';
import { storybookMajorVersion } from '../../utils/utilities';

export default async function changeStorybookTargets(tree: Tree) {
const storybookVersion = storybookMajorVersion();
if (!storybookVersion || storybookVersion === 7) {
return;
}

output.log({
title: 'Migrating Storybook to v7',
bodyLines: [
Expand Down
12 changes: 2 additions & 10 deletions packages/storybook/src/utils/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { storybookVersion } from './versions';
import { statSync } from 'fs';
import { findNodes } from '@nx/js';
import ts = require('typescript');
import { gte, lt, major } from 'semver';
import { major } from 'semver';
import { join } from 'path';

export const Constants = {
Expand Down Expand Up @@ -51,15 +51,7 @@ type Framework = {
uiFramework: Constants['uiFrameworks'][keyof Constants['uiFrameworks']];
};

export function isStorybookV7() {
const storybookPackageVersion = require(join(
'@storybook/core-server',
'package.json'
)).version;
return gte(storybookPackageVersion, '7.0.0-alpha.0');
}

export function storybookMajorVersion() {
export function storybookMajorVersion(): number | undefined {
try {
const storybookPackageVersion = require(join(
'@storybook/core-server',
Expand Down

0 comments on commit 6fde64f

Please sign in to comment.