@thegetty/quire-cli 1.0.0-rc.45 → 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 (245) 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 +10 -27
  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/man/quire.1 +0 -341
  56. package/man/quire.1.md +0 -232
  57. package/schemas/config.schema.json +0 -194
  58. package/schemas/figures.schema.json +0 -56
  59. package/schemas/layout.schema.json +0 -5
  60. package/schemas/objects.schema.json +0 -62
  61. package/schemas/publication.schema.json +0 -140
  62. package/schemas/references.schema.json +0 -29
  63. package/src/Command.spec.js +0 -99
  64. package/src/commands/build.spec.js +0 -113
  65. package/src/commands/build.test.js +0 -397
  66. package/src/commands/clean.spec.js +0 -118
  67. package/src/commands/clean.test.js +0 -382
  68. package/src/commands/config.js +0 -238
  69. package/src/commands/config.spec.js +0 -107
  70. package/src/commands/config.test.js +0 -845
  71. package/src/commands/create.spec.js +0 -112
  72. package/src/commands/create.test.js +0 -415
  73. package/src/commands/doctor.js +0 -251
  74. package/src/commands/doctor.spec.js +0 -115
  75. package/src/commands/doctor.test.js +0 -1409
  76. package/src/commands/epub.spec.js +0 -114
  77. package/src/commands/epub.test.js +0 -503
  78. package/src/commands/help.js +0 -60
  79. package/src/commands/help.test.js +0 -132
  80. package/src/commands/info.spec.js +0 -72
  81. package/src/commands/info.test.js +0 -512
  82. package/src/commands/pdf.spec.js +0 -114
  83. package/src/commands/pdf.test.js +0 -464
  84. package/src/commands/preview.spec.js +0 -97
  85. package/src/commands/preview.test.js +0 -250
  86. package/src/commands/use.js +0 -56
  87. package/src/commands/use.spec.js +0 -61
  88. package/src/commands/use.test.js +0 -280
  89. package/src/commands/validate.spec.js +0 -90
  90. package/src/commands/validate.test.js +0 -378
  91. package/src/commands/workflows.js +0 -70
  92. package/src/errors/build/build-failed-error.js +0 -19
  93. package/src/errors/build/config-field-missing-error.js +0 -20
  94. package/src/errors/build/config-file-not-found-error.js +0 -20
  95. package/src/errors/build/index.js +0 -11
  96. package/src/errors/help/help-topic-not-found-error.js +0 -30
  97. package/src/errors/help/index.js +0 -8
  98. package/src/errors/index.js +0 -58
  99. package/src/errors/input/index.js +0 -8
  100. package/src/errors/input/invalid-input-error.js +0 -21
  101. package/src/errors/install/dependency-install-error.js +0 -19
  102. package/src/errors/install/directory-not-empty-error.js +0 -25
  103. package/src/errors/install/index.js +0 -12
  104. package/src/errors/install/invalid-path-error.js +0 -31
  105. package/src/errors/install/invalid-starter-error.js +0 -27
  106. package/src/errors/install/version-not-found-error.js +0 -35
  107. package/src/errors/output/epub-generation-error.js +0 -19
  108. package/src/errors/output/index.js +0 -14
  109. package/src/errors/output/invalid-epub-library-error.js +0 -20
  110. package/src/errors/output/invalid-pdf-library-error.js +0 -20
  111. package/src/errors/output/missing-build-output-error.js +0 -21
  112. package/src/errors/output/pdf-generation-error.js +0 -24
  113. package/src/errors/output/tool-not-found-error.js +0 -37
  114. package/src/errors/project/index.js +0 -10
  115. package/src/errors/project/not-in-project-error.js +0 -20
  116. package/src/errors/project/project-create-error.js +0 -21
  117. package/src/errors/quire-error.js +0 -27
  118. package/src/errors/validation/index.js +0 -3
  119. package/src/errors/validation/unknown-config-key-error.js +0 -27
  120. package/src/errors/validation/unknown-config-operation-error.js +0 -24
  121. package/src/helpers/docs-url.js +0 -32
  122. package/src/helpers/pager.js +0 -59
  123. package/src/helpers/pager.test.js +0 -85
  124. package/src/helpers/suggest-similar.js +0 -124
  125. package/src/helpers/suggest-similar.test.js +0 -108
  126. package/src/helpers/test-cwd.test.js +0 -192
  127. package/src/lib/11ty/index.test.js +0 -655
  128. package/src/lib/commander/index.js +0 -103
  129. package/src/lib/commander/index.test.js +0 -86
  130. package/src/lib/commander/options.js +0 -237
  131. package/src/lib/commander/options.test.js +0 -205
  132. package/src/lib/conf/build-status.js +0 -103
  133. package/src/lib/conf/build-status.test.js +0 -247
  134. package/src/lib/conf/config.test.js +0 -281
  135. package/src/lib/conf/format.js +0 -60
  136. package/src/lib/conf/format.test.js +0 -106
  137. package/src/lib/conf/helpers.js +0 -91
  138. package/src/lib/conf/helpers.test.js +0 -136
  139. package/src/lib/conf/index.js +0 -22
  140. package/src/lib/constants.js +0 -28
  141. package/src/lib/doctor/README.md +0 -667
  142. package/src/lib/doctor/checks/environment/cli-version.js +0 -62
  143. package/src/lib/doctor/checks/environment/cli-version.test.js +0 -132
  144. package/src/lib/doctor/checks/environment/git-available.js +0 -77
  145. package/src/lib/doctor/checks/environment/git-available.test.js +0 -52
  146. package/src/lib/doctor/checks/environment/index.js +0 -13
  147. package/src/lib/doctor/checks/environment/node-version.js +0 -66
  148. package/src/lib/doctor/checks/environment/node-version.test.js +0 -17
  149. package/src/lib/doctor/checks/environment/npm-available.js +0 -66
  150. package/src/lib/doctor/checks/environment/npm-available.test.js +0 -52
  151. package/src/lib/doctor/checks/environment/os-info.js +0 -48
  152. package/src/lib/doctor/checks/environment/os-info.test.js +0 -81
  153. package/src/lib/doctor/checks/environment/runtime-info.js +0 -51
  154. package/src/lib/doctor/checks/environment/runtime-info.test.js +0 -132
  155. package/src/lib/doctor/checks/outputs/epub-output.js +0 -119
  156. package/src/lib/doctor/checks/outputs/epub-output.test.js +0 -277
  157. package/src/lib/doctor/checks/outputs/index.js +0 -10
  158. package/src/lib/doctor/checks/outputs/pdf-output.js +0 -144
  159. package/src/lib/doctor/checks/outputs/pdf-output.test.js +0 -377
  160. package/src/lib/doctor/checks/outputs/stale-build.js +0 -122
  161. package/src/lib/doctor/checks/outputs/stale-build.test.js +0 -282
  162. package/src/lib/doctor/checks/project/data-files.js +0 -56
  163. package/src/lib/doctor/checks/project/data-files.test.js +0 -125
  164. package/src/lib/doctor/checks/project/dependencies.js +0 -53
  165. package/src/lib/doctor/checks/project/dependencies.test.js +0 -71
  166. package/src/lib/doctor/checks/project/index.js +0 -11
  167. package/src/lib/doctor/checks/project/quire-11ty.js +0 -98
  168. package/src/lib/doctor/checks/project/quire-11ty.test.js +0 -170
  169. package/src/lib/doctor/checks/project/quire-project.js +0 -38
  170. package/src/lib/doctor/checks/project/quire-project.test.js +0 -47
  171. package/src/lib/doctor/checks/tools/index.js +0 -10
  172. package/src/lib/doctor/checks/tools/pandoc-available.js +0 -82
  173. package/src/lib/doctor/checks/tools/pandoc-available.test.js +0 -73
  174. package/src/lib/doctor/checks/tools/prince-available.js +0 -81
  175. package/src/lib/doctor/checks/tools/prince-available.test.js +0 -73
  176. package/src/lib/doctor/constants.js +0 -39
  177. package/src/lib/doctor/formatDuration.js +0 -108
  178. package/src/lib/doctor/formatDuration.test.js +0 -76
  179. package/src/lib/doctor/formatters/human.js +0 -257
  180. package/src/lib/doctor/formatters/human.test.js +0 -463
  181. package/src/lib/doctor/formatters/index.js +0 -8
  182. package/src/lib/doctor/formatters/json.js +0 -78
  183. package/src/lib/doctor/formatters/json.test.js +0 -174
  184. package/src/lib/doctor/formatters/shared.js +0 -129
  185. package/src/lib/doctor/formatters/shared.test.js +0 -194
  186. package/src/lib/doctor/index.js +0 -271
  187. package/src/lib/doctor/index.test.js +0 -797
  188. package/src/lib/epub/engines.js +0 -46
  189. package/src/lib/epub/index.test.js +0 -518
  190. package/src/lib/epub/pandoc.test.js +0 -122
  191. package/src/lib/epub/schema.js +0 -21
  192. package/src/lib/error/README.md +0 -170
  193. package/src/lib/error/handler.js +0 -107
  194. package/src/lib/git/index.spec.js +0 -80
  195. package/src/lib/git/index.test.js +0 -453
  196. package/src/lib/help/frontmatter.js +0 -77
  197. package/src/lib/help/frontmatter.test.js +0 -139
  198. package/src/lib/help/index.js +0 -146
  199. package/src/lib/help/index.test.js +0 -188
  200. package/src/lib/help/topics/configuration.md +0 -77
  201. package/src/lib/help/topics/debugging.md +0 -69
  202. package/src/lib/help/topics/epub.md +0 -74
  203. package/src/lib/help/topics/pdf.md +0 -74
  204. package/src/lib/help/topics/publishing.md +0 -80
  205. package/src/lib/help/topics/workflows.md +0 -50
  206. package/src/lib/installer/index.js +0 -309
  207. package/src/lib/installer/index.spec.js +0 -83
  208. package/src/lib/installer/index.test.js +0 -545
  209. package/src/lib/logger/README.md +0 -424
  210. package/src/lib/logger/debug.js +0 -132
  211. package/src/lib/logger/debug.spec.js +0 -130
  212. package/src/lib/logger/debug.test.js +0 -128
  213. package/src/lib/logger/index.js +0 -228
  214. package/src/lib/logger/index.spec.js +0 -131
  215. package/src/lib/logger/index.test.js +0 -578
  216. package/src/lib/npm/README.md +0 -127
  217. package/src/lib/npm/index.js +0 -198
  218. package/src/lib/npm/index.spec.js +0 -60
  219. package/src/lib/npm/index.test.js +0 -355
  220. package/src/lib/pdf/engines.js +0 -46
  221. package/src/lib/pdf/index.test.js +0 -708
  222. package/src/lib/pdf/paged.test.js +0 -366
  223. package/src/lib/pdf/prince.test.js +0 -202
  224. package/src/lib/pdf/schema.js +0 -21
  225. package/src/lib/pdf/split.test.js +0 -445
  226. package/src/lib/platform.js +0 -95
  227. package/src/lib/process/manager.js +0 -110
  228. package/src/lib/process/manager.test.js +0 -55
  229. package/src/lib/project/build.js +0 -162
  230. package/src/lib/project/build.test.js +0 -275
  231. package/src/lib/project/config.js +0 -48
  232. package/src/lib/project/config.test.js +0 -134
  233. package/src/lib/project/detect.js +0 -47
  234. package/src/lib/project/detect.test.js +0 -157
  235. package/src/lib/project/index.js +0 -56
  236. package/src/lib/project/output-paths.js +0 -87
  237. package/src/lib/project/output-paths.test.js +0 -66
  238. package/src/lib/project/paths.js +0 -272
  239. package/src/lib/project/version.js +0 -110
  240. package/src/lib/project/version.test.js +0 -350
  241. package/src/lib/reporter/index.test.js +0 -862
  242. package/src/main.spec.js +0 -61
  243. package/src/main.test.js +0 -347
  244. package/src/validators/validate-data-files.js +0 -154
  245. package/src/validators/validate-data-files.test.js +0 -217
