@zgeoff/format-codemod 0.1.0 → 0.1.1
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/dist/cli/parse-cli-args.d.ts +1 -1
- package/dist/cli.js +42 -27
- package/package.json +3 -2
|
@@ -8,4 +8,4 @@ export interface CLIArgs {
|
|
|
8
8
|
readonly ignore: readonly string[];
|
|
9
9
|
readonly inputs: readonly string[];
|
|
10
10
|
}
|
|
11
|
-
export declare function parseCLIArgs(argv: readonly string[]): CLIArgs | string
|
|
11
|
+
export declare function parseCLIArgs(argv: readonly string[]): Promise<CLIArgs | string>;
|
package/dist/cli.js
CHANGED
|
@@ -62,35 +62,43 @@ function loadFormatIgnore(dir) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
// src/cli/parse-cli-args.ts
|
|
65
|
-
import {
|
|
66
|
-
|
|
65
|
+
import { cli } from "gunshi/bone";
|
|
66
|
+
import { define } from "gunshi/definition";
|
|
67
|
+
var CLI_ARGS = {
|
|
68
|
+
check: { type: "boolean", default: false },
|
|
69
|
+
dry: { type: "boolean", default: false },
|
|
70
|
+
bench: { type: "boolean", default: false },
|
|
71
|
+
quiet: { type: "boolean", default: false },
|
|
72
|
+
version: { type: "boolean", default: false },
|
|
73
|
+
help: { type: "boolean", default: false },
|
|
74
|
+
ignore: { type: "string", multiple: true }
|
|
75
|
+
};
|
|
76
|
+
async function parseCLIArgs(argv) {
|
|
77
|
+
let parsed = null;
|
|
78
|
+
const command = define({
|
|
79
|
+
name: "format-codemod",
|
|
80
|
+
args: CLI_ARGS,
|
|
81
|
+
run: (ctx) => {
|
|
82
|
+
if (ctx.validationError !== undefined) {
|
|
83
|
+
throw ctx.validationError;
|
|
84
|
+
}
|
|
85
|
+
parsed = {
|
|
86
|
+
mode: pickMode(ctx.values.check, ctx.values.dry),
|
|
87
|
+
quiet: ctx.values.quiet,
|
|
88
|
+
bench: ctx.values.bench,
|
|
89
|
+
help: ctx.values.help,
|
|
90
|
+
version: ctx.values.version,
|
|
91
|
+
ignore: ctx.values.ignore ?? [],
|
|
92
|
+
inputs: [...ctx.positionals, ...ctx.rest]
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
});
|
|
67
96
|
try {
|
|
68
|
-
|
|
69
|
-
args: [...argv],
|
|
70
|
-
options: {
|
|
71
|
-
check: { type: "boolean", default: false },
|
|
72
|
-
dry: { type: "boolean", default: false },
|
|
73
|
-
bench: { type: "boolean", default: false },
|
|
74
|
-
quiet: { type: "boolean", default: false },
|
|
75
|
-
version: { type: "boolean", default: false },
|
|
76
|
-
help: { type: "boolean", default: false },
|
|
77
|
-
ignore: { type: "string", multiple: true, default: [] }
|
|
78
|
-
},
|
|
79
|
-
allowPositionals: true,
|
|
80
|
-
strict: true
|
|
81
|
-
});
|
|
82
|
-
return {
|
|
83
|
-
mode: pickMode(parsed.values.check, parsed.values.dry),
|
|
84
|
-
quiet: parsed.values.quiet,
|
|
85
|
-
bench: parsed.values.bench,
|
|
86
|
-
help: parsed.values.help,
|
|
87
|
-
version: parsed.values.version,
|
|
88
|
-
ignore: parsed.values.ignore,
|
|
89
|
-
inputs: parsed.positionals
|
|
90
|
-
};
|
|
97
|
+
await cli([...argv], command, { strict: true });
|
|
91
98
|
} catch (error) {
|
|
92
|
-
return
|
|
99
|
+
return formatParseError(error);
|
|
93
100
|
}
|
|
101
|
+
return parsed ?? "the command line could not be parsed";
|
|
94
102
|
}
|
|
95
103
|
function pickMode(check, dry) {
|
|
96
104
|
if (check) {
|
|
@@ -98,6 +106,13 @@ function pickMode(check, dry) {
|
|
|
98
106
|
}
|
|
99
107
|
return dry ? "dry" : "write";
|
|
100
108
|
}
|
|
109
|
+
function formatParseError(error) {
|
|
110
|
+
if (error instanceof AggregateError) {
|
|
111
|
+
return error.errors.map((reason) => formatParseError(reason)).join(`
|
|
112
|
+
`);
|
|
113
|
+
}
|
|
114
|
+
return error instanceof Error ? error.message : String(error);
|
|
115
|
+
}
|
|
101
116
|
|
|
102
117
|
// src/cli/print-help.ts
|
|
103
118
|
function printHelp() {
|
|
@@ -729,7 +744,7 @@ function tryCheckFile(file, mode) {
|
|
|
729
744
|
}
|
|
730
745
|
|
|
731
746
|
// src/cli.ts
|
|
732
|
-
var parsedArgs = parseCLIArgs(process.argv.slice(2));
|
|
747
|
+
var parsedArgs = await parseCLIArgs(process.argv.slice(2));
|
|
733
748
|
if (typeof parsedArgs === "string") {
|
|
734
749
|
console.error(parsedArgs);
|
|
735
750
|
process.exit(2);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgeoff/format-codemod",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Enforce blank-line padding conventions in TypeScript via a fast text-splice codemod",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"typecheck": "tsc"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"
|
|
33
|
+
"gunshi": "1.0.0-rc.1",
|
|
34
|
+
"oxc-parser": "0.153.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@types/bun": "1.3.14",
|