appease 0.0.2 → 0.0.3
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/README.md +22 -19
- package/dist/cli.d.ts +6 -2
- package/dist/cli.js +33 -27
- package/dist/cli.js.map +1 -1
- package/dist/core/types.d.ts +0 -4
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -144,18 +144,21 @@ indent_style = tab
|
|
|
144
144
|
|
|
145
145
|
## Modes
|
|
146
146
|
|
|
147
|
-
Every
|
|
147
|
+
Every command prints at the end **which files it created or modified**.
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
Each command takes the directory to process as an optional positional argument
|
|
150
|
+
(`appease <command> [dir]`; defaults to the current directory).
|
|
151
|
+
|
|
152
|
+
| Command | Reads | Writes | Destructive |
|
|
150
153
|
|---|---|---|---|
|
|
151
|
-
|
|
|
152
|
-
|
|
|
153
|
-
|
|
|
154
|
-
|
|
|
154
|
+
| `audit` | existing configs (or the defaults it would propose) + the files | nothing, only **reports** what is out of spec | no |
|
|
155
|
+
| `add-config-defaults` | — | the configs with **pure defaults** (without looking at reality) | no (only creates config) |
|
|
156
|
+
| `adapt-configs` | configs + audit | creates or **adapts** the configs to reflect what was found | does not touch source code |
|
|
157
|
+
| `fix-format` | configs | **modifies the files** (BOM, trailing, newline; EOL via Git) honoring the configs | yes (Git reverts) |
|
|
155
158
|
|
|
156
|
-
###
|
|
159
|
+
### `audit`: report format
|
|
157
160
|
|
|
158
|
-
|
|
161
|
+
`audit` prints canonical JSON with **two** lists. The key point is that conforming files
|
|
159
162
|
**appear in neither**: only the ones that need attention and the ones that couldn't be
|
|
160
163
|
evaluated are listed. A clean repo yields both lists empty:
|
|
161
164
|
|
|
@@ -176,16 +179,16 @@ evaluated are listed. A clean repo yields both lists empty:
|
|
|
176
179
|
This format is **provisional**: today the output is the direct serialization of the
|
|
177
180
|
`AuditResult` type, meant to be easy to parse and test. It may grow if the value justifies it.
|
|
178
181
|
|
|
179
|
-
###
|
|
182
|
+
### `adapt-configs`: records every deviation as an exception
|
|
180
183
|
|
|
181
|
-
|
|
184
|
+
`adapt-configs` records **every** deviation it finds as an explicit exception, across all
|
|
182
185
|
axes equally (without classifying or guessing intent). This gives a safety invariant: **right
|
|
183
|
-
after
|
|
184
|
-
reality 100%. Only when you **prune** (delete) exceptions does
|
|
186
|
+
after `adapt-configs`, a `fix-format` changes nothing**, because the config describes
|
|
187
|
+
reality 100%. Only when you **prune** (delete) exceptions does `fix-format` touch *that and
|
|
185
188
|
only that*.
|
|
186
189
|
|
|
187
190
|
So, "everything is wrong and I want to fix it all at once" is solved by deleting the block of
|
|
188
|
-
exceptions: everything falls back to the default →
|
|
191
|
+
exceptions: everything falls back to the default → `fix-format` rewrites whatever is needed.
|
|
189
192
|
|
|
190
193
|
Behavior details:
|
|
191
194
|
|
|
@@ -206,13 +209,13 @@ by hand.
|
|
|
206
209
|
|
|
207
210
|
## Suggested workflow
|
|
208
211
|
|
|
209
|
-
0. *(optional)*
|
|
212
|
+
0. *(optional)* `add-config-defaults` → **commit**. Versions the "north star" (the pure
|
|
210
213
|
norm), so that in step 1 deviations stand out in the diff against that norm.
|
|
211
|
-
1.
|
|
214
|
+
1. `adapt-configs` → the `git diff` of the configs shows **every added exception = every
|
|
212
215
|
deviation**. That diff is the real report.
|
|
213
216
|
2. Review those exceptions: keep the ones that were on purpose, **delete** by hand the ones
|
|
214
217
|
that were junk (if almost everything is wrong, delete the whole block).
|
|
215
|
-
3.
|
|
218
|
+
3. `fix-format` → normalizes everything no longer protected by an exception.
|
|
216
219
|
|
|
217
220
|
Since Git reverts anything, the destructive steps are safe to try.
|
|
218
221
|
|
|
@@ -252,12 +255,12 @@ Strongly typed, `strict`, no `any`. Errors are handled, not ignored.
|
|
|
252
255
|
|
|
253
256
|
### `cli.ts`
|
|
254
257
|
|
|
255
|
-
Maps the
|
|
258
|
+
Maps the commands (`audit`, `add-config-defaults`, `adapt-configs`, `fix-format`) to
|
|
256
259
|
TS calls and orchestrates the effects:
|
|
257
260
|
|
|
258
261
|
1. Discovers files (`git ls-files`), skips binaries and the ones marked `-text`.
|
|
259
262
|
2. Reads `.gitattributes` and `.editorconfig` to resolve the per-file options.
|
|
260
|
-
3. Depending on the
|
|
263
|
+
3. Depending on the command: only reports, generates/adapts configs, or reads each file, calls
|
|
261
264
|
the pure function and rewrites if it changed.
|
|
262
265
|
4. Prints the summary of created/modified files.
|
|
263
266
|
|
|
@@ -267,7 +270,7 @@ TS calls and orchestrates the effects:
|
|
|
267
270
|
## To be defined at implementation time
|
|
268
271
|
|
|
269
272
|
- Default value for `indent_size` (probably detected per project/language).
|
|
270
|
-
- Exact format of the
|
|
273
|
+
- Exact format of the `audit` report (provisional today, documented above).
|
|
271
274
|
- Binary detection and handling of files in encodings other than UTF-8.
|
|
272
275
|
- Concrete `--tabs-*` switches.
|
|
273
276
|
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import type { RunOptions } from "./core/types.js";
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Parse argv into resolved RunOptions. cleye is the single source of truth: each RunMode is a
|
|
5
|
+
* subcommand (`appease <command> [dir]`), so the modes are mutually exclusive by construction and
|
|
6
|
+
* each gets its own `--help`. cleye prints usage and exits on unknown flags and on `--help`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseArgs(argv?: string[]): RunOptions;
|
|
5
9
|
export declare function main(argv: string[]): Promise<number>;
|
package/dist/cli.js
CHANGED
|
@@ -1,43 +1,49 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// CLI entry point. Maps switches to the public API and orchestrates the effects.
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
|
-
import { parseArgs as nodeParseArgs } from "node:util";
|
|
5
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { cli, command } from "cleye";
|
|
6
6
|
import { runAppease } from "./index.js";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
/** `--dry-run`, shared by the commands that write to disk (not by `audit`, which never writes). */
|
|
8
|
+
const dryRunFlag = {
|
|
9
|
+
dryRun: { type: Boolean, description: "Simulate writes; report what would change but touch nothing" },
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Parse argv into resolved RunOptions. cleye is the single source of truth: each RunMode is a
|
|
13
|
+
* subcommand (`appease <command> [dir]`), so the modes are mutually exclusive by construction and
|
|
14
|
+
* each gets its own `--help`. cleye prints usage and exits on unknown flags and on `--help`.
|
|
15
|
+
*/
|
|
9
16
|
export function parseArgs(argv) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
const modes = MODES.filter((mode) => values[mode] === true);
|
|
26
|
-
if (modes.length !== 1) {
|
|
27
|
-
throw new Error("Specify exactly one mode: --audit | --add-config-defaults | --adapt-configs | --fix-format");
|
|
17
|
+
const parsed = cli({
|
|
18
|
+
name: "appease",
|
|
19
|
+
help: { description: "Normalize a repo's text files to its .editorconfig / .gitattributes. One command is required." },
|
|
20
|
+
commands: [
|
|
21
|
+
command({ name: "audit", parameters: ["[dir]"], strictFlags: true, help: { description: "Report deviations only (no writes)" } }),
|
|
22
|
+
command({ name: "add-config-defaults", parameters: ["[dir]"], strictFlags: true, flags: dryRunFlag, help: { description: "Write pure-default configs (only the ones that do not exist yet)" } }),
|
|
23
|
+
command({ name: "adapt-configs", parameters: ["[dir]"], strictFlags: true, flags: dryRunFlag, help: { description: "Write/adapt configs to reflect the repo's current reality" } }),
|
|
24
|
+
command({ name: "fix-format", parameters: ["[dir]"], strictFlags: true, flags: dryRunFlag, help: { description: "Normalize files (BOM / EOL / trailing whitespace / final newline)" } }),
|
|
25
|
+
],
|
|
26
|
+
}, undefined, argv);
|
|
27
|
+
if (parsed.command === undefined) {
|
|
28
|
+
parsed.showHelp();
|
|
29
|
+
process.stderr.write("\nSpecify a command: audit | add-config-defaults | adapt-configs | fix-format\n");
|
|
30
|
+
process.exit(1);
|
|
28
31
|
}
|
|
32
|
+
const dir = parsed._.dir;
|
|
29
33
|
return {
|
|
30
|
-
mode:
|
|
31
|
-
cwd:
|
|
32
|
-
dryRun:
|
|
33
|
-
yes: values.yes ?? false,
|
|
34
|
-
verbose: values.verbose ?? false,
|
|
34
|
+
mode: parsed.command,
|
|
35
|
+
cwd: dir !== undefined ? resolve(dir) : process.cwd(),
|
|
36
|
+
dryRun: parsed.command === "audit" ? false : parsed.flags.dryRun ?? false,
|
|
35
37
|
};
|
|
36
38
|
}
|
|
39
|
+
/** Drop empty `unresolved` arrays from the audit JSON (an empty list carries no information). */
|
|
40
|
+
function omitEmptyUnresolved(key, value) {
|
|
41
|
+
return key === "unresolved" && Array.isArray(value) && value.length === 0 ? undefined : value;
|
|
42
|
+
}
|
|
37
43
|
export async function main(argv) {
|
|
38
44
|
const report = await runAppease(parseArgs(argv));
|
|
39
45
|
if (report.audit !== undefined)
|
|
40
|
-
process.stdout.write(`${JSON.stringify(report.audit,
|
|
46
|
+
process.stdout.write(`${JSON.stringify(report.audit, omitEmptyUnresolved, 2)}\n`);
|
|
41
47
|
for (const path of report.created)
|
|
42
48
|
process.stdout.write(`${report.dryRun ? "would create" : "created"}: ${path}\n`);
|
|
43
49
|
for (const path of report.modified)
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,iFAAiF;AAEjF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,i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AAM,CAAC,OAAO;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,KAAK,IAAI,IAAI,CAAC,CAAC;IACpH,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,QAAQ;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,KAAK,IAAI,IAAI,CAAC,CAAC;IACtH,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,SAAS;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,IAAI,IAAI,CAAC,CAAC;IAClF,OAAO,CAAC,CAAC;AACX,CAAC;AAED,+DAA+D;AAC/D,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACvD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAC9B,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAC5B,CAAC,GAAY,EAAE,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC3F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -87,10 +87,6 @@ export interface RunOptions {
|
|
|
87
87
|
cwd: string;
|
|
88
88
|
/** Simulate writes; report what would change but touch nothing. */
|
|
89
89
|
dryRun: boolean;
|
|
90
|
-
/** Skip interactive confirmations for destructive operations. */
|
|
91
|
-
yes: boolean;
|
|
92
|
-
/** Verbose logging. */
|
|
93
|
-
verbose: boolean;
|
|
94
90
|
}
|
|
95
91
|
/** Outcome of a run: which files were created/modified, plus mode-specific payload. */
|
|
96
92
|
export interface RunReport {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appease",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Make pease in this app.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Emilio Platzer",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"build": "tsc",
|
|
25
25
|
"build:test": "tsc -p test/tsconfig.json",
|
|
26
26
|
"pretest": "npm run build:test",
|
|
27
|
-
"test": "mocha",
|
|
27
|
+
"test": "npm run && npm run build:test && mocha",
|
|
28
28
|
"precoverage": "npm run build:test",
|
|
29
29
|
"coverage": "c8 mocha",
|
|
30
30
|
"prepublishOnly": "npm run build"
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"uuid": ">=14.0.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
+
"cleye": "^2.6.0",
|
|
38
39
|
"picomatch": "^4.0.4"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|