@@ -1,464 +0,0 @@
1
- import test from 'ava'
2
- import sinon from 'sinon'
3
- import esmock from 'esmock'
4
-
5
- test.beforeEach((t) => {
6
- t.context.sandbox = sinon.createSandbox()
7
-
8
- // Create mock reporter
9
- t.context.mockReporter = {
10
- configure: t.context.sandbox.stub().returnsThis(),
11
- start: t.context.sandbox.stub().returnsThis(),
12
- update: t.context.sandbox.stub().returnsThis(),
13
- succeed: t.context.sandbox.stub().returnsThis(),
14
- fail: t.context.sandbox.stub().returnsThis(),
15
- stop: t.context.sandbox.stub().returnsThis(),
16
- }
17
- })
18
-
19
- test.afterEach.always((t) => {
20
- t.context.sandbox.restore()
21
- })
22
-
23
- test('pdf command should call generatePdf with pagedjs engine', async (t) => {
24
- const { sandbox, mockReporter } = t.context
25
-
26
- const mockGeneratePdf = sandbox.stub().resolves('/project/_site/_pdf/test-book.pdf')
27
-
28
- const PDFCommand = await esmock('./pdf.js', {
29
- '#lib/pdf/index.js': {
30
- default: mockGeneratePdf
31
- },
32
- '#lib/project/index.js': {
33
- hasSiteOutput: () => true
34
- },
35
- '#lib/reporter/index.js': {
36
- default: mockReporter
37
- },
38
- open: {
39
- default: sandbox.stub()
40
- }
41
- })
42
-
43
- const command = new PDFCommand()
44
- command.name = sandbox.stub().returns('pdf')
45
-
46
- await command.action({ engine: 'pagedjs' }, command)
47
-
48
- t.true(mockGeneratePdf.called, 'generatePdf should be called')
49
- t.is(mockGeneratePdf.firstCall.args[0].lib, 'pagedjs', 'should pass lib to generatePdf')
50
- // Nota bene: reporter lifecycle (start/succeed/fail) is handled by the façade, not the command
51
- })
52
-
53
- test('pdf command should call generatePdf with prince engine', async (t) => {
54
- const { sandbox, mockReporter } = t.context
55
-
56
- const mockGeneratePdf = sandbox.stub().resolves('/project/_site/_pdf/test-book.pdf')
57
-
58
- const PDFCommand = await esmock('./pdf.js', {
59
- '#lib/pdf/index.js': {
60
- default: mockGeneratePdf
61
- },
62
- '#lib/project/index.js': {
63
- hasSiteOutput: () => true
64
- },
65
- '#lib/reporter/index.js': {
66
- default: mockReporter
67
- },
68
- open: {
69
- default: sandbox.stub()
70
- }
71
- })
72
-
73
- const command = new PDFCommand()
74
- command.name = sandbox.stub().returns('pdf')
75
-
76
- await command.action({ engine: 'prince' }, command)
77
-
78
- t.true(mockGeneratePdf.called, 'generatePdf should be called')
79
- t.is(mockGeneratePdf.firstCall.args[0].lib, 'prince', 'should pass lib to generatePdf')
80
- })
81
-
82
- test('pdf command should open PDF when --open flag is provided', async (t) => {
83
- const { sandbox, mockReporter } = t.context
84
-
85
- const outputPath = '/project/_site/_pdf/test-book.pdf'
86
- const mockGeneratePdf = sandbox.stub().resolves(outputPath)
87
- const mockOpen = sandbox.stub()
88
-
89
- const PDFCommand = await esmock('./pdf.js', {
90
- '#lib/pdf/index.js': {
91
- default: mockGeneratePdf
92
- },
93
- '#lib/project/index.js': {
94
- hasSiteOutput: () => true
95
- },
96
- '#lib/reporter/index.js': {
97
- default: mockReporter
98
- },
99
- open: {
100
- default: mockOpen
101
- }
102
- })
103
-
104
- const command = new PDFCommand()
105
- command.name = sandbox.stub().returns('pdf')
106
-
107
- await command.action({ engine: 'pagedjs', open: true }, command)
108
-
109
- t.true(mockGeneratePdf.called, 'generatePdf should be called')
110
- t.true(mockOpen.called, 'open should be called when --open flag is provided')
111
- t.is(mockOpen.firstCall.args[0], outputPath, 'should open the generated PDF path')
112
- })
113
-
114
- test('pdf command should not open PDF when --open flag is not provided', async (t) => {
115
- const { sandbox, mockReporter } = t.context
116
-
117
- const mockGeneratePdf = sandbox.stub().resolves('/project/_site/_pdf/test-book.pdf')
118
- const mockOpen = sandbox.stub()
119
-
120
- const PDFCommand = await esmock('./pdf.js', {
121
- '#lib/pdf/index.js': {
122
- default: mockGeneratePdf
123
- },
124
- '#lib/project/index.js': {
125
- hasSiteOutput: () => true
126
- },
127
- '#lib/reporter/index.js': {
128
- default: mockReporter
129
- },
130
- open: {
131
- default: mockOpen
132
- }
133
- })
134
-
135
- const command = new PDFCommand()
136
- command.name = sandbox.stub().returns('pdf')
137
-
138
- await command.action({ engine: 'pagedjs' }, command)
139
-
140
- t.true(mockGeneratePdf.called, 'generatePdf should be called')
141
- t.false(mockOpen.called, 'open should not be called without --open flag')
142
- })
143
-
144
- test('pdf command should pass debug option to generatePdf', async (t) => {
145
- const { sandbox, mockReporter } = t.context
146
-
147
- const mockGeneratePdf = sandbox.stub().resolves('/project/_site/_pdf/test-book.pdf')
148
-
149
- const PDFCommand = await esmock('./pdf.js', {
150
- '#lib/pdf/index.js': {
151
- default: mockGeneratePdf
152
- },
153
- '#lib/project/index.js': {
154
- hasSiteOutput: () => true
155
- },
156
- '#lib/reporter/index.js': {
157
- default: mockReporter
158
- },
159
- open: {
160
- default: sandbox.stub()
161
- }
162
- })
163
-
164
- const command = new PDFCommand()
165
- command.name = sandbox.stub().returns('pdf')
166
-
167
- await command.action({ engine: 'pagedjs', debug: true }, command)
168
-
169
- t.true(mockGeneratePdf.called, 'generatePdf should be called')
170
- t.is(mockGeneratePdf.firstCall.args[0].lib, 'pagedjs', 'should pass lib to generatePdf')
171
- t.true(mockGeneratePdf.firstCall.args[0].debug, 'should pass debug option')
172
- })
173
-
174
- test('pdf command should propagate MissingBuildOutputError from façade', async (t) => {
175
- const { sandbox, mockReporter } = t.context
176
-
177
- // Simulate the façade throwing MissingBuildOutputError when pdf.html is missing
178
- const missingBuildError = new Error('Cannot generate pdf.html: build output not found')
179
- missingBuildError.code = 'BUILD_OUTPUT_MISSING'
180
- const mockGeneratePdf = sandbox.stub().rejects(missingBuildError)
181
-
182
- const PDFCommand = await esmock('./pdf.js', {
183
- '#lib/pdf/index.js': {
184
- default: mockGeneratePdf
185
- },
186
- '#lib/project/index.js': {
187
- hasSiteOutput: () => true // Command doesn't check this for validation anymore
188
- },
189
- '#lib/reporter/index.js': {
190
- default: mockReporter
191
- },
192
- open: {
193
- default: sandbox.stub()
194
- }
195
- })
196
-
197
- const command = new PDFCommand()
198
- command.name = sandbox.stub().returns('pdf')
199
-
200
- const error = await t.throwsAsync(() => command.action({ engine: 'pagedjs' }, command))
201
-
202
- t.is(error.code, 'BUILD_OUTPUT_MISSING', 'should propagate error code from façade')
203
- t.true(mockGeneratePdf.called, 'generatePdf should be called (validation is in façade)')
204
- })
205
-
206
- test('pdf command should run build first when --build flag is set and output missing', async (t) => {
207
- const { sandbox, mockReporter } = t.context
208
-
209
- const mockGeneratePdf = sandbox.stub().resolves('/project/_site/_pdf/test-book.pdf')
210
- const mockBuild = sandbox.stub().resolves()
211
- let buildCalled = false
212
-
213
- const PDFCommand = await esmock('./pdf.js', {
214
- '#lib/pdf/index.js': {
215
- default: mockGeneratePdf
216
- },
217
- '#lib/project/index.js': {
218
- hasSiteOutput: () => {
219
- // Return false first (before build), true after build
220
- if (!buildCalled) return false
221
- return true
222
- }
223
- },
224
- '#lib/11ty/index.js': {
225
- default: {
226
- build: async (opts) => {
227
- buildCalled = true
228
- return mockBuild(opts)
229
- }
230
- }
231
- },
232
- '#lib/reporter/index.js': {
233
- default: mockReporter
234
- },
235
- open: {
236
- default: sandbox.stub()
237
- }
238
- })
239
-
240
- const command = new PDFCommand()
241
- command.name = sandbox.stub().returns('pdf')
242
-
243
- await command.action({ engine: 'pagedjs', build: true }, command)
244
-
245
- t.true(mockBuild.called, 'build should be called when --build flag is set')
246
- t.true(mockGeneratePdf.called, 'generatePdf should be called after build')
247
- })
248
-
249
- test('pdf command should support deprecated --lib option', async (t) => {
250
- const { sandbox, mockReporter } = t.context
251
-
252
- const mockGeneratePdf = sandbox.stub().resolves('/project/_site/_pdf/test-book.pdf')
253
-
254
- const PDFCommand = await esmock('./pdf.js', {
255
- '#lib/pdf/index.js': {
256
- default: mockGeneratePdf
257
- },
258
- '#lib/project/index.js': {
259
- hasSiteOutput: () => true
260
- },
261
- '#lib/reporter/index.js': {
262
- default: mockReporter
263
- },
264
- open: {
265
- default: sandbox.stub()
266
- }
267
- })
268
-
269
- const command = new PDFCommand()
270
- command.name = sandbox.stub().returns('pdf')
271
-
272
- // Use deprecated --lib option (should still work)
273
- await command.action({ lib: 'prince' }, command)
274
-
275
- t.true(mockGeneratePdf.called, 'generatePdf should be called with deprecated --lib')
276
- t.is(mockGeneratePdf.firstCall.args[0].lib, 'prince', 'should pass lib to generatePdf from deprecated option')
277
- })
278
-
279
- test('pdf command should propagate errors from generatePdf', async (t) => {
280
- const { sandbox, mockReporter } = t.context
281
-
282
- const pdfError = new Error('PDF generation failed')
283
- const mockGeneratePdf = sandbox.stub().rejects(pdfError)
284
-
285
- const PDFCommand = await esmock('./pdf.js', {
286
- '#lib/pdf/index.js': {
287
- default: mockGeneratePdf
288
- },
289
- '#lib/project/index.js': {
290
- hasSiteOutput: () => true
291
- },
292
- '#lib/reporter/index.js': {
293
- default: mockReporter
294
- },
295
- open: {
296
- default: sandbox.stub()
297
- }
298
- })
299
-
300
- const command = new PDFCommand()
301
- command.name = sandbox.stub().returns('pdf')
302
-
303
- await t.throwsAsync(() => command.action({ engine: 'pagedjs' }, command), { message: 'PDF generation failed' })
304
-
305
- // Note: reporter lifecycle (start/succeed/fail) is handled by the façade, not the command
306
- t.true(mockGeneratePdf.called, 'generatePdf should be called')
307
- })
308
-
309
- test('pdf command should configure reporter with quiet option', async (t) => {
310
- const { sandbox, mockReporter } = t.context
311
-
312
- const mockGeneratePdf = sandbox.stub().resolves('/project/_site/_pdf/test-book.pdf')
313
-
314
- const PDFCommand = await esmock('./pdf.js', {
315
- '#lib/pdf/index.js': {
316
- default: mockGeneratePdf
317
- },
318
- '#lib/project/index.js': {
319
- hasSiteOutput: () => true
320
- },
321
- '#lib/reporter/index.js': {
322
- default: mockReporter
323
- },
324
- open: {
325
- default: sandbox.stub()
326
- }
327
- })
328
-
329
- const command = new PDFCommand()
330
- command.name = sandbox.stub().returns('pdf')
331
-
332
- await command.action({ engine: 'pagedjs', quiet: true }, command)
333
-
334
- t.true(
335
- mockReporter.configure.calledWith(sinon.match({ quiet: true })),
336
- 'reporter.configure should be called with quiet option'
337
- )
338
- })
339
-
340
- test('pdf command should pass output option to generatePdf', async (t) => {
341
- const { sandbox, mockReporter } = t.context
342
-
343
- const customOutput = '/custom/path/my-book.pdf'
344
- const mockGeneratePdf = sandbox.stub().resolves(customOutput)
345
-
346
- const PDFCommand = await esmock('./pdf.js', {
347
- '#lib/pdf/index.js': {
348
- default: mockGeneratePdf
349
- },
350
- '#lib/project/index.js': {
351
- hasSiteOutput: () => true
352
- },
353
- '#lib/reporter/index.js': {
354
- default: mockReporter
355
- },
356
- open: {
357
- default: sandbox.stub()
358
- }
359
- })
360
-
361
- const command = new PDFCommand()
362
- command.name = sandbox.stub().returns('pdf')
363
-
364
- await command.action({ engine: 'pagedjs', output: customOutput }, command)
365
-
366
- t.true(mockGeneratePdf.called, 'generatePdf should be called')
367
- t.is(mockGeneratePdf.firstCall.args[0].output, customOutput, 'should pass output option to generatePdf')
368
- })
369
-
370
- test('pdf command should use pdfEngine from config when --engine not specified', async (t) => {
371
- const { sandbox, mockReporter } = t.context
372
-
373
- const mockGeneratePdf = sandbox.stub().resolves('/project/_site/_pdf/test-book.pdf')
374
-
375
- const PDFCommand = await esmock('./pdf.js', {
376
- '#lib/pdf/index.js': {
377
- default: mockGeneratePdf
378
- },
379
- '#lib/project/index.js': {
380
- hasSiteOutput: () => true
381
- },
382
- '#lib/reporter/index.js': {
383
- default: mockReporter
384
- },
385
- open: {
386
- default: sandbox.stub()
387
- }
388
- })
389
-
390
- const command = new PDFCommand()
391
- command.name = sandbox.stub().returns('pdf')
392
- // Mock config to return 'prince' for pdfEngine
393
- command.config = { get: (key) => key === 'pdfEngine' ? 'prince' : undefined }
394
-
395
- // No --engine specified, should use config value
396
- await command.action({}, command)
397
-
398
- t.true(mockGeneratePdf.called, 'generatePdf should be called')
399
- t.is(mockGeneratePdf.firstCall.args[0].lib, 'prince', 'should use pdfEngine from config')
400
- })
401
-
402
- test('pdf command should use default engine when --engine not specified and config not set', async (t) => {
403
- const { sandbox, mockReporter } = t.context
404
-
405
- const mockGeneratePdf = sandbox.stub().resolves('/project/_site/_pdf/test-book.pdf')
406
-
407
- const PDFCommand = await esmock('./pdf.js', {
408
- '#lib/pdf/index.js': {
409
- default: mockGeneratePdf
410
- },
411
- '#lib/project/index.js': {
412
- hasSiteOutput: () => true
413
- },
414
- '#lib/reporter/index.js': {
415
- default: mockReporter
416
- },
417
- open: {
418
- default: sandbox.stub()
419
- }
420
- })
421
-
422
- const command = new PDFCommand()
423
- command.name = sandbox.stub().returns('pdf')
424
- // Mock config to return undefined (no pdfEngine set)
425
- command.config = { get: () => undefined }
426
-
427
- // No --engine specified, no config, should use default 'pagedjs'
428
- await command.action({}, command)
429
-
430
- t.true(mockGeneratePdf.called, 'generatePdf should be called')
431
- t.is(mockGeneratePdf.firstCall.args[0].lib, 'pagedjs', 'should use default pagedjs when no config')
432
- })
433
-
434
- test('pdf command --engine flag should override config pdfEngine', async (t) => {
435
- const { sandbox, mockReporter } = t.context
436
-
437
- const mockGeneratePdf = sandbox.stub().resolves('/project/_site/_pdf/test-book.pdf')
438
-
439
- const PDFCommand = await esmock('./pdf.js', {
440
- '#lib/pdf/index.js': {
441
- default: mockGeneratePdf
442
- },
443
- '#lib/project/index.js': {
444
- hasSiteOutput: () => true
445
- },
446
- '#lib/reporter/index.js': {
447
- default: mockReporter
448
- },
449
- open: {
450
- default: sandbox.stub()
451
- }
452
- })
453
-
454
- const command = new PDFCommand()
455
- command.name = sandbox.stub().returns('pdf')
456
- // Mock config to return 'prince' for pdfEngine
457
- command.config = { get: (key) => key === 'pdfEngine' ? 'prince' : undefined }
458
-
459
- // --engine pagedjs should override config's 'prince'
460
- await command.action({ engine: 'pagedjs' }, command)
461
-
462
- t.true(mockGeneratePdf.called, 'generatePdf should be called')
463
- t.is(mockGeneratePdf.firstCall.args[0].lib, 'pagedjs', 'CLI --engine should override config')
464
- })
@@ -1,97 +0,0 @@
1
- import { Command, Option } from 'commander'
2
- import program from '#src/main.js'
3
- import test from 'ava'
4
-
5
- /**
6
- * Command Contract/Interface Tests
7
- *
8
- * Verifies the command's public API and Commander.js integration.
9
- * @see docs/testing-commands.md
10
- */
11
-
12
- test.before((t) => {
13
- // Get the registered command (from program.commands) once and share across all tests
14
- t.context.command = program.commands.find((cmd) => cmd.name() === 'preview')
15
- })
16
-
17
- test('command is registered in CLI program', (t) => {
18
- const { command } = t.context
19
-
20
- t.truthy(command, 'command "preview" should be registered in program')
21
- t.true(command instanceof Command, 'registered command should be Commander.js Command instance')
22
- })
23
-
24
- test('registered command has correct metadata', (t) => {
25
- const { command } = t.context
26
-
27
- t.is(command.name(), 'preview')
28
- t.truthy(command.description())
29
- t.is(typeof command._actionHandler, 'function', 'command should have action handler')
30
- })
31
-
32
- test('registered command has no arguments', (t) => {
33
- const { command } = t.context
34
- const registeredArguments = command.registeredArguments
35
-
36
- t.is(registeredArguments.length, 0, 'preview command should have no arguments')
37
- })
38
-
39
- test('registered command has correct options', (t) => {
40
- const { command } = t.context
41
-
42
- // Get all options
43
- const portOption = command.options.find((opt) => opt.long === '--port')
44
- const quietOption = command.options.find((opt) => opt.long === '--quiet')
45
- const verboseOption = command.options.find((opt) => opt.long === '--verbose')
46
- const eleventyOption = command.options.find((opt) => opt.long === '--11ty')
47
- const debugOption = command.options.find((opt) => opt.long === '--debug')
48
-
49
- // Verify all options exist
50
- t.truthy(portOption, '--port option should exist')
51
- t.truthy(quietOption, '--quiet option should exist')
52
- t.truthy(verboseOption, '--verbose option should exist')
53
- t.truthy(eleventyOption, '--11ty option should exist')
54
- t.truthy(debugOption, '--debug option should exist')
55
-
56
- // Verify they are Option instances
57
- t.true(portOption instanceof Option, '--port should be Option instance')
58
- t.true(quietOption instanceof Option, '--quiet should be Option instance')
59
- t.true(verboseOption instanceof Option, '--verbose should be Option instance')
60
- t.true(eleventyOption instanceof Option, '--11ty should be Option instance')
61
- t.true(debugOption instanceof Option, '--debug should be Option instance')
62
-
63
- // Verify option properties
64
- t.is(portOption.long, '--port')
65
- t.is(portOption.short, '-p')
66
- t.truthy(portOption.description)
67
- t.true(portOption.required, '--port should require a value')
68
-
69
- t.is(quietOption.long, '--quiet')
70
- t.is(quietOption.short, '-q')
71
- t.truthy(quietOption.description)
72
-
73
- t.is(verboseOption.long, '--verbose')
74
- t.is(verboseOption.short, '-v')
75
- t.truthy(verboseOption.description)
76
-
77
- t.is(eleventyOption.long, '--11ty')
78
- t.truthy(eleventyOption.description)
79
- t.true(eleventyOption.required, '--11ty should require a value')
80
-
81
- t.is(debugOption.long, '--debug')
82
- t.truthy(debugOption.description)
83
- t.false(debugOption.required, '--debug should not require a value')
84
- })
85
-
86
- test('command options are accessible via public API', (t) => {
87
- const { command } = t.context
88
-
89
- // Test that options can be accessed the way Commander.js does
90
- const optionNames = command.options.map((opt) => opt.long)
91
-
92
- t.true(optionNames.includes('--port'))
93
- t.true(optionNames.includes('--quiet'))
94
- t.true(optionNames.includes('--verbose'))
95
- t.true(optionNames.includes('--11ty'))
96
- t.true(optionNames.includes('--debug'))
97
- })