From 1aa8fe1e37a8a23280c11f36311894ac9e4b0913 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Fri, 12 Nov 2021 10:22:11 +0100 Subject: [PATCH 1/4] cli: add specified type in sb init --type output --- lib/cli/src/initiate.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cli/src/initiate.ts b/lib/cli/src/initiate.ts index be785962229c..58d1038a5eef 100644 --- a/lib/cli/src/initiate.ts +++ b/lib/cli/src/initiate.ts @@ -296,7 +296,7 @@ export function initiate(options: CommandOptions, pkg: Package): Promise { let projectType; const projectTypeProvided = options.type; const infoText = projectTypeProvided - ? 'Installing Storybook for user specified project type' + ? `Installing Storybook for user specified project type: ${projectTypeProvided}` : 'Detecting project type'; const done = commandLog(infoText); @@ -305,13 +305,13 @@ export function initiate(options: CommandOptions, pkg: Package): Promise { try { if (projectTypeProvided) { - if (installableProjectTypes.includes(options.type)) { + if (installableProjectTypes.includes(projectTypeProvided)) { const storybookInstalled = isStorybookInstalled(packageJson, options.force); projectType = storybookInstalled ? ProjectType.ALREADY_HAS_STORYBOOK - : options.type.toUpperCase(); + : projectTypeProvided.toUpperCase(); } else { - done(`The provided project type was not recognized by Storybook.`); + done(`The provided project type was not recognized by Storybook: ${projectTypeProvided}`); logger.log(`\nThe project types currently supported by Storybook are:\n`); installableProjectTypes.sort().forEach((framework) => paddedLog(`- ${framework}`)); logger.log(); From f67918077a130b22f963459f07ada132575369b8 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Fri, 12 Nov 2021 12:11:46 +0100 Subject: [PATCH 2/4] cli: add automigrate to sb init --- lib/cli/src/initiate.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/cli/src/initiate.ts b/lib/cli/src/initiate.ts index 58d1038a5eef..f5a53feb2a68 100644 --- a/lib/cli/src/initiate.ts +++ b/lib/cli/src/initiate.ts @@ -28,6 +28,7 @@ import raxGenerator from './generators/RAX'; import serverGenerator from './generators/SERVER'; import { JsPackageManagerFactory, readPackageJson } from './js-package-manager'; import { NpmOptions } from './NpmOptions'; +import { automigrate } from './automigrate'; const logger = console; @@ -283,7 +284,7 @@ const projectTypeInquirer = async (options: { yes?: boolean }) => { return Promise.resolve(); }; -export function initiate(options: CommandOptions, pkg: Package): Promise { +export async function initiate(options: CommandOptions, pkg: Package): Promise { const welcomeMessage = 'sb init - the simplest way to add a Storybook to your project.'; logger.log(chalk.inverse(`\n ${welcomeMessage} \n`)); @@ -326,8 +327,10 @@ export function initiate(options: CommandOptions, pkg: Package): Promise { } done(); - return installStorybook(projectType, { + await installStorybook(projectType, { ...options, ...(isEsm ? { commonJs: true } : undefined), }); + + return automigrate({ yes: true }); } From 05e426ec08f2bdb47a1fea8129ca7af68b85a297 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Fri, 12 Nov 2021 12:29:12 +0100 Subject: [PATCH 3/4] CLI: run automigrate with prompts --- lib/cli/src/automigrate/index.ts | 2 +- lib/cli/src/initiate.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cli/src/automigrate/index.ts b/lib/cli/src/automigrate/index.ts index 7d0a517819a6..198e1c3828f0 100644 --- a/lib/cli/src/automigrate/index.ts +++ b/lib/cli/src/automigrate/index.ts @@ -14,7 +14,7 @@ interface FixOptions { dryRun?: boolean; } -export const automigrate = async ({ fixId, dryRun, yes }: FixOptions) => { +export const automigrate = async ({ fixId, dryRun, yes }: FixOptions = {}) => { const packageManager = JsPackageManagerFactory.getPackageManager(); const filtered = fixId ? fixes.filter((f) => f.id === fixId) : fixes; diff --git a/lib/cli/src/initiate.ts b/lib/cli/src/initiate.ts index f5a53feb2a68..2b8778c7178f 100644 --- a/lib/cli/src/initiate.ts +++ b/lib/cli/src/initiate.ts @@ -332,5 +332,5 @@ export async function initiate(options: CommandOptions, pkg: Package): Promise Date: Fri, 12 Nov 2021 12:54:57 +0100 Subject: [PATCH 4/4] CLI: throw and handle error in eslint-plugin automigrate --- .../src/automigrate/fixes/eslint-plugin.ts | 20 ++++++++----------- lib/cli/src/automigrate/index.ts | 10 ++++++++-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/cli/src/automigrate/fixes/eslint-plugin.ts b/lib/cli/src/automigrate/fixes/eslint-plugin.ts index 6426f1ea459d..6d6a16293dfc 100644 --- a/lib/cli/src/automigrate/fixes/eslint-plugin.ts +++ b/lib/cli/src/automigrate/fixes/eslint-plugin.ts @@ -80,18 +80,14 @@ export const eslintPlugin: Fix = { if (!dryRun) packageManager.addDependencies({ installAsDevDependencies: true }, deps); if (!dryRun && unsupportedExtension) { - logger.warn( - dedent(` - ⚠️ The plugin was successfuly installed but failed to configure. - - Found an .eslintrc config file with an unsupported automigration format: ${unsupportedExtension}. - Supported formats for automigration are: ${SUPPORTED_ESLINT_EXTENSIONS.join(', ')}. - - Please refer to https://github.com/storybookjs/eslint-plugin-storybook#usage to finish setting up the plugin manually. - `) - ); - - return; + throw new Error(dedent` + ⚠️ The plugin was successfuly installed but failed to configure. + + Found an .eslintrc config file with an unsupported automigration format: ${unsupportedExtension}. + Supported formats for automigration are: ${SUPPORTED_ESLINT_EXTENSIONS.join(', ')}. + + Please refer to https://github.com/storybookjs/eslint-plugin-storybook#usage to finish setting up the plugin manually. + `); } const eslint = await readConfig(eslintFile); diff --git a/lib/cli/src/automigrate/index.ts b/lib/cli/src/automigrate/index.ts index 198e1c3828f0..9ff0d9f8713e 100644 --- a/lib/cli/src/automigrate/index.ts +++ b/lib/cli/src/automigrate/index.ts @@ -41,8 +41,14 @@ export const automigrate = async ({ fixId, dryRun, yes }: FixOptions = {}) => { ]); if (runAnswer.fix) { - await f.run({ result, packageManager, dryRun }); - logger.info(`✅ fixed ${chalk.cyan(f.id)}`); + try { + await f.run({ result, packageManager, dryRun }); + logger.info(`✅ fixed ${chalk.cyan(f.id)}`); + } catch (error) { + logger.info(`❌ error in ${chalk.cyan(f.id)}:`); + logger.info(error.message); + logger.info(); + } } else { logger.info(`Skipping the ${chalk.cyan(f.id)} fix.`); logger.info();