@nx/storybook
Version:
68 lines (67 loc) • 3.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.migrate7Generator = migrate7Generator;
const devkit_1 = require("@nx/devkit");
const output_1 = require("nx/src/utils/output");
const versions_1 = require("../../utils/versions");
const calling_storybook_cli_1 = require("./calling-storybook-cli");
const helper_functions_1 = require("./helper-functions");
async function migrate7Generator(tree, schema) {
const tasks = [];
const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
if (!(0, helper_functions_1.checkStorybookInstalled)(packageJson)) {
output_1.output.error({
title: 'No Storybook packages installed',
bodyLines: [
`🚨 Nx did not find any Storybook packages installed in your workspace.`,
`So no migration is necessary.`,
],
});
return;
}
const allStorybookProjects = (0, helper_functions_1.getAllStorybookInfo)(tree);
let migrateResult;
if (schema.onlyShowListOfCommands) {
(0, helper_functions_1.onlyShowGuide)(allStorybookProjects);
return;
}
if (!schema.afterMigration) {
if (!schema.noUpgrade) {
(0, calling_storybook_cli_1.callUpgrade)(schema);
}
if (Object.entries(allStorybookProjects).length) {
(0, helper_functions_1.prepareFiles)(tree, allStorybookProjects);
if (schema.onlyPrepare) {
return;
}
migrateResult = (0, calling_storybook_cli_1.callAutomigrate)(allStorybookProjects, schema);
migrateResult = (0, helper_functions_1.handleMigrationResult)(migrateResult, allStorybookProjects);
}
}
output_1.output.log({
title: `Final adjustments`,
bodyLines: [
`We are now running some final adjustments to your configuration files.`,
`The adjustments are:`,
` - Remove the "vite-tsconfig-paths" plugin from the Storybook configuration files since it's no longer needed`,
` - Add the "viteConfigPath" option to the Storybook builder, where needed`,
` - Change the import package for the StorybookConfig type to be framework specific`,
` - Add the "lit" package to your workspace, if you are using Web Components`,
` - Remove the "uiFramework" option from your project's Storybook targets`,
],
color: 'blue',
});
if (Object.entries(allStorybookProjects).length) {
(0, helper_functions_1.afterMigration)(tree, allStorybookProjects);
}
if ((0, helper_functions_1.checkWebComponentsInstalled)(packageJson)) {
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, { lit: versions_1.litVersion }));
}
(0, helper_functions_1.removeUiFrameworkFromProjectJson)(tree);
if (!schema.afterMigration) {
(0, helper_functions_1.logResult)(tree, migrateResult);
}
await (0, devkit_1.formatFiles)(tree);
return (0, devkit_1.runTasksInSerial)(...tasks);
}
exports.default = migrate7Generator;