@thegetty/quire-cli 1.0.0-rc.35 → 1.0.0-rc.36

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.
Files changed (158) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +9 -0
  3. package/bin/cli.js +19 -1
  4. package/package.json +21 -8
  5. package/patches/README.md +19 -0
  6. package/patches/install-npm-version+1.0.9.patch +12119 -0
  7. package/schemas/objects.schema.json +12 -38
  8. package/schemas/publication.schema.json +0 -22
  9. package/schemas/references.schema.json +0 -1
  10. package/src/Command.js +26 -6
  11. package/src/Command.spec.js +99 -0
  12. package/src/commands/README.md +213 -122
  13. package/src/commands/build.js +46 -37
  14. package/src/commands/build.spec.js +113 -0
  15. package/src/commands/build.test.js +402 -0
  16. package/src/commands/clean.js +25 -19
  17. package/src/commands/clean.spec.js +108 -0
  18. package/src/commands/clean.test.js +260 -0
  19. package/src/commands/config.js +251 -0
  20. package/src/commands/config.spec.js +107 -0
  21. package/src/commands/config.test.js +715 -0
  22. package/src/commands/create.js +42 -14
  23. package/src/commands/create.spec.js +112 -0
  24. package/src/commands/create.test.js +415 -0
  25. package/src/commands/epub.js +59 -30
  26. package/src/commands/epub.spec.js +114 -0
  27. package/src/commands/epub.test.js +503 -0
  28. package/src/commands/index.js +9 -2
  29. package/src/commands/info.js +18 -24
  30. package/src/commands/info.spec.js +64 -0
  31. package/src/commands/info.test.js +415 -0
  32. package/src/commands/pdf.js +58 -84
  33. package/src/commands/pdf.spec.js +114 -0
  34. package/src/commands/pdf.test.js +464 -0
  35. package/src/commands/preview.js +26 -31
  36. package/src/commands/preview.spec.js +97 -0
  37. package/src/commands/preview.test.js +250 -0
  38. package/src/commands/use.js +56 -0
  39. package/src/commands/use.spec.js +61 -0
  40. package/src/commands/use.test.js +280 -0
  41. package/src/commands/validate.js +31 -19
  42. package/src/commands/validate.spec.js +82 -0
  43. package/src/commands/validate.test.js +234 -0
  44. package/src/commands/workflows.js +70 -0
  45. package/src/errors/build/build-failed-error.js +19 -0
  46. package/src/errors/build/config-field-missing-error.js +20 -0
  47. package/src/errors/build/config-file-not-found-error.js +20 -0
  48. package/src/errors/build/index.js +11 -0
  49. package/src/errors/index.js +48 -0
  50. package/src/errors/install/dependency-install-error.js +19 -0
  51. package/src/errors/install/directory-not-empty-error.js +25 -0
  52. package/src/errors/install/index.js +12 -0
  53. package/src/errors/install/invalid-path-error.js +31 -0
  54. package/src/errors/install/invalid-starter-error.js +27 -0
  55. package/src/errors/install/version-not-found-error.js +35 -0
  56. package/src/errors/output/epub-generation-error.js +19 -0
  57. package/src/errors/output/index.js +14 -0
  58. package/src/errors/output/invalid-epub-library-error.js +20 -0
  59. package/src/errors/output/invalid-pdf-library-error.js +20 -0
  60. package/src/errors/output/missing-build-output-error.js +21 -0
  61. package/src/errors/output/pdf-generation-error.js +24 -0
  62. package/src/errors/output/tool-not-found-error.js +37 -0
  63. package/src/errors/project/index.js +10 -0
  64. package/src/errors/project/not-in-project-error.js +20 -0
  65. package/src/errors/project/project-create-error.js +21 -0
  66. package/src/errors/quire-error.js +27 -0
  67. package/src/errors/validation/validation-error.js +20 -11
  68. package/src/helpers/clean.js +1 -1
  69. package/src/helpers/docs-url.js +32 -0
  70. package/src/helpers/test-cwd.js +5 -6
  71. package/src/helpers/test-cwd.test.js +192 -0
  72. package/src/helpers/which.js +10 -4
  73. package/src/lib/11ty/README.md +135 -19
  74. package/src/lib/11ty/api.js +176 -93
  75. package/src/lib/11ty/cli.js +77 -35
  76. package/src/lib/11ty/index.js +64 -5
  77. package/src/lib/11ty/index.test.js +655 -0
  78. package/src/lib/README.md +275 -0
  79. package/src/lib/commander/index.js +100 -0
  80. package/src/lib/commander/index.test.js +86 -0
  81. package/src/lib/commander/options.js +195 -0
  82. package/src/lib/commander/options.test.js +109 -0
  83. package/src/lib/conf/README.md +84 -73
  84. package/src/lib/conf/config.js +5 -3
  85. package/src/lib/conf/config.test.js +281 -0
  86. package/src/lib/conf/defaults.js +44 -0
  87. package/src/lib/conf/format.js +60 -0
  88. package/src/lib/conf/format.test.js +106 -0
  89. package/src/lib/conf/helpers.js +91 -0
  90. package/src/lib/conf/helpers.test.js +136 -0
  91. package/src/lib/conf/index.js +22 -0
  92. package/src/lib/conf/schema.js +53 -8
  93. package/src/lib/epub/README.md +133 -2
  94. package/src/lib/epub/engines.js +46 -0
  95. package/src/lib/epub/epub.js +36 -11
  96. package/src/lib/epub/index.js +111 -21
  97. package/src/lib/epub/index.test.js +518 -0
  98. package/src/lib/epub/pandoc.js +33 -4
  99. package/src/lib/epub/pandoc.test.js +122 -0
  100. package/src/lib/epub/schema.js +21 -0
  101. package/src/lib/error/README.md +170 -0
  102. package/src/lib/error/handler.js +107 -0
  103. package/src/lib/git/README.md +151 -2
  104. package/src/lib/git/index.js +217 -13
  105. package/src/lib/git/index.spec.js +80 -0
  106. package/src/lib/git/index.test.js +453 -0
  107. package/src/lib/installer/index.js +309 -0
  108. package/src/lib/installer/index.spec.js +83 -0
  109. package/src/lib/installer/index.test.js +545 -0
  110. package/src/lib/logger/README.md +424 -0
  111. package/src/lib/logger/debug.js +90 -0
  112. package/src/lib/logger/debug.spec.js +130 -0
  113. package/src/lib/logger/index.js +228 -0
  114. package/src/lib/logger/index.spec.js +131 -0
  115. package/src/lib/logger/index.test.js +477 -0
  116. package/src/lib/npm/README.md +127 -0
  117. package/src/lib/npm/index.js +198 -0
  118. package/src/lib/npm/index.spec.js +60 -0
  119. package/src/lib/npm/index.test.js +355 -0
  120. package/src/lib/pdf/README.md +131 -0
  121. package/src/lib/pdf/engines.js +46 -0
  122. package/src/lib/pdf/index.js +124 -21
  123. package/src/lib/pdf/index.test.js +708 -0
  124. package/src/lib/pdf/paged.js +100 -52
  125. package/src/lib/pdf/paged.test.js +366 -0
  126. package/src/lib/pdf/prince.js +115 -37
  127. package/src/lib/pdf/prince.test.js +202 -0
  128. package/src/lib/pdf/schema.js +21 -0
  129. package/src/lib/pdf/split.js +61 -33
  130. package/src/lib/pdf/split.test.js +445 -0
  131. package/src/lib/process/manager.js +110 -0
  132. package/src/lib/process/manager.test.js +55 -0
  133. package/src/lib/project/build.js +143 -0
  134. package/src/lib/project/build.test.js +253 -0
  135. package/src/lib/project/config.js +48 -0
  136. package/src/lib/project/config.test.js +134 -0
  137. package/src/{helpers/is-quire.js → lib/project/detect.js} +5 -3
  138. package/src/lib/project/detect.test.js +157 -0
  139. package/src/lib/project/index.js +40 -0
  140. package/src/lib/project/paths.js +224 -0
  141. package/src/lib/project/version.js +110 -0
  142. package/src/lib/project/version.test.js +350 -0
  143. package/src/lib/reporter/README.md +211 -2
  144. package/src/lib/reporter/index.js +512 -0
  145. package/src/lib/reporter/index.test.js +593 -0
  146. package/src/main.js +134 -47
  147. package/src/main.spec.js +61 -0
  148. package/src/main.test.js +347 -0
  149. package/src/validators/utils.js +2 -1
  150. package/src/commands/conf.js +0 -43
  151. package/src/commands/version.js +0 -43
  152. package/src/lib/11ty/paths.js +0 -103
  153. package/src/lib/i18n/README.md +0 -3
  154. package/src/lib/i18n/config.js +0 -53
  155. package/src/lib/i18n/index.js +0 -43
  156. package/src/lib/i18n/localeService.js +0 -58
  157. package/src/lib/quire/README.md +0 -19
  158. package/src/lib/quire/index.js +0 -350
