@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.
- package/CHANGELOG.md +36 -0
- package/README.md +9 -0
- package/bin/cli.js +19 -1
- package/package.json +21 -8
- package/patches/README.md +19 -0
- package/patches/install-npm-version+1.0.9.patch +12119 -0
- package/schemas/objects.schema.json +12 -38
- package/schemas/publication.schema.json +0 -22
- package/schemas/references.schema.json +0 -1
- 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 +37 -36
- package/src/commands/build.spec.js +113 -0
- package/src/commands/build.test.js +397 -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 +32 -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 +196 -94
- package/src/lib/11ty/cli.js +91 -37
- 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 +132 -0
- package/src/lib/logger/debug.spec.js +130 -0
- package/src/lib/logger/debug.test.js +128 -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,114 @@
|
|
|
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() === 'pdf')
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test('command is registered in CLI program', (t) => {
|
|
18
|
+
const { command } = t.context
|
|
19
|
+
|
|
20
|
+
t.truthy(command, 'command "pdf" 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(), 'pdf')
|
|
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, 'pdf 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 engineOption = command.options.find((opt) => opt.long === '--engine')
|
|
44
|
+
const libOption = command.options.find((opt) => opt.long === '--lib')
|
|
45
|
+
const buildOption = command.options.find((opt) => opt.long === '--build')
|
|
46
|
+
const openOption = command.options.find((opt) => opt.long === '--open')
|
|
47
|
+
const quietOption = command.options.find((opt) => opt.long === '--quiet')
|
|
48
|
+
const verboseOption = command.options.find((opt) => opt.long === '--verbose')
|
|
49
|
+
const debugOption = command.options.find((opt) => opt.long === '--debug')
|
|
50
|
+
|
|
51
|
+
// Verify all options exist
|
|
52
|
+
t.truthy(engineOption, '--engine option should exist')
|
|
53
|
+
t.truthy(libOption, '--lib option should exist (deprecated alias)')
|
|
54
|
+
t.truthy(buildOption, '--build option should exist')
|
|
55
|
+
t.truthy(openOption, '--open option should exist')
|
|
56
|
+
t.truthy(quietOption, '--quiet option should exist')
|
|
57
|
+
t.truthy(verboseOption, '--verbose option should exist')
|
|
58
|
+
t.truthy(debugOption, '--debug option should exist')
|
|
59
|
+
|
|
60
|
+
// Verify they are Option instances
|
|
61
|
+
t.true(engineOption instanceof Option, '--engine should be Option instance')
|
|
62
|
+
t.true(libOption instanceof Option, '--lib should be Option instance')
|
|
63
|
+
t.true(buildOption instanceof Option, '--build should be Option instance')
|
|
64
|
+
t.true(openOption instanceof Option, '--open should be Option instance')
|
|
65
|
+
t.true(quietOption instanceof Option, '--quiet should be Option instance')
|
|
66
|
+
t.true(verboseOption instanceof Option, '--verbose should be Option instance')
|
|
67
|
+
t.true(debugOption instanceof Option, '--debug should be Option instance')
|
|
68
|
+
|
|
69
|
+
// Verify --engine option properties
|
|
70
|
+
t.is(engineOption.long, '--engine')
|
|
71
|
+
t.truthy(engineOption.description)
|
|
72
|
+
t.true(engineOption.required, '--engine should require a value')
|
|
73
|
+
|
|
74
|
+
// Verify --lib is hidden (deprecated alias)
|
|
75
|
+
t.is(libOption.long, '--lib')
|
|
76
|
+
t.true(libOption.hidden, '--lib should be hidden (deprecated)')
|
|
77
|
+
|
|
78
|
+
t.is(buildOption.long, '--build')
|
|
79
|
+
t.truthy(buildOption.description)
|
|
80
|
+
t.false(buildOption.required, '--build should not require a value')
|
|
81
|
+
|
|
82
|
+
t.is(openOption.long, '--open')
|
|
83
|
+
t.truthy(openOption.description)
|
|
84
|
+
t.false(openOption.required, '--open should not require a value')
|
|
85
|
+
|
|
86
|
+
t.is(quietOption.long, '--quiet')
|
|
87
|
+
t.is(quietOption.short, '-q', '--quiet should have -q short flag')
|
|
88
|
+
t.truthy(quietOption.description)
|
|
89
|
+
t.false(quietOption.required, '--quiet should not require a value')
|
|
90
|
+
|
|
91
|
+
t.is(verboseOption.long, '--verbose')
|
|
92
|
+
t.is(verboseOption.short, '-v', '--verbose should have -v short flag')
|
|
93
|
+
t.truthy(verboseOption.description)
|
|
94
|
+
t.false(verboseOption.required, '--verbose should not require a value')
|
|
95
|
+
|
|
96
|
+
t.is(debugOption.long, '--debug')
|
|
97
|
+
t.truthy(debugOption.description)
|
|
98
|
+
t.false(debugOption.required, '--debug should not require a value')
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('command options are accessible via public API', (t) => {
|
|
102
|
+
const { command } = t.context
|
|
103
|
+
|
|
104
|
+
// Test that options can be accessed the way Commander.js does
|
|
105
|
+
const optionNames = command.options.map((opt) => opt.long)
|
|
106
|
+
|
|
107
|
+
t.true(optionNames.includes('--engine'))
|
|
108
|
+
t.true(optionNames.includes('--lib')) // deprecated alias still exists
|
|
109
|
+
t.true(optionNames.includes('--build'))
|
|
110
|
+
t.true(optionNames.includes('--open'))
|
|
111
|
+
t.true(optionNames.includes('--quiet'))
|
|
112
|
+
t.true(optionNames.includes('--verbose'))
|
|
113
|
+
t.true(optionNames.includes('--debug'))
|
|
114
|
+
})
|
|
@@ -0,0 +1,464 @@
|
|
|
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
|
+
})
|
package/src/commands/preview.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import Command from '#src/Command.js'
|
|
2
|
-
import {
|
|
2
|
+
import { Option } from 'commander'
|
|
3
|
+
import { withOutputModes } from '#lib/commander/index.js'
|
|
4
|
+
import { api, cli } from '#lib/11ty/index.js'
|
|
5
|
+
import reporter from '#lib/reporter/index.js'
|
|
3
6
|
import testcwd from '#helpers/test-cwd.js'
|
|
4
7
|
|
|
5
8
|
/**
|
|
@@ -11,50 +14,48 @@ import testcwd from '#helpers/test-cwd.js'
|
|
|
11
14
|
* @extends {Command}
|
|
12
15
|
*/
|
|
13
16
|
export default class PreviewCommand extends Command {
|
|
14
|
-
static definition = {
|
|
17
|
+
static definition = withOutputModes({
|
|
15
18
|
name: 'preview',
|
|
16
19
|
description: 'Run the development server and watch on file changes',
|
|
17
|
-
summary: '
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
summary: 'start local preview server',
|
|
21
|
+
docsLink: 'quire-commands/#start-and-preview-projects',
|
|
22
|
+
helpText: `
|
|
23
|
+
Examples:
|
|
24
|
+
quire preview Start preview server on default port
|
|
25
|
+
quire preview --port 3000 Run on custom port
|
|
26
|
+
quire preview --open Start server and open in browser
|
|
27
|
+
quire preview --verbose Start with detailed progress
|
|
28
|
+
`,
|
|
29
|
+
version: '1.1.0',
|
|
27
30
|
options: [
|
|
28
|
-
[ '-p
|
|
29
|
-
[ '
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
'
|
|
33
|
-
// { choices: ['api', 'cli'], default: 'cli' }
|
|
34
|
-
],
|
|
35
|
-
[ '--debug', 'run preview with debug output to console' ],
|
|
31
|
+
[ '-p, --port <port>', 'configure development server port', 8080 ],
|
|
32
|
+
[ '--open', 'open in default browser when server starts' ],
|
|
33
|
+
// Use Option object syntax to configure this as a hidden option
|
|
34
|
+
new Option('--11ty <module>', 'use the specified 11ty module')
|
|
35
|
+
.choices(['api', 'cli']).default('api').hideHelp(),
|
|
36
36
|
],
|
|
37
|
-
}
|
|
37
|
+
})
|
|
38
38
|
|
|
39
39
|
constructor() {
|
|
40
40
|
super(PreviewCommand.definition)
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
async action(options, command) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
this.debug('called with options %O', options)
|
|
45
|
+
|
|
46
|
+
// Configure reporter for this command
|
|
47
|
+
reporter.configure({ quiet: options.quiet, verbose: options.verbose })
|
|
47
48
|
|
|
48
|
-
if (options['11ty'] === '
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if (options['11ty'] === 'api') {
|
|
50
|
+
this.debug('running eleventy using lib/11ty api')
|
|
51
|
+
await api.serve(options)
|
|
51
52
|
} else {
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
this.debug('running eleventy using lib/11ty cli')
|
|
54
|
+
await cli.serve(options)
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
preAction(
|
|
58
|
-
testcwd(
|
|
58
|
+
preAction(thisCommand, actionCommand) {
|
|
59
|
+
testcwd(thisCommand)
|
|
59
60
|
}
|
|
60
61
|
}
|