@thegetty/quire-cli 1.0.0-rc.45 → 1.0.0-rc.47
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 +0 -36
- package/README.md +0 -9
- package/bin/cli.js +1 -46
- package/package.json +10 -27
- package/src/Command.js +6 -26
- package/src/commands/README.md +122 -213
- package/src/commands/build.js +37 -45
- package/src/commands/clean.js +19 -33
- package/src/commands/conf.js +43 -0
- package/src/commands/create.js +14 -42
- package/src/commands/epub.js +31 -67
- package/src/commands/index.js +2 -9
- package/src/commands/info.js +86 -88
- package/src/commands/pdf.js +82 -63
- package/src/commands/preview.js +31 -32
- package/src/commands/validate.js +20 -64
- package/src/commands/version.js +43 -0
- package/src/errors/validation/validation-error.js +11 -20
- package/src/helpers/clean.js +1 -1
- package/src/helpers/is-quire.js +31 -0
- package/src/helpers/test-cwd.js +6 -5
- package/src/helpers/which.js +4 -10
- package/src/lib/11ty/README.md +19 -135
- package/src/lib/11ty/api.js +93 -235
- package/src/lib/11ty/cli.js +37 -112
- package/src/lib/11ty/index.js +5 -64
- package/src/lib/11ty/paths.js +103 -0
- package/src/lib/README.md +0 -330
- package/src/lib/conf/README.md +69 -86
- package/src/lib/conf/config.js +3 -5
- package/src/lib/conf/defaults.js +0 -65
- package/src/lib/conf/schema.js +9 -103
- package/src/lib/epub/README.md +2 -133
- package/src/lib/epub/epub.js +11 -36
- package/src/lib/epub/index.js +21 -111
- package/src/lib/epub/pandoc.js +4 -33
- package/src/lib/git/README.md +2 -151
- package/src/lib/git/index.js +13 -217
- package/src/lib/i18n/README.md +3 -0
- package/src/lib/i18n/config.js +53 -0
- package/src/lib/i18n/index.js +43 -0
- package/src/lib/i18n/localeService.js +58 -0
- package/src/lib/pdf/README.md +0 -131
- package/src/lib/pdf/index.js +21 -124
- package/src/lib/pdf/paged.js +52 -100
- package/src/lib/pdf/prince.js +37 -115
- package/src/lib/pdf/split.js +33 -61
- package/src/lib/quire/README.md +19 -0
- package/src/lib/quire/index.js +353 -0
- package/src/lib/reporter/README.md +2 -211
- package/src/lib/reporter/index.js +0 -607
- package/src/main.js +48 -221
- package/src/packageConfig.js +0 -17
- package/src/validators/utils.js +1 -2
- package/man/quire.1 +0 -341
- package/man/quire.1.md +0 -232
- package/schemas/config.schema.json +0 -194
- package/schemas/figures.schema.json +0 -56
- package/schemas/layout.schema.json +0 -5
- package/schemas/objects.schema.json +0 -62
- package/schemas/publication.schema.json +0 -140
- package/schemas/references.schema.json +0 -29
- package/src/Command.spec.js +0 -99
- package/src/commands/build.spec.js +0 -113
- package/src/commands/build.test.js +0 -397
- package/src/commands/clean.spec.js +0 -118
- package/src/commands/clean.test.js +0 -382
- package/src/commands/config.js +0 -238
- package/src/commands/config.spec.js +0 -107
- package/src/commands/config.test.js +0 -845
- package/src/commands/create.spec.js +0 -112
- package/src/commands/create.test.js +0 -415
- package/src/commands/doctor.js +0 -251
- package/src/commands/doctor.spec.js +0 -115
- package/src/commands/doctor.test.js +0 -1409
- package/src/commands/epub.spec.js +0 -114
- package/src/commands/epub.test.js +0 -503
- package/src/commands/help.js +0 -60
- package/src/commands/help.test.js +0 -132
- package/src/commands/info.spec.js +0 -72
- package/src/commands/info.test.js +0 -512
- package/src/commands/pdf.spec.js +0 -114
- package/src/commands/pdf.test.js +0 -464
- package/src/commands/preview.spec.js +0 -97
- package/src/commands/preview.test.js +0 -250
- package/src/commands/use.js +0 -56
- package/src/commands/use.spec.js +0 -61
- package/src/commands/use.test.js +0 -280
- package/src/commands/validate.spec.js +0 -90
- package/src/commands/validate.test.js +0 -378
- package/src/commands/workflows.js +0 -70
- package/src/errors/build/build-failed-error.js +0 -19
- package/src/errors/build/config-field-missing-error.js +0 -20
- package/src/errors/build/config-file-not-found-error.js +0 -20
- package/src/errors/build/index.js +0 -11
- package/src/errors/help/help-topic-not-found-error.js +0 -30
- package/src/errors/help/index.js +0 -8
- package/src/errors/index.js +0 -58
- package/src/errors/input/index.js +0 -8
- package/src/errors/input/invalid-input-error.js +0 -21
- package/src/errors/install/dependency-install-error.js +0 -19
- package/src/errors/install/directory-not-empty-error.js +0 -25
- package/src/errors/install/index.js +0 -12
- package/src/errors/install/invalid-path-error.js +0 -31
- package/src/errors/install/invalid-starter-error.js +0 -27
- package/src/errors/install/version-not-found-error.js +0 -35
- package/src/errors/output/epub-generation-error.js +0 -19
- package/src/errors/output/index.js +0 -14
- package/src/errors/output/invalid-epub-library-error.js +0 -20
- package/src/errors/output/invalid-pdf-library-error.js +0 -20
- package/src/errors/output/missing-build-output-error.js +0 -21
- package/src/errors/output/pdf-generation-error.js +0 -24
- package/src/errors/output/tool-not-found-error.js +0 -37
- package/src/errors/project/index.js +0 -10
- package/src/errors/project/not-in-project-error.js +0 -20
- package/src/errors/project/project-create-error.js +0 -21
- package/src/errors/quire-error.js +0 -27
- package/src/errors/validation/index.js +0 -3
- package/src/errors/validation/unknown-config-key-error.js +0 -27
- package/src/errors/validation/unknown-config-operation-error.js +0 -24
- package/src/helpers/docs-url.js +0 -32
- package/src/helpers/pager.js +0 -59
- package/src/helpers/pager.test.js +0 -85
- package/src/helpers/suggest-similar.js +0 -124
- package/src/helpers/suggest-similar.test.js +0 -108
- package/src/helpers/test-cwd.test.js +0 -192
- package/src/lib/11ty/index.test.js +0 -655
- package/src/lib/commander/index.js +0 -103
- package/src/lib/commander/index.test.js +0 -86
- package/src/lib/commander/options.js +0 -237
- package/src/lib/commander/options.test.js +0 -205
- package/src/lib/conf/build-status.js +0 -103
- package/src/lib/conf/build-status.test.js +0 -247
- package/src/lib/conf/config.test.js +0 -281
- package/src/lib/conf/format.js +0 -60
- package/src/lib/conf/format.test.js +0 -106
- package/src/lib/conf/helpers.js +0 -91
- package/src/lib/conf/helpers.test.js +0 -136
- package/src/lib/conf/index.js +0 -22
- package/src/lib/constants.js +0 -28
- package/src/lib/doctor/README.md +0 -667
- package/src/lib/doctor/checks/environment/cli-version.js +0 -62
- package/src/lib/doctor/checks/environment/cli-version.test.js +0 -132
- package/src/lib/doctor/checks/environment/git-available.js +0 -77
- package/src/lib/doctor/checks/environment/git-available.test.js +0 -52
- package/src/lib/doctor/checks/environment/index.js +0 -13
- package/src/lib/doctor/checks/environment/node-version.js +0 -66
- package/src/lib/doctor/checks/environment/node-version.test.js +0 -17
- package/src/lib/doctor/checks/environment/npm-available.js +0 -66
- package/src/lib/doctor/checks/environment/npm-available.test.js +0 -52
- package/src/lib/doctor/checks/environment/os-info.js +0 -48
- package/src/lib/doctor/checks/environment/os-info.test.js +0 -81
- package/src/lib/doctor/checks/environment/runtime-info.js +0 -51
- package/src/lib/doctor/checks/environment/runtime-info.test.js +0 -132
- package/src/lib/doctor/checks/outputs/epub-output.js +0 -119
- package/src/lib/doctor/checks/outputs/epub-output.test.js +0 -277
- package/src/lib/doctor/checks/outputs/index.js +0 -10
- package/src/lib/doctor/checks/outputs/pdf-output.js +0 -144
- package/src/lib/doctor/checks/outputs/pdf-output.test.js +0 -377
- package/src/lib/doctor/checks/outputs/stale-build.js +0 -122
- package/src/lib/doctor/checks/outputs/stale-build.test.js +0 -282
- package/src/lib/doctor/checks/project/data-files.js +0 -56
- package/src/lib/doctor/checks/project/data-files.test.js +0 -125
- package/src/lib/doctor/checks/project/dependencies.js +0 -53
- package/src/lib/doctor/checks/project/dependencies.test.js +0 -71
- package/src/lib/doctor/checks/project/index.js +0 -11
- package/src/lib/doctor/checks/project/quire-11ty.js +0 -98
- package/src/lib/doctor/checks/project/quire-11ty.test.js +0 -170
- package/src/lib/doctor/checks/project/quire-project.js +0 -38
- package/src/lib/doctor/checks/project/quire-project.test.js +0 -47
- package/src/lib/doctor/checks/tools/index.js +0 -10
- package/src/lib/doctor/checks/tools/pandoc-available.js +0 -82
- package/src/lib/doctor/checks/tools/pandoc-available.test.js +0 -73
- package/src/lib/doctor/checks/tools/prince-available.js +0 -81
- package/src/lib/doctor/checks/tools/prince-available.test.js +0 -73
- package/src/lib/doctor/constants.js +0 -39
- package/src/lib/doctor/formatDuration.js +0 -108
- package/src/lib/doctor/formatDuration.test.js +0 -76
- package/src/lib/doctor/formatters/human.js +0 -257
- package/src/lib/doctor/formatters/human.test.js +0 -463
- package/src/lib/doctor/formatters/index.js +0 -8
- package/src/lib/doctor/formatters/json.js +0 -78
- package/src/lib/doctor/formatters/json.test.js +0 -174
- package/src/lib/doctor/formatters/shared.js +0 -129
- package/src/lib/doctor/formatters/shared.test.js +0 -194
- package/src/lib/doctor/index.js +0 -271
- package/src/lib/doctor/index.test.js +0 -797
- package/src/lib/epub/engines.js +0 -46
- package/src/lib/epub/index.test.js +0 -518
- package/src/lib/epub/pandoc.test.js +0 -122
- package/src/lib/epub/schema.js +0 -21
- package/src/lib/error/README.md +0 -170
- package/src/lib/error/handler.js +0 -107
- package/src/lib/git/index.spec.js +0 -80
- package/src/lib/git/index.test.js +0 -453
- package/src/lib/help/frontmatter.js +0 -77
- package/src/lib/help/frontmatter.test.js +0 -139
- package/src/lib/help/index.js +0 -146
- package/src/lib/help/index.test.js +0 -188
- package/src/lib/help/topics/configuration.md +0 -77
- package/src/lib/help/topics/debugging.md +0 -69
- package/src/lib/help/topics/epub.md +0 -74
- package/src/lib/help/topics/pdf.md +0 -74
- package/src/lib/help/topics/publishing.md +0 -80
- package/src/lib/help/topics/workflows.md +0 -50
- package/src/lib/installer/index.js +0 -309
- package/src/lib/installer/index.spec.js +0 -83
- package/src/lib/installer/index.test.js +0 -545
- package/src/lib/logger/README.md +0 -424
- package/src/lib/logger/debug.js +0 -132
- package/src/lib/logger/debug.spec.js +0 -130
- package/src/lib/logger/debug.test.js +0 -128
- package/src/lib/logger/index.js +0 -228
- package/src/lib/logger/index.spec.js +0 -131
- package/src/lib/logger/index.test.js +0 -578
- package/src/lib/npm/README.md +0 -127
- package/src/lib/npm/index.js +0 -198
- package/src/lib/npm/index.spec.js +0 -60
- package/src/lib/npm/index.test.js +0 -355
- package/src/lib/pdf/engines.js +0 -46
- package/src/lib/pdf/index.test.js +0 -708
- package/src/lib/pdf/paged.test.js +0 -366
- package/src/lib/pdf/prince.test.js +0 -202
- package/src/lib/pdf/schema.js +0 -21
- package/src/lib/pdf/split.test.js +0 -445
- package/src/lib/platform.js +0 -95
- package/src/lib/process/manager.js +0 -110
- package/src/lib/process/manager.test.js +0 -55
- package/src/lib/project/build.js +0 -162
- package/src/lib/project/build.test.js +0 -275
- package/src/lib/project/config.js +0 -48
- package/src/lib/project/config.test.js +0 -134
- package/src/lib/project/detect.js +0 -47
- package/src/lib/project/detect.test.js +0 -157
- package/src/lib/project/index.js +0 -56
- package/src/lib/project/output-paths.js +0 -87
- package/src/lib/project/output-paths.test.js +0 -66
- package/src/lib/project/paths.js +0 -272
- package/src/lib/project/version.js +0 -110
- package/src/lib/project/version.test.js +0 -350
- package/src/lib/reporter/index.test.js +0 -862
- package/src/main.spec.js +0 -61
- package/src/main.test.js +0 -347
- package/src/validators/validate-data-files.js +0 -154
- package/src/validators/validate-data-files.test.js +0 -217
|
@@ -1,112 +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() === 'new')
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
test('command is registered in CLI program', (t) => {
|
|
18
|
-
const { command } = t.context
|
|
19
|
-
|
|
20
|
-
t.truthy(command, 'command "new" 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(), 'new')
|
|
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, 2, 'command should have 2 arguments')
|
|
37
|
-
|
|
38
|
-
// First argument: projectPath
|
|
39
|
-
const projectPath = registeredArguments[0]
|
|
40
|
-
t.true(projectPath instanceof Argument, 'projectPath should be Argument instance')
|
|
41
|
-
t.is(projectPath.name(), 'projectPath', 'first argument should be projectPath')
|
|
42
|
-
t.false(projectPath.required, 'projectPath should be optional')
|
|
43
|
-
t.truthy(projectPath.description)
|
|
44
|
-
|
|
45
|
-
// Second argument: starter
|
|
46
|
-
const starter = registeredArguments[1]
|
|
47
|
-
t.true(starter instanceof Argument, 'starter should be Argument instance')
|
|
48
|
-
t.is(starter.name(), 'starter', 'second argument should be starter')
|
|
49
|
-
t.false(starter.required, 'starter should be optional')
|
|
50
|
-
t.truthy(starter.description)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
test('registered command has correct options', (t) => {
|
|
54
|
-
const { command } = t.context
|
|
55
|
-
|
|
56
|
-
// Get all options
|
|
57
|
-
const quirePathOption = command.options.find((opt) => opt.long === '--quire-path')
|
|
58
|
-
const quireVersionOption = command.options.find((opt) => opt.long === '--quire-version')
|
|
59
|
-
const quietOption = command.options.find((opt) => opt.long === '--quiet')
|
|
60
|
-
const verboseOption = command.options.find((opt) => opt.long === '--verbose')
|
|
61
|
-
const debugOption = command.options.find((opt) => opt.long === '--debug')
|
|
62
|
-
|
|
63
|
-
// Verify all options exist
|
|
64
|
-
t.truthy(quirePathOption, '--quire-path option should exist')
|
|
65
|
-
t.truthy(quireVersionOption, '--quire-version option should exist')
|
|
66
|
-
t.truthy(quietOption, '--quiet option should exist')
|
|
67
|
-
t.truthy(verboseOption, '--verbose option should exist')
|
|
68
|
-
t.truthy(debugOption, '--debug option should exist')
|
|
69
|
-
|
|
70
|
-
// Verify they are Option instances
|
|
71
|
-
t.true(quirePathOption instanceof Option, '--quire-path should be Option instance')
|
|
72
|
-
t.true(quireVersionOption instanceof Option, '--quire-version should be Option instance')
|
|
73
|
-
t.true(quietOption instanceof Option, '--quiet should be Option instance')
|
|
74
|
-
t.true(verboseOption instanceof Option, '--verbose should be Option instance')
|
|
75
|
-
t.true(debugOption instanceof Option, '--debug should be Option instance')
|
|
76
|
-
|
|
77
|
-
// Verify option properties
|
|
78
|
-
t.is(quirePathOption.long, '--quire-path')
|
|
79
|
-
t.truthy(quirePathOption.description)
|
|
80
|
-
t.true(quirePathOption.required, '--quire-path should require a value')
|
|
81
|
-
|
|
82
|
-
t.is(quireVersionOption.long, '--quire-version')
|
|
83
|
-
t.truthy(quireVersionOption.description)
|
|
84
|
-
t.true(quireVersionOption.required, '--quire-version should 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('--quire-path'))
|
|
108
|
-
t.true(optionNames.includes('--quire-version'))
|
|
109
|
-
t.true(optionNames.includes('--quiet'))
|
|
110
|
-
t.true(optionNames.includes('--verbose'))
|
|
111
|
-
t.true(optionNames.includes('--debug'))
|
|
112
|
-
})
|
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
import esmock from 'esmock'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import sinon from 'sinon'
|
|
4
|
-
import test from 'ava'
|
|
5
|
-
import { Volume, createFsFromVolume } from 'memfs'
|
|
6
|
-
|
|
7
|
-
test.beforeEach((t) => {
|
|
8
|
-
// Create sinon sandbox for mocking
|
|
9
|
-
t.context.sandbox = sinon.createSandbox()
|
|
10
|
-
|
|
11
|
-
// Create in-memory file system
|
|
12
|
-
t.context.vol = new Volume()
|
|
13
|
-
t.context.fs = createFsFromVolume(t.context.vol)
|
|
14
|
-
|
|
15
|
-
// Setup mock directory structure
|
|
16
|
-
t.context.vol.fromJSON({
|
|
17
|
-
'/starter-template/content/_data/config.yaml': 'title: Starter Template',
|
|
18
|
-
'/starter-template/package.json': JSON.stringify({ name: 'starter-template' })
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
t.context.projectRoot = '/new-project'
|
|
22
|
-
|
|
23
|
-
// Create mock logger (no global console stubbing needed!)
|
|
24
|
-
t.context.mockLogger = {
|
|
25
|
-
info: t.context.sandbox.stub(),
|
|
26
|
-
error: t.context.sandbox.stub(),
|
|
27
|
-
debug: t.context.sandbox.stub(),
|
|
28
|
-
log: t.context.sandbox.stub(),
|
|
29
|
-
warn: t.context.sandbox.stub()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Create mock reporter
|
|
33
|
-
t.context.mockReporter = {
|
|
34
|
-
configure: t.context.sandbox.stub().returnsThis(),
|
|
35
|
-
start: t.context.sandbox.stub().returnsThis(),
|
|
36
|
-
update: t.context.sandbox.stub().returnsThis(),
|
|
37
|
-
succeed: t.context.sandbox.stub().returnsThis(),
|
|
38
|
-
fail: t.context.sandbox.stub().returnsThis(),
|
|
39
|
-
stop: t.context.sandbox.stub().returnsThis(),
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
test.afterEach.always((t) => {
|
|
44
|
-
// Restore all mocks
|
|
45
|
-
t.context.sandbox.restore()
|
|
46
|
-
|
|
47
|
-
// Clear in-memory file system
|
|
48
|
-
t.context.vol.reset()
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
test('create command should initialize starter and install quire', async (t) => {
|
|
52
|
-
const { sandbox, fs, mockLogger, mockReporter } = t.context
|
|
53
|
-
|
|
54
|
-
// Mock quire library
|
|
55
|
-
const mockQuire = {
|
|
56
|
-
initStarter: sandbox.stub().callsFake(async (starter, projectPath) => {
|
|
57
|
-
// Simulate creating project directory
|
|
58
|
-
fs.mkdirSync(projectPath, { recursive: true })
|
|
59
|
-
fs.writeFileSync(`${projectPath}/package.json`, JSON.stringify({ name: 'new-project' }))
|
|
60
|
-
return '1.0.0'
|
|
61
|
-
}),
|
|
62
|
-
installInProject: sandbox.stub().resolves()
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Mock config
|
|
66
|
-
const mockConfig = {
|
|
67
|
-
get: sandbox.stub().returns('default-starter')
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Use esmock to replace imports
|
|
71
|
-
const { default: CreateCommand } = await esmock('./create.js', {
|
|
72
|
-
'#lib/installer/index.js': {
|
|
73
|
-
installer: mockQuire
|
|
74
|
-
},
|
|
75
|
-
'#lib/reporter/index.js': {
|
|
76
|
-
default: mockReporter
|
|
77
|
-
},
|
|
78
|
-
'fs-extra': fs
|
|
79
|
-
}, {
|
|
80
|
-
'#lib/logger/index.js': {
|
|
81
|
-
default: () => mockLogger
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
const command = new CreateCommand()
|
|
86
|
-
command.config = mockConfig
|
|
87
|
-
command.logger = mockLogger
|
|
88
|
-
command.debug = sandbox.stub()
|
|
89
|
-
|
|
90
|
-
// Run action
|
|
91
|
-
await command.action('/new-project', 'starter-template', {})
|
|
92
|
-
|
|
93
|
-
t.true(mockQuire.initStarter.called, 'initStarter should be called')
|
|
94
|
-
t.true(mockQuire.initStarter.calledWith('starter-template', '/new-project'), 'initStarter should be called with correct arguments')
|
|
95
|
-
t.true(mockQuire.installInProject.called, 'installInProject should be called')
|
|
96
|
-
t.true(mockQuire.installInProject.calledWith('/new-project', '1.0.0'), 'installInProject should be called with project path and version')
|
|
97
|
-
t.true(mockReporter.configure.called, 'reporter.configure should be called')
|
|
98
|
-
t.true(mockReporter.succeed.called, 'reporter.succeed should be called on success')
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
test('create command should use default starter from config when not provided', async (t) => {
|
|
102
|
-
const { sandbox, fs, mockLogger, mockReporter } = t.context
|
|
103
|
-
|
|
104
|
-
// Mock quire library
|
|
105
|
-
const mockQuire = {
|
|
106
|
-
initStarter: sandbox.stub().callsFake(async (starter, projectPath) => {
|
|
107
|
-
fs.mkdirSync(projectPath, { recursive: true })
|
|
108
|
-
fs.writeFileSync(`${projectPath}/package.json`, JSON.stringify({ name: 'new-project' }))
|
|
109
|
-
return '1.0.0'
|
|
110
|
-
}),
|
|
111
|
-
installInProject: sandbox.stub().resolves()
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Mock config
|
|
115
|
-
const mockConfig = {
|
|
116
|
-
get: sandbox.stub().returns('https://github.com/thegetty/quire-starter-default')
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Use esmock to replace imports
|
|
120
|
-
const { default: CreateCommand } = await esmock('./create.js', {
|
|
121
|
-
'#lib/installer/index.js': {
|
|
122
|
-
installer: mockQuire
|
|
123
|
-
},
|
|
124
|
-
'#lib/reporter/index.js': {
|
|
125
|
-
default: mockReporter
|
|
126
|
-
},
|
|
127
|
-
'fs-extra': fs
|
|
128
|
-
}, {
|
|
129
|
-
'#lib/logger/index.js': {
|
|
130
|
-
default: () => mockLogger
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
const command = new CreateCommand()
|
|
135
|
-
command.config = mockConfig
|
|
136
|
-
command.logger = mockLogger
|
|
137
|
-
command.debug = sandbox.stub()
|
|
138
|
-
|
|
139
|
-
// Run action without starter argument
|
|
140
|
-
await command.action('/new-project', null, {})
|
|
141
|
-
|
|
142
|
-
t.true(mockConfig.get.calledWith('projectTemplate'), 'config.get should be called for projectTemplate')
|
|
143
|
-
t.true(mockQuire.initStarter.calledWith('https://github.com/thegetty/quire-starter-default', '/new-project'), 'initStarter should use default starter from config')
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
test('create command should pass quire-version option to installInProject', async (t) => {
|
|
147
|
-
const { sandbox, fs, mockLogger, mockReporter } = t.context
|
|
148
|
-
|
|
149
|
-
// Mock quire library
|
|
150
|
-
const mockQuire = {
|
|
151
|
-
initStarter: sandbox.stub().callsFake(async (starter, projectPath) => {
|
|
152
|
-
fs.mkdirSync(projectPath, { recursive: true })
|
|
153
|
-
fs.writeFileSync(`${projectPath}/package.json`, JSON.stringify({ name: 'new-project' }))
|
|
154
|
-
return '1.0.0-rc.10'
|
|
155
|
-
}),
|
|
156
|
-
installInProject: sandbox.stub().resolves()
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Mock config
|
|
160
|
-
const mockConfig = {
|
|
161
|
-
get: sandbox.stub().returns('default-starter')
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Use esmock to replace imports
|
|
165
|
-
const { default: CreateCommand } = await esmock('./create.js', {
|
|
166
|
-
'#lib/installer/index.js': {
|
|
167
|
-
installer: mockQuire
|
|
168
|
-
},
|
|
169
|
-
'#lib/reporter/index.js': {
|
|
170
|
-
default: mockReporter
|
|
171
|
-
},
|
|
172
|
-
'fs-extra': fs
|
|
173
|
-
}, {
|
|
174
|
-
'#lib/logger/index.js': {
|
|
175
|
-
default: () => mockLogger
|
|
176
|
-
}
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
const command = new CreateCommand()
|
|
180
|
-
command.config = mockConfig
|
|
181
|
-
command.logger = mockLogger
|
|
182
|
-
command.debug = sandbox.stub()
|
|
183
|
-
|
|
184
|
-
const options = { quireVersion: '1.0.0-rc.10' }
|
|
185
|
-
|
|
186
|
-
// Run action with quire-version option
|
|
187
|
-
await command.action('/new-project', 'starter-template', options)
|
|
188
|
-
|
|
189
|
-
t.true(mockQuire.installInProject.called, 'installInProject should be called')
|
|
190
|
-
const installCall = mockQuire.installInProject.getCall(0)
|
|
191
|
-
t.true(installCall.args[2] === options, 'installInProject should receive options object')
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
test('create command should handle initStarter errors gracefully', async (t) => {
|
|
195
|
-
const { sandbox, fs, mockLogger, mockReporter } = t.context
|
|
196
|
-
|
|
197
|
-
const error = new Error('Failed to initialize starter template')
|
|
198
|
-
|
|
199
|
-
// Mock quire library
|
|
200
|
-
const mockQuire = {
|
|
201
|
-
initStarter: sandbox.stub().rejects(error),
|
|
202
|
-
installInProject: sandbox.stub().resolves()
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Mock config
|
|
206
|
-
const mockConfig = {
|
|
207
|
-
get: sandbox.stub().returns('default-starter')
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Add removeSync to fs if it doesn't exist (memfs compatibility)
|
|
211
|
-
if (!fs.removeSync) {
|
|
212
|
-
fs.removeSync = sandbox.stub().callsFake((path) => {
|
|
213
|
-
if (fs.existsSync(path)) {
|
|
214
|
-
fs.rmSync(path, { recursive: true, force: true })
|
|
215
|
-
}
|
|
216
|
-
})
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Use esmock to replace imports
|
|
220
|
-
const { default: CreateCommand } = await esmock('./create.js', {
|
|
221
|
-
'#lib/installer/index.js': {
|
|
222
|
-
installer: mockQuire
|
|
223
|
-
},
|
|
224
|
-
'#lib/reporter/index.js': {
|
|
225
|
-
default: mockReporter
|
|
226
|
-
},
|
|
227
|
-
'fs-extra': fs
|
|
228
|
-
}, {
|
|
229
|
-
'#lib/logger/index.js': {
|
|
230
|
-
default: () => mockLogger
|
|
231
|
-
}
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
const command = new CreateCommand()
|
|
235
|
-
command.config = mockConfig
|
|
236
|
-
command.logger = mockLogger
|
|
237
|
-
command.debug = sandbox.stub()
|
|
238
|
-
|
|
239
|
-
// Run action - should throw ProjectCreateError
|
|
240
|
-
// Note: We check error properties instead of instanceOf because esmock creates
|
|
241
|
-
// a separate module instance with its own class reference
|
|
242
|
-
const thrown = await t.throwsAsync(
|
|
243
|
-
() => command.action('/new-project', 'starter-template', {})
|
|
244
|
-
)
|
|
245
|
-
|
|
246
|
-
t.is(thrown.name, 'ProjectCreateError', 'error should be ProjectCreateError')
|
|
247
|
-
t.is(thrown.code, 'PROJECT_CREATE_FAILED', 'error should have correct code')
|
|
248
|
-
t.is(thrown.exitCode, 2, 'error should have correct exit code')
|
|
249
|
-
t.true(mockQuire.initStarter.called, 'initStarter should be called')
|
|
250
|
-
t.false(mockQuire.installInProject.called, 'installInProject should not be called when initStarter fails')
|
|
251
|
-
t.true(fs.removeSync.called || !fs.existsSync('/new-project'), 'project directory should be removed on error')
|
|
252
|
-
t.true(mockLogger.error.calledWith(error.message), 'error message should be logged')
|
|
253
|
-
t.true(mockReporter.fail.called, 'reporter.fail should be called on error')
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
test('create command should pass through debug option', async (t) => {
|
|
257
|
-
const { sandbox, fs, mockLogger, mockReporter } = t.context
|
|
258
|
-
|
|
259
|
-
const mockDebug = sandbox.stub()
|
|
260
|
-
|
|
261
|
-
// Mock quire library
|
|
262
|
-
const mockQuire = {
|
|
263
|
-
initStarter: sandbox.stub().callsFake(async (starter, projectPath) => {
|
|
264
|
-
fs.mkdirSync(projectPath, { recursive: true })
|
|
265
|
-
fs.writeFileSync(`${projectPath}/package.json`, JSON.stringify({ name: 'new-project' }))
|
|
266
|
-
return '1.0.0'
|
|
267
|
-
}),
|
|
268
|
-
installInProject: sandbox.stub().resolves()
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// Mock config
|
|
272
|
-
const mockConfig = {
|
|
273
|
-
get: sandbox.stub().returns('default-starter')
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Use esmock to replace imports
|
|
277
|
-
const { default: CreateCommand } = await esmock('./create.js', {
|
|
278
|
-
'#lib/installer/index.js': { installer: mockQuire },
|
|
279
|
-
'#lib/reporter/index.js': { default: mockReporter },
|
|
280
|
-
'fs-extra': fs
|
|
281
|
-
}, {
|
|
282
|
-
'#lib/logger/index.js': {
|
|
283
|
-
default: () => mockLogger
|
|
284
|
-
}
|
|
285
|
-
})
|
|
286
|
-
|
|
287
|
-
const command = new CreateCommand()
|
|
288
|
-
command.config = mockConfig
|
|
289
|
-
command.logger = mockLogger
|
|
290
|
-
command.debug = mockDebug
|
|
291
|
-
|
|
292
|
-
// Run action with debug option
|
|
293
|
-
await command.action('/new-project', 'starter-template', { debug: true })
|
|
294
|
-
|
|
295
|
-
t.true(mockDebug.called, 'debug should be called with debug option')
|
|
296
|
-
t.true(mockQuire.initStarter.called, 'initStarter should be called')
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
test('create command should pass quire-path option to methods', async (t) => {
|
|
300
|
-
const { sandbox, fs, mockLogger, mockReporter } = t.context
|
|
301
|
-
|
|
302
|
-
// Mock quire library
|
|
303
|
-
const mockQuire = {
|
|
304
|
-
initStarter: sandbox.stub().callsFake(async (starter, projectPath) => {
|
|
305
|
-
fs.mkdirSync(projectPath, { recursive: true })
|
|
306
|
-
fs.writeFileSync(`${projectPath}/package.json`, JSON.stringify({ name: 'new-project' }))
|
|
307
|
-
return '1.0.0'
|
|
308
|
-
}),
|
|
309
|
-
installInProject: sandbox.stub().resolves()
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// Mock config
|
|
313
|
-
const mockConfig = {
|
|
314
|
-
get: sandbox.stub().returns('default-starter')
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// Use esmock to replace imports
|
|
318
|
-
const { default: CreateCommand } = await esmock('./create.js', {
|
|
319
|
-
'#lib/installer/index.js': {
|
|
320
|
-
installer: mockQuire
|
|
321
|
-
},
|
|
322
|
-
'#lib/reporter/index.js': {
|
|
323
|
-
default: mockReporter
|
|
324
|
-
},
|
|
325
|
-
'fs-extra': fs
|
|
326
|
-
}, {
|
|
327
|
-
'#lib/logger/index.js': {
|
|
328
|
-
default: () => mockLogger
|
|
329
|
-
}
|
|
330
|
-
})
|
|
331
|
-
|
|
332
|
-
const command = new CreateCommand()
|
|
333
|
-
command.config = mockConfig
|
|
334
|
-
command.logger = mockLogger
|
|
335
|
-
command.debug = sandbox.stub()
|
|
336
|
-
|
|
337
|
-
const options = { quirePath: '/custom/path/to/quire-11ty' }
|
|
338
|
-
|
|
339
|
-
// Run action with quire-path option
|
|
340
|
-
await command.action('/new-project', 'starter-template', options)
|
|
341
|
-
|
|
342
|
-
const initCall = mockQuire.initStarter.getCall(0)
|
|
343
|
-
const installCall = mockQuire.installInProject.getCall(0)
|
|
344
|
-
|
|
345
|
-
t.true(initCall.args[2] === options, 'initStarter should receive options with quire-path')
|
|
346
|
-
t.true(installCall.args[2] === options, 'installInProject should receive options with quire-path')
|
|
347
|
-
})
|
|
348
|
-
|
|
349
|
-
test('create command initial commit does not include temporary install artifacts', async (t) => {
|
|
350
|
-
const { sandbox, fs, projectRoot, vol, mockReporter } = t.context
|
|
351
|
-
|
|
352
|
-
// Setup project directory
|
|
353
|
-
fs.mkdirSync(projectRoot)
|
|
354
|
-
|
|
355
|
-
// Track filesystem state at the time of git operations
|
|
356
|
-
let tempDirExistedAtAdd = null
|
|
357
|
-
let tempDirExistedAtCommit = null
|
|
358
|
-
|
|
359
|
-
const tempDir = path.join(projectRoot, '.temp')
|
|
360
|
-
const tarballPath = path.join(tempDir, 'thegetty-quire-11ty-1.0.0.tgz')
|
|
361
|
-
|
|
362
|
-
// Mock npm façade to simulate npm pack behavior
|
|
363
|
-
const mockNpm = {
|
|
364
|
-
pack: sandbox.stub().callsFake(() => {
|
|
365
|
-
// Simulate npm pack creating a tarball in .temp
|
|
366
|
-
fs.writeFileSync(tarballPath, '')
|
|
367
|
-
}),
|
|
368
|
-
cacheClean: sandbox.stub().resolves(),
|
|
369
|
-
install: sandbox.stub().resolves()
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// Mock Git class that captures filesystem state when methods are called
|
|
373
|
-
class MockGit {
|
|
374
|
-
add() {
|
|
375
|
-
// Capture filesystem state at the moment add() is called
|
|
376
|
-
tempDirExistedAtAdd = fs.existsSync(tempDir)
|
|
377
|
-
return Promise.resolve()
|
|
378
|
-
}
|
|
379
|
-
commit() {
|
|
380
|
-
// Capture filesystem state at the moment commit() is called
|
|
381
|
-
tempDirExistedAtCommit = fs.existsSync(tempDir)
|
|
382
|
-
return Promise.resolve()
|
|
383
|
-
}
|
|
384
|
-
rm() {
|
|
385
|
-
return Promise.resolve()
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
// Mock fs and git
|
|
390
|
-
// Nota bene: Pass `vol` here as fs because memfs only provides cpSync there
|
|
391
|
-
const { installer } = await esmock('#lib/installer/index.js', {
|
|
392
|
-
'fs-extra': vol,
|
|
393
|
-
'#lib/npm/index.js': {
|
|
394
|
-
default: mockNpm,
|
|
395
|
-
},
|
|
396
|
-
'#lib/git/index.js': {
|
|
397
|
-
Git: MockGit,
|
|
398
|
-
},
|
|
399
|
-
'#lib/reporter/index.js': {
|
|
400
|
-
default: mockReporter,
|
|
401
|
-
},
|
|
402
|
-
'execa': {
|
|
403
|
-
// Mock tar extraction command (uses array-based execa, not execaCommand)
|
|
404
|
-
execa: sandbox.stub().resolves(),
|
|
405
|
-
},
|
|
406
|
-
})
|
|
407
|
-
|
|
408
|
-
await installer.installInProject(projectRoot, '1.0.0')
|
|
409
|
-
|
|
410
|
-
// Verify that temp dir was removed BEFORE git add was called
|
|
411
|
-
t.false(tempDirExistedAtAdd, '.temp directory should be removed before git add')
|
|
412
|
-
|
|
413
|
-
// Verify that temp dir was removed BEFORE git commit was called
|
|
414
|
-
t.false(tempDirExistedAtCommit, '.temp directory should be removed before git commit')
|
|
415
|
-
})
|