@nx/storybook
Version:
52 lines (51 loc) âĸ 2.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.callUpgrade = callUpgrade;
exports.checkStorybookInstalled = checkStorybookInstalled;
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@latest upgrade`,
],
color: 'red',
});
console.log(e);
return 1;
}
}
function checkStorybookInstalled(packageJson) {
return ((packageJson.dependencies['storybook'] ||
packageJson.devDependencies['storybook']) &&
(packageJson.dependencies['@nx/storybook'] ||
packageJson.devDependencies['@nx/storybook']));
}