Skip to content

Commit

Permalink
fix: storybook v7 generator dependencies error
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin committed Oct 27, 2023
1 parent b90da8d commit a9d74c6
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 87 deletions.
8 changes: 8 additions & 0 deletions .changeset/slow-beans-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@modern-js/storybook-next-generator': patch
'@modern-js/generator-common': patch
---

fix: storybook v7 generator dependencies error

fix: storybook v7 生成器依赖安装错误
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const ModuleActionFunctions = [
ActionFunction.Test,
ActionFunction.TailwindCSS,
ActionFunction.Storybook,
ActionFunction.StorybookV7,
ActionFunction.RuntimeApi,
];

Expand Down Expand Up @@ -66,6 +67,7 @@ export const ModuleActionFunctionsDevDependencies: Partial<
Record<ActionFunction, string>
> = {
[ActionFunction.Storybook]: '@modern-js/plugin-storybook',
[ActionFunction.StorybookV7]: '@modern-js/storybook',
[ActionFunction.Test]: '@modern-js/plugin-testing',
[ActionFunction.RuntimeApi]: '@modern-js/runtime',
[ActionFunction.TailwindCSS]: 'tailwindcss',
Expand Down Expand Up @@ -102,7 +104,6 @@ export const ModuleNewActionPluginName: Partial<
[ActionType.Function]: {
[ActionFunction.TailwindCSS]: 'tailwindcssPlugin',
[ActionFunction.Storybook]: 'storybookPlugin',
[ActionFunction.StorybookV7]: 'storybookFramework',
[ActionFunction.Test]: 'testPlugin',
},
};
Expand All @@ -114,6 +115,5 @@ export const ModuleNewActionPluginDependence: Partial<
[ActionFunction.Test]: '@modern-js/plugin-testing',
[ActionFunction.TailwindCSS]: '@modern-js/plugin-tailwindcss',
[ActionFunction.Storybook]: '@modern-js/plugin-storybook',
[ActionFunction.StorybookV7]: '@modern-js/storybook',
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ export const MWANewActionPluginDependence: Record<
[ActionFunction.MicroFrontend]: '@modern-js/plugin-garfish',
[ActionFunction.Test]: '@modern-js/plugin-testing',
[ActionFunction.Storybook]: '@modern-js/plugin-storybook',
[ActionFunction.StorybookV7]: '@modern-js/storybook',
[ActionFunction.SSG]: '@modern-js/plugin-ssg',
[ActionFunction.Polyfill]: '@modern-js/plugin-polyfill',
[ActionFunction.Proxy]: '@modern-js/plugin-proxy',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import {
fs,
isReact18,
getPackageVersion,
getPackageManagerText,
} from '@modern-js/generator-utils';
import {
DependenceGenerator,
i18n as commonI18n,
Language,
} from '@modern-js/generator-common';
import { i18n } from './locale';
import { i18n, localeKeys } from './locale';
import { getMajorVersion } from './utils';

const ADDON_ESSENTIAL = '@storybook/addon-essentials';
const MODERN_STORYBOOK = '@modern-js/storybook';

const getGeneratorPath = (generator: string, distTag: string) => {
if (process.env.CODESMITH_ENV === 'development') {
Expand Down Expand Up @@ -75,14 +75,9 @@ const handleTemplateFile = async (
react: isReact18(context.materials.default.basePath) ? '^18' : '^17',
};

const { modernVersion } = context.config;

const exitAddonsVersion =
pkg.devDependencies?.[ADDON_ESSENTIAL] ||
pkg.dependencies?.[ADDON_ESSENTIAL];
const isExitStorybook =
pkg.devDependencies?.[MODERN_STORYBOOK] ||
pkg.dependencies?.[MODERN_STORYBOOK];

const latestVersion = await getPackageVersion(ADDON_ESSENTIAL);
let availableVersion = latestVersion;
Expand All @@ -108,11 +103,6 @@ const handleTemplateFile = async (

const addStorybookDependence = {
[ADDON_ESSENTIAL]: availableVersion,
...(!isExitStorybook
? {
[MODERN_STORYBOOK]: modernVersion,
}
: {}),
};

const jsonAPI = new JsonAPI(generator);
Expand Down Expand Up @@ -164,7 +154,19 @@ export default async (context: GeneratorContext, generator: GeneratorCore) => {
generator.logger.debug(`context=${JSON.stringify(context)}`);
generator.logger.debug(`context.data=${JSON.stringify(context.data)}`);

await handleTemplateFile(context, appApi, generator);
const { packageManager } = await handleTemplateFile(
context,
appApi,
generator,
);

if (context.config.isSubGenerator) {
appApi.showSuccessInfo(
i18n.t(localeKeys.success, {
packageManager: getPackageManagerText(packageManager),
}),
);
}

generator.logger.debug(`forge @modern-js/storybook-next-generator succeed `);
};
Loading

0 comments on commit a9d74c6

Please sign in to comment.