@omnimod/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 salnika
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # @omnimod/cli
2
+
3
+ [![npm](https://img.shields.io/npm/v/%40omnimod%2Fcli?label=npm)](https://www.npmjs.com/package/@omnimod/cli)
4
+ [![CI](https://img.shields.io/github/actions/workflow/status/Salnika/omnimod/ci.yml?branch=master&label=ci)](https://github.com/Salnika/omnimod/actions/workflows/ci.yml)
5
+ [![License](https://img.shields.io/github/license/Salnika/omnimod)](../../LICENSE)
6
+
7
+ Command-line runner for omnimod codemods.
8
+
9
+ The CLI bundles the official migration plugins and can also resolve external
10
+ plugins by package name or local path.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ pnpm add -D @omnimod/cli
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```bash
21
+ omnimod list
22
+ omnimod run styled-to-vanilla-extract "src/**/*.tsx"
23
+ omnimod run styled-to-vanilla-extract "src/**/*.tsx" --write
24
+ ```
25
+
26
+ Runs are dry by default. Pass `--write` to update files and `--no-format` to
27
+ skip formatter/linter detection after writing.
28
+
29
+ ## Commands
30
+
31
+ - `omnimod list`: list bundled plugins.
32
+ - `omnimod run <plugin> [...paths]`: run one plugin against a project.
33
+
34
+ ## Bundled Plugins
35
+
36
+ - `styled-to-vanilla-extract`
37
+ - `moment-to-dayjs`
38
+ - `jest-to-vitest`
39
+ - `lodash-to-es-toolkit`
40
+ - `redux-to-toolkit`
41
+ - `react-class-to-hooks`
42
+ - `webpack-to-vite`
@@ -0,0 +1,17 @@
1
+ import { Plugin, RunResult } from "@omnimod/core";
2
+
3
+ //#region src/index.d.ts
4
+ /** Sorted names of every built-in plugin. */
5
+ declare function listPlugins(): string[];
6
+ /** `name — description` lines for every built-in plugin, sorted by name. */
7
+ declare function describePlugins(): string[];
8
+ /**
9
+ * Resolve a plugin by registered name, a relative/absolute path, or a bare name
10
+ * using the `@omnimod/plugin-<name>` / `omnimod-plugin-<name>` conventions.
11
+ */
12
+ declare function resolvePlugin(nameOrPath: string): Promise<Plugin>;
13
+ /** Render a run result (diffs, emitted files, diagnostics, summary) for the terminal. */
14
+ declare function formatResult(result: RunResult, write: boolean, root: string): string;
15
+ declare function main(argv?: string[]): Promise<number>;
16
+ //#endregion
17
+ export { describePlugins, formatResult, listPlugins, main, resolvePlugin };
package/dist/index.mjs ADDED
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env node
2
+ import { realpath } from "node:fs/promises";
3
+ import { resolve } from "node:path";
4
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
+ import { detectFixers, renderDiff, renderEmitted, run } from "@omnimod/core";
6
+ import { jestToVitest } from "@omnimod/plugin-jest-to-vitest";
7
+ import { lodashToEsToolkit } from "@omnimod/plugin-lodash-to-es-toolkit";
8
+ import { momentToDayjs } from "@omnimod/plugin-moment-to-dayjs";
9
+ import { reactClassToHooks } from "@omnimod/plugin-react-class-to-hooks";
10
+ import { reduxToToolkit } from "@omnimod/plugin-redux-to-toolkit";
11
+ import { styledToVanillaExtract } from "@omnimod/plugin-styled-to-vanilla-extract";
12
+ import { webpackToVite } from "@omnimod/plugin-webpack-to-vite";
13
+ import { cac } from "cac";
14
+ import pc from "picocolors";
15
+ //#region src/index.ts
16
+ /** Built-in plugin registry, keyed by plugin name. */
17
+ const REGISTRY = new Map([
18
+ styledToVanillaExtract,
19
+ momentToDayjs,
20
+ jestToVitest,
21
+ lodashToEsToolkit,
22
+ reduxToToolkit,
23
+ reactClassToHooks,
24
+ webpackToVite
25
+ ].map((plugin) => [plugin.name, plugin]));
26
+ /** Sorted names of every built-in plugin. */
27
+ function listPlugins() {
28
+ return [...REGISTRY.keys()].sort();
29
+ }
30
+ /** `name — description` lines for every built-in plugin, sorted by name. */
31
+ function describePlugins() {
32
+ return listPlugins().map((name) => `${name} — ${REGISTRY.get(name)?.description ?? ""}`);
33
+ }
34
+ async function importPlugin(specifier) {
35
+ const mod = await import(specifier);
36
+ const plugin = mod.default ?? mod.plugin;
37
+ if (!plugin) throw new Error(`Module "${specifier}" has no plugin export (default or \`plugin\`)`);
38
+ return plugin;
39
+ }
40
+ function isModuleNotFound(error) {
41
+ return typeof error === "object" && error !== null && error.code === "ERR_MODULE_NOT_FOUND";
42
+ }
43
+ /**
44
+ * Resolve a plugin by registered name, a relative/absolute path, or a bare name
45
+ * using the `@omnimod/plugin-<name>` / `omnimod-plugin-<name>` conventions.
46
+ */
47
+ async function resolvePlugin(nameOrPath) {
48
+ const known = REGISTRY.get(nameOrPath);
49
+ if (known) return known;
50
+ if (nameOrPath.startsWith(".") || nameOrPath.startsWith("/")) return importPlugin(pathToFileURL(resolve(nameOrPath)).href);
51
+ const candidates = /[@/]/.test(nameOrPath) ? [nameOrPath] : [
52
+ `@omnimod/plugin-${nameOrPath}`,
53
+ `omnimod-plugin-${nameOrPath}`,
54
+ nameOrPath
55
+ ];
56
+ for (const specifier of candidates) try {
57
+ return await importPlugin(specifier);
58
+ } catch (error) {
59
+ if (!isModuleNotFound(error)) throw error;
60
+ }
61
+ throw new Error(`Could not resolve plugin "${nameOrPath}". Tried: ${candidates.join(", ")}.`);
62
+ }
63
+ /** Render a run result (diffs, emitted files, diagnostics, summary) for the terminal. */
64
+ function formatResult(result, write, root) {
65
+ const blocks = [];
66
+ for (const change of result.changed) blocks.push(renderDiff(change));
67
+ for (const file of result.emitted) blocks.push(renderEmitted(file));
68
+ for (const diagnostic of result.diagnostics) {
69
+ const tag = diagnostic.severity === "error" ? pc.red("error") : diagnostic.severity === "warn" ? pc.yellow("warn") : pc.blue("info");
70
+ blocks.push(`${tag} ${diagnostic.file}: ${diagnostic.message}`);
71
+ }
72
+ if (result.format && result.format.tools.length > 0) {
73
+ blocks.push(pc.blue(`formatted with ${result.format.tools.join(", ")}`));
74
+ for (const error of result.format.errors) blocks.push(pc.yellow(`format: ${error}`));
75
+ } else if (!write) {
76
+ const fixers = detectFixers(root).map((fixer) => fixer.tool);
77
+ if (fixers.length > 0) blocks.push(pc.dim(`on --write, output will be formatted with ${fixers.join(", ")}`));
78
+ }
79
+ const summary = `${result.changed.length} changed, ${result.emitted.length} created, ${result.diagnostics.length} diagnostic(s)`;
80
+ blocks.push(write ? pc.green(summary) : pc.dim(`${summary} — dry-run, pass --write to apply`));
81
+ return blocks.join("\n\n");
82
+ }
83
+ function toArray(value) {
84
+ if (value === void 0) return void 0;
85
+ return Array.isArray(value) ? value : [value];
86
+ }
87
+ async function main(argv = process.argv) {
88
+ const cli = cac("omnimod");
89
+ cli.command("run <plugin> [...paths]", "Run a codemod plugin over the project").option("--write", "Write changes to disk (default: dry-run)").option("--cwd <dir>", "Project root to operate on", { default: "." }).option("--exclude <glob>", "Glob to exclude (repeatable)").option("--no-format", "Skip the project formatter/linter after writing").action(async (plugin, paths, flags) => {
90
+ const result = await run(await resolvePlugin(plugin), {
91
+ root: flags.cwd,
92
+ include: paths.length > 0 ? paths : void 0,
93
+ exclude: toArray(flags.exclude),
94
+ write: flags.write,
95
+ format: flags.format
96
+ });
97
+ process.stdout.write(`${formatResult(result, flags.write ?? false, flags.cwd)}\n`);
98
+ });
99
+ cli.command("list", "List available plugins").action(() => {
100
+ process.stdout.write(`${describePlugins().join("\n")}\n`);
101
+ });
102
+ cli.help();
103
+ cli.version("0.1.0");
104
+ cli.parse(argv, { run: false });
105
+ await cli.runMatchedCommand();
106
+ return 0;
107
+ }
108
+ async function isDirectInvocation(invoked) {
109
+ if (!invoked) return false;
110
+ try {
111
+ return await realpath(invoked) === await realpath(fileURLToPath(import.meta.url));
112
+ } catch {
113
+ return import.meta.url === pathToFileURL(invoked).href;
114
+ }
115
+ }
116
+ if (await isDirectInvocation(process.argv[1])) main().then((code) => process.exit(code), (error) => {
117
+ process.stderr.write(`${String(error)}\n`);
118
+ process.exit(1);
119
+ });
120
+ //#endregion
121
+ export { describePlugins, formatResult, listPlugins, main, resolvePlugin };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@omnimod/cli",
3
+ "version": "0.1.0",
4
+ "description": "Command-line runner for omnimod codemods.",
5
+ "keywords": [
6
+ "cli",
7
+ "codemod",
8
+ "omnimod",
9
+ "styled-components",
10
+ "vanilla-extract"
11
+ ],
12
+ "homepage": "https://salnika.github.io/omnimod/",
13
+ "bugs": "https://github.com/salnika/omnimod/issues",
14
+ "license": "MIT",
15
+ "author": "salnika",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/salnika/omnimod.git",
19
+ "directory": "packages/cli"
20
+ },
21
+ "bin": {
22
+ "omnimod": "./dist/index.mjs"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "type": "module",
28
+ "exports": {
29
+ ".": "./dist/index.mjs",
30
+ "./package.json": "./package.json"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "dependencies": {
36
+ "cac": "^7.0.0",
37
+ "picocolors": "^1.1.1",
38
+ "@omnimod/core": "0.1.0",
39
+ "@omnimod/plugin-jest-to-vitest": "0.1.0",
40
+ "@omnimod/plugin-lodash-to-es-toolkit": "0.1.0",
41
+ "@omnimod/plugin-react-class-to-hooks": "0.1.0",
42
+ "@omnimod/plugin-redux-to-toolkit": "0.1.0",
43
+ "@omnimod/plugin-styled-to-vanilla-extract": "0.1.0",
44
+ "@omnimod/plugin-webpack-to-vite": "0.1.0",
45
+ "@omnimod/plugin-moment-to-dayjs": "0.1.0"
46
+ },
47
+ "devDependencies": {
48
+ "@types/node": "^25.6.2",
49
+ "@typescript/native-preview": "7.0.0-dev.20260509.2",
50
+ "typescript": "^6.0.3",
51
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.2.2",
52
+ "vite-plus": "0.2.2"
53
+ },
54
+ "scripts": {
55
+ "build": "vp pack",
56
+ "dev": "vp pack --watch",
57
+ "test": "vp test",
58
+ "check": "vp check"
59
+ }
60
+ }