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

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 (159) 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 +37 -36
  14. package/src/commands/build.spec.js +113 -0
  15. package/src/commands/build.test.js +397 -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 +32 -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 +196 -94
  75. package/src/lib/11ty/cli.js +91 -37
  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 +132 -0
  112. package/src/lib/logger/debug.spec.js +130 -0
  113. package/src/lib/logger/debug.test.js +128 -0
  114. package/src/lib/logger/index.js +228 -0
  115. package/src/lib/logger/index.spec.js +131 -0
  116. package/src/lib/logger/index.test.js +477 -0
  117. package/src/lib/npm/README.md +127 -0
  118. package/src/lib/npm/index.js +198 -0
  119. package/src/lib/npm/index.spec.js +60 -0
  120. package/src/lib/npm/index.test.js +355 -0
  121. package/src/lib/pdf/README.md +131 -0
  122. package/src/lib/pdf/engines.js +46 -0
  123. package/src/lib/pdf/index.js +124 -21
  124. package/src/lib/pdf/index.test.js +708 -0
  125. package/src/lib/pdf/paged.js +100 -52
  126. package/src/lib/pdf/paged.test.js +366 -0
  127. package/src/lib/pdf/prince.js +115 -37
  128. package/src/lib/pdf/prince.test.js +202 -0
  129. package/src/lib/pdf/schema.js +21 -0
  130. package/src/lib/pdf/split.js +61 -33
  131. package/src/lib/pdf/split.test.js +445 -0
  132. package/src/lib/process/manager.js +110 -0
  133. package/src/lib/process/manager.test.js +55 -0
  134. package/src/lib/project/build.js +143 -0
  135. package/src/lib/project/build.test.js +253 -0
  136. package/src/lib/project/config.js +48 -0
  137. package/src/lib/project/config.test.js +134 -0
  138. package/src/{helpers/is-quire.js → lib/project/detect.js} +5 -3
  139. package/src/lib/project/detect.test.js +157 -0
  140. package/src/lib/project/index.js +40 -0
  141. package/src/lib/project/paths.js +224 -0
  142. package/src/lib/project/version.js +110 -0
  143. package/src/lib/project/version.test.js +350 -0
  144. package/src/lib/reporter/README.md +211 -2
  145. package/src/lib/reporter/index.js +512 -0
  146. package/src/lib/reporter/index.test.js +593 -0
  147. package/src/main.js +134 -47
  148. package/src/main.spec.js +61 -0
  149. package/src/main.test.js +347 -0
  150. package/src/validators/utils.js +2 -1
  151. package/src/commands/conf.js +0 -43
  152. package/src/commands/version.js +0 -43
  153. package/src/lib/11ty/paths.js +0 -103
  154. package/src/lib/i18n/README.md +0 -3
  155. package/src/lib/i18n/config.js +0 -53
  156. package/src/lib/i18n/index.js +0 -43
  157. package/src/lib/i18n/localeService.js +0 -58
  158. package/src/lib/quire/README.md +0 -19
  159. package/src/lib/quire/index.js +0 -350
