@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,250 +0,0 @@
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': '# Welcome',
18
- '/project/package.json': JSON.stringify({ name: 'test-project' })
19
- })
20
-
21
- t.context.projectRoot = '/project'
22
-
23
- // Stub console methods to suppress output during tests
24
- // Create mock logger (no global console stubbing needed!)
25
- t.context.mockLogger = {
26
- info: t.context.sandbox.stub(),
27
- error: t.context.sandbox.stub(),
28
- debug: t.context.sandbox.stub(),
29
- log: t.context.sandbox.stub(),
30
- warn: t.context.sandbox.stub()
31
- }
32
- })
33
-
34
- test.afterEach.always((t) => {
35
- // Restore all mocks
36
- t.context.sandbox.restore()
37
-
38
- // Clear in-memory file system
39
- t.context.vol.reset()
40
- })
41
-
42
- test('preview command should call eleventy CLI serve with default options', async (t) => {
43
- const { sandbox, fs, mockLogger } = t.context
44
-
45
- // Mock eleventy CLI module
46
- const mockEleventyCli = {
47
- serve: sandbox.stub().resolves({ exitCode: 0 })
48
- }
49
-
50
- // Mock eleventy API module
51
- const mockEleventyApi = {
52
- serve: sandbox.stub().resolves()
53
- }
54
-
55
- // Mock testcwd helper
56
- const mockTestcwd = sandbox.stub()
57
-
58
- // Use esmock to replace imports
59
- const PreviewCommand = await esmock('./preview.js', {
60
- '#lib/11ty/index.js': {
61
- api: mockEleventyApi,
62
- cli: mockEleventyCli
63
- },
64
- '#helpers/test-cwd.js': {
65
- default: mockTestcwd
66
- },
67
- '#lib/logger/index.js': {
68
- logger: mockLogger
69
- },
70
- 'fs-extra': fs
71
- })
72
-
73
- const command = new PreviewCommand()
74
- command.name = sandbox.stub().returns('preview')
75
-
76
- // Run preAction
77
- command.preAction(command)
78
-
79
- // Run action with default options (uses cli by default)
80
- await command.action({ '11ty': 'cli', port: 8080 }, command)
81
-
82
- t.true(mockTestcwd.called, 'testcwd should be called in preAction')
83
- t.true(mockEleventyCli.serve.called, 'eleventy CLI serve should be called')
84
- t.false(mockEleventyApi.serve.called, 'eleventy API serve should not be called')
85
- })
86
-
87
- test('preview command should call eleventy API when 11ty option is "api"', async (t) => {
88
- const { sandbox, fs, mockLogger } = t.context
89
-
90
- // Mock eleventy CLI module
91
- const mockEleventyCli = {
92
- serve: sandbox.stub().resolves({ exitCode: 0 })
93
- }
94
-
95
- // Mock eleventy API module
96
- const mockEleventyApi = {
97
- serve: sandbox.stub().resolves()
98
- }
99
-
100
- // Mock testcwd helper
101
- const mockTestcwd = sandbox.stub()
102
-
103
- // Use esmock to replace imports
104
- const PreviewCommand = await esmock('./preview.js', {
105
- '#lib/11ty/index.js': {
106
- api: mockEleventyApi,
107
- cli: mockEleventyCli
108
- },
109
- '#helpers/test-cwd.js': {
110
- default: mockTestcwd
111
- },
112
- '#lib/logger/index.js': {
113
- logger: mockLogger
114
- },
115
- 'fs-extra': fs
116
- })
117
-
118
- const command = new PreviewCommand()
119
- command.name = sandbox.stub().returns('preview')
120
-
121
- // Run action with api option
122
- await command.action({ '11ty': 'api', port: 8080 }, command)
123
-
124
- t.false(mockEleventyCli.serve.called, 'eleventy CLI serve should not be called')
125
- t.true(mockEleventyApi.serve.called, 'eleventy API serve should be called')
126
- })
127
-
128
- test('preview command should pass port option to eleventy serve', async (t) => {
129
- const { sandbox, fs, mockLogger } = t.context
130
-
131
- // Mock eleventy CLI module
132
- const mockEleventyCli = {
133
- serve: sandbox.stub().resolves({ exitCode: 0 })
134
- }
135
-
136
- // Mock eleventy API module
137
- const mockEleventyApi = {
138
- serve: sandbox.stub().resolves()
139
- }
140
-
141
- // Mock testcwd helper
142
- const mockTestcwd = sandbox.stub()
143
-
144
- // Use esmock to replace imports
145
- const PreviewCommand = await esmock('./preview.js', {
146
- '#lib/11ty/index.js': {
147
- api: mockEleventyApi,
148
- cli: mockEleventyCli
149
- },
150
- '#helpers/test-cwd.js': {
151
- default: mockTestcwd
152
- },
153
- '#lib/logger/index.js': {
154
- logger: mockLogger
155
- },
156
- 'fs-extra': fs
157
- })
158
-
159
- const command = new PreviewCommand()
160
- command.name = sandbox.stub().returns('preview')
161
-
162
- const options = { '11ty': 'cli', port: 3000 }
163
-
164
- // Run action with custom port
165
- await command.action(options, command)
166
-
167
- t.true(mockEleventyCli.serve.calledWith(options), 'eleventy CLI serve should be called with port option')
168
- })
169
-
170
- test('preview command should pass quiet and verbose options', async (t) => {
171
- const { sandbox, fs, mockLogger } = t.context
172
-
173
- // Mock eleventy CLI module
174
- const mockEleventyCli = {
175
- serve: sandbox.stub().resolves({ exitCode: 0 })
176
- }
177
-
178
- // Mock eleventy API module
179
- const mockEleventyApi = {
180
- serve: sandbox.stub().resolves()
181
- }
182
-
183
- // Mock testcwd helper
184
- const mockTestcwd = sandbox.stub()
185
-
186
- // Use esmock to replace imports
187
- const PreviewCommand = await esmock('./preview.js', {
188
- '#lib/11ty/index.js': {
189
- api: mockEleventyApi,
190
- cli: mockEleventyCli
191
- },
192
- '#helpers/test-cwd.js': {
193
- default: mockTestcwd
194
- },
195
- '#lib/logger/index.js': {
196
- logger: mockLogger
197
- },
198
- 'fs-extra': fs
199
- })
200
-
201
- const command = new PreviewCommand()
202
- command.name = sandbox.stub().returns('preview')
203
-
204
- const options = { '11ty': 'cli', quiet: true, verbose: false, port: 8080 }
205
-
206
- // Run action with quiet and verbose options
207
- await command.action(options, command)
208
-
209
- t.true(mockEleventyCli.serve.calledWith(options), 'eleventy CLI serve should be called with all options')
210
- })
211
-
212
- test('preview command should call testcwd in preAction', async (t) => {
213
- const { sandbox, fs, mockLogger } = t.context
214
-
215
- // Mock eleventy modules
216
- const mockEleventyCli = {
217
- serve: sandbox.stub().resolves({ exitCode: 0 })
218
- }
219
-
220
- const mockEleventyApi = {
221
- serve: sandbox.stub().resolves()
222
- }
223
-
224
- // Mock testcwd helper
225
- const mockTestcwd = sandbox.stub()
226
-
227
- // Use esmock to replace imports
228
- const PreviewCommand = await esmock('./preview.js', {
229
- '#lib/11ty/index.js': {
230
- api: mockEleventyApi,
231
- cli: mockEleventyCli
232
- },
233
- '#helpers/test-cwd.js': {
234
- default: mockTestcwd
235
- },
236
- '#lib/logger/index.js': {
237
- logger: mockLogger
238
- },
239
- 'fs-extra': fs
240
- })
241
-
242
- const command = new PreviewCommand()
243
- command.name = sandbox.stub().returns('preview')
244
-
245
- // Run preAction
246
- command.preAction(command)
247
-
248
- t.true(mockTestcwd.called, 'testcwd should be called in preAction')
249
- t.true(mockTestcwd.calledWith(command), 'testcwd should be called with command object')
250
- })
@@ -1,56 +0,0 @@
1
- import Command from '#src/Command.js'
2
- import { setVersion } from '#lib/project/index.js'
3
- import { latest } from '#lib/installer/index.js'
4
- import testcwd from '#helpers/test-cwd.js'
5
-
6
- /**
7
- * Quire CLI `use` Command
8
- *
9
- * Running `quire use` sets the `quire-11ty` version for a project.
10
- * The version is written to a `.quire` file in the project directory.
11
- *
12
- * @class UseCommand
13
- * @extends {Command}
14
- */
15
- export default class UseCommand extends Command {
16
- static definition = {
17
- name: 'use',
18
- aliases: ['version'],
19
- hidden: true, // hide command (incomplete functionality; possible Quire v2)
20
- description: 'Sets the Quire version to use when running commands on the project.',
21
- summary: 'set project quire-11ty version',
22
- docsLink: 'quire-commands/',
23
- version: '1.0.0',
24
- args: [
25
- [ '<version>', 'quire-11ty version to use' ],
26
- ],
27
- options: [
28
- // [ '-g', '--global', 'set the quire version globally' ],
29
- ],
30
- }
31
-
32
- constructor() {
33
- super(UseCommand.definition)
34
- }
35
-
36
- /**
37
- * Set the quire-11ty version for the current project
38
- *
39
- * Validates the version against npm registry before setting.
40
- * Supports exact versions, semver ranges, and 'latest'.
41
- *
42
- * @param {string} version - The quire-11ty version to use
43
- * @param {Object} options - Command options
44
- */
45
- async action(version, options = {}) {
46
- this.debug('called with options %O', options)
47
-
48
- // Validate and resolve the version against npm registry
49
- const resolvedVersion = await latest(version)
50
- setVersion(resolvedVersion)
51
- }
52
-
53
- preAction(thisCommand, actionCommand) {
54
- testcwd(thisCommand)
55
- }
56
- }
@@ -1,61 +0,0 @@
1
- import { Argument, 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() === 'use')
15
- })
16
-
17
- test('command is registered in CLI program', (t) => {
18
- const { command } = t.context
19
-
20
- t.truthy(command, 'command "use" 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(), 'use')
28
- t.truthy(command.description())
29
- t.is(typeof command._actionHandler, 'function', 'command should have action handler')
30
- })
31
-
32
- test('registered command has correct arguments', (t) => {
33
- const { command } = t.context
34
- const registeredArguments = command.registeredArguments
35
-
36
- t.is(registeredArguments.length, 1, 'command should have 1 argument')
37
-
38
- // First argument: version
39
- const version = registeredArguments[0]
40
- t.true(version instanceof Argument, 'version should be Argument instance')
41
- t.is(version.name(), 'version', 'first argument should be version')
42
- t.true(version.required, 'version should be required')
43
- t.truthy(version.description)
44
- })
45
-
46
- test('registered command has no options', (t) => {
47
- const { command } = t.context
48
-
49
- // Use command should have no custom options (only inherited help options)
50
- const options = command.options.filter((opt) => !opt.long.includes('help'))
51
- t.is(options.length, 0, 'use command should have no custom options')
52
- })
53
-
54
- test('command arguments are accessible via public API', (t) => {
55
- const { command } = t.context
56
-
57
- // Test that arguments can be accessed the way Commander.js does
58
- const argumentNames = command.registeredArguments.map((arg) => arg.name())
59
-
60
- t.true(argumentNames.includes('version'))
61
- })
@@ -1,280 +0,0 @@
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 Quire project directory structure
15
- t.context.vol.fromJSON({
16
- '/project/.quire': '',
17
- '/project/content/_data/config.yaml': 'title: Test Project',
18
- '/project/package.json': JSON.stringify({ name: 'test-project' })
19
- })
20
-
21
- t.context.projectRoot = '/project'
22
-
23
- // Create mock logger
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
- // Mock testcwd helper (returns true for Quire projects)
33
- t.context.mockTestcwd = t.context.sandbox.stub()
34
- })
35
-
36
- test.afterEach.always((t) => {
37
- // Restore all mocks
38
- t.context.sandbox.restore()
39
-
40
- // Clear in-memory file system
41
- t.context.vol.reset()
42
- })
43
-
44
- test('use command should validate Quire project in preAction', async (t) => {
45
- const { sandbox, mockLogger, mockTestcwd } = t.context
46
-
47
- const { default: UseCommand } = await esmock('./use.js', {
48
- '#helpers/test-cwd.js': {
49
- default: mockTestcwd
50
- }
51
- }, {
52
- '#lib/logger/index.js': {
53
- default: () => mockLogger
54
- }
55
- })
56
-
57
- const command = new UseCommand()
58
- command.logger = mockLogger
59
- command.debug = sandbox.stub()
60
-
61
- // Mock Commander.js command object
62
- const mockCommand = {
63
- name: () => 'use',
64
- opts: () => ({})
65
- }
66
-
67
- // Call preAction
68
- command.preAction(mockCommand)
69
-
70
- t.true(mockTestcwd.called, 'testcwd should be called in preAction')
71
- t.true(mockTestcwd.calledWith(mockCommand), 'testcwd should be called with command')
72
- })
73
-
74
- test('use command should accept version argument', async (t) => {
75
- const { sandbox, mockLogger, mockTestcwd } = t.context
76
-
77
- const mockLatest = sandbox.stub().resolves('1.0.0-rc.33')
78
- const mockSetVersion = sandbox.stub()
79
-
80
- const { default: UseCommand } = await esmock('./use.js', {
81
- '#helpers/test-cwd.js': {
82
- default: mockTestcwd
83
- },
84
- '#lib/installer/index.js': {
85
- latest: mockLatest
86
- },
87
- '#lib/project/index.js': {
88
- setVersion: mockSetVersion
89
- }
90
- }, {
91
- '#lib/logger/index.js': {
92
- default: () => mockLogger
93
- }
94
- })
95
-
96
- const command = new UseCommand()
97
- command.logger = mockLogger
98
- command.debug = sandbox.stub()
99
-
100
- // Call action with version argument
101
- await command.action('1.0.0-rc.33', {})
102
-
103
- t.true(mockLatest.calledWith('1.0.0-rc.33'), 'latest should be called with version')
104
- t.true(mockSetVersion.calledWith('1.0.0-rc.33'), 'setVersion should be called with resolved version')
105
- })
106
-
107
- test('use command should log debug information when debug flag is set', async (t) => {
108
- const { sandbox, mockLogger, mockTestcwd } = t.context
109
-
110
- const mockDebug = sandbox.stub()
111
- const mockLatest = sandbox.stub().resolves('1.0.0-rc.33')
112
- const mockSetVersion = sandbox.stub()
113
-
114
- const { default: UseCommand } = await esmock('./use.js', {
115
- '#helpers/test-cwd.js': {
116
- default: mockTestcwd
117
- },
118
- '#lib/installer/index.js': {
119
- latest: mockLatest
120
- },
121
- '#lib/project/index.js': {
122
- setVersion: mockSetVersion
123
- }
124
- }, {
125
- '#lib/logger/index.js': {
126
- default: () => mockLogger
127
- }
128
- })
129
-
130
- const command = new UseCommand()
131
- command.logger = mockLogger
132
- command.debug = mockDebug
133
-
134
- // Call action with debug flag
135
- await command.action('1.0.0-rc.33', { debug: true })
136
-
137
- // Verify debug was called
138
- t.true(mockDebug.called, 'debug should be called with debug flag')
139
- t.true(mockDebug.calledWith('called with options %O', { debug: true }))
140
- })
141
-
142
- test('use command should handle semver version strings', async (t) => {
143
- const { sandbox, mockLogger, mockTestcwd } = t.context
144
-
145
- // Mock the installer's latest function to return the version
146
- const mockLatest = sandbox.stub().callsFake(async (version) => version)
147
- const mockSetVersion = sandbox.stub()
148
-
149
- const { default: UseCommand } = await esmock('./use.js', {
150
- '#helpers/test-cwd.js': {
151
- default: mockTestcwd
152
- },
153
- '#lib/installer/index.js': {
154
- latest: mockLatest
155
- },
156
- '#lib/project/index.js': {
157
- setVersion: mockSetVersion
158
- }
159
- }, {
160
- '#lib/logger/index.js': {
161
- default: () => mockLogger
162
- }
163
- })
164
-
165
- const command = new UseCommand()
166
- command.logger = mockLogger
167
- command.debug = sandbox.stub()
168
-
169
- // Test various semver formats
170
- const validVersions = [
171
- '1.0.0',
172
- '1.0.0-rc.1',
173
- '1.0.0-beta.2',
174
- '2.1.3',
175
- '0.0.1'
176
- ]
177
-
178
- for (const version of validVersions) {
179
- await command.action(version, {})
180
- t.pass(`should accept valid semver: ${version}`)
181
- }
182
-
183
- t.is(mockLatest.callCount, validVersions.length, 'latest should be called for each version')
184
- t.is(mockSetVersion.callCount, validVersions.length, 'setVersion should be called for each version')
185
- })
186
-
187
- test('use command should work with options object', async (t) => {
188
- const { sandbox, mockLogger, mockTestcwd } = t.context
189
-
190
- // Mock the installer's latest function to return the version
191
- const mockLatest = sandbox.stub().callsFake(async (version) => version)
192
- const mockSetVersion = sandbox.stub()
193
-
194
- const { default: UseCommand } = await esmock('./use.js', {
195
- '#helpers/test-cwd.js': {
196
- default: mockTestcwd
197
- },
198
- '#lib/installer/index.js': {
199
- latest: mockLatest
200
- },
201
- '#lib/project/index.js': {
202
- setVersion: mockSetVersion
203
- }
204
- }, {
205
- '#lib/logger/index.js': {
206
- default: () => mockLogger
207
- }
208
- })
209
-
210
- const command = new UseCommand()
211
- command.logger = mockLogger
212
- command.debug = sandbox.stub()
213
-
214
- // Test with various options
215
- await command.action('1.0.0', { debug: false })
216
- await command.action('1.0.0', { debug: true })
217
- await command.action('1.0.0', {})
218
-
219
- t.is(mockLatest.callCount, 3, 'latest should be called for each action')
220
- t.is(mockSetVersion.callCount, 3, 'setVersion should be called for each action')
221
- t.pass('command should handle various option combinations')
222
- })
223
-
224
- test('use command preAction should be called before action', async (t) => {
225
- const { sandbox, mockLogger, mockTestcwd } = t.context
226
-
227
- const { default: UseCommand } = await esmock('./use.js', {
228
- '#helpers/test-cwd.js': {
229
- default: mockTestcwd
230
- }
231
- }, {
232
- '#lib/logger/index.js': {
233
- default: () => mockLogger
234
- }
235
- })
236
-
237
- const command = new UseCommand()
238
- command.logger = mockLogger
239
- command.debug = sandbox.stub()
240
-
241
- // Mock Commander.js command object
242
- const mockCommand = {
243
- name: () => 'use',
244
- opts: () => ({})
245
- }
246
-
247
- // Verify preAction exists and can be called
248
- t.is(typeof command.preAction, 'function', 'preAction should be a function')
249
-
250
- // Call preAction (would be called by Commander.js before action)
251
- command.preAction(mockCommand)
252
-
253
- // Verify testcwd was called
254
- t.true(mockTestcwd.called, 'testcwd should validate project directory')
255
- })
256
-
257
- test('use command should have correct command definition', async (t) => {
258
- const { sandbox, mockLogger, mockTestcwd } = t.context
259
-
260
- const { default: UseCommand } = await esmock('./use.js', {
261
- '#helpers/test-cwd.js': {
262
- default: mockTestcwd
263
- }
264
- }, {
265
- '#lib/logger/index.js': {
266
- default: () => mockLogger
267
- }
268
- })
269
-
270
- const command = new UseCommand()
271
- command.logger = mockLogger
272
- command.debug = sandbox.stub()
273
-
274
- t.is(command.name, 'use', 'command name should be "use"')
275
- t.truthy(command.description, 'command should have description')
276
- t.truthy(command.summary, 'command should have summary')
277
- t.truthy(command.version, 'command should have version')
278
- t.true(Array.isArray(command.args), 'command should have args array')
279
- t.is(command.args.length, 1, 'command should have 1 argument')
280
- })