@nx/react-native
Version:
58 lines (57 loc) • 2.55 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = changeStorybookTargets;
const devkit_1 = require("@nx/devkit");
const output_1 = require("nx/src/utils/output");
const migrate_7_1 = require("@nx/storybook/src/generators/migrate-7/migrate-7");
const utilities_1 = require("@nx/storybook/src/utils/utilities");
const configuration_1 = require("@nx/react/src/generators/storybook-configuration/configuration");
/**
* Upgrade react native storybook target to use web
*/
async function changeStorybookTargets(tree) {
const tasks = [];
// update the storybook target
const projects = (0, devkit_1.getProjects)(tree);
let hasStorybookTarget = false;
for (const [projectName, config] of projects.entries()) {
if (config.targets?.['storybook']?.executor === '@nx/react-native:storybook') {
hasStorybookTarget = true;
delete config.targets['storybook'];
(0, devkit_1.updateProjectConfiguration)(tree, projectName, config);
tasks.push(await (0, configuration_1.default)(tree, {
project: projectName,
}));
}
}
/**
* This just checks if Storybook is installed in the workspace.
* The thing here is that during the previous step of the migration,
* during packageJsonUpdates, Nx has already set Storybook
* to version 7, if Storybook exists in the workspace.
* So, it makes no sense here to check if the version is
* 7, because it will always be.
*/
const storybookVersion = (0, utilities_1.storybookMajorVersion)();
if (!hasStorybookTarget || !storybookVersion) {
return;
}
output_1.output.log({
title: 'Migrating Storybook to v7',
bodyLines: [
`🚀 This migration will update your Storybook configuration to v7.`,
`It will call the @nx/storybook:migrate-7 generator for you.`,
`You can read more about the migration and how this generator works here:`,
`https://nx.dev/nx-api/storybook/generators/migrate-7`,
],
});
tasks.push(await (0, migrate_7_1.default)(tree, { autoAcceptAllPrompts: true }));
tasks.push((0, devkit_1.removeDependenciesFromPackageJson)(tree, [], [
'@storybook/react-native',
'@storybook/addon-ondevice-actions',
'@storybook/addon-ondevice-backgrounds',
'@storybook/addon-ondevice-controls',
'@storybook/addon-ondevice-notes',
]));
return (0, devkit_1.runTasksInSerial)(...tasks);
}
;