Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rivka-ungar committed Oct 27, 2024
1 parent a12f272 commit 8d711df
Showing 1 changed file with 31 additions and 51 deletions.
82 changes: 31 additions & 51 deletions packages/codemod/bin/vibe-codemod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async function runWizard() {
{
type: "confirm",
name: "runOptional",
message: "Would you like to run the optional migrations as well?",
message: "Would you like to run the optional enum migrations as well?",
default: false,
when: true
}
Expand Down Expand Up @@ -136,6 +136,34 @@ async function main() {
}
}

async function processTransformations(transformationFiles: string[], type = "Transformation") {
for (let index = 0; index < transformationFiles.length; index++) {
const transform = transformationFiles[index];
const transformName = path.basename(transform, path.extname(transform));

spinner.text = `Processing ${type.toLowerCase()} (${index + 1}/${transformationFiles.length}): ${transformName}`;

try {
const result = await runSingleTransformation(transform);

if (result) {
successCount++;
spinner.succeed(chalk.green(`${type} completed: ${transformName}`));
} else {
failureCount++;
spinner.fail(chalk.red(`${type} finished with errors: ${transformName}`));
}
} catch (error) {
failureCount++;
spinner.fail(chalk.red(`${type} failed: ${transformName}`));
}

if (index < transformationFiles.length - 1) {
spinner.start();
}
}
}

const verbosityLevel: number = verbose ? 2 : 0;
const outputTarget: string = verbose ? `>> "${logFile}"` : "";

Expand Down Expand Up @@ -223,31 +251,7 @@ async function main() {
...filesToProcessLast
];

for (let index = 0; index < orderedTransformationFiles.length; index++) {
const transform = orderedTransformationFiles[index];
const transformName = path.basename(transform, path.extname(transform));

spinner.text = `Processing transformation (${index + 1}/${orderedTransformationFiles.length}): ${transformName}`;

try {
const result = await runSingleTransformation(transform);

if (result) {
successCount++;
spinner.succeed(chalk.green(`Transformation completed: ${transformName}`));
} else {
failureCount++;
spinner.fail(chalk.red(`Transformation finished with errors: ${transformName}`));
}
} catch (error) {
failureCount++;
spinner.fail(chalk.red(`Transformation failed: ${transformName}`));
}

if (index < orderedTransformationFiles.length - 1) {
spinner.start();
}
}
await processTransformations(orderedTransformationFiles);

if (runOptional && fs.existsSync(optionalTransformationsDir)) {
console.log(chalk.blue(`\nRunning optional transformations from: ${optionalTransformationsDir}`));
Expand All @@ -256,31 +260,7 @@ async function main() {
ignore: ["node_modules/**", "**/*.d.ts"]
});

for (let index = 0; index < optionalTransformationFiles.length; index++) {
const transform = optionalTransformationFiles[index];
const transformName = path.basename(transform, path.extname(transform));

spinner.text = `Processing optional transformation (${index + 1}/${optionalTransformationFiles.length}): ${transformName}`;

try {
const result = await runSingleTransformation(transform);

if (result) {
successCount++;
spinner.succeed(chalk.green(`Optional transformation completed: ${transformName}`));
} else {
failureCount++;
spinner.fail(chalk.red(`Optional transformation finished with errors: ${transformName}`));
}
} catch (error) {
failureCount++;
spinner.fail(chalk.red(`Optional transformation failed: ${transformName}`));
}

if (index < optionalTransformationFiles.length - 1) {
spinner.start();
}
}
await processTransformations(optionalTransformationFiles, "Optional transformation");
}

spinner.stop();
Expand Down

0 comments on commit 8d711df

Please sign in to comment.