docvars 0.3.0 โ 0.3.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/README.md +69 -28
- package/dist/application/use-cases/dry-run.js +1 -1
- package/dist/application/use-cases/list-variables.d.ts +1 -1
- package/dist/application/use-cases/list-variables.js +2 -2
- package/dist/application/use-cases/process-templates.js +1 -1
- package/dist/application/use-cases/rename-variable.d.ts +1 -1
- package/dist/application/use-cases/rename-variable.js +2 -2
- package/dist/infrastructure/services/file-scanner.d.ts +1 -1
- package/dist/infrastructure/services/file-scanner.js +36 -5
- package/dist/presentation/cli/commands/main.d.ts +1 -1
- package/dist/presentation/cli/commands/main.js +6 -6
- package/dist/shared/types.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ docvars <input> <output> [options]
|
|
|
34
34
|
| Option | Default | Description |
|
|
35
35
|
| --------------- | ---------------- | --------------------------------------------------- |
|
|
36
36
|
| `--vars` | `variables.yaml` | Path to the variables YAML file |
|
|
37
|
-
| `--
|
|
37
|
+
| `--only` | `**/*` | Glob pattern to filter files (e.g. **/*.md) |
|
|
38
38
|
| `--exclude` | - | Glob pattern to exclude specific files |
|
|
39
39
|
| `--watch` | `false` | Watch for file changes and rebuild automatically |
|
|
40
40
|
| `--rename-from` | - | Variable name to rename from (use with --rename-to) |
|
|
@@ -59,24 +59,51 @@ docvars ./templates ./output --vars production.yaml
|
|
|
59
59
|
### Filter files
|
|
60
60
|
|
|
61
61
|
```bash
|
|
62
|
-
#
|
|
63
|
-
docvars ./templates ./output --
|
|
62
|
+
# Process only markdown files
|
|
63
|
+
docvars ./templates ./output --only "**/*.md"
|
|
64
|
+
|
|
65
|
+
# Process multiple file types
|
|
66
|
+
docvars ./templates ./output --only "**/*.{md,html,txt}"
|
|
67
|
+
|
|
68
|
+
# Process only files matching pattern
|
|
69
|
+
docvars ./templates ./output --only "api-*.md"
|
|
64
70
|
|
|
65
71
|
# Exclude files matching pattern
|
|
66
72
|
docvars ./templates ./output --exclude "draft-*.md"
|
|
67
73
|
```
|
|
68
74
|
|
|
75
|
+
By default, all text files are processed (binary files like images are automatically excluded).
|
|
76
|
+
|
|
69
77
|
### Watch mode
|
|
70
78
|
|
|
71
79
|
```bash
|
|
72
80
|
docvars ./templates ./output --watch
|
|
73
81
|
```
|
|
74
82
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
Output:
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
๐ Watch mode enabled
|
|
78
87
|
|
|
79
|
-
|
|
88
|
+
โโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
89
|
+
โ Templates โ /path/to/templates โ
|
|
90
|
+
โ Variables โ /path/to/variables.yaml โ
|
|
91
|
+
โโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
92
|
+
|
|
93
|
+
Waiting for changes... (Ctrl+C to stop)
|
|
94
|
+
|
|
95
|
+
๐ Change detected: README.md (change)
|
|
96
|
+
|
|
97
|
+
โจ Build complete
|
|
98
|
+
|
|
99
|
+
โโโโโโโโโโโโโฌโโโโโโโโโ
|
|
100
|
+
โ File โ Status โ
|
|
101
|
+
โโโโโโโโโโโโโผโโโโโโโโโค
|
|
102
|
+
โ README.md โ โ done โ
|
|
103
|
+
โโโโโโโโโโโโโดโโโโโโโโโ
|
|
104
|
+
|
|
105
|
+
Processed: 1 file(s)
|
|
106
|
+
```
|
|
80
107
|
|
|
81
108
|
### Rename variables
|
|
82
109
|
|
|
@@ -90,9 +117,21 @@ docvars ./templates ./output --rename-from "name" --rename-to "title"
|
|
|
90
117
|
docvars ./templates ./output --rename-from "database.host" --rename-to "db.host"
|
|
91
118
|
```
|
|
92
119
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
120
|
+
Output:
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
โ๏ธ Rename complete
|
|
124
|
+
database.host โ db.host
|
|
125
|
+
|
|
126
|
+
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโ
|
|
127
|
+
โ File โ Status โ
|
|
128
|
+
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโค
|
|
129
|
+
โ variables.yaml โ โ updated โ
|
|
130
|
+
โ README.md โ โ updated โ
|
|
131
|
+
โโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโ
|
|
132
|
+
|
|
133
|
+
Updated: 2 file(s)
|
|
134
|
+
```
|
|
96
135
|
|
|
97
136
|
### List variables
|
|
98
137
|
|
|
@@ -105,17 +144,20 @@ docvars ./templates ./output --list-vars
|
|
|
105
144
|
Output:
|
|
106
145
|
|
|
107
146
|
```
|
|
108
|
-
Variables
|
|
147
|
+
๐ Variables
|
|
109
148
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
149
|
+
โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโฌโโโโโโโโโโโโ
|
|
150
|
+
โ Variable โ Status โ Used in โ
|
|
151
|
+
โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโผโโโโโโโโโโโโค
|
|
152
|
+
โ app.name โ โ defined โ README.md โ
|
|
153
|
+
โ api.key โ โ undefined โ config.md โ
|
|
154
|
+
โโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโ
|
|
115
155
|
|
|
116
|
-
Unused variables (defined but not used):
|
|
156
|
+
โ Unused variables (defined but not used):
|
|
117
157
|
|
|
118
158
|
deprecated.setting
|
|
159
|
+
|
|
160
|
+
Summary: 1 defined ยท 1 undefined ยท 1 unused
|
|
119
161
|
```
|
|
120
162
|
|
|
121
163
|
### Dry run
|
|
@@ -129,19 +171,18 @@ docvars ./templates ./output --dry-run
|
|
|
129
171
|
Output:
|
|
130
172
|
|
|
131
173
|
```
|
|
132
|
-
Dry run - no files written
|
|
133
|
-
|
|
134
|
-
Files to create (1):
|
|
135
|
-
+ config.md
|
|
136
|
-
|
|
137
|
-
Files to update (2):
|
|
138
|
-
~ README.md
|
|
139
|
-
~ api.md
|
|
174
|
+
๐ Dry run - no files written
|
|
140
175
|
|
|
141
|
-
|
|
142
|
-
|
|
176
|
+
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
|
|
177
|
+
โ File โ Status โ
|
|
178
|
+
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโค
|
|
179
|
+
โ config.md โ + create โ
|
|
180
|
+
โ README.md โ ~ update โ
|
|
181
|
+
โ api.md โ ~ update โ
|
|
182
|
+
โ changelog.md โ = unchanged โ
|
|
183
|
+
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ
|
|
143
184
|
|
|
144
|
-
Summary: 1 create
|
|
185
|
+
Summary: 1 create ยท 2 update ยท 1 unchanged
|
|
145
186
|
```
|
|
146
187
|
|
|
147
188
|
## Template Syntax
|
|
@@ -5,7 +5,7 @@ import { loadVariables } from "../../infrastructure/repositories/variables-repos
|
|
|
5
5
|
import { VariablesFileNotFoundError } from "../../shared/errors.js";
|
|
6
6
|
const VARIABLE_PATTERN = /\{\{([\w.]+)\}\}/g;
|
|
7
7
|
export async function listVariables(options) {
|
|
8
|
-
const { input, vars,
|
|
8
|
+
const { input, vars, only, exclude } = options;
|
|
9
9
|
if (!existsSync(vars)) {
|
|
10
10
|
throw new VariablesFileNotFoundError(vars);
|
|
11
11
|
}
|
|
@@ -13,7 +13,7 @@ export async function listVariables(options) {
|
|
|
13
13
|
const definedVars = loadVariables(vars);
|
|
14
14
|
const definedVarNames = new Set(Object.keys(definedVars));
|
|
15
15
|
// Scan templates and extract variable usage
|
|
16
|
-
const templateFiles = await scanTemplates(input, {
|
|
16
|
+
const templateFiles = await scanTemplates(input, { only, exclude });
|
|
17
17
|
const variableUsageMap = new Map();
|
|
18
18
|
for (const file of templateFiles) {
|
|
19
19
|
const content = readFileSync(file, "utf-8");
|
|
@@ -12,7 +12,7 @@ export async function processTemplates(options) {
|
|
|
12
12
|
}
|
|
13
13
|
const variables = loadVariables(options.vars);
|
|
14
14
|
const files = await scanTemplates(inputDir, {
|
|
15
|
-
|
|
15
|
+
only: options.only,
|
|
16
16
|
exclude: options.exclude,
|
|
17
17
|
});
|
|
18
18
|
const processedFiles = [];
|
|
@@ -6,7 +6,7 @@ function escapeRegex(str) {
|
|
|
6
6
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
7
7
|
}
|
|
8
8
|
export async function renameVariable(options) {
|
|
9
|
-
const { input, vars, from, to,
|
|
9
|
+
const { input, vars, from, to, only, exclude } = options;
|
|
10
10
|
if (!existsSync(vars)) {
|
|
11
11
|
throw new VariablesFileNotFoundError(vars);
|
|
12
12
|
}
|
|
@@ -15,7 +15,7 @@ export async function renameVariable(options) {
|
|
|
15
15
|
renamedInVars: false,
|
|
16
16
|
};
|
|
17
17
|
// Rename in template files
|
|
18
|
-
const templateFiles = await scanTemplates(input, {
|
|
18
|
+
const templateFiles = await scanTemplates(input, { only, exclude });
|
|
19
19
|
const pattern = new RegExp(`\\{\\{${escapeRegex(from)}(\\}\\}|\\|)`, "g");
|
|
20
20
|
for (const file of templateFiles) {
|
|
21
21
|
const content = readFileSync(file, "utf-8");
|
|
@@ -1,8 +1,39 @@
|
|
|
1
1
|
import fg from "fast-glob";
|
|
2
|
+
// Binary and non-text files to ignore by default
|
|
3
|
+
const DEFAULT_IGNORE = [
|
|
4
|
+
"**/*.png",
|
|
5
|
+
"**/*.jpg",
|
|
6
|
+
"**/*.jpeg",
|
|
7
|
+
"**/*.gif",
|
|
8
|
+
"**/*.webp",
|
|
9
|
+
"**/*.ico",
|
|
10
|
+
"**/*.svg",
|
|
11
|
+
"**/*.pdf",
|
|
12
|
+
"**/*.zip",
|
|
13
|
+
"**/*.tar",
|
|
14
|
+
"**/*.gz",
|
|
15
|
+
"**/*.exe",
|
|
16
|
+
"**/*.dll",
|
|
17
|
+
"**/*.so",
|
|
18
|
+
"**/*.dylib",
|
|
19
|
+
"**/*.woff",
|
|
20
|
+
"**/*.woff2",
|
|
21
|
+
"**/*.ttf",
|
|
22
|
+
"**/*.eot",
|
|
23
|
+
"**/*.mp3",
|
|
24
|
+
"**/*.mp4",
|
|
25
|
+
"**/*.wav",
|
|
26
|
+
"**/*.avi",
|
|
27
|
+
"**/*.mov",
|
|
28
|
+
"**/node_modules/**",
|
|
29
|
+
"**/.git/**",
|
|
30
|
+
"**/.DS_Store",
|
|
31
|
+
];
|
|
2
32
|
export async function scanTemplates(inputDir, options = {}) {
|
|
3
|
-
const pattern = options.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
33
|
+
const pattern = options.only ? `${inputDir}/${options.only}` : `${inputDir}/**/*`;
|
|
34
|
+
const ignore = [
|
|
35
|
+
...DEFAULT_IGNORE.map((p) => `${inputDir}/${p}`),
|
|
36
|
+
...(options.exclude ? [`${inputDir}/${options.exclude}`] : []),
|
|
37
|
+
];
|
|
38
|
+
return fg(pattern, { ignore, onlyFiles: true });
|
|
8
39
|
}
|
|
@@ -92,9 +92,9 @@ export const mainCommand = defineCommand({
|
|
|
92
92
|
description: "Path to variables YAML file",
|
|
93
93
|
default: "variables.yaml",
|
|
94
94
|
},
|
|
95
|
-
|
|
95
|
+
only: {
|
|
96
96
|
type: "string",
|
|
97
|
-
description: "Glob pattern to
|
|
97
|
+
description: "Glob pattern to filter files (e.g. **/*.md)",
|
|
98
98
|
},
|
|
99
99
|
exclude: {
|
|
100
100
|
type: "string",
|
|
@@ -132,7 +132,7 @@ export const mainCommand = defineCommand({
|
|
|
132
132
|
input: args.input,
|
|
133
133
|
output: args.output,
|
|
134
134
|
vars: args.vars,
|
|
135
|
-
|
|
135
|
+
only: args.only,
|
|
136
136
|
exclude: args.exclude,
|
|
137
137
|
});
|
|
138
138
|
console.log(pc.bold(pc.cyan("\n๐ Dry run - no files written\n")));
|
|
@@ -194,7 +194,7 @@ export const mainCommand = defineCommand({
|
|
|
194
194
|
const result = await listVariables({
|
|
195
195
|
input: args.input,
|
|
196
196
|
vars: args.vars,
|
|
197
|
-
|
|
197
|
+
only: args.only,
|
|
198
198
|
exclude: args.exclude,
|
|
199
199
|
});
|
|
200
200
|
console.log(pc.bold(pc.cyan("\n๐ Variables\n")));
|
|
@@ -252,7 +252,7 @@ export const mainCommand = defineCommand({
|
|
|
252
252
|
vars: args.vars,
|
|
253
253
|
from: args["rename-from"],
|
|
254
254
|
to: args["rename-to"],
|
|
255
|
-
|
|
255
|
+
only: args.only,
|
|
256
256
|
exclude: args.exclude,
|
|
257
257
|
});
|
|
258
258
|
if (result.renamedInFiles.length === 0 && !result.renamedInVars) {
|
|
@@ -294,7 +294,7 @@ export const mainCommand = defineCommand({
|
|
|
294
294
|
input: args.input,
|
|
295
295
|
output: args.output,
|
|
296
296
|
vars: args.vars,
|
|
297
|
-
|
|
297
|
+
only: args.only,
|
|
298
298
|
exclude: args.exclude,
|
|
299
299
|
};
|
|
300
300
|
const success = await runProcess(options);
|
package/dist/shared/types.d.ts
CHANGED
package/package.json
CHANGED