Skip to content

Commit

Permalink
feat(storybook): show warning about version 5 support drop (#9257)
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Mar 9, 2022
1 parent 064d7ec commit 261b35d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
@@ -1,9 +1,11 @@
import { ExecutorContext, logger } from '@nrwl/devkit';
import * as build from '@storybook/core/standalone';
import 'dotenv/config';
import { showStorybookV5Warning } from '../../utils/utilities';
import { CommonNxStorybookConfig } from '../models';
import {
getStorybookFrameworkPath,
isStorybookLT6,
normalizeAngularBuilderStylesOptions,
resolveCommonStorybookOptionMapper,
runStorybookSetupCheck,
Expand All @@ -30,6 +32,10 @@ export default async function buildStorybookExecutor(
// print warnings
runStorybookSetupCheck(options);

if (isStorybookLT6()) {
showStorybookV5Warning(options.uiFramework);
}

logger.info(`NX Storybook builder starting ...`);
await runInstance(option);
logger.info(`NX Storybook builder finished ...`);
Expand Down
6 changes: 6 additions & 0 deletions packages/storybook/src/executors/storybook/storybook.impl.ts
@@ -1,12 +1,14 @@
import { ExecutorContext, logger } from '@nrwl/devkit';
import { buildDevStandalone } from '@storybook/core/server';
import 'dotenv/config';
import { showStorybookV5Warning } from '../../utils/utilities';
import { CommonNxStorybookConfig } from '../models';
import {
getStorybookFrameworkPath,
normalizeAngularBuilderStylesOptions,
resolveCommonStorybookOptionMapper,
runStorybookSetupCheck,
isStorybookLT6,
} from '../utils';
export interface StorybookExecutorOptions extends CommonNxStorybookConfig {
host?: string;
Expand Down Expand Up @@ -34,6 +36,10 @@ export default async function* storybookExecutor(
// print warnings
runStorybookSetupCheck(options);

if (isStorybookLT6()) {
showStorybookV5Warning(options.uiFramework);
}

await runInstance(option);

yield { success: true };
Expand Down
11 changes: 10 additions & 1 deletion packages/storybook/src/executors/utils.ts
Expand Up @@ -13,7 +13,7 @@ import { checkAndCleanWithSemver } from '@nrwl/workspace/src/utilities/version-u
import 'dotenv/config';
import { existsSync, readFileSync } from 'fs';
import { join } from 'path';
import { gte } from 'semver';
import { gte, lt } from 'semver';
import {
findOrCreateConfig,
readCurrentWorkspaceStorybookVersionFromExecutor,
Expand Down Expand Up @@ -296,6 +296,15 @@ function isStorybookGTE6_4() {
);
}

export function isStorybookLT6() {
const storybookVersion = readCurrentWorkspaceStorybookVersionFromExecutor();

return lt(
checkAndCleanWithSemver('@storybook/core', storybookVersion),
'6.0.0'
);
}

export function findStorybookAndBuildTargets(targets: {
[targetName: string]: TargetConfiguration;
}): {
Expand Down
Expand Up @@ -22,6 +22,7 @@ import { join } from 'path';
import {
isFramework,
readCurrentWorkspaceStorybookVersionFromGenerator,
showStorybookV5Warning,
TsConfig,
} from '../../utils/utilities';
import { cypressProjectGenerator } from '../cypress-project/cypress-project';
Expand Down Expand Up @@ -78,6 +79,10 @@ export async function configurationGenerator(
}
}

if (workspaceStorybookVersion !== '6') {
showStorybookV5Warning(rawSchema.uiFramework);
}

await formatFiles(tree);

return runTasksInSerial(...tasks);
Expand Down Expand Up @@ -112,6 +117,7 @@ function createRootStorybookDir(
`adding .storybook folder to the root directory -
based on the Storybook version installed (v${workspaceStorybookVersion}), we'll bootstrap a scaffold for that particular version.`
);

const templatePath = join(
__dirname,
workspaceStorybookVersion === '6' ? './root-files' : './root-files-5'
Expand Down
35 changes: 34 additions & 1 deletion packages/storybook/src/utils/utilities.ts
@@ -1,4 +1,10 @@
import { ExecutorContext, readJson, readJsonFile, Tree } from '@nrwl/devkit';
import {
ExecutorContext,
logger,
readJson,
readJsonFile,
Tree,
} from '@nrwl/devkit';
import { CompilerOptions } from 'typescript';
import { storybookVersion } from './versions';
import { StorybookConfig } from '../executors/models';
Expand Down Expand Up @@ -198,3 +204,30 @@ function createStorybookConfig(
);
return tmpFolder;
}

export function showStorybookV5Warning(
uiFramework:
| '@storybook/angular'
| '@storybook/react'
| '@storybook/html'
| '@storybook/web-components'
| '@storybook/vue'
| '@storybook/vue3'
| '@storybook/svelte'
| '@storybook/react-native'
) {
logger.warn(
`It looks like you're using Storybook version 5.
Please note that starting with version 14, Nx will drop support for Storybook version 5.
Before upgrading to Nx 14, please make sure you have migrated your Storybook configurations
to the latest version of Storybook.
For more information, please take a look at our upgrade guide:
${
uiFramework === '@storybook/angular'
? 'https://nx.dev/storybook/upgrade-storybook-v6-angular'
: 'https://nx.dev/storybook/upgrade-storybook-v6-react'
}
`
);
}

0 comments on commit 261b35d

Please sign in to comment.