@@ -0,0 +1,424 @@
1
+ # Logger Module
2
+
3
+ A logging façade for the Quire CLI that provides colored output, log level filtering, and module-specific prefixes. Aligned with the 11ty package logging format for a consistent user experience.
4
+
5
+ ## Features
6
+
7
+ - **Log level filtering** via [loglevel](https://github.com/pimterry/loglevel)
8
+ - **Colored output** via [chalk](https://github.com/chalk/chalk)
9
+ - **Module-specific prefixes** for traceable log messages
10
+ - **Configuration integration** reads level from `QUIRE_LOG_LEVEL` environment variable
11
+ - **11ty format alignment** consistent `[quire] LEVEL prefix message` output
12
+ - **Namespace debugging** via [debug](https://github.com/debug-js/debug) for surgical internal debugging
13
+
14
+ ## Two Logging Systems
15
+
16
+ The logger module provides two complementary systems:
17
+
18
+ | System | Purpose | Environment Variable | Use Case |
19
+ |--------|---------|---------------------|----------|
20
+ | **Logger** (loglevel) | User-facing output | `QUIRE_LOG_LEVEL` | Status messages, warnings, errors |
21
+ | **Debug** (debug) | Developer debugging | `DEBUG` | Internal tracing, troubleshooting |
22
+
23
+ ### When to Use Each
24
+
25
+ ```javascript
26
+ // User-facing output - use logger
27
+ import { logger } from '#lib/logger/index.js'
28
+ logger.info('Building PDF...') // Always relevant to users
29
+ logger.error('Build failed') // User needs to see this
30
+
31
+ // Internal debugging - use debug
32
+ import createDebug from '#lib/logger/debug.js'
33
+ const debug = createDebug('lib:pdf')
34
+ debug('printer options: %O', opts) // Only developers care about this
35
+ ```
36
+
37
+ ## Command Integration
38
+
39
+ The base `Command` class provides inherited `logger` and `debug` properties to all commands:
40
+
41
+ ```javascript
42
+ // In a command class - use inherited properties
43
+ export default class BuildCommand extends Command {
44
+ async action(options, command) {
45
+ // Debug output (via DEBUG env var)
46
+ this.debug('called with options %O', options)
47
+
48
+ // User-facing logger
49
+ this.logger.info('Building publication...')
50
+ this.logger.warn('Deprecated option used')
51
+ this.logger.error('Build failed')
52
+ }
53
+ }
54
+ ```
55
+
56
+ Each command automatically gets:
57
+ - `this.logger` - A logger with prefix `commands:{name}` (e.g., `commands:build`)
58
+ - `this.debug` - A debug instance with namespace `quire:commands:{name}`
59
+
60
+ This ensures consistent prefixes and makes it easy to filter debug output:
61
+
62
+ ```bash
63
+ # Debug all commands
64
+ DEBUG=quire:commands:* quire build
65
+
66
+ # Debug specific command
67
+ DEBUG=quire:commands:build quire build
68
+ ```
69
+
70
+ ## Usage
71
+
72
+ ### Simple Usage (Singleton)
73
+
74
+ ```javascript
75
+ import { logger } from '#lib/logger/index.js'
76
+
77
+ logger.info('Starting build...')
78
+ logger.debug('Processing file:', filename)
79
+ logger.warn('Deprecated option used')
80
+ logger.error('Build failed:', error.message)
81
+ ```
82
+
83
+ ### Module-Specific Logger
84
+
85
+ ```javascript
86
+ import createLogger from '#lib/logger/index.js'
87
+
88
+ const logger = createLogger('lib:pdf')
89
+
90
+ logger.info('Generating PDF...')
91
+ // Output: [quire] INFO lib:pdf Generating PDF...
92
+ ```
93
+
94
+ ### With Explicit Level
95
+
96
+ ```javascript
97
+ import createLogger from '#lib/logger/index.js'
98
+
99
+ // Create a debug-level logger regardless of config
100
+ const logger = createLogger('debug:module', 'debug')
101
+ ```
102
+
103
+ ## Log Levels
104
+
105
+ | Level | Value | Description |
106
+ |-------|-------|-------------|
107
+ | `trace` | 0 | Most verbose, for detailed debugging |
108
+ | `debug` | 1 | Debug information |
109
+ | `info` | 2 | General information (default) |
110
+ | `warn` | 3 | Warnings |
111
+ | `error` | 4 | Errors only |
112
+ | `silent` | 5 | No output |
113
+
114
+ ## Configuration
115
+
116
+ The logger reads its default level from the `QUIRE_LOG_LEVEL` environment variable, which is set by the CLI entry point from the user's configuration.
117
+
118
+ ### Priority Order
119
+
120
+ 1. **Explicit level parameter** - `createLogger('prefix', 'debug')`
121
+ 2. **Environment variable** - `QUIRE_LOG_LEVEL=debug`
122
+ 3. **Default** - `info`
123
+
124
+ ### Setting Log Level
125
+
126
+ ```javascript
127
+ // At runtime
128
+ logger.setLevel('debug')
129
+
130
+ // Check current level
131
+ const level = logger.getLevel() // Returns numeric level (0-5)
132
+ ```
133
+
134
+ ### Via Configuration
135
+
136
+ The CLI reads `logLevel` from the user's config file (`~/.config/quire-cli/config.json`):
137
+
138
+ ```json
139
+ {
140
+ "logLevel": "debug"
141
+ }
142
+ ```
143
+
144
+ This is set as `QUIRE_LOG_LEVEL` environment variable before logger modules are loaded.
145
+
146
+ ## Output Format
147
+
148
+ ```
149
+ [quire] LEVEL prefix message
150
+ ```
151
+
152
+ Example output:
153
+
154
+ ```
155
+ [quire] INFO quire Starting build...
156
+ [quire] DEBUG lib:pdf Resolving library: prince
157
+ [quire] WARN lib:epub Missing cover image
158
+ [quire] ERROR lib:git Failed to clone repository
159
+ ```
160
+
161
+ The format matches the 11ty package's logging for visual consistency.
162
+
163
+ ## Testing
164
+
165
+ ### Mocking in Tests
166
+
167
+ ```javascript
168
+ import test from 'ava'
169
+ import esmock from 'esmock'
170
+
171
+ test('example test', async (t) => {
172
+ const mockLogger = {
173
+ info: t.context.sandbox.stub(),
174
+ error: t.context.sandbox.stub(),
175
+ debug: t.context.sandbox.stub(),
176
+ warn: t.context.sandbox.stub(),
177
+ trace: t.context.sandbox.stub(),
178
+ setLevel: t.context.sandbox.stub(),
179
+ getLevel: t.context.sandbox.stub().returns(2)
180
+ }
181
+
182
+ const MyModule = await esmock('./my-module.js', {
183
+ '#lib/logger/index.js': { logger: mockLogger }
184
+ })
185
+
186
+ // Test code...
187
+
188
+ t.true(mockLogger.info.calledWith('expected message'))
189
+ })
190
+ ```
191
+
192
+ ### Testing with Environment Variable
193
+
194
+ ```javascript
195
+ test.serial('logger respects QUIRE_LOG_LEVEL', async (t) => {
196
+ const original = process.env.QUIRE_LOG_LEVEL
197
+
198
+ try {
199
+ process.env.QUIRE_LOG_LEVEL = 'debug'
200
+
201
+ // Import fresh module
202
+ const { default: createLogger } = await import('./index.js?test-env')
203
+ const log = createLogger('test:prefix')
204
+
205
+ t.is(log.getLevel(), 1) // debug = 1
206
+ } finally {
207
+ process.env.QUIRE_LOG_LEVEL = original
208
+ }
209
+ })
210
+ ```
211
+
212
+ ## API Reference
213
+
214
+ ### `createLogger(prefix?, level?)`
215
+
216
+ Creates a new logger instance.
217
+
218
+ **Parameters:**
219
+ - `prefix` (string, default: `'quire'`) - Module prefix for log messages
220
+ - `level` (string|number, optional) - Log level override
221
+
222
+ **Returns:** Logger instance with methods:
223
+ - `trace(...args)` - Log at trace level
224
+ - `debug(...args)` - Log at debug level
225
+ - `info(...args)` - Log at info level
226
+ - `warn(...args)` - Log at warn level
227
+ - `error(...args)` - Log at error level
228
+ - `setLevel(level)` - Change log level at runtime
229
+ - `getLevel()` - Get current numeric log level
230
+
231
+ ### `logger`
232
+
233
+ Default singleton logger instance with prefix `'quire'`.
234
+
235
+ ### `LOG_LEVELS`
236
+
237
+ Exported constants for log level values:
238
+
239
+ ```javascript
240
+ import { LOG_LEVELS } from '#lib/logger/index.js'
241
+
242
+ LOG_LEVELS.trace // 0
243
+ LOG_LEVELS.debug // 1
244
+ LOG_LEVELS.info // 2
245
+ LOG_LEVELS.warn // 3
246
+ LOG_LEVELS.error // 4
247
+ LOG_LEVELS.silent // 5
248
+ ```
249
+
250
+ ### `LOG_LEVEL_ENV_VAR`
251
+
252
+ The environment variable name used for configuration: `'QUIRE_LOG_LEVEL'`
253
+
254
+ ## Architecture
255
+
256
+ ```
257
+ bin/cli.js
258
+
259
+ ├── Reads config.get('logLevel')
260
+ ├── Sets process.env.QUIRE_LOG_LEVEL
261
+
262
+ └── Dynamic import main.js
263
+
264
+ └── Imports commands
265
+
266
+ └── Import logger
267
+
268
+ └── resolveLevel() reads QUIRE_LOG_LEVEL
269
+ ```
270
+
271
+ This architecture ensures:
272
+ 1. Config is read before any logger modules are loaded
273
+ 2. All loggers (including module-level ones) use the configured level
274
+ 3. Tests can set the env var before importing to control levels
275
+
276
+ ## Debug Module
277
+
278
+ The debug module provides namespace-based debugging using the industry-standard [debug](https://github.com/debug-js/debug) package. This aligns with Eleventy core, which uses the same system.
279
+
280
+ ### Basic Usage
281
+
282
+ ```javascript
283
+ // Short import alias
284
+ import createDebug from '#debug'
285
+
286
+ // Or full path
287
+ // import createDebug from '#lib/logger/debug.js'
288
+
289
+ const debug = createDebug('lib:pdf')
290
+
291
+ debug('starting PDF generation')
292
+ debug('options: %O', options)
293
+ debug('processing file: %s', filename)
294
+ ```
295
+
296
+ ### Enabling Debug Output
297
+
298
+ Debug output is controlled via the `DEBUG` environment variable:
299
+
300
+ ```bash
301
+ # Single namespace
302
+ DEBUG=quire:lib:pdf quire pdf
303
+
304
+ # Wildcard matching
305
+ DEBUG=quire:lib:* quire build
306
+
307
+ # All Quire debug output
308
+ DEBUG=quire:* quire build
309
+
310
+ # Combined with Eleventy debugging
311
+ DEBUG=quire:*,Eleventy:* quire build
312
+
313
+ # Exclude specific namespaces
314
+ DEBUG=quire:*,-quire:lib:git quire create my-project
315
+ ```
316
+
317
+ ### Namespace Conventions
318
+
319
+ Use colon-separated namespaces that mirror the module path:
320
+
321
+ | Module Path | Namespace |
322
+ |-------------|-----------|
323
+ | `lib/pdf/index.js` | `lib:pdf` |
324
+ | `lib/pdf/paged.js` | `lib:pdf:paged` |
325
+ | `commands/build.js` | `commands:build` |
326
+ | `helpers/test-cwd.js` | `helpers:cwd` |
327
+
328
+ ### Debug API Reference
329
+
330
+ #### `createDebug(namespace)`
331
+
332
+ Creates a debug instance with the `quire:` prefix.
333
+
334
+ ```javascript
335
+ import createDebug from '#lib/logger/debug.js'
336
+ const debug = createDebug('lib:pdf')
337
+ // Creates debugger with namespace: quire:lib:pdf
338
+ ```
339
+
340
+ #### `createRawDebug(namespace)`
341
+
342
+ Creates a debug instance without the `quire:` prefix.
343
+
344
+ ```javascript
345
+ import { createRawDebug } from '#lib/logger/debug.js'
346
+ const debug = createRawDebug('my:custom:namespace')
347
+ ```
348
+
349
+ #### `isDebugEnabled(namespace)`
350
+
351
+ Check if debug output is enabled for a namespace.
352
+
353
+ ```javascript
354
+ import { isDebugEnabled } from '#lib/logger/debug.js'
355
+
356
+ if (isDebugEnabled('lib:pdf')) {
357
+ // Expensive debug-only computation
358
+ const details = computeExpensiveDebugInfo()
359
+ debug('details: %O', details)
360
+ }
361
+ ```
362
+
363
+ #### `enableDebug(namespaces)` / `disableDebug()`
364
+
365
+ Programmatically enable/disable debug output.
366
+
367
+ ```javascript
368
+ import { enableDebug, disableDebug } from '#lib/logger/debug.js'
369
+
370
+ enableDebug('quire:lib:*')
371
+ // ... debugging code ...
372
+ disableDebug()
373
+ ```
374
+
375
+ ### Debug Formatters
376
+
377
+ The `debug` package supports printf-style formatters:
378
+
379
+ | Formatter | Description |
380
+ |-----------|-------------|
381
+ | `%s` | String |
382
+ | `%d` | Number |
383
+ | `%j` | JSON |
384
+ | `%O` | Pretty-print object (multi-line) |
385
+ | `%o` | Pretty-print object (single-line) |
386
+ | `%%` | Literal `%` |
387
+
388
+ ```javascript
389
+ debug('user: %s, count: %d', username, count)
390
+ debug('config: %O', config) // Pretty printed
391
+ debug('inline: %o', { a: 1 }) // Single line
392
+ ```
393
+
394
+ ### Extending Debug Instances
395
+
396
+ Debug instances can be extended for sub-modules:
397
+
398
+ ```javascript
399
+ const debug = createDebug('lib:pdf')
400
+ const debugPaged = debug.extend('paged')
401
+ // debugPaged.namespace === 'quire:lib:pdf:paged'
402
+ ```
403
+
404
+ ### Testing with Debug
405
+
406
+ ```javascript
407
+ import test from 'ava'
408
+ import { enableDebug, disableDebug } from '#lib/logger/debug.js'
409
+
410
+ test.serial('debug output test', (t) => {
411
+ enableDebug('quire:test:*')
412
+
413
+ // Test code that uses debug...
414
+
415
+ disableDebug()
416
+ })
417
+ ```
418
+
419
+ ## Related
420
+
421
+ - [11ty chalk factory](../../../11ty/_lib/chalk/index.js) - 11ty's equivalent logger
422
+ - [debug package](https://github.com/debug-js/debug) - Underlying debug library
423
+ - [conf module](../conf/) - Configuration management
424
+ - [cli-architecture.md](../../docs/cli-architecture.md) - Architecture documentation
@@ -0,0 +1,90 @@
1
+ import debug from 'debug'
2
+
3
+ /**
4
+ * Debug utility for internal developer debugging
5
+ *
6
+ * Creates debug instances with the `quire:` namespace prefix.
7
+ * Uses the standard `debug` package for namespace-based filtering.
8
+ *
9
+ * @example
10
+ * // In a module (short alias)
11
+ * import createDebug from '#debug'
12
+ * const debug = createDebug('lib:pdf')
13
+ * debug('processing file: %s', filename)
14
+ *
15
+ * @example
16
+ * // Enable via DEBUG environment variable
17
+ * DEBUG=quire:lib:pdf quire pdf # Single namespace
18
+ * DEBUG=quire:lib:* quire build # Wildcard matching
19
+ * DEBUG=quire:* quire build # All quire debug output
20
+ * DEBUG=quire:*,Eleventy:* quire build # Combined with Eleventy
21
+ *
22
+ * @see https://www.npmjs.com/package/debug
23
+ */
24
+
25
+ /**
26
+ * Root namespace for all Quire CLI debug output
27
+ */
28
+ export const DEBUG_NAMESPACE = 'quire'
29
+
30
+ /**
31
+ * Create a debug instance with the quire namespace prefix
32
+ *
33
+ * @param {string} namespace - Module namespace (e.g., 'lib:pdf', 'commands:build')
34
+ * @returns {debug.Debugger} Debug instance
35
+ *
36
+ * @example
37
+ * const debug = createDebug('lib:pdf:paged')
38
+ * debug('printer options: %O', options)
39
+ * // Output (when DEBUG=quire:lib:pdf:paged):
40
+ * // quire:lib:pdf:paged printer options: { ... } +0ms
41
+ */
42
+ export default function createDebug(namespace) {
43
+ return debug(`${DEBUG_NAMESPACE}:${namespace}`)
44
+ }
45
+
46
+ /**
47
+ * Create a debug instance without the quire prefix
48
+ * Useful for debugging external libraries or special cases
49
+ *
50
+ * @param {string} namespace - Full namespace
51
+ * @returns {debug.Debugger} Debug instance
52
+ */
53
+ export function createRawDebug(namespace) {
54
+ return debug(namespace)
55
+ }
56
+
57
+ /**
58
+ * Enable debug output for specific namespaces programmatically
59
+ *
60
+ * @param {string} namespaces - Comma-separated namespaces (supports wildcards)
61
+ *
62
+ * @example
63
+ * enableDebug('quire:lib:*')
64
+ * enableDebug('quire:*,Eleventy:*')
65
+ */
66
+ export function enableDebug(namespaces) {
67
+ debug.enable(namespaces)
68
+ }
69
+
70
+ /**
71
+ * Disable all debug output
72
+ */
73
+ export function disableDebug() {
74
+ debug.disable()
75
+ }
76
+
77
+ /**
78
+ * Check if debug output is enabled for a namespace
79
+ *
80
+ * @param {string} namespace - Namespace to check (without quire: prefix)
81
+ * @returns {boolean} True if debug output would be shown
82
+ *
83
+ * @example
84
+ * if (isDebugEnabled('lib:pdf')) {
85
+ * // Expensive debug-only computation
86
+ * }
87
+ */
88
+ export function isDebugEnabled(namespace) {
89
+ return debug.enabled(`${DEBUG_NAMESPACE}:${namespace}`)
90
+ }
@@ -0,0 +1,130 @@
1
+ import test from 'ava'
2
+ import createDebug, {
3
+ DEBUG_NAMESPACE,
4
+ createRawDebug,
5
+ disableDebug,
6
+ enableDebug,
7
+ isDebugEnabled
8
+ } from './debug.js'
9
+
10
+ /**
11
+ * Debug Module Unit Tests
12
+ *
13
+ * Tests the debug factory exports and API surface.
14
+ */
15
+
16
+ // ─────────────────────────────────────────────────────────────────────────────
17
+ // Export tests
18
+ // ─────────────────────────────────────────────────────────────────────────────
19
+
20
+ test('createDebug is exported as default', (t) => {
21
+ t.is(typeof createDebug, 'function')
22
+ })
23
+
24
+ test('DEBUG_NAMESPACE constant is exported', (t) => {
25
+ t.is(DEBUG_NAMESPACE, 'quire')
26
+ })
27
+
28
+ test('createRawDebug is exported', (t) => {
29
+ t.is(typeof createRawDebug, 'function')
30
+ })
31
+
32
+ test('disableDebug is exported', (t) => {
33
+ t.is(typeof disableDebug, 'function')
34
+ })
35
+
36
+ test('enableDebug is exported', (t) => {
37
+ t.is(typeof enableDebug, 'function')
38
+ })
39
+
40
+ test('isDebugEnabled is exported', (t) => {
41
+ t.is(typeof isDebugEnabled, 'function')
42
+ })
43
+
44
+ // ─────────────────────────────────────────────────────────────────────────────
45
+ // Factory function tests
46
+ // ─────────────────────────────────────────────────────────────────────────────
47
+
48
+ test('createDebug returns a function', (t) => {
49
+ const debug = createDebug('test')
50
+ t.is(typeof debug, 'function')
51
+ })
52
+
53
+ test('createDebug creates debug instance with quire prefix', (t) => {
54
+ const debug = createDebug('lib:pdf')
55
+ // Debug instances have a namespace property
56
+ t.is(debug.namespace, 'quire:lib:pdf')
57
+ })
58
+
59
+ test('createDebug supports nested namespaces', (t) => {
60
+ const debug = createDebug('lib:pdf:paged')
61
+ t.is(debug.namespace, 'quire:lib:pdf:paged')
62
+ })
63
+
64
+ test('createRawDebug creates debug instance without prefix', (t) => {
65
+ const debug = createRawDebug('custom:namespace')
66
+ t.is(debug.namespace, 'custom:namespace')
67
+ })
68
+
69
+ // ─────────────────────────────────────────────────────────────────────────────
70
+ // Enable/disable tests
71
+ // ─────────────────────────────────────────────────────────────────────────────
72
+
73
+ test.serial('enableDebug enables debug output for namespace', (t) => {
74
+ // Clean state
75
+ disableDebug()
76
+ t.false(isDebugEnabled('lib:pdf'))
77
+
78
+ enableDebug('quire:lib:pdf')
79
+ t.true(isDebugEnabled('lib:pdf'))
80
+
81
+ // Cleanup
82
+ disableDebug()
83
+ })
84
+
85
+ test.serial('enableDebug supports wildcards', (t) => {
86
+ disableDebug()
87
+ t.false(isDebugEnabled('lib:pdf'))
88
+ t.false(isDebugEnabled('lib:epub'))
89
+
90
+ enableDebug('quire:lib:*')
91
+ t.true(isDebugEnabled('lib:pdf'))
92
+ t.true(isDebugEnabled('lib:epub'))
93
+
94
+ // Cleanup
95
+ disableDebug()
96
+ })
97
+
98
+ test.serial('disableDebug disables all debug output', (t) => {
99
+ enableDebug('quire:*')
100
+ t.true(isDebugEnabled('lib:pdf'))
101
+
102
+ disableDebug()
103
+ t.false(isDebugEnabled('lib:pdf'))
104
+ })
105
+
106
+ test.serial('isDebugEnabled returns false when not enabled', (t) => {
107
+ disableDebug()
108
+ t.false(isDebugEnabled('lib:pdf'))
109
+ t.false(isDebugEnabled('commands:build'))
110
+ })
111
+
112
+ // ─────────────────────────────────────────────────────────────────────────────
113
+ // Debug instance behavior tests
114
+ // ─────────────────────────────────────────────────────────────────────────────
115
+
116
+ test('debug instance has extend method', (t) => {
117
+ const debug = createDebug('lib:pdf')
118
+ t.is(typeof debug.extend, 'function')
119
+ })
120
+
121
+ test('debug instance can be extended', (t) => {
122
+ const debug = createDebug('lib:pdf')
123
+ const extended = debug.extend('paged')
124
+ t.is(extended.namespace, 'quire:lib:pdf:paged')
125
+ })
126
+
127
+ test('debug instance has enabled property', (t) => {
128
+ const debug = createDebug('test:namespace')
129
+ t.is(typeof debug.enabled, 'boolean')
130
+ })