Skip to content

Commit

Permalink
update cli
Browse files Browse the repository at this point in the history
  • Loading branch information
rivka-ungar committed Oct 16, 2024
1 parent b17c54e commit 2b5bee5
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion packages/codemod/bin/vibe-codemod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,20 @@ async function runWizard() {
choices: [{ name: "jsx", checked: true }, { name: "tsx", checked: true }, { name: "js" }, { name: "ts" }],
default: argv.extensions || ["jsx", "tsx"],
when: !argv.extensions
},
{
type: "confirm",
name: "runOptional",
message: "Would you like to run the optional migrations as well?",
default: false,
when: true
}
]);

return {
migration: answers.migration || argv.migration,
extensions: answers.extensions || argv.extensions
extensions: answers.extensions || argv.extensions,
runOptional: answers.runOptional || false
};
}

Expand All @@ -91,9 +99,11 @@ async function main() {

const migrationType = answers.migration;
const transformationsDir = join(__dirname, "..", "transformations", "core", mapMigrationType[migrationType]);
const optionalTransformationsDir = join(transformationsDir, "optional");
const extensions = answers.extensions;
const targetDir = argv.target;
const verbose = argv.verbose;
const runOptional = answers.runOptional;

const logFile = resolve(targetDir, "codemod.log");

Expand Down Expand Up @@ -239,6 +249,40 @@ async function main() {
}
}

if (runOptional && fs.existsSync(optionalTransformationsDir)) {
console.log(chalk.blue(`\nRunning optional transformations from: ${optionalTransformationsDir}`));

const optionalTransformationFiles: string[] = globby.sync(`${optionalTransformationsDir}/*.js`, {
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();
}
}
}

spinner.stop();

const duration = ((Date.now() - startTime) / 1000).toFixed(2) + "s";
Expand Down

0 comments on commit 2b5bee5

Please sign in to comment.