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 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
- | `--include` | - | Glob pattern to include specific files |
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
- # Include only files matching pattern
63
- docvars ./templates ./output --include "api-*.md"
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
- This will watch for changes in:
76
- - Template files in the input directory
77
- - The variables YAML file
83
+ Output:
84
+
85
+ ```
86
+ ๐Ÿ‘ Watch mode enabled
78
87
 
79
- When changes are detected, templates are automatically rebuilt.
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
- This updates:
94
- - All `{{oldName}}` occurrences in template files โ†’ `{{newName}}`
95
- - The key in the variables YAML file
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 used in templates:
147
+ ๐Ÿ“‹ Variables
109
148
 
110
- app.name (โœ“)
111
- โ†’ README.md
112
- โ†’ config.md
113
- api.key (โœ— undefined)
114
- โ†’ config.md
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
- Files unchanged (1):
142
- = changelog.md
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, 2 update, 1 unchanged
185
+ Summary: 1 create ยท 2 update ยท 1 unchanged
145
186
  ```
146
187
 
147
188
  ## Template Syntax
@@ -13,7 +13,7 @@ export async function dryRun(options) {
13
13
  }
14
14
  const variables = loadVariables(options.vars);
15
15
  const files = await scanTemplates(inputDir, {
16
- include: options.include,
16
+ only: options.only,
17
17
  exclude: options.exclude,
18
18
  });
19
19
  const changes = [];
@@ -1,7 +1,7 @@
1
1
  export interface ListVariablesOptions {
2
2
  input: string;
3
3
  vars: string;
4
- include?: string;
4
+ only?: string;
5
5
  exclude?: string;
6
6
  }
7
7
  export interface VariableUsage {
@@ -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, include, exclude } = options;
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, { include, exclude });
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
- include: options.include,
15
+ only: options.only,
16
16
  exclude: options.exclude,
17
17
  });
18
18
  const processedFiles = [];
@@ -3,7 +3,7 @@ export interface RenameOptions {
3
3
  vars: string;
4
4
  from: string;
5
5
  to: string;
6
- include?: string;
6
+ only?: string;
7
7
  exclude?: string;
8
8
  }
9
9
  export interface RenameResult {
@@ -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, include, exclude } = options;
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, { include, exclude });
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,5 +1,5 @@
1
1
  export interface ScanOptions {
2
- include?: string;
2
+ only?: string;
3
3
  exclude?: string;
4
4
  }
5
5
  export declare function scanTemplates(inputDir: string, options?: ScanOptions): Promise<string[]>;
@@ -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.include
4
- ? `${inputDir}/${options.include}`
5
- : `${inputDir}/**/*.md`;
6
- const ignore = options.exclude ? [`${inputDir}/${options.exclude}`] : [];
7
- return fg(pattern, { ignore });
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
  }
@@ -14,7 +14,7 @@ export declare const mainCommand: import("citty").CommandDef<{
14
14
  description: string;
15
15
  default: string;
16
16
  };
17
- include: {
17
+ only: {
18
18
  type: "string";
19
19
  description: string;
20
20
  };
@@ -92,9 +92,9 @@ export const mainCommand = defineCommand({
92
92
  description: "Path to variables YAML file",
93
93
  default: "variables.yaml",
94
94
  },
95
- include: {
95
+ only: {
96
96
  type: "string",
97
- description: "Glob pattern to include files",
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
- include: args.include,
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
- include: args.include,
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
- include: args.include,
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
- include: args.include,
297
+ only: args.only,
298
298
  exclude: args.exclude,
299
299
  };
300
300
  const success = await runProcess(options);
@@ -2,7 +2,7 @@ export interface CliOptions {
2
2
  input: string;
3
3
  output: string;
4
4
  vars: string;
5
- include?: string;
5
+ only?: string;
6
6
  exclude?: string;
7
7
  }
8
8
  export interface ProcessResult {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docvars",
3
3
  "author": "Shunta Toda",
4
- "version": "0.3.0",
4
+ "version": "0.3.1",
5
5
  "description": "Replace {{variables}} in document templates with YAML values",
6
6
  "type": "module",
7
7
  "main": "./dist/application/use-cases/process-templates.js",