docvars 0.3.1 → 0.3.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
CHANGED
|
@@ -31,16 +31,16 @@ docvars <input> <output> [options]
|
|
|
31
31
|
|
|
32
32
|
### Options
|
|
33
33
|
|
|
34
|
-
| Option | Default | Description |
|
|
35
|
-
| --------------- | ---------------- | --------------------------------------------------- |
|
|
36
|
-
| `--vars` | `variables.yaml` | Path to the variables YAML file |
|
|
37
|
-
| `--only` | `**/*` | Glob pattern to filter files (e.g. **/*.md) |
|
|
38
|
-
| `--exclude` | - | Glob pattern to exclude specific files |
|
|
39
|
-
| `--watch` | `false` | Watch for file changes and rebuild automatically |
|
|
40
|
-
| `--rename-from` | - | Variable name to rename from (use with --rename-to) |
|
|
41
|
-
| `--rename-to` | - | Variable name to rename to (use with --rename-from) |
|
|
42
|
-
| `--list-vars` | `false` | List all variables used in templates |
|
|
43
|
-
| `--dry-run` | `false` | Preview changes without writing files |
|
|
34
|
+
| Option | Alias | Default | Description |
|
|
35
|
+
| --------------- | ----- | ---------------- | --------------------------------------------------- |
|
|
36
|
+
| `--vars` | `-v` | `variables.yaml` | Path to the variables YAML file |
|
|
37
|
+
| `--only` | `-o` | `**/*` | Glob pattern to filter files (e.g. **/*.md) |
|
|
38
|
+
| `--exclude` | `-e` | - | Glob pattern to exclude specific files |
|
|
39
|
+
| `--watch` | `-w` | `false` | Watch for file changes and rebuild automatically |
|
|
40
|
+
| `--rename-from` | `-r` | - | Variable name to rename from (use with --rename-to) |
|
|
41
|
+
| `--rename-to` | `-t` | - | Variable name to rename to (use with --rename-from) |
|
|
42
|
+
| `--list-vars` | `-l` | `false` | List all variables used in templates |
|
|
43
|
+
| `--dry-run` | `-d` | `false` | Preview changes without writing files |
|
|
44
44
|
|
|
45
45
|
## Examples
|
|
46
46
|
|
|
@@ -6,11 +6,16 @@ export interface ListVariablesOptions {
|
|
|
6
6
|
}
|
|
7
7
|
export interface VariableUsage {
|
|
8
8
|
name: string;
|
|
9
|
+
value?: string;
|
|
9
10
|
files: string[];
|
|
10
11
|
isDefined: boolean;
|
|
11
12
|
}
|
|
13
|
+
export interface UnusedVariable {
|
|
14
|
+
name: string;
|
|
15
|
+
value: string;
|
|
16
|
+
}
|
|
12
17
|
export interface ListVariablesResult {
|
|
13
18
|
variables: VariableUsage[];
|
|
14
|
-
unusedVariables:
|
|
19
|
+
unusedVariables: UnusedVariable[];
|
|
15
20
|
}
|
|
16
21
|
export declare function listVariables(options: ListVariablesOptions): Promise<ListVariablesResult>;
|
|
@@ -34,6 +34,7 @@ export async function listVariables(options) {
|
|
|
34
34
|
for (const [name, files] of variableUsageMap) {
|
|
35
35
|
variables.push({
|
|
36
36
|
name,
|
|
37
|
+
value: definedVars[name],
|
|
37
38
|
files: Array.from(files).sort(),
|
|
38
39
|
isDefined: definedVarNames.has(name),
|
|
39
40
|
});
|
|
@@ -43,6 +44,7 @@ export async function listVariables(options) {
|
|
|
43
44
|
// Find unused variables (defined but not used)
|
|
44
45
|
const unusedVariables = Array.from(definedVarNames)
|
|
45
46
|
.filter((name) => !usedVarNames.has(name))
|
|
46
|
-
.sort()
|
|
47
|
+
.sort()
|
|
48
|
+
.map((name) => ({ name, value: definedVars[name] }));
|
|
47
49
|
return { variables, unusedVariables };
|
|
48
50
|
}
|
|
@@ -11,37 +11,45 @@ export declare const mainCommand: import("citty").CommandDef<{
|
|
|
11
11
|
};
|
|
12
12
|
vars: {
|
|
13
13
|
type: "string";
|
|
14
|
+
alias: string;
|
|
14
15
|
description: string;
|
|
15
16
|
default: string;
|
|
16
17
|
};
|
|
17
18
|
only: {
|
|
18
19
|
type: "string";
|
|
20
|
+
alias: string;
|
|
19
21
|
description: string;
|
|
20
22
|
};
|
|
21
23
|
exclude: {
|
|
22
24
|
type: "string";
|
|
25
|
+
alias: string;
|
|
23
26
|
description: string;
|
|
24
27
|
};
|
|
25
28
|
watch: {
|
|
26
29
|
type: "boolean";
|
|
30
|
+
alias: string;
|
|
27
31
|
description: string;
|
|
28
32
|
default: false;
|
|
29
33
|
};
|
|
30
34
|
"rename-from": {
|
|
31
35
|
type: "string";
|
|
36
|
+
alias: string;
|
|
32
37
|
description: string;
|
|
33
38
|
};
|
|
34
39
|
"rename-to": {
|
|
35
40
|
type: "string";
|
|
41
|
+
alias: string;
|
|
36
42
|
description: string;
|
|
37
43
|
};
|
|
38
44
|
"list-vars": {
|
|
39
45
|
type: "boolean";
|
|
46
|
+
alias: string;
|
|
40
47
|
description: string;
|
|
41
48
|
default: false;
|
|
42
49
|
};
|
|
43
50
|
"dry-run": {
|
|
44
51
|
type: "boolean";
|
|
52
|
+
alias: string;
|
|
45
53
|
description: string;
|
|
46
54
|
default: false;
|
|
47
55
|
};
|
|
@@ -3,6 +3,11 @@ import { resolve } from "node:path";
|
|
|
3
3
|
import pc from "picocolors";
|
|
4
4
|
import Table from "cli-table3";
|
|
5
5
|
import { watch } from "chokidar";
|
|
6
|
+
function truncate(str, maxLength) {
|
|
7
|
+
if (str.length <= maxLength)
|
|
8
|
+
return str;
|
|
9
|
+
return str.slice(0, maxLength - 1) + "…";
|
|
10
|
+
}
|
|
6
11
|
import { processTemplates } from "../../../application/use-cases/process-templates.js";
|
|
7
12
|
import { renameVariable } from "../../../application/use-cases/rename-variable.js";
|
|
8
13
|
import { listVariables } from "../../../application/use-cases/list-variables.js";
|
|
@@ -89,37 +94,45 @@ export const mainCommand = defineCommand({
|
|
|
89
94
|
},
|
|
90
95
|
vars: {
|
|
91
96
|
type: "string",
|
|
97
|
+
alias: "v",
|
|
92
98
|
description: "Path to variables YAML file",
|
|
93
99
|
default: "variables.yaml",
|
|
94
100
|
},
|
|
95
101
|
only: {
|
|
96
102
|
type: "string",
|
|
103
|
+
alias: "o",
|
|
97
104
|
description: "Glob pattern to filter files (e.g. **/*.md)",
|
|
98
105
|
},
|
|
99
106
|
exclude: {
|
|
100
107
|
type: "string",
|
|
108
|
+
alias: "e",
|
|
101
109
|
description: "Glob pattern to exclude files",
|
|
102
110
|
},
|
|
103
111
|
watch: {
|
|
104
112
|
type: "boolean",
|
|
113
|
+
alias: "w",
|
|
105
114
|
description: "Watch for file changes and rebuild automatically",
|
|
106
115
|
default: false,
|
|
107
116
|
},
|
|
108
117
|
"rename-from": {
|
|
109
118
|
type: "string",
|
|
119
|
+
alias: "r",
|
|
110
120
|
description: "Variable name to rename from (use with --rename-to)",
|
|
111
121
|
},
|
|
112
122
|
"rename-to": {
|
|
113
123
|
type: "string",
|
|
124
|
+
alias: "t",
|
|
114
125
|
description: "Variable name to rename to (use with --rename-from)",
|
|
115
126
|
},
|
|
116
127
|
"list-vars": {
|
|
117
128
|
type: "boolean",
|
|
129
|
+
alias: "l",
|
|
118
130
|
description: "List all variables used in templates",
|
|
119
131
|
default: false,
|
|
120
132
|
},
|
|
121
133
|
"dry-run": {
|
|
122
134
|
type: "boolean",
|
|
135
|
+
alias: "d",
|
|
123
136
|
description: "Preview changes without writing files",
|
|
124
137
|
default: false,
|
|
125
138
|
},
|
|
@@ -204,22 +217,29 @@ export const mainCommand = defineCommand({
|
|
|
204
217
|
}
|
|
205
218
|
if (result.variables.length > 0) {
|
|
206
219
|
const table = new Table({
|
|
207
|
-
head: [pc.bold("Variable"), pc.bold("
|
|
220
|
+
head: [pc.bold("Variable"), pc.bold("Value"), pc.bold("Used in")],
|
|
208
221
|
style: { head: [], border: [] },
|
|
209
222
|
wordWrap: true,
|
|
223
|
+
colWidths: [null, 30, null],
|
|
210
224
|
});
|
|
211
225
|
for (const v of result.variables) {
|
|
212
|
-
const
|
|
226
|
+
const value = v.isDefined ? pc.green(truncate(v.value || "", 25)) : pc.red("✗ undefined");
|
|
213
227
|
const files = v.files.map((f) => pc.gray(f)).join("\n");
|
|
214
|
-
table.push([v.name,
|
|
228
|
+
table.push([v.name, value, files]);
|
|
215
229
|
}
|
|
216
230
|
console.log(table.toString());
|
|
217
231
|
}
|
|
218
232
|
if (result.unusedVariables.length > 0) {
|
|
219
233
|
console.log(pc.bold(pc.yellow("\n⚠ Unused variables (defined but not used):\n")));
|
|
220
|
-
|
|
221
|
-
|
|
234
|
+
const unusedTable = new Table({
|
|
235
|
+
head: [pc.bold("Variable"), pc.bold("Value")],
|
|
236
|
+
style: { head: [], border: [] },
|
|
237
|
+
colWidths: [null, 40],
|
|
238
|
+
});
|
|
239
|
+
for (const v of result.unusedVariables) {
|
|
240
|
+
unusedTable.push([pc.gray(v.name), pc.gray(truncate(v.value, 35))]);
|
|
222
241
|
}
|
|
242
|
+
console.log(unusedTable.toString());
|
|
223
243
|
}
|
|
224
244
|
console.log();
|
|
225
245
|
const defined = result.variables.filter((v) => v.isDefined).length;
|
package/package.json
CHANGED