@thegetty/quire-cli 1.0.0-rc.34 → 1.0.0-rc.36
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.
- package/CHANGELOG.md +36 -0
- package/README.md +9 -0
- package/bin/cli.js +19 -1
- package/package.json +21 -8
- package/schemas/config.schema.json +194 -0
- package/schemas/figures.schema.json +56 -0
- package/schemas/layout.schema.json +5 -0
- package/schemas/objects.schema.json +62 -0
- package/schemas/publication.schema.json +140 -0
- package/schemas/references.schema.json +29 -0
- package/src/Command.js +26 -6
- package/src/Command.spec.js +99 -0
- package/src/commands/README.md +213 -122
- package/src/commands/build.js +46 -37
- package/src/commands/build.spec.js +113 -0
- package/src/commands/build.test.js +402 -0
- package/src/commands/clean.js +25 -19
- package/src/commands/clean.spec.js +108 -0
- package/src/commands/clean.test.js +260 -0
- package/src/commands/config.js +251 -0
- package/src/commands/config.spec.js +107 -0
- package/src/commands/config.test.js +715 -0
- package/src/commands/create.js +42 -14
- package/src/commands/create.spec.js +112 -0
- package/src/commands/create.test.js +415 -0
- package/src/commands/epub.js +59 -30
- package/src/commands/epub.spec.js +114 -0
- package/src/commands/epub.test.js +503 -0
- package/src/commands/index.js +9 -2
- package/src/commands/info.js +18 -24
- package/src/commands/info.spec.js +64 -0
- package/src/commands/info.test.js +415 -0
- package/src/commands/pdf.js +58 -84
- package/src/commands/pdf.spec.js +114 -0
- package/src/commands/pdf.test.js +464 -0
- package/src/commands/preview.js +26 -31
- package/src/commands/preview.spec.js +97 -0
- package/src/commands/preview.test.js +250 -0
- package/src/commands/use.js +56 -0
- package/src/commands/use.spec.js +61 -0
- package/src/commands/use.test.js +280 -0
- package/src/commands/validate.js +31 -19
- package/src/commands/validate.spec.js +82 -0
- package/src/commands/validate.test.js +234 -0
- package/src/commands/workflows.js +70 -0
- package/src/errors/build/build-failed-error.js +19 -0
- package/src/errors/build/config-field-missing-error.js +20 -0
- package/src/errors/build/config-file-not-found-error.js +20 -0
- package/src/errors/build/index.js +11 -0
- package/src/errors/index.js +48 -0
- package/src/errors/install/dependency-install-error.js +19 -0
- package/src/errors/install/directory-not-empty-error.js +25 -0
- package/src/errors/install/index.js +12 -0
- package/src/errors/install/invalid-path-error.js +31 -0
- package/src/errors/install/invalid-starter-error.js +27 -0
- package/src/errors/install/version-not-found-error.js +35 -0
- package/src/errors/output/epub-generation-error.js +19 -0
- package/src/errors/output/index.js +14 -0
- package/src/errors/output/invalid-epub-library-error.js +20 -0
- package/src/errors/output/invalid-pdf-library-error.js +20 -0
- package/src/errors/output/missing-build-output-error.js +21 -0
- package/src/errors/output/pdf-generation-error.js +24 -0
- package/src/errors/output/tool-not-found-error.js +37 -0
- package/src/errors/project/index.js +10 -0
- package/src/errors/project/not-in-project-error.js +20 -0
- package/src/errors/project/project-create-error.js +21 -0
- package/src/errors/quire-error.js +27 -0
- package/src/errors/validation/validation-error.js +20 -11
- package/src/helpers/clean.js +1 -1
- package/src/helpers/docs-url.js +32 -0
- package/src/helpers/test-cwd.js +5 -6
- package/src/helpers/test-cwd.test.js +192 -0
- package/src/helpers/which.js +10 -4
- package/src/lib/11ty/README.md +135 -19
- package/src/lib/11ty/api.js +176 -93
- package/src/lib/11ty/cli.js +77 -35
- package/src/lib/11ty/index.js +64 -5
- package/src/lib/11ty/index.test.js +655 -0
- package/src/lib/README.md +275 -0
- package/src/lib/commander/index.js +100 -0
- package/src/lib/commander/index.test.js +86 -0
- package/src/lib/commander/options.js +195 -0
- package/src/lib/commander/options.test.js +109 -0
- package/src/lib/conf/README.md +84 -73
- package/src/lib/conf/config.js +5 -3
- package/src/lib/conf/config.test.js +281 -0
- package/src/lib/conf/defaults.js +44 -0
- package/src/lib/conf/format.js +60 -0
- package/src/lib/conf/format.test.js +106 -0
- package/src/lib/conf/helpers.js +91 -0
- package/src/lib/conf/helpers.test.js +136 -0
- package/src/lib/conf/index.js +22 -0
- package/src/lib/conf/schema.js +53 -8
- package/src/lib/epub/README.md +133 -2
- package/src/lib/epub/engines.js +46 -0
- package/src/lib/epub/epub.js +36 -11
- package/src/lib/epub/index.js +111 -21
- package/src/lib/epub/index.test.js +518 -0
- package/src/lib/epub/pandoc.js +33 -4
- package/src/lib/epub/pandoc.test.js +122 -0
- package/src/lib/epub/schema.js +21 -0
- package/src/lib/error/README.md +170 -0
- package/src/lib/error/handler.js +107 -0
- package/src/lib/git/README.md +151 -2
- package/src/lib/git/index.js +217 -13
- package/src/lib/git/index.spec.js +80 -0
- package/src/lib/git/index.test.js +453 -0
- package/src/lib/installer/index.js +309 -0
- package/src/lib/installer/index.spec.js +83 -0
- package/src/lib/installer/index.test.js +545 -0
- package/src/lib/logger/README.md +424 -0
- package/src/lib/logger/debug.js +90 -0
- package/src/lib/logger/debug.spec.js +130 -0
- package/src/lib/logger/index.js +228 -0
- package/src/lib/logger/index.spec.js +131 -0
- package/src/lib/logger/index.test.js +477 -0
- package/src/lib/npm/README.md +127 -0
- package/src/lib/npm/index.js +198 -0
- package/src/lib/npm/index.spec.js +60 -0
- package/src/lib/npm/index.test.js +355 -0
- package/src/lib/pdf/README.md +131 -0
- package/src/lib/pdf/engines.js +46 -0
- package/src/lib/pdf/index.js +124 -21
- package/src/lib/pdf/index.test.js +708 -0
- package/src/lib/pdf/paged.js +100 -52
- package/src/lib/pdf/paged.test.js +366 -0
- package/src/lib/pdf/prince.js +115 -37
- package/src/lib/pdf/prince.test.js +202 -0
- package/src/lib/pdf/schema.js +21 -0
- package/src/lib/pdf/split.js +61 -33
- package/src/lib/pdf/split.test.js +445 -0
- package/src/lib/process/manager.js +110 -0
- package/src/lib/process/manager.test.js +55 -0
- package/src/lib/project/build.js +143 -0
- package/src/lib/project/build.test.js +253 -0
- package/src/lib/project/config.js +48 -0
- package/src/lib/project/config.test.js +134 -0
- package/src/{helpers/is-quire.js → lib/project/detect.js} +5 -3
- package/src/lib/project/detect.test.js +157 -0
- package/src/lib/project/index.js +40 -0
- package/src/lib/project/paths.js +224 -0
- package/src/lib/project/version.js +110 -0
- package/src/lib/project/version.test.js +350 -0
- package/src/lib/reporter/README.md +211 -2
- package/src/lib/reporter/index.js +512 -0
- package/src/lib/reporter/index.test.js +593 -0
- package/src/main.js +134 -47
- package/src/main.spec.js +61 -0
- package/src/main.test.js +347 -0
- package/src/validators/utils.js +2 -1
- package/src/commands/conf.js +0 -43
- package/src/commands/version.js +0 -43
- package/src/lib/11ty/paths.js +0 -103
- package/src/lib/i18n/README.md +0 -3
- package/src/lib/i18n/config.js +0 -53
- package/src/lib/i18n/index.js +0 -43
- package/src/lib/i18n/localeService.js +0 -58
- package/src/lib/quire/README.md +0 -19
- package/src/lib/quire/index.js +0 -350
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,250 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
})
|