@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,397 @@
1
+ import test from 'ava'
2
+ import { Volume, createFsFromVolume } from 'memfs'
3
+ import sinon from 'sinon'
4
+ import esmock from 'esmock'
5
+
6
+ test.beforeEach((t) => {
7
+ // Create sinon sandbox for mocking
8
+ t.context.sandbox = sinon.createSandbox()
9
+
10
+ // Create in-memory file system
11
+ t.context.vol = new Volume()
12
+ t.context.fs = createFsFromVolume(t.context.vol)
13
+
14
+ // Setup mock directory structure
15
+ t.context.vol.fromJSON({
16
+ '/project/content/_data/config.yaml': 'title: Test Project',
17
+ '/project/content/index.md': '# Quire Test Project',
18
+ '/project/package.json': JSON.stringify({ name: 'test-project' })
19
+ })
20
+
21
+ t.context.projectRoot = '/project'
22
+
23
+ // Create mock logger (no global console stubbing needed!)
24
+ t.context.mockLogger = {
25
+ info: t.context.sandbox.stub(),
26
+ error: t.context.sandbox.stub(),
27
+ debug: t.context.sandbox.stub(),
28
+ log: t.context.sandbox.stub(),
29
+ warn: t.context.sandbox.stub()
30
+ }
31
+
32
+ // Create mock reporter
33
+ t.context.mockReporter = {
34
+ configure: t.context.sandbox.stub().returnsThis(),
35
+ start: t.context.sandbox.stub().returnsThis(),
36
+ update: t.context.sandbox.stub().returnsThis(),
37
+ succeed: t.context.sandbox.stub().returnsThis(),
38
+ fail: t.context.sandbox.stub().returnsThis(),
39
+ stop: t.context.sandbox.stub().returnsThis(),
40
+ }
41
+ })
42
+
43
+ test.afterEach.always((t) => {
44
+ // Restore all mocks
45
+ t.context.sandbox.restore()
46
+
47
+ // Clear in-memory file system
48
+ t.context.vol.reset()
49
+ })
50
+
51
+ test('build command should call eleventy CLI with default options', async (t) => {
52
+ const { sandbox, fs, mockLogger, mockReporter } = t.context
53
+
54
+ // Mock eleventy CLI module
55
+ const mockEleventyCli = {
56
+ build: sandbox.stub().resolves({ exitCode: 0 })
57
+ }
58
+
59
+ // Mock eleventy API module
60
+ const mockEleventyApi = {
61
+ build: sandbox.stub().resolves()
62
+ }
63
+
64
+ // Mock clean helper
65
+ const mockClean = sandbox.stub()
66
+
67
+ // Mock testcwd helper
68
+ const mockTestcwd = sandbox.stub()
69
+
70
+ // Use esmock to replace imports
71
+ const BuildCommand = await esmock('./build.js', {
72
+ '#lib/11ty/index.js': {
73
+ api: mockEleventyApi,
74
+ cli: mockEleventyCli
75
+ },
76
+ '#lib/project/index.js': {
77
+ default: {
78
+ getProjectRoot: () => '/project',
79
+ toObject: () => ({ output: '_site' })
80
+ }
81
+ },
82
+ '#helpers/clean.js': {
83
+ clean: mockClean
84
+ },
85
+ '#helpers/test-cwd.js': {
86
+ default: mockTestcwd
87
+ },
88
+ '#lib/logger/index.js': {
89
+ logger: mockLogger
90
+ },
91
+ '#lib/reporter/index.js': {
92
+ default: mockReporter
93
+ },
94
+ 'fs-extra': fs
95
+ })
96
+
97
+ const command = new BuildCommand()
98
+ command.name = sandbox.stub().returns('build')
99
+ command.opts = sandbox.stub().returns({})
100
+
101
+ // Run preAction
102
+ command.preAction(command)
103
+
104
+ // Run action with default options (uses cli by default)
105
+ await command.action({ '11ty': 'cli' }, command)
106
+
107
+ t.true(mockTestcwd.called, 'testcwd should be called in preAction')
108
+ t.true(mockClean.called, 'clean should be called in preAction')
109
+ t.false(mockEleventyApi.build.called, 'eleventy API build should not be called')
110
+ t.true(mockEleventyCli.build.called, 'eleventy CLI build should be called')
111
+ })
112
+
113
+ test('build command should call eleventy API when 11ty option is "api"', async (t) => {
114
+ const { sandbox, fs, mockLogger, mockReporter } = t.context
115
+
116
+ // Mock eleventy CLI module
117
+ const mockEleventyCli = {
118
+ build: sandbox.stub().resolves({ exitCode: 0 })
119
+ }
120
+
121
+ // Mock eleventy API module
122
+ const mockEleventyApi = {
123
+ build: sandbox.stub().resolves()
124
+ }
125
+
126
+ // Mock clean helper
127
+ const mockClean = sandbox.stub()
128
+
129
+ // Mock testcwd helper
130
+ const mockTestcwd = sandbox.stub()
131
+
132
+ // Use esmock to replace imports
133
+ const BuildCommand = await esmock('./build.js', {
134
+ '#lib/11ty/index.js': {
135
+ cli: mockEleventyCli,
136
+ api: mockEleventyApi
137
+ },
138
+ '#lib/project/index.js': {
139
+ default: {
140
+ getProjectRoot: () => '/project',
141
+ toObject: () => ({ output: '_site' })
142
+ }
143
+ },
144
+ '#helpers/clean.js': {
145
+ clean: mockClean
146
+ },
147
+ '#helpers/test-cwd.js': {
148
+ default: mockTestcwd
149
+ },
150
+ '#lib/logger/index.js': {
151
+ logger: mockLogger
152
+ },
153
+ '#lib/reporter/index.js': {
154
+ default: mockReporter
155
+ },
156
+ 'fs-extra': fs
157
+ })
158
+
159
+ const command = new BuildCommand()
160
+ command.name = sandbox.stub().returns('build')
161
+
162
+ // Run action with api option
163
+ await command.action({ '11ty': 'api' }, command)
164
+
165
+ t.false(mockEleventyCli.build.called, 'eleventy CLI build should not be called')
166
+ t.true(mockEleventyApi.build.called, 'eleventy API build should be called')
167
+ })
168
+
169
+ test('build command should call clean with correct parameters in preAction', async (t) => {
170
+ const { sandbox, fs, mockLogger, mockReporter } = t.context
171
+
172
+ // Mock eleventy modules
173
+ const mockEleventyCli = {
174
+ build: sandbox.stub().resolves({ exitCode: 0 })
175
+ }
176
+
177
+ const mockEleventyApi = {
178
+ build: sandbox.stub().resolves()
179
+ }
180
+
181
+ // Mock clean helper
182
+ const mockClean = sandbox.stub()
183
+
184
+ // Mock testcwd helper
185
+ const mockTestcwd = sandbox.stub()
186
+
187
+ // Use esmock to replace imports
188
+ const BuildCommand = await esmock('./build.js', {
189
+ '#lib/11ty/index.js': {
190
+ cli: mockEleventyCli,
191
+ api: mockEleventyApi
192
+ },
193
+ '#lib/project/index.js': {
194
+ default: {
195
+ getProjectRoot: () => '/project',
196
+ toObject: () => ({ output: '_site' })
197
+ }
198
+ },
199
+ '#helpers/clean.js': {
200
+ clean: mockClean
201
+ },
202
+ '#helpers/test-cwd.js': {
203
+ default: mockTestcwd
204
+ },
205
+ '#lib/logger/index.js': {
206
+ logger: mockLogger
207
+ },
208
+ '#lib/reporter/index.js': {
209
+ default: mockReporter
210
+ },
211
+ 'fs-extra': fs
212
+ })
213
+
214
+ const command = new BuildCommand()
215
+ command.name = sandbox.stub().returns('build')
216
+ const options = { verbose: true }
217
+ command.opts = sandbox.stub().returns(options)
218
+
219
+ // Run preAction
220
+ command.preAction(command)
221
+
222
+ t.true(mockClean.called, 'clean should be called')
223
+ t.true(mockClean.calledWith('/project', { output: '_site' }, options), 'clean should be called with correct parameters')
224
+ })
225
+
226
+ test('build command should pass options to eleventy build', async (t) => {
227
+ const { sandbox, fs, mockLogger, mockReporter } = t.context
228
+
229
+ // Mock eleventy CLI module
230
+ const mockEleventyCli = {
231
+ build: sandbox.stub().resolves({ exitCode: 0 })
232
+ }
233
+
234
+ // Mock eleventy API module
235
+ const mockEleventyApi = {
236
+ build: sandbox.stub().resolves()
237
+ }
238
+
239
+ // Mock clean helper
240
+ const mockClean = sandbox.stub()
241
+
242
+ // Mock testcwd helper
243
+ const mockTestcwd = sandbox.stub()
244
+
245
+ // Use esmock to replace imports
246
+ const BuildCommand = await esmock('./build.js', {
247
+ '#lib/11ty/index.js': {
248
+ cli: mockEleventyCli,
249
+ api: mockEleventyApi
250
+ },
251
+ '#lib/project/index.js': {
252
+ default: {
253
+ getProjectRoot: () => '/project',
254
+ toObject: () => ({ output: '_site' })
255
+ }
256
+ },
257
+ '#helpers/clean.js': {
258
+ clean: mockClean
259
+ },
260
+ '#helpers/test-cwd.js': {
261
+ default: mockTestcwd
262
+ },
263
+ '#lib/logger/index.js': {
264
+ logger: mockLogger
265
+ },
266
+ '#lib/reporter/index.js': {
267
+ default: mockReporter
268
+ },
269
+ 'fs-extra': fs
270
+ })
271
+
272
+ const command = new BuildCommand()
273
+ command.name = sandbox.stub().returns('build')
274
+
275
+ const options = { '11ty': 'cli', verbose: true, quiet: false }
276
+
277
+ // Run action with options
278
+ await command.action(options, command)
279
+
280
+ t.true(mockEleventyCli.build.calledWith(options), 'eleventy CLI build should be called with options')
281
+ })
282
+
283
+ test('build command should propagate errors from eleventy build', async (t) => {
284
+ const { sandbox, fs, mockLogger, mockReporter } = t.context
285
+
286
+ const buildError = new Error('Build failed')
287
+
288
+ // Mock eleventy API module to throw error
289
+ const mockEleventyApi = {
290
+ build: sandbox.stub().rejects(buildError)
291
+ }
292
+
293
+ // Mock eleventy CLI module
294
+ const mockEleventyCli = {
295
+ build: sandbox.stub().resolves({ exitCode: 0 })
296
+ }
297
+
298
+ // Mock clean helper
299
+ const mockClean = sandbox.stub()
300
+
301
+ // Mock testcwd helper
302
+ const mockTestcwd = sandbox.stub()
303
+
304
+ // Use esmock to replace imports
305
+ const BuildCommand = await esmock('./build.js', {
306
+ '#lib/11ty/index.js': {
307
+ api: mockEleventyApi,
308
+ cli: mockEleventyCli
309
+ },
310
+ '#lib/project/index.js': {
311
+ default: {
312
+ getProjectRoot: () => '/project',
313
+ toObject: () => ({ output: '_site' })
314
+ }
315
+ },
316
+ '#helpers/clean.js': {
317
+ clean: mockClean
318
+ },
319
+ '#helpers/test-cwd.js': {
320
+ default: mockTestcwd
321
+ },
322
+ '#lib/logger/index.js': {
323
+ logger: mockLogger
324
+ },
325
+ '#lib/reporter/index.js': {
326
+ default: mockReporter
327
+ },
328
+ 'fs-extra': fs
329
+ })
330
+
331
+ const command = new BuildCommand()
332
+ command.name = sandbox.stub().returns('build')
333
+
334
+ // Run action and expect it to throw
335
+ // Nota bene: reporter.start/succeed/fail are called by the lib layer, not the command
336
+ await t.throwsAsync(() => command.action({ '11ty': 'api' }, command), { message: 'Build failed' })
337
+ })
338
+
339
+ test('build command should configure reporter with quiet option', async (t) => {
340
+ const { sandbox, fs, mockLogger, mockReporter } = t.context
341
+
342
+ // Mock eleventy CLI module
343
+ const mockEleventyCli = {
344
+ build: sandbox.stub().resolves({ exitCode: 0 })
345
+ }
346
+
347
+ // Mock eleventy API module
348
+ const mockEleventyApi = {
349
+ build: sandbox.stub().resolves()
350
+ }
351
+
352
+ // Mock clean helper
353
+ const mockClean = sandbox.stub()
354
+
355
+ // Mock testcwd helper
356
+ const mockTestcwd = sandbox.stub()
357
+
358
+ // Use esmock to replace imports
359
+ const BuildCommand = await esmock('./build.js', {
360
+ '#lib/11ty/index.js': {
361
+ cli: mockEleventyCli,
362
+ api: mockEleventyApi
363
+ },
364
+ '#lib/project/index.js': {
365
+ default: {
366
+ getProjectRoot: () => '/project',
367
+ toObject: () => ({ output: '_site' })
368
+ }
369
+ },
370
+ '#helpers/clean.js': {
371
+ clean: mockClean
372
+ },
373
+ '#helpers/test-cwd.js': {
374
+ default: mockTestcwd
375
+ },
376
+ '#lib/logger/index.js': {
377
+ logger: mockLogger
378
+ },
379
+ '#lib/reporter/index.js': {
380
+ default: mockReporter
381
+ },
382
+ 'fs-extra': fs
383
+ })
384
+
385
+ const command = new BuildCommand()
386
+ command.name = sandbox.stub().returns('build')
387
+
388
+ const options = { '11ty': 'api', quiet: true }
389
+
390
+ // Run action with quiet option
391
+ await command.action(options, command)
392
+
393
+ t.true(
394
+ mockReporter.configure.calledWith(sinon.match({ quiet: true })),
395
+ 'reporter.configure should be called with quiet option'
396
+ )
397
+ })
@@ -1,6 +1,7 @@
1
1
  import Command from '#src/Command.js'
