@nx/storybook
Version:
91 lines (90 loc) âĸ 3.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.callUpgrade = callUpgrade;
exports.callAutomigrate = callAutomigrate;
const devkit_1 = require("@nx/devkit");
const child_process_1 = require("child_process");
function callUpgrade(schema) {
const packageManager = (0, devkit_1.detectPackageManager)();
const pm = (0, devkit_1.getPackageManagerCommand)(packageManager);
try {
devkit_1.output.log({
title: `Calling sb upgrade`,
bodyLines: [
`âšī¸ Nx will call the Storybook CLI to upgrade your @storybook/* packages to the latest version.`,
`đ You can read more about the Storybook upgrade command here: https://storybook.js.org/docs/react/configure/upgrading`,
],
color: 'blue',
});
(0, child_process_1.execSync)(`${pm.dlx} ${packageManager === 'yarn' ? 'storybook' : 'storybook@latest'} upgrade ${schema.autoAcceptAllPrompts ? '--yes' : ''}`, {
stdio: [0, 1, 2],
windowsHide: true,
});
devkit_1.output.log({
title: `Storybook packages upgraded.`,
bodyLines: [
`âī¸ The upgrade command was successful.`,
`Your Storybook packages are now at the latest version.`,
],
color: 'green',
});
}
catch (e) {
devkit_1.output.log({
title: 'Migration failed',
bodyLines: [
`đ¨ The Storybook CLI failed to upgrade your @storybook/* packages to the latest version.`,
`Please try running the sb upgrade command manually:`,
`${pm.exec} storybook@${schema.versionTag} upgrade`,
],
color: 'red',
});
console.log(e);
return 1;
}
}
function callAutomigrate(allStorybookProjects, schema) {
devkit_1.output.log({
title: `âī¸ Calling sb automigrate`,
bodyLines: [
`âšī¸ Nx will call the Storybook CLI to automigrate the Storybook configuration of all your projects that use Storybook.`,
`đ You can read more about the Storybook automigrate command here: https://storybook.js.org/docs/react/configure/upgrading#automigrate-script`,
],
color: 'green',
});
const resultOfMigration = {
successfulProjects: {},
failedProjects: {},
};
Object.entries(allStorybookProjects).forEach(([projectName, storybookProjectInfo]) => {
const packageManager = (0, devkit_1.detectPackageManager)();
const pm = (0, devkit_1.getPackageManagerCommand)(packageManager);
const commandToRun = `${pm.dlx} storybook automigrate --config-dir ${storybookProjectInfo.configDir}`;
try {
devkit_1.output.log({
title: `Calling sb automigrate for ${projectName}`,
bodyLines: ['Command:', commandToRun],
color: 'green',
});
(0, child_process_1.execSync)(`${commandToRun} ${schema.autoAcceptAllPrompts ? '--yes' : ''}`, {
stdio: 'inherit',
windowsHide: true,
env: process.env,
});
resultOfMigration.successfulProjects[projectName] = commandToRun;
}
catch (e) {
devkit_1.output.error({
title: 'Migration failed',
bodyLines: [
`đ¨ The Storybook CLI failed to automigrate the Storybook configuration of your project.`,
`The error was: ${e}`,
`Please try running the sb automigrate command manually:`,
commandToRun,
],
});
resultOfMigration.failedProjects[projectName] = commandToRun;
}
});
return resultOfMigration;
}