UNPKG

@nx/storybook

Version:

The Nx Plugin for Storybook contains executors and generators for allowing your workspace to use the powerful Storybook integration testing & documenting capabilities.

90 lines (89 loc) â€ĸ 3.92 kB
"use strict"; 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} ${packageManager === 'yarn' ? 'storybook' : 'storybook@latest'} 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} ${packageManager === 'yarn' ? 'storybook' : 'storybook@latest'} 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, }); 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; }