docvars 0.3.2 → 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.
|
@@ -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
|
}
|
|
@@ -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";
|
|
@@ -212,22 +217,29 @@ export const mainCommand = defineCommand({
|
|
|
212
217
|
}
|
|
213
218
|
if (result.variables.length > 0) {
|
|
214
219
|
const table = new Table({
|
|
215
|
-
head: [pc.bold("Variable"), pc.bold("
|
|
220
|
+
head: [pc.bold("Variable"), pc.bold("Value"), pc.bold("Used in")],
|
|
216
221
|
style: { head: [], border: [] },
|
|
217
222
|
wordWrap: true,
|
|
223
|
+
colWidths: [null, 30, null],
|
|
218
224
|
});
|
|
219
225
|
for (const v of result.variables) {
|
|
220
|
-
const
|
|
226
|
+
const value = v.isDefined ? pc.green(truncate(v.value || "", 25)) : pc.red("✗ undefined");
|
|
221
227
|
const files = v.files.map((f) => pc.gray(f)).join("\n");
|
|
222
|
-
table.push([v.name,
|
|
228
|
+
table.push([v.name, value, files]);
|
|
223
229
|
}
|
|
224
230
|
console.log(table.toString());
|
|
225
231
|
}
|
|
226
232
|
if (result.unusedVariables.length > 0) {
|
|
227
233
|
console.log(pc.bold(pc.yellow("\n⚠ Unused variables (defined but not used):\n")));
|
|
228
|
-
|
|
229
|
-
|
|
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))]);
|
|
230
241
|
}
|
|
242
|
+
console.log(unusedTable.toString());
|
|
231
243
|
}
|
|
232
244
|
console.log();
|
|
233
245
|
const defined = result.variables.filter((v) => v.isDefined).length;
|
package/package.json
CHANGED