diff --git a/.changeset/gentle-cups-beam.md b/.changeset/gentle-cups-beam.md new file mode 100644 index 0000000..e2937c2 --- /dev/null +++ b/.changeset/gentle-cups-beam.md @@ -0,0 +1,5 @@ +--- +"@effect/codemod": patch +--- + +add descriptions for dry-run and print diff --git a/src/main.ts b/src/main.ts index 8beca55..e9e7d22 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,18 +7,27 @@ import * as NodeContext from "@effect/platform-node/NodeContext" import { runMain } from "@effect/platform-node/Runtime" import * as Console from "effect/Console" import * as Effect from "effect/Effect" +import * as ReadonlyArray from "effect/ReadonlyArray" import * as jscodeshift from "jscodeshift/src/Runner" +import assert from "node:assert" import * as Fs from "node:fs" import * as Path from "node:path" -const codemod = Args.choice( - Fs.readdirSync(`${__dirname}/codemods`).map(file => { - const name = Path.basename(file, ".ts") - return [name, name] as const - }) as any, +const codemodFiles = Fs.readdirSync(`${__dirname}/codemods`) +assert( + ReadonlyArray.isNonEmptyReadonlyArray(codemodFiles), + "Could not find any code mod files", +) +const codemod = Args.choice( + ReadonlyArray.map( + codemodFiles, + file => [ + Path.basename(file, ".ts"), + Path.join(`${__dirname}/codemods`, file), + ], + ), { name: "codemod" }, ).pipe( - Args.map(codemod => `${__dirname}/codemods/${codemod}.ts`), Args.withDescription("The code modification to run"), ) @@ -26,20 +35,25 @@ const run = Command.make("codemod", { codemod, paths: Args.text({ name: "paths" }).pipe( Args.repeated, + Args.map(ReadonlyArray.fromIterable), // TODO: Remove when `Args.repeated` returns Array Args.withDescription("The paths to run the codemod on"), ), options: { dry: Options.boolean("dry-run").pipe( Options.withAlias("d"), + Options.withDescription("If set, the codemod will not modify any files"), ), print: Options.boolean("print").pipe( Options.withAlias("p"), + Options.withDescription( + "If set, the codemod will print the changes to the console", + ), ), }, }).pipe( Command.withHandler(({ codemod, options, paths }) => Effect.promise(() => - jscodeshift.run(codemod, paths as Array, { + jscodeshift.run(codemod, paths, { ...options, babel: true, parser: "ts",