@thegetty/quire-cli 1.0.0-rc.44 → 1.0.0-rc.46

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 (243) hide show
  1. package/CHANGELOG.md +0 -36
  2. package/README.md +0 -9
  3. package/bin/cli.js +1 -46
  4. package/package.json +9 -25
  5. package/src/Command.js +6 -26
  6. package/src/commands/README.md +122 -213
  7. package/src/commands/build.js +37 -45
  8. package/src/commands/clean.js +19 -33
  9. package/src/commands/conf.js +43 -0
  10. package/src/commands/create.js +14 -42
  11. package/src/commands/epub.js +31 -67
  12. package/src/commands/index.js +2 -9
  13. package/src/commands/info.js +86 -88
  14. package/src/commands/pdf.js +82 -63
  15. package/src/commands/preview.js +31 -32
  16. package/src/commands/validate.js +20 -64
  17. package/src/commands/version.js +43 -0
  18. package/src/errors/validation/validation-error.js +11 -20
  19. package/src/helpers/clean.js +1 -1
  20. package/src/helpers/is-quire.js +31 -0
  21. package/src/helpers/test-cwd.js +6 -5
  22. package/src/helpers/which.js +4 -10
  23. package/src/lib/11ty/README.md +19 -135
  24. package/src/lib/11ty/api.js +93 -235
  25. package/src/lib/11ty/cli.js +37 -112
  26. package/src/lib/11ty/index.js +5 -64
  27. package/src/lib/11ty/paths.js +103 -0
  28. package/src/lib/README.md +0 -330
  29. package/src/lib/conf/README.md +69 -86
  30. package/src/lib/conf/config.js +3 -5
  31. package/src/lib/conf/defaults.js +0 -65
  32. package/src/lib/conf/schema.js +9 -103
  33. package/src/lib/epub/README.md +2 -133
  34. package/src/lib/epub/epub.js +11 -36
  35. package/src/lib/epub/index.js +21 -111
  36. package/src/lib/epub/pandoc.js +4 -33
  37. package/src/lib/git/README.md +2 -151
  38. package/src/lib/git/index.js +13 -217
  39. package/src/lib/i18n/README.md +3 -0
  40. package/src/lib/i18n/config.js +53 -0
  41. package/src/lib/i18n/index.js +43 -0
  42. package/src/lib/i18n/localeService.js +58 -0
  43. package/src/lib/pdf/README.md +0 -131
  44. package/src/lib/pdf/index.js +21 -124
  45. package/src/lib/pdf/paged.js +52 -100
  46. package/src/lib/pdf/prince.js +37 -115
  47. package/src/lib/pdf/split.js +33 -61
  48. package/src/lib/quire/README.md +19 -0
  49. package/src/lib/quire/index.js +353 -0
  50. package/src/lib/reporter/README.md +2 -211
  51. package/src/lib/reporter/index.js +0 -607
  52. package/src/main.js +48 -221
  53. package/src/packageConfig.js +0 -17
  54. package/src/validators/utils.js +1 -2
  55. package/schemas/config.schema.json +0 -194
  56. package/schemas/figures.schema.json +0 -56
  57. package/schemas/layout.schema.json +0 -5
  58. package/schemas/objects.schema.json +0 -62
  59. package/schemas/publication.schema.json +0 -140
  60. package/schemas/references.schema.json +0 -29
  61. package/src/Command.spec.js +0 -99
  62. package/src/commands/build.spec.js +0 -113
  63. package/src/commands/build.test.js +0 -397
  64. package/src/commands/clean.spec.js +0 -118
  65. package/src/commands/clean.test.js +0 -382
  66. package/src/commands/config.js +0 -238
  67. package/src/commands/config.spec.js +0 -107
  68. package/src/commands/config.test.js +0 -845
  69. package/src/commands/create.spec.js +0 -112
  70. package/src/commands/create.test.js +0 -415
  71. package/src/commands/doctor.js +0 -251
  72. package/src/commands/doctor.spec.js +0 -115
  73. package/src/commands/doctor.test.js +0 -1409
  74. package/src/commands/epub.spec.js +0 -114
  75. package/src/commands/epub.test.js +0 -503
  76. package/src/commands/help.js +0 -60
  77. package/src/commands/help.test.js +0 -132
  78. package/src/commands/info.spec.js +0 -72
  79. package/src/commands/info.test.js +0 -512
  80. package/src/commands/pdf.spec.js +0 -114
  81. package/src/commands/pdf.test.js +0 -464
  82. package/src/commands/preview.spec.js +0 -97
  83. package/src/commands/preview.test.js +0 -250
  84. package/src/commands/use.js +0 -56
  85. package/src/commands/use.spec.js +0 -61
  86. package/src/commands/use.test.js +0 -280
  87. package/src/commands/validate.spec.js +0 -90
  88. package/src/commands/validate.test.js +0 -378
  89. package/src/commands/workflows.js +0 -70
  90. package/src/errors/build/build-failed-error.js +0 -19
  91. package/src/errors/build/config-field-missing-error.js +0 -20
  92. package/src/errors/build/config-file-not-found-error.js +0 -20
  93. package/src/errors/build/index.js +0 -11
  94. package/src/errors/help/help-topic-not-found-error.js +0 -30
  95. package/src/errors/help/index.js +0 -8
  96. package/src/errors/index.js +0 -58
  97. package/src/errors/input/index.js +0 -8
  98. package/src/errors/input/invalid-input-error.js +0 -21
  99. package/src/errors/install/dependency-install-error.js +0 -19
  100. package/src/errors/install/directory-not-empty-error.js +0 -25
  101. package/src/errors/install/index.js +0 -12
  102. package/src/errors/install/invalid-path-error.js +0 -31
  103. package/src/errors/install/invalid-starter-error.js +0 -27
  104. package/src/errors/install/version-not-found-error.js +0 -35
  105. package/src/errors/output/epub-generation-error.js +0 -19
  106. package/src/errors/output/index.js +0 -14
  107. package/src/errors/output/invalid-epub-library-error.js +0 -20
  108. package/src/errors/output/invalid-pdf-library-error.js +0 -20
  109. package/src/errors/output/missing-build-output-error.js +0 -21
  110. package/src/errors/output/pdf-generation-error.js +0 -24
  111. package/src/errors/output/tool-not-found-error.js +0 -37
  112. package/src/errors/project/index.js +0 -10
  113. package/src/errors/project/not-in-project-error.js +0 -20
  114. package/src/errors/project/project-create-error.js +0 -21
  115. package/src/errors/quire-error.js +0 -27
  116. package/src/errors/validation/index.js +0 -3
  117. package/src/errors/validation/unknown-config-key-error.js +0 -27
  118. package/src/errors/validation/unknown-config-operation-error.js +0 -24
  119. package/src/helpers/docs-url.js +0 -32
  120. package/src/helpers/pager.js +0 -59
  121. package/src/helpers/pager.test.js +0 -85
  122. package/src/helpers/suggest-similar.js +0 -124
  123. package/src/helpers/suggest-similar.test.js +0 -108
  124. package/src/helpers/test-cwd.test.js +0 -192
  125. package/src/lib/11ty/index.test.js +0 -655
  126. package/src/lib/commander/index.js +0 -103
  127. package/src/lib/commander/index.test.js +0 -86
  128. package/src/lib/commander/options.js +0 -237
  129. package/src/lib/commander/options.test.js +0 -205
  130. package/src/lib/conf/build-status.js +0 -103
  131. package/src/lib/conf/build-status.test.js +0 -247
  132. package/src/lib/conf/config.test.js +0 -281
  133. package/src/lib/conf/format.js +0 -60
  134. package/src/lib/conf/format.test.js +0 -106
  135. package/src/lib/conf/helpers.js +0 -91
  136. package/src/lib/conf/helpers.test.js +0 -136
  137. package/src/lib/conf/index.js +0 -22
  138. package/src/lib/constants.js +0 -28
  139. package/src/lib/doctor/README.md +0 -667
  140. package/src/lib/doctor/checks/environment/cli-version.js +0 -62
  141. package/src/lib/doctor/checks/environment/cli-version.test.js +0 -132
  142. package/src/lib/doctor/checks/environment/git-available.js +0 -77
  143. package/src/lib/doctor/checks/environment/git-available.test.js +0 -52
  144. package/src/lib/doctor/checks/environment/index.js +0 -13
  145. package/src/lib/doctor/checks/environment/node-version.js +0 -66
  146. package/src/lib/doctor/checks/environment/node-version.test.js +0 -17
  147. package/src/lib/doctor/checks/environment/npm-available.js +0 -66
  148. package/src/lib/doctor/checks/environment/npm-available.test.js +0 -52
  149. package/src/lib/doctor/checks/environment/os-info.js +0 -48
  150. package/src/lib/doctor/checks/environment/os-info.test.js +0 -81
  151. package/src/lib/doctor/checks/environment/runtime-info.js +0 -51
  152. package/src/lib/doctor/checks/environment/runtime-info.test.js +0 -132
  153. package/src/lib/doctor/checks/outputs/epub-output.js +0 -119
  154. package/src/lib/doctor/checks/outputs/epub-output.test.js +0 -277
  155. package/src/lib/doctor/checks/outputs/index.js +0 -10
  156. package/src/lib/doctor/checks/outputs/pdf-output.js +0 -144
  157. package/src/lib/doctor/checks/outputs/pdf-output.test.js +0 -377
  158. package/src/lib/doctor/checks/outputs/stale-build.js +0 -122
  159. package/src/lib/doctor/checks/outputs/stale-build.test.js +0 -282
  160. package/src/lib/doctor/checks/project/data-files.js +0 -56
  161. package/src/lib/doctor/checks/project/data-files.test.js +0 -125
  162. package/src/lib/doctor/checks/project/dependencies.js +0 -53
  163. package/src/lib/doctor/checks/project/dependencies.test.js +0 -71
  164. package/src/lib/doctor/checks/project/index.js +0 -11
  165. package/src/lib/doctor/checks/project/quire-11ty.js +0 -98
  166. package/src/lib/doctor/checks/project/quire-11ty.test.js +0 -170
  167. package/src/lib/doctor/checks/project/quire-project.js +0 -38
  168. package/src/lib/doctor/checks/project/quire-project.test.js +0 -47
  169. package/src/lib/doctor/checks/tools/index.js +0 -10
  170. package/src/lib/doctor/checks/tools/pandoc-available.js +0 -82
  171. package/src/lib/doctor/checks/tools/pandoc-available.test.js +0 -73
  172. package/src/lib/doctor/checks/tools/prince-available.js +0 -81
  173. package/src/lib/doctor/checks/tools/prince-available.test.js +0 -73
  174. package/src/lib/doctor/constants.js +0 -39
  175. package/src/lib/doctor/formatDuration.js +0 -108
  176. package/src/lib/doctor/formatDuration.test.js +0 -76
  177. package/src/lib/doctor/formatters/human.js +0 -257
  178. package/src/lib/doctor/formatters/human.test.js +0 -463
  179. package/src/lib/doctor/formatters/index.js +0 -8
  180. package/src/lib/doctor/formatters/json.js +0 -78
  181. package/src/lib/doctor/formatters/json.test.js +0 -174
  182. package/src/lib/doctor/formatters/shared.js +0 -129
  183. package/src/lib/doctor/formatters/shared.test.js +0 -194
  184. package/src/lib/doctor/index.js +0 -271
  185. package/src/lib/doctor/index.test.js +0 -797
  186. package/src/lib/epub/engines.js +0 -46
  187. package/src/lib/epub/index.test.js +0 -518
  188. package/src/lib/epub/pandoc.test.js +0 -122
  189. package/src/lib/epub/schema.js +0 -21
  190. package/src/lib/error/README.md +0 -170
  191. package/src/lib/error/handler.js +0 -107
  192. package/src/lib/git/index.spec.js +0 -80
  193. package/src/lib/git/index.test.js +0 -453
  194. package/src/lib/help/frontmatter.js +0 -77
  195. package/src/lib/help/frontmatter.test.js +0 -139
  196. package/src/lib/help/index.js +0 -146
  197. package/src/lib/help/index.test.js +0 -188
  198. package/src/lib/help/topics/configuration.md +0 -77
  199. package/src/lib/help/topics/debugging.md +0 -69
  200. package/src/lib/help/topics/epub.md +0 -74
  201. package/src/lib/help/topics/pdf.md +0 -74
  202. package/src/lib/help/topics/publishing.md +0 -80
  203. package/src/lib/help/topics/workflows.md +0 -50
  204. package/src/lib/installer/index.js +0 -309
  205. package/src/lib/installer/index.spec.js +0 -83
  206. package/src/lib/installer/index.test.js +0 -545
  207. package/src/lib/logger/README.md +0 -424
  208. package/src/lib/logger/debug.js +0 -132
  209. package/src/lib/logger/debug.spec.js +0 -130
  210. package/src/lib/logger/debug.test.js +0 -128
  211. package/src/lib/logger/index.js +0 -228
  212. package/src/lib/logger/index.spec.js +0 -131
  213. package/src/lib/logger/index.test.js +0 -578
  214. package/src/lib/npm/README.md +0 -127
  215. package/src/lib/npm/index.js +0 -198
  216. package/src/lib/npm/index.spec.js +0 -60
  217. package/src/lib/npm/index.test.js +0 -355
  218. package/src/lib/pdf/engines.js +0 -46
  219. package/src/lib/pdf/index.test.js +0 -708
  220. package/src/lib/pdf/paged.test.js +0 -366
  221. package/src/lib/pdf/prince.test.js +0 -202
  222. package/src/lib/pdf/schema.js +0 -21
  223. package/src/lib/pdf/split.test.js +0 -445
  224. package/src/lib/platform.js +0 -95
  225. package/src/lib/process/manager.js +0 -110
  226. package/src/lib/process/manager.test.js +0 -55
  227. package/src/lib/project/build.js +0 -162
  228. package/src/lib/project/build.test.js +0 -275
  229. package/src/lib/project/config.js +0 -48
  230. package/src/lib/project/config.test.js +0 -134
  231. package/src/lib/project/detect.js +0 -47
  232. package/src/lib/project/detect.test.js +0 -157
  233. package/src/lib/project/index.js +0 -56
  234. package/src/lib/project/output-paths.js +0 -87
  235. package/src/lib/project/output-paths.test.js +0 -66
  236. package/src/lib/project/paths.js +0 -272
  237. package/src/lib/project/version.js +0 -110
  238. package/src/lib/project/version.test.js +0 -350
  239. package/src/lib/reporter/index.test.js +0 -862
  240. package/src/main.spec.js +0 -61
  241. package/src/main.test.js +0 -347
  242. package/src/validators/validate-data-files.js +0 -154
  243. package/src/validators/validate-data-files.test.js +0 -217
@@ -1,708 +0,0 @@
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
- })