2
+ import { withOutputModes } from '#lib/commander/index.js'
2
3
  import { clean } from '#helpers/clean.js'
3
- import { paths, projectRoot } from '#lib/11ty/index.js'
4
+ import paths from '#lib/project/index.js'
4
5
  import testcwd from '#helpers/test-cwd.js'
5
6
 
6
7
  /**
@@ -15,39 +16,44 @@ import testcwd from '#helpers/test-cwd.js'
15
16
  * @extends {Command}
16
17
  */
17
18
  export default class CleanCommand extends Command {
18
- static definition = {
19
+ static definition = withOutputModes({
19
20
  name: 'clean',
20
21
  description: 'Remove build outputs',
21
- summary: 'remove build outputs',
22
+ summary: 'delete generated files',
23
+ docsLink: 'quire-commands/#output-files',
24
+ helpText: `
25
+ Examples:
26
+ quire clean Remove build outputs
27
+ quire clean --dry-run Preview files to be deleted
28
+ quire clean --verbose Clean with detailed progress
29
+ `,
22
30
  version: '1.0.0',
23
- args: [],
24
31
  options: [
25
- [ '-d', '--dry-run', 'show paths to be cleaned without deleting files' ],
26
- [ '-p', '--progress', 'display progress of removing files' ],
27
- [ '-v', '--verbose', 'run clean with verbose console messages' ],
28
- [ '--debug', 'run clean with debug output to console' ],
32
+ [ '-d, --dry-run', 'show paths to be cleaned without deleting files' ],
33
+ [ '--dryrun', 'alias for --dry-run', { hidden: true, implies: { dryRun: true } } ],
29
34
  ],
30
- }
35
+ })
31
36
 
32
37
  constructor() {
33
38
  super(CleanCommand.definition)
34
39
  }
35
40
 
36
41
  async action(options, command) {
37
- if (options.debug) {
38
- console.debug('[CLI] Command \'%s\' called with options %o', this.name(), options)
39
- }
42
+ this.debug('called with options %O', options)
40
43
 
41
- const deletedPaths = await clean(projectRoot, paths, options)
44
+ const deletedPaths = await clean(paths.getProjectRoot(), paths.toObject(), options)
42
45
 
43
- const message = deletedPaths && deletedPaths.length
44
- ? `the following files ${options.dryRun ? 'will be' : 'have been'} deleted:`
45
- : 'no files to delete'
46
+ if (!deletedPaths || !deletedPaths.length) {
47
+ this.logger.info('No files to delete')
48
+ return
49
+ }
46
50
 
47
- console.debug(`[CLI] ${message}\n${deletedPaths.join('\n')}`)
51
+ const verb = options.dryRun ? 'Will delete' : 'Deleted'
52
+ const listing = deletedPaths.map((p) => ` ${p}`).join('\n')
53
+ this.logger.info(`${verb} ${deletedPaths.length} file(s):\n${listing}`)
48
54
  }
49
55
 
50
- preAction(command) {
51
- testcwd(command)
56
+ preAction(thisCommand, actionCommand) {
57
+ testcwd(thisCommand)
52
58
  }
53
59
  }
@@ -0,0 +1,108 @@
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() === 'clean')
15
+ })
16
+
17
+ test('command is registered in CLI program', (t) => {
18
+ const { command } = t.context
19
+
20
+ t.truthy(command, 'command "clean" 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(), 'clean')
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, 'clean 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 dryRunOption = command.options.find((opt) => opt.long === '--dry-run')
44
+ const dryrunAlias = command.options.find((opt) => opt.long === '--dryrun')
45
+ const progressOption = command.options.find((opt) => opt.long === '--progress')
46
+ const quietOption = command.options.find((opt) => opt.long === '--quiet')
47
+ const verboseOption = command.options.find((opt) => opt.long === '--verbose')
48
+ const debugOption = command.options.find((opt) => opt.long === '--debug')
49
+
50
+ // Verify all options exist
51
+ t.truthy(dryRunOption, '--dry-run option should exist')
52
+ t.truthy(dryrunAlias, '--dryrun alias should exist')
53
+ t.truthy(progressOption, '--progress option should exist')
54
+ t.truthy(quietOption, '--quiet option should exist')
55
+ t.truthy(verboseOption, '--verbose option should exist')
56
+ t.truthy(debugOption, '--debug option should exist')
57
+
58
+ // Verify they are Option instances
59
+ t.true(dryRunOption instanceof Option, '--dry-run should be Option instance')
60
+ t.true(dryrunAlias instanceof Option, '--dryrun should be Option instance')
61
+ t.true(progressOption instanceof Option, '--progress should be Option instance')
62
+ t.true(quietOption instanceof Option, '--quiet should be Option instance')
63
+ t.true(verboseOption instanceof Option, '--verbose should be Option instance')
64
+ t.true(debugOption instanceof Option, '--debug should be Option instance')
65
+
66
+ // Verify option properties
67
+ t.is(dryRunOption.long, '--dry-run')
68
+ t.is(dryRunOption.short, '-d')
69
+ t.truthy(dryRunOption.description)
70
+ t.false(dryRunOption.required, '--dry-run should not require a value')
71
+
72
+ // --dryrun is a hidden alias for --dry-run
73
+ t.is(dryrunAlias.long, '--dryrun')
74
+ t.true(dryrunAlias.hidden, '--dryrun should be hidden from help')
75
+
76
+ // --progress is a hidden alias for --verbose
77
+ t.is(progressOption.long, '--progress')
78
+ t.truthy(progressOption.description)
79
+ t.true(progressOption.hidden, '--progress should be hidden from help')
80
+
81
+ t.is(quietOption.long, '--quiet')
82
+ t.is(quietOption.short, '-q')
83
+ t.truthy(quietOption.description)
84
+ t.false(quietOption.required, '--quiet should not require a value')
85
+
86
+ t.is(verboseOption.long, '--verbose')
87
+ t.is(verboseOption.short, '-v')
88
+ t.truthy(verboseOption.description)
89
+ t.false(verboseOption.required, '--verbose should not require a value')
90
+
91
+ t.is(debugOption.long, '--debug')
92
+ t.truthy(debugOption.description)
93
+ t.false(debugOption.required, '--debug should not require a value')
94
+ })
95
+
96
+ test('command options are accessible via public API', (t) => {
97
+ const { command } = t.context
98
+
99
+ // Test that options can be accessed the way Commander.js does
100
+ const optionNames = command.options.map((opt) => opt.long)
101
+
102
+ t.true(optionNames.includes('--dry-run'))
103
+ t.true(optionNames.includes('--dryrun'))
104
+ t.true(optionNames.includes('--progress'))
105
+ t.true(optionNames.includes('--quiet'))
106
+ t.true(optionNames.includes('--verbose'))
107
+ t.true(optionNames.includes('--debug'))
108
+ })