@@ -0,0 +1,708 @@
1
+ import esmock from 'esmock'
2
+ import path from 'node:path'
3
+ import sinon from 'sinon'
4
+ import test from 'ava'
5
+
6
+ /**
7
+ * PDF Module Integration Tests
8
+ *
9
+ * Tests the PDF generation façade module behavior with mocked dependencies.
10
+ * Uses esmock to isolate the module from file system and external PDF tools.
11
+ */
12
+
13
+ /**
14
+ * Create a cross-platform absolute path for testing
15
+ * Uses platform-appropriate root (C:\ on Windows, / on Unix)
16
+ * @param {...string} segments - Path segments to join
17
+ * @returns {string} Platform-appropriate absolute path
18
+ */
19
+ function testPath(...segments) {
20
+ const root = process.platform === 'win32' ? 'C:\\' : '/'
21
+ return path.join(root, ...segments)
22
+ }
23
+
24
+ test.beforeEach((t) => {
25
+ t.context.sandbox = sinon.createSandbox()
26
+ })
27
+
28
+ test.afterEach.always((t) => {
29
+ t.context.sandbox.restore()
30
+ })
31
+
32
+ // ─────────────────────────────────────────────────────────────────────────────
33
+ // Library resolution tests
34
+ // ─────────────────────────────────────────────────────────────────────────────
35
+
36
+ test('generatePdf resolves pagedjs library correctly', async (t) => {
37
+ const { sandbox } = t.context
38
+
39
+ const mockPdfLib = sandbox.stub().resolves()
40
+ const mockDynamicImport = sandbox.stub().resolves({ default: mockPdfLib })
41
+
42
+ const mockPaths = {
43
+ getProjectRoot: () => testPath('project'),
44
+ getOutputDir: () => '_site'
45
+ }
46
+
47
+ const mockFs = {
48
+ existsSync: sandbox.stub().returns(true)
49
+ }
50
+
51
+ const mockReporter = {
52
+ start: sandbox.stub().returnsThis(),
53
+ update: sandbox.stub().returnsThis(),
54
+ succeed: sandbox.stub().returnsThis(),
55
+ fail: sandbox.stub().returnsThis(),
56
+ detail: sandbox.stub().returnsThis()
57
+ }
58
+
59
+ const generatePdf = await esmock('./index.js', {
60
+ '#helpers/os-utils.js': { dynamicImport: mockDynamicImport },
61
+ '#lib/project/index.js': {
62
+ default: mockPaths,
63
+ loadProjectConfig: sandbox.stub().resolves({ pdf: null })
64
+ },
65
+ 'fs-extra': mockFs,
66
+ '#lib/reporter/index.js': { default: mockReporter }
67
+ })
68
+
69
+ await generatePdf.default({ lib: 'pagedjs' })
70
+
71
+ t.true(mockDynamicImport.calledOnce)
72
+ t.true(mockDynamicImport.firstCall.args[0].includes('paged.js'))
73
+ t.true(mockReporter.start.calledWith(sinon.match(/Paged\.js/)))
74
+ })
75
+
76
+ test('generatePdf resolves prince library correctly', async (t) => {
77
+ const { sandbox } = t.context
78
+
79
+ const mockPdfLib = sandbox.stub().resolves()
80
+ const mockDynamicImport = sandbox.stub().resolves({ default: mockPdfLib })
81
+
82
+ const mockPaths = {
83
+ getProjectRoot: () => testPath('project'),
84
+ getOutputDir: () => '_site'
85
+ }
86
+
87
+ const mockFs = {
88
+ existsSync: sandbox.stub().returns(true)
89
+ }
90
+
91
+ const mockReporter = {
92
+ start: sandbox.stub().returnsThis(),
93
+ update: sandbox.stub().returnsThis(),
94
+ succeed: sandbox.stub().returnsThis(),
95
+ fail: sandbox.stub().returnsThis(),
96
+ detail: sandbox.stub().returnsThis()
97
+ }
98
+
99
+ const mockWhich = sandbox.stub().returns('/usr/local/bin/prince')
100
+
101
+ const generatePdf = await esmock('./index.js', {
102
+ '#helpers/os-utils.js': { dynamicImport: mockDynamicImport },
103
+ '#helpers/which.js': { default: mockWhich },
104
+ '#lib/project/index.js': {
105
+ default: mockPaths,
106
+ loadProjectConfig: sandbox.stub().resolves({ pdf: null })
107
+ },
108
+ 'fs-extra': mockFs,
109
+ '#lib/reporter/index.js': { default: mockReporter }
110
+ })
111
+
112
+ await generatePdf.default({ lib: 'prince' })
113
+
114
+ t.true(mockDynamicImport.firstCall.args[0].includes('prince.js'))
115
+ t.true(mockReporter.start.calledWith(sinon.match(/Prince/)))
116
+ })
117
+
118
+ test('generatePdf normalizes library name variations', async (t) => {
119
+ const { sandbox } = t.context
120
+
121
+ const mockPdfLib = sandbox.stub().resolves()
122
+ const mockDynamicImport = sandbox.stub().resolves({ default: mockPdfLib })
123
+
124
+ const mockPaths = {
125
+ getProjectRoot: () => testPath('project'),
126
+ getOutputDir: () => '_site'
127
+ }
128
+
129
+ const mockFs = {
130
+ existsSync: sandbox.stub().returns(true)
131
+ }
132
+
133
+ const mockReporter = {
134
+ start: sandbox.stub().returnsThis(),
135
+ update: sandbox.stub().returnsThis(),
136
+ succeed: sandbox.stub().returnsThis(),
137
+ fail: sandbox.stub().returnsThis(),
138
+ detail: sandbox.stub().returnsThis()
139
+ }
140
+
141
+ const mockWhich = sandbox.stub().returns('/usr/local/bin/prince')
142
+
143
+ const generatePdf = await esmock('./index.js', {
144
+ '#helpers/os-utils.js': { dynamicImport: mockDynamicImport },
145
+ '#helpers/which.js': { default: mockWhich },
146
+ '#lib/project/index.js': {
147
+ default: mockPaths,
148
+ loadProjectConfig: sandbox.stub().resolves({ pdf: null })
149
+ },
150
+ 'fs-extra': mockFs,
151
+ '#lib/reporter/index.js': { default: mockReporter }
152
+ })
153
+
154
+ // Test "paged" variant
155
+ await generatePdf.default({ lib: 'paged' })
156
+ t.true(mockDynamicImport.firstCall.args[0].includes('paged.js'))
157
+
158
+ // Test "princexml" variant
159
+ mockDynamicImport.resetHistory()
160
+ await generatePdf.default({ lib: 'princexml' })
161
+ t.true(mockDynamicImport.firstCall.args[0].includes('prince.js'))
162
+ })
163
+
164
+ test('generatePdf defaults to pagedjs when no library specified', async (t) => {
165
+ const { sandbox } = t.context
166
+
167
+ const mockPdfLib = sandbox.stub().resolves()
168
+ const mockDynamicImport = sandbox.stub().resolves({ default: mockPdfLib })
169
+
170
+ const mockPaths = {
171
+ getProjectRoot: () => testPath('project'),
172
+ getOutputDir: () => '_site'
173
+ }
174
+
175
+ const mockFs = {
176
+ existsSync: sandbox.stub().returns(true)
177
+ }
178
+
179
+ const mockReporter = {
180
+ start: sandbox.stub().returnsThis(),
181
+ update: sandbox.stub().returnsThis(),
182
+ succeed: sandbox.stub().returnsThis(),
183
+ fail: sandbox.stub().returnsThis(),
184
+ detail: sandbox.stub().returnsThis()
185
+ }
186
+
187
+ const generatePdf = await esmock('./index.js', {
188
+ '#helpers/os-utils.js': { dynamicImport: mockDynamicImport },
189
+ '#lib/project/index.js': {
190
+ default: mockPaths,
191
+ loadProjectConfig: sandbox.stub().resolves({ pdf: null })
192
+ },
193
+ 'fs-extra': mockFs,
194
+ '#lib/reporter/index.js': { default: mockReporter }
195
+ })
196
+
197
+ await generatePdf.default({})
198
+
199
+ t.true(mockDynamicImport.firstCall.args[0].includes('paged.js'))
200
+ })
201
+
202
+ // ─────────────────────────────────────────────────────────────────────────────
203
+ // Engine availability tests
204
+ // ─────────────────────────────────────────────────────────────────────────────
205
+
206
+ test('generatePdf throws ToolNotFoundError when prince is not in PATH', async (t) => {
207
+ const { sandbox } = t.context
208
+
209
+ const mockReporter = {
210
+ start: sandbox.stub().returnsThis(),
211
+ update: sandbox.stub().returnsThis(),
212
+ succeed: sandbox.stub().returnsThis(),
213
+ fail: sandbox.stub().returnsThis(),
214
+ detail: sandbox.stub().returnsThis()
215
+ }
216
+
217
+ // Import the actual ToolNotFoundError to throw from mock
218
+ const { ToolNotFoundError } = await import('#src/errors/index.js')
219
+
220
+ // Mock which to throw ToolNotFoundError (simulating prince not found)
221
+ const mockWhich = sandbox.stub().callsFake((executable, toolInfo) => {
222
+ throw new ToolNotFoundError(executable, toolInfo)
223
+ })
224
+
225
+ const generatePdf = await esmock('./index.js', {
226
+ '#helpers/os-utils.js': { dynamicImport: sandbox.stub() },
227
+ '#helpers/which.js': { default: mockWhich },
228
+ '#lib/project/index.js': {
229
+ default: { getProjectRoot: () => testPath('project'), getOutputDir: () => '_site' },
230
+ loadProjectConfig: sandbox.stub()
231
+ },
232
+ 'fs-extra': { existsSync: sandbox.stub() },
233
+ '#lib/reporter/index.js': { default: mockReporter }
234
+ })
235
+
236
+ const error = await t.throwsAsync(() => generatePdf.default({ lib: 'prince' }))
237
+
238
+ t.is(error.code, 'TOOL_NOT_FOUND')
239
+ t.true(error.message.includes('PrinceXML'))
240
+ t.true(error.suggestion.includes('princexml.com'))
241
+ t.true(error.suggestion.includes('pagedjs')) // Fallback suggestion
242
+ // Reporter should NOT have been started (fail fast before spinner)
243
+ t.false(mockReporter.start.called)
244
+ })
245
+
246
+ test('generatePdf does not check binary for pagedjs (built-in engine)', async (t) => {
247
+ const { sandbox } = t.context
248
+
249
+ const mockPdfLib = sandbox.stub().resolves()
250
+ const mockDynamicImport = sandbox.stub().resolves({ default: mockPdfLib })
251
+
252
+ const mockPaths = {
253
+ getProjectRoot: () => testPath('project'),
254
+ getOutputDir: () => '_site'
255
+ }
256
+
257
+ const mockFs = {
258
+ existsSync: sandbox.stub().returns(true)
259
+ }
260
+
261
+ const mockReporter = {
262
+ start: sandbox.stub().returnsThis(),
263
+ update: sandbox.stub().returnsThis(),
264
+ succeed: sandbox.stub().returnsThis(),
265
+ fail: sandbox.stub().returnsThis(),
266
+ detail: sandbox.stub().returnsThis()
267
+ }
268
+
269
+ const mockWhich = sandbox.stub().throws(new Error('which should not be called for pagedjs'))
270
+
271
+ const generatePdf = await esmock('./index.js', {
272
+ '#helpers/os-utils.js': { dynamicImport: mockDynamicImport },
273
+ '#helpers/which.js': { default: mockWhich },
274
+ '#lib/project/index.js': {
275
+ default: mockPaths,
276
+ loadProjectConfig: sandbox.stub().resolves({ pdf: null })
277
+ },
278
+ 'fs-extra': mockFs,
279
+ '#lib/reporter/index.js': { default: mockReporter }
280
+ })
281
+
282
+ // Should not throw - pagedjs doesn't require an external binary
283
+ await t.notThrowsAsync(() => generatePdf.default({ lib: 'pagedjs' }))
284
+ // which should not have been called
285
+ t.false(mockWhich.called)
286
+ })
287
+
288
+ test('generatePdf succeeds when prince is in PATH', async (t) => {
289
+ const { sandbox } = t.context
290
+
291
+ const mockPdfLib = sandbox.stub().resolves()
292
+ const mockDynamicImport = sandbox.stub().resolves({ default: mockPdfLib })
293
+
294
+ const mockPaths = {
295
+ getProjectRoot: () => testPath('project'),
296
+ getOutputDir: () => '_site'
297
+ }
298
+
299
+ const mockFs = {
300
+ existsSync: sandbox.stub().returns(true)
301
+ }
302
+
303
+ const mockReporter = {
304
+ start: sandbox.stub().returnsThis(),
305
+ update: sandbox.stub().returnsThis(),
306
+ succeed: sandbox.stub().returnsThis(),
307
+ fail: sandbox.stub().returnsThis(),
308
+ detail: sandbox.stub().returnsThis()
309
+ }
310
+
311
+ const mockWhich = sandbox.stub().returns('/usr/local/bin/prince') // Prince found
312
+
313
+ const generatePdf = await esmock('./index.js', {
314
+ '#helpers/os-utils.js': { dynamicImport: mockDynamicImport },
315
+ '#helpers/which.js': { default: mockWhich },
316
+ '#lib/project/index.js': {
317
+ default: mockPaths,
318
+ loadProjectConfig: sandbox.stub().resolves({ pdf: null })
319
+ },
320
+ 'fs-extra': mockFs,
321
+ '#lib/reporter/index.js': { default: mockReporter }
322
+ })
323
+
324
+ // Should succeed when prince is found
325
+ await t.notThrowsAsync(() => generatePdf.default({ lib: 'prince' }))
326
+ t.true(mockWhich.calledWith('prince', sinon.match.object))
327
+ t.true(mockReporter.start.called)
328
+ })
329
+
330
+ // ─────────────────────────────────────────────────────────────────────────────
331
+ // Error handling tests
332
+ // ─────────────────────────────────────────────────────────────────────────────
333
+
334
+ test('generatePdf throws InvalidPdfLibraryError for unrecognized library', async (t) => {
335
+ const { sandbox } = t.context
336
+
337
+ const mockReporter = {
338
+ start: sandbox.stub().returnsThis(),
339
+ update: sandbox.stub().returnsThis(),
340
+ succeed: sandbox.stub().returnsThis(),
341
+ fail: sandbox.stub().returnsThis(),
342
+ detail: sandbox.stub().returnsThis()
343
+ }
344
+
345
+ const generatePdf = await esmock('./index.js', {
346
+ '#helpers/os-utils.js': { dynamicImport: sandbox.stub() },
347
+ '#lib/project/index.js': {
348
+ default: { getProjectRoot: () => testPath('project'), getOutputDir: () => '_site' },
349
+ loadProjectConfig: sandbox.stub()
350
+ },
351
+ 'fs-extra': { existsSync: sandbox.stub() },
352
+ '#lib/reporter/index.js': { default: mockReporter }
353
+ })
354
+
355
+ const error = await t.throwsAsync(() => generatePdf.default({ lib: 'unknown-library' }))
356
+
357
+ t.is(error.code, 'INVALID_PDF_LIBRARY')
358
+ t.true(error.message.includes('unknown-library'))
359
+ })
360
+
361
+ test('generatePdf throws MissingBuildOutputError when pdf.html is missing', async (t) => {
362
+ const { sandbox } = t.context
363
+
364
+ const mockPaths = {
365
+ getProjectRoot: () => testPath('project'),
366
+ getOutputDir: () => '_site'
367
+ }
368
+
369
+ const mockFs = {
370
+ existsSync: sandbox.stub().returns(false)
371
+ }
372
+
373
+ const mockReporter = {
374
+ start: sandbox.stub().returnsThis(),
375
+ update: sandbox.stub().returnsThis(),
376
+ succeed: sandbox.stub().returnsThis(),
377
+ fail: sandbox.stub().returnsThis(),
378
+ detail: sandbox.stub().returnsThis()
379
+ }
380
+
381
+ const generatePdf = await esmock('./index.js', {
382
+ '#helpers/os-utils.js': { dynamicImport: sandbox.stub() },
383
+ '#lib/project/index.js': {
384
+ default: mockPaths,
385
+ loadProjectConfig: sandbox.stub().resolves({ pdf: null })
386
+ },
387
+ 'fs-extra': mockFs,
388
+ '#lib/reporter/index.js': { default: mockReporter }
389
+ })
390
+
391
+ const error = await t.throwsAsync(() => generatePdf.default({ lib: 'pagedjs' }))
392
+
393
+ t.is(error.code, 'BUILD_OUTPUT_MISSING')
394
+ t.true(error.message.includes('pdf.html'))
395
+ })
396
+
397
+ // ─────────────────────────────────────────────────────────────────────────────
398
+ // Output path tests
399
+ // ─────────────────────────────────────────────────────────────────────────────
400
+
401
+ test('generatePdf uses pdf config for output path when available', async (t) => {
402
+ const { sandbox } = t.context
403
+
404
+ const mockPdfLib = sandbox.stub().resolves()
405
+ const mockDynamicImport = sandbox.stub().resolves({ default: mockPdfLib })
406
+
407
+ const mockPaths = {
408
+ getProjectRoot: () => testPath('project'),
409
+ getOutputDir: () => '_site'
410
+ }
411
+
412
+ const mockFs = {
413
+ existsSync: sandbox.stub().returns(true)
414
+ }
415
+
416
+ const mockReporter = {
417
+ start: sandbox.stub().returnsThis(),
418
+ update: sandbox.stub().returnsThis(),
419
+ succeed: sandbox.stub().returnsThis(),
420
+ fail: sandbox.stub().returnsThis(),
421
+ detail: sandbox.stub().returnsThis()
422
+ }
423
+
424
+ const pdfConfig = {
425
+ outputDir: '_downloads',
426
+ filename: 'my-publication'
427
+ }
428
+
429
+ const generatePdf = await esmock('./index.js', {
430
+ '#helpers/os-utils.js': { dynamicImport: mockDynamicImport },
431
+ '#lib/project/index.js': {
432
+ default: mockPaths,
433
+ loadProjectConfig: sandbox.stub().resolves({ pdf: pdfConfig })
434
+ },
435
+ 'fs-extra': mockFs,
436
+ '#lib/reporter/index.js': { default: mockReporter }
437
+ })
438
+
439
+ const output = await generatePdf.default({ lib: 'pagedjs' })
440
+
441
+ t.is(output, path.join(testPath('project'), '_site', '_downloads', 'my-publication.pdf'))
442
+ })
443
+
444
+ test('generatePdf uses fallback output path when no pdf config', async (t) => {
445
+ const { sandbox } = t.context
446
+
447
+ const mockPdfLib = sandbox.stub().resolves()
448
+ const mockDynamicImport = sandbox.stub().resolves({ default: mockPdfLib })
449
+
450
+ const mockPaths = {
451
+ getProjectRoot: () => testPath('project'),
452
+ getOutputDir: () => '_site'
453
+ }
454
+
455
+ const mockFs = {
456
+ existsSync: sandbox.stub().returns(true)
457
+ }
458
+
459
+ const mockReporter = {
460
+ start: sandbox.stub().returnsThis(),
461
+ update: sandbox.stub().returnsThis(),
462
+ succeed: sandbox.stub().returnsThis(),
463
+ fail: sandbox.stub().returnsThis(),
464
+ detail: sandbox.stub().returnsThis()
465
+ }
466
+
467
+ const generatePdf = await esmock('./index.js', {
468
+ '#helpers/os-utils.js': { dynamicImport: mockDynamicImport },
469
+ '#lib/project/index.js': {
470
+ default: mockPaths,
471
+ loadProjectConfig: sandbox.stub().resolves({ pdf: null })
472
+ },
473
+ 'fs-extra': mockFs,
474
+ '#lib/reporter/index.js': { default: mockReporter }
475
+ })
476
+
477
+ const output = await generatePdf.default({ lib: 'pagedjs' })
478
+
479
+ t.is(output, path.join(testPath('project'), 'pagedjs.pdf'))
480
+ })
481
+
482
+ test('generatePdf uses --output option when provided (absolute path)', async (t) => {
483
+ const { sandbox } = t.context
484
+
485
+ const mockPdfLib = sandbox.stub().resolves()
486
+ const mockDynamicImport = sandbox.stub().resolves({ default: mockPdfLib })
487
+
488
+ const mockPaths = {
489
+ getProjectRoot: () => testPath('project'),
490
+ getOutputDir: () => '_site'
491
+ }
492
+
493
+ const mockFs = {
494
+ existsSync: sandbox.stub().returns(true)
495
+ }
496
+
497
+ const mockReporter = {
498
+ start: sandbox.stub().returnsThis(),
499
+ update: sandbox.stub().returnsThis(),
500
+ succeed: sandbox.stub().returnsThis(),
501
+ fail: sandbox.stub().returnsThis(),
502
+ detail: sandbox.stub().returnsThis()
503
+ }
504
+
505
+ const pdfConfig = {
506
+ outputDir: '_downloads',
507
+ filename: 'my-publication'
508
+ }
509
+
510
+ const generatePdf = await esmock('./index.js', {
511
+ '#helpers/os-utils.js': { dynamicImport: mockDynamicImport },
512
+ '#lib/project/index.js': {
513
+ default: mockPaths,
514
+ loadProjectConfig: sandbox.stub().resolves({ pdf: pdfConfig })
515
+ },
516
+ 'fs-extra': mockFs,
517
+ '#lib/reporter/index.js': { default: mockReporter }
518
+ })
519
+
520
+ const customPath = testPath('custom', 'path', 'book.pdf')
521
+ const output = await generatePdf.default({ lib: 'pagedjs', output: customPath })
522
+
523
+ t.is(output, customPath)
524
+ // Verify the custom path was passed to the PDF library
525
+ const [, , pdfPath] = mockPdfLib.firstCall.args
526
+ t.is(pdfPath, customPath)
527
+ })
528
+
529
+ test('generatePdf uses --output option when provided (relative path)', async (t) => {
530
+ const { sandbox } = t.context
531
+
532
+ const mockPdfLib = sandbox.stub().resolves()
533
+ const mockDynamicImport = sandbox.stub().resolves({ default: mockPdfLib })
534
+
535
+ const mockPaths = {
536
+ getProjectRoot: () => testPath('project'),
537
+ getOutputDir: () => '_site'
538
+ }
539
+
540
+ const mockFs = {
541
+ existsSync: sandbox.stub().returns(true)
542
+ }
543
+
544
+ const mockReporter = {
545
+ start: sandbox.stub().returnsThis(),
546
+ update: sandbox.stub().returnsThis(),
547
+ succeed: sandbox.stub().returnsThis(),
548
+ fail: sandbox.stub().returnsThis(),
549
+ detail: sandbox.stub().returnsThis()
550
+ }
551
+
552
+ const generatePdf = await esmock('./index.js', {
553
+ '#helpers/os-utils.js': { dynamicImport: mockDynamicImport },
554
+ '#lib/project/index.js': {
555
+ default: mockPaths,
556
+ loadProjectConfig: sandbox.stub().resolves({ pdf: null })
557
+ },
558
+ 'fs-extra': mockFs,
559
+ '#lib/reporter/index.js': { default: mockReporter }
560
+ })
561
+
562
+ const output = await generatePdf.default({ lib: 'pagedjs', output: 'output/my-book.pdf' })
563
+
564
+ // Relative path should be resolved against project root
565
+ t.is(output, path.join(testPath('project'), 'output/my-book.pdf'))
566
+ })
567
+
568
+ test('generatePdf --output option overrides pdf config', async (t) => {
569
+ const { sandbox } = t.context
570
+
571
+ const mockPdfLib = sandbox.stub().resolves()
572
+ const mockDynamicImport = sandbox.stub().resolves({ default: mockPdfLib })
573
+
574
+ const mockPaths = {
575
+ getProjectRoot: () => testPath('project'),
576
+ getOutputDir: () => '_site'
577
+ }
578
+
579
+ const mockFs = {
580
+ existsSync: sandbox.stub().returns(true)
581
+ }
582
+
583
+ const mockReporter = {
584
+ start: sandbox.stub().returnsThis(),
585
+ update: sandbox.stub().returnsThis(),
586
+ succeed: sandbox.stub().returnsThis(),
587
+ fail: sandbox.stub().returnsThis(),
588
+ detail: sandbox.stub().returnsThis()
589
+ }
590
+
591
+ const pdfConfig = {
592
+ outputDir: '_downloads',
593
+ filename: 'configured-name'
594
+ }
595
+
596
+ const generatePdf = await esmock('./index.js', {
597
+ '#helpers/os-utils.js': { dynamicImport: mockDynamicImport },
598
+ '#lib/project/index.js': {
599
+ default: mockPaths,
600
+ loadProjectConfig: sandbox.stub().resolves({ pdf: pdfConfig })
601
+ },
602
+ 'fs-extra': mockFs,
603
+ '#lib/reporter/index.js': { default: mockReporter }
604
+ })
605
+
606
+ const output = await generatePdf.default({ lib: 'pagedjs', output: 'custom.pdf' })
607
+
608
+ // --output should override the config path
609
+ t.is(output, path.join(testPath('project'), 'custom.pdf'))
610
+ // Default would have been: {projectRoot}/_site/_downloads/configured-name.pdf
611
+ })
612
+
613
+ // ─────────────────────────────────────────────────────────────────────────────
614
+ // PDF library invocation tests
615
+ // ─────────────────────────────────────────────────────────────────────────────
616
+
617
+ test('generatePdf passes correct arguments to PDF library', async (t) => {
618
+ const { sandbox } = t.context
619
+
620
+ const mockPdfLib = sandbox.stub().resolves()
621
+ const mockDynamicImport = sandbox.stub().resolves({ default: mockPdfLib })
622
+
623
+ const mockPaths = {
624
+ getProjectRoot: () => testPath('project'),
625
+ getOutputDir: () => '_site'
626
+ }
627
+
628
+ const mockFs = {
629
+ existsSync: sandbox.stub().returns(true)
630
+ }
631
+
632
+ const mockReporter = {
633
+ start: sandbox.stub().returnsThis(),
634
+ update: sandbox.stub().returnsThis(),
635
+ succeed: sandbox.stub().returnsThis(),
636
+ fail: sandbox.stub().returnsThis(),
637
+ detail: sandbox.stub().returnsThis()
638
+ }
639
+
640
+ const pdfConfig = {
641
+ outputDir: '_downloads',
642
+ filename: 'publication'
643
+ }
644
+
645
+ const generatePdf = await esmock('./index.js', {
646
+ '#helpers/os-utils.js': { dynamicImport: mockDynamicImport },
647
+ '#lib/project/index.js': {
648
+ default: mockPaths,
649
+ loadProjectConfig: sandbox.stub().resolves({ pdf: pdfConfig })
650
+ },
651
+ 'fs-extra': mockFs,
652
+ '#lib/reporter/index.js': { default: mockReporter }
653
+ })
654
+
655
+ await generatePdf.default({ lib: 'pagedjs', debug: true })
656
+
657
+ t.true(mockPdfLib.calledOnce)
658
+ const [input, covers, output, options] = mockPdfLib.firstCall.args
659
+ t.is(input, path.join(testPath('project'), '_site', 'pdf.html'))
660
+ t.is(covers, path.join(testPath('project'), '_site', 'pdf-covers.html'))
661
+ t.is(output, path.join(testPath('project'), '_site', '_downloads', 'publication.pdf'))
662
+ t.true(options.debug)
663
+ t.deepEqual(options.pdfConfig, pdfConfig)
664
+ })
665
+
666
+ test('generatePdf passes options through to PDF library', async (t) => {
667
+ const { sandbox } = t.context
668
+
669
+ const mockPdfLib = sandbox.stub().resolves()
670
+ const mockDynamicImport = sandbox.stub().resolves({ default: mockPdfLib })
671
+
672
+ const mockPaths = {
673
+ getProjectRoot: () => testPath('project'),
674
+ getOutputDir: () => '_site'
675
+ }
676
+
677
+ const mockFs = {
678
+ existsSync: sandbox.stub().returns(true)
679
+ }
680
+
681
+ const mockReporter = {
682
+ start: sandbox.stub().returnsThis(),
683
+ update: sandbox.stub().returnsThis(),
684
+ succeed: sandbox.stub().returnsThis(),
685
+ fail: sandbox.stub().returnsThis(),
686
+ detail: sandbox.stub().returnsThis()
687
+ }
688
+
689
+ const generatePdf = await esmock('./index.js', {
690
+ '#helpers/os-utils.js': { dynamicImport: mockDynamicImport },
691
+ '#lib/project/index.js': {
692
+ default: mockPaths,
693
+ loadProjectConfig: sandbox.stub().resolves({ pdf: null })
694
+ },
695
+ 'fs-extra': mockFs,
696
+ '#lib/reporter/index.js': { default: mockReporter }
697
+ })
698
+
699
+ await generatePdf.default({
700
+ lib: 'pagedjs',
701
+ debug: true,
702
+ customOption: 'value'
703
+ })
704
+
705
+ const [, , , options] = mockPdfLib.firstCall.args
706
+ t.true(options.debug)
707
+ t.is(options.customOption, 'value')
708
+ })