Skip to content

Commit

Permalink
Run bareMdxStoriesGlob in codemod and not in automigration
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed Mar 28, 2023
1 parent e18c22b commit 35e693f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 28 deletions.
2 changes: 0 additions & 2 deletions code/lib/cli/src/automigrate/fixes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { autodocsTrue } from './autodocs-true';
import { addReact } from './add-react';
import { nodeJsRequirement } from './nodejs-requirement';
import { missingBabelRc } from './missing-babelrc';
import { bareMdxStoriesGlob } from './bare-mdx-stories-glob';
import { angularBuilders } from './angular-builders';
import { angularBuildersMultiproject } from './angular-builders-multiproject';

Expand All @@ -36,7 +35,6 @@ export const allFixes: Fix[] = [
removedGlobalClientAPIs,
mdx1to2,
mdxgfm,
bareMdxStoriesGlob,
autodocsTrue,
addReact,
missingBabelRc,
Expand Down
86 changes: 60 additions & 26 deletions code/lib/cli/src/automigrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ export const automigrate = async ({
return null;
}

if (useNpm) {
useNpmWarning();
// eslint-disable-next-line no-param-reassign
pkgMgr = 'npm';
}

const selectedFixes = inputFixes || allFixes;
const fixes = fixId ? selectedFixes.filter((f) => f.id === fixId) : selectedFixes;

Expand All @@ -122,6 +116,64 @@ export const automigrate = async ({

augmentLogsToFile();

logger.info('🔎 checking possible migrations..');

const { fixResults, fixSummary } = await runFixes({
fixes,
useNpm,
pkgMgr,
userSpecifiedConfigDir,
rendererPackage,
skipInstall,
dryRun,
yes,
});

const hasFailures = Object.values(fixResults).some(
(r) => r === FixStatus.FAILED || r === FixStatus.CHECK_FAILED
);

// if migration failed, display a log file in the users cwd
if (hasFailures) {
await move(TEMP_LOG_FILE_PATH, join(process.cwd(), LOG_FILE_NAME), { overwrite: true });
} else {
await remove(TEMP_LOG_FILE_PATH);
}

logger.info();
logger.info(getMigrationSummary(fixResults, fixSummary, LOG_FILE_PATH));
logger.info();

cleanup();

return fixResults;
};

export async function runFixes({
fixes,
dryRun,
yes,
useNpm,
pkgMgr,
userSpecifiedConfigDir,
rendererPackage,
skipInstall,
}: {
fixes: Fix[];
yes?: boolean;
dryRun?: boolean;
useNpm?: boolean;
pkgMgr?: PackageManagerName;
userSpecifiedConfigDir?: string;
rendererPackage?: string;
skipInstall?: boolean;
}) {
if (useNpm) {
useNpmWarning();
// eslint-disable-next-line no-param-reassign
pkgMgr = 'npm';
}

const packageManager = JsPackageManagerFactory.getPackageManager({ force: pkgMgr });

const {
Expand Down Expand Up @@ -167,7 +219,6 @@ export const automigrate = async ({
};
}

logger.info('🔎 checking possible migrations..');
const fixResults = {} as Record<FixId, FixStatus>;
const fixSummary: FixSummary = { succeeded: [], failed: {}, manual: [], skipped: [] };

Expand Down Expand Up @@ -289,25 +340,8 @@ export const automigrate = async ({
}
}

const hasFailures = Object.values(fixResults).some(
(r) => r === FixStatus.FAILED || r === FixStatus.CHECK_FAILED
);

// if migration failed, display a log file in the users cwd
if (hasFailures) {
await move(TEMP_LOG_FILE_PATH, join(process.cwd(), LOG_FILE_NAME), { overwrite: true });
} else {
await remove(TEMP_LOG_FILE_PATH);
}

logger.info();
logger.info(getMigrationSummary(fixResults, fixSummary, LOG_FILE_PATH));
logger.info();

cleanup();

return fixResults;
};
return { fixResults, fixSummary };
}

function getMigrationSummary(
fixResults: Record<string, FixStatus>,
Expand Down
3 changes: 3 additions & 0 deletions code/lib/cli/src/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { listCodemods, runCodemod } from '@storybook/codemod';
import { runFixes } from './automigrate';
import { bareMdxStoriesGlob } from './automigrate/fixes/bare-mdx-stories-glob';

export async function migrate(migration: any, { glob, dryRun, list, rename, logger, parser }: any) {
if (list) {
listCodemods().forEach((key: any) => logger.log(key));
} else if (migration) {
await runFixes({ fixes: [bareMdxStoriesGlob] });
await runCodemod(migration, { glob, dryRun, logger, rename, parser });
} else {
throw new Error('Migrate: please specify a migration name or --list');
Expand Down

0 comments on commit 35e693f

Please sign in to comment.