@thegetty/quire-cli 1.0.0-rc.44 → 1.0.0-rc.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/CHANGELOG.md +0 -36
  2. package/README.md +0 -9
  3. package/bin/cli.js +1 -46
  4. package/package.json +9 -25
  5. package/src/Command.js +6 -26
  6. package/src/commands/README.md +122 -213
  7. package/src/commands/build.js +37 -45
  8. package/src/commands/clean.js +19 -33
  9. package/src/commands/conf.js +43 -0
  10. package/src/commands/create.js +14 -42
  11. package/src/commands/epub.js +31 -67
  12. package/src/commands/index.js +2 -9
  13. package/src/commands/info.js +86 -88
  14. package/src/commands/pdf.js +82 -63
  15. package/src/commands/preview.js +31 -32
  16. package/src/commands/validate.js +20 -64
  17. package/src/commands/version.js +43 -0
  18. package/src/errors/validation/validation-error.js +11 -20
  19. package/src/helpers/clean.js +1 -1
  20. package/src/helpers/is-quire.js +31 -0
  21. package/src/helpers/test-cwd.js +6 -5
  22. package/src/helpers/which.js +4 -10
  23. package/src/lib/11ty/README.md +19 -135
  24. package/src/lib/11ty/api.js +93 -235
  25. package/src/lib/11ty/cli.js +37 -112
  26. package/src/lib/11ty/index.js +5 -64
  27. package/src/lib/11ty/paths.js +103 -0
  28. package/src/lib/README.md +0 -330
  29. package/src/lib/conf/README.md +69 -86
  30. package/src/lib/conf/config.js +3 -5
  31. package/src/lib/conf/defaults.js +0 -65
  32. package/src/lib/conf/schema.js +9 -103
  33. package/src/lib/epub/README.md +2 -133
  34. package/src/lib/epub/epub.js +11 -36
  35. package/src/lib/epub/index.js +21 -111
  36. package/src/lib/epub/pandoc.js +4 -33
  37. package/src/lib/git/README.md +2 -151
  38. package/src/lib/git/index.js +13 -217
  39. package/src/lib/i18n/README.md +3 -0
  40. package/src/lib/i18n/config.js +53 -0
  41. package/src/lib/i18n/index.js +43 -0
  42. package/src/lib/i18n/localeService.js +58 -0
  43. package/src/lib/pdf/README.md +0 -131
  44. package/src/lib/pdf/index.js +21 -124
  45. package/src/lib/pdf/paged.js +52 -100
  46. package/src/lib/pdf/prince.js +37 -115
  47. package/src/lib/pdf/split.js +33 -61
  48. package/src/lib/quire/README.md +19 -0
  49. package/src/lib/quire/index.js +353 -0
  50. package/src/lib/reporter/README.md +2 -211
  51. package/src/lib/reporter/index.js +0 -607
  52. package/src/main.js +48 -221
  53. package/src/packageConfig.js +0 -17
  54. package/src/validators/utils.js +1 -2
  55. package/schemas/config.schema.json +0 -194
  56. package/schemas/figures.schema.json +0 -56
  57. package/schemas/layout.schema.json +0 -5
  58. package/schemas/objects.schema.json +0 -62
  59. package/schemas/publication.schema.json +0 -140
  60. package/schemas/references.schema.json +0 -29
  61. package/src/Command.spec.js +0 -99
  62. package/src/commands/build.spec.js +0 -113
  63. package/src/commands/build.test.js +0 -397
  64. package/src/commands/clean.spec.js +0 -118
  65. package/src/commands/clean.test.js +0 -382
  66. package/src/commands/config.js +0 -238
  67. package/src/commands/config.spec.js +0 -107
  68. package/src/commands/config.test.js +0 -845
  69. package/src/commands/create.spec.js +0 -112
  70. package/src/commands/create.test.js +0 -415
  71. package/src/commands/doctor.js +0 -251
  72. package/src/commands/doctor.spec.js +0 -115
  73. package/src/commands/doctor.test.js +0 -1409
  74. package/src/commands/epub.spec.js +0 -114
  75. package/src/commands/epub.test.js +0 -503
  76. package/src/commands/help.js +0 -60
  77. package/src/commands/help.test.js +0 -132
  78. package/src/commands/info.spec.js +0 -72
  79. package/src/commands/info.test.js +0 -512
  80. package/src/commands/pdf.spec.js +0 -114
  81. package/src/commands/pdf.test.js +0 -464
  82. package/src/commands/preview.spec.js +0 -97
  83. package/src/commands/preview.test.js +0 -250
  84. package/src/commands/use.js +0 -56
  85. package/src/commands/use.spec.js +0 -61
  86. package/src/commands/use.test.js +0 -280
  87. package/src/commands/validate.spec.js +0 -90
  88. package/src/commands/validate.test.js +0 -378
  89. package/src/commands/workflows.js +0 -70
  90. package/src/errors/build/build-failed-error.js +0 -19
  91. package/src/errors/build/config-field-missing-error.js +0 -20
  92. package/src/errors/build/config-file-not-found-error.js +0 -20
  93. package/src/errors/build/index.js +0 -11
  94. package/src/errors/help/help-topic-not-found-error.js +0 -30
  95. package/src/errors/help/index.js +0 -8
  96. package/src/errors/index.js +0 -58
  97. package/src/errors/input/index.js +0 -8
  98. package/src/errors/input/invalid-input-error.js +0 -21
  99. package/src/errors/install/dependency-install-error.js +0 -19
  100. package/src/errors/install/directory-not-empty-error.js +0 -25
  101. package/src/errors/install/index.js +0 -12
  102. package/src/errors/install/invalid-path-error.js +0 -31
  103. package/src/errors/install/invalid-starter-error.js +0 -27
  104. package/src/errors/install/version-not-found-error.js +0 -35
  105. package/src/errors/output/epub-generation-error.js +0 -19
  106. package/src/errors/output/index.js +0 -14
  107. package/src/errors/output/invalid-epub-library-error.js +0 -20
  108. package/src/errors/output/invalid-pdf-library-error.js +0 -20
  109. package/src/errors/output/missing-build-output-error.js +0 -21
  110. package/src/errors/output/pdf-generation-error.js +0 -24
  111. package/src/errors/output/tool-not-found-error.js +0 -37
  112. package/src/errors/project/index.js +0 -10
  113. package/src/errors/project/not-in-project-error.js +0 -20
  114. package/src/errors/project/project-create-error.js +0 -21
  115. package/src/errors/quire-error.js +0 -27
  116. package/src/errors/validation/index.js +0 -3
  117. package/src/errors/validation/unknown-config-key-error.js +0 -27
  118. package/src/errors/validation/unknown-config-operation-error.js +0 -24
  119. package/src/helpers/docs-url.js +0 -32
  120. package/src/helpers/pager.js +0 -59
  121. package/src/helpers/pager.test.js +0 -85
  122. package/src/helpers/suggest-similar.js +0 -124
  123. package/src/helpers/suggest-similar.test.js +0 -108
  124. package/src/helpers/test-cwd.test.js +0 -192
  125. package/src/lib/11ty/index.test.js +0 -655
  126. package/src/lib/commander/index.js +0 -103
  127. package/src/lib/commander/index.test.js +0 -86
  128. package/src/lib/commander/options.js +0 -237
  129. package/src/lib/commander/options.test.js +0 -205
  130. package/src/lib/conf/build-status.js +0 -103
  131. package/src/lib/conf/build-status.test.js +0 -247
  132. package/src/lib/conf/config.test.js +0 -281
  133. package/src/lib/conf/format.js +0 -60
  134. package/src/lib/conf/format.test.js +0 -106
  135. package/src/lib/conf/helpers.js +0 -91
  136. package/src/lib/conf/helpers.test.js +0 -136
  137. package/src/lib/conf/index.js +0 -22
  138. package/src/lib/constants.js +0 -28
  139. package/src/lib/doctor/README.md +0 -667
  140. package/src/lib/doctor/checks/environment/cli-version.js +0 -62
  141. package/src/lib/doctor/checks/environment/cli-version.test.js +0 -132
  142. package/src/lib/doctor/checks/environment/git-available.js +0 -77
  143. package/src/lib/doctor/checks/environment/git-available.test.js +0 -52
  144. package/src/lib/doctor/checks/environment/index.js +0 -13
  145. package/src/lib/doctor/checks/environment/node-version.js +0 -66
  146. package/src/lib/doctor/checks/environment/node-version.test.js +0 -17
  147. package/src/lib/doctor/checks/environment/npm-available.js +0 -66
  148. package/src/lib/doctor/checks/environment/npm-available.test.js +0 -52
  149. package/src/lib/doctor/checks/environment/os-info.js +0 -48
  150. package/src/lib/doctor/checks/environment/os-info.test.js +0 -81
  151. package/src/lib/doctor/checks/environment/runtime-info.js +0 -51
  152. package/src/lib/doctor/checks/environment/runtime-info.test.js +0 -132
  153. package/src/lib/doctor/checks/outputs/epub-output.js +0 -119
  154. package/src/lib/doctor/checks/outputs/epub-output.test.js +0 -277
  155. package/src/lib/doctor/checks/outputs/index.js +0 -10
  156. package/src/lib/doctor/checks/outputs/pdf-output.js +0 -144
  157. package/src/lib/doctor/checks/outputs/pdf-output.test.js +0 -377
  158. package/src/lib/doctor/checks/outputs/stale-build.js +0 -122
  159. package/src/lib/doctor/checks/outputs/stale-build.test.js +0 -282
  160. package/src/lib/doctor/checks/project/data-files.js +0 -56
  161. package/src/lib/doctor/checks/project/data-files.test.js +0 -125
  162. package/src/lib/doctor/checks/project/dependencies.js +0 -53
  163. package/src/lib/doctor/checks/project/dependencies.test.js +0 -71
  164. package/src/lib/doctor/checks/project/index.js +0 -11
  165. package/src/lib/doctor/checks/project/quire-11ty.js +0 -98
  166. package/src/lib/doctor/checks/project/quire-11ty.test.js +0 -170
  167. package/src/lib/doctor/checks/project/quire-project.js +0 -38
  168. package/src/lib/doctor/checks/project/quire-project.test.js +0 -47
  169. package/src/lib/doctor/checks/tools/index.js +0 -10
  170. package/src/lib/doctor/checks/tools/pandoc-available.js +0 -82
  171. package/src/lib/doctor/checks/tools/pandoc-available.test.js +0 -73
  172. package/src/lib/doctor/checks/tools/prince-available.js +0 -81
  173. package/src/lib/doctor/checks/tools/prince-available.test.js +0 -73
  174. package/src/lib/doctor/constants.js +0 -39
  175. package/src/lib/doctor/formatDuration.js +0 -108
  176. package/src/lib/doctor/formatDuration.test.js +0 -76
  177. package/src/lib/doctor/formatters/human.js +0 -257
  178. package/src/lib/doctor/formatters/human.test.js +0 -463
  179. package/src/lib/doctor/formatters/index.js +0 -8
  180. package/src/lib/doctor/formatters/json.js +0 -78
  181. package/src/lib/doctor/formatters/json.test.js +0 -174
  182. package/src/lib/doctor/formatters/shared.js +0 -129
  183. package/src/lib/doctor/formatters/shared.test.js +0 -194
  184. package/src/lib/doctor/index.js +0 -271
  185. package/src/lib/doctor/index.test.js +0 -797
  186. package/src/lib/epub/engines.js +0 -46
  187. package/src/lib/epub/index.test.js +0 -518
  188. package/src/lib/epub/pandoc.test.js +0 -122
  189. package/src/lib/epub/schema.js +0 -21
  190. package/src/lib/error/README.md +0 -170
  191. package/src/lib/error/handler.js +0 -107
  192. package/src/lib/git/index.spec.js +0 -80
  193. package/src/lib/git/index.test.js +0 -453
  194. package/src/lib/help/frontmatter.js +0 -77
  195. package/src/lib/help/frontmatter.test.js +0 -139
  196. package/src/lib/help/index.js +0 -146
  197. package/src/lib/help/index.test.js +0 -188
  198. package/src/lib/help/topics/configuration.md +0 -77
  199. package/src/lib/help/topics/debugging.md +0 -69
  200. package/src/lib/help/topics/epub.md +0 -74
  201. package/src/lib/help/topics/pdf.md +0 -74
  202. package/src/lib/help/topics/publishing.md +0 -80
  203. package/src/lib/help/topics/workflows.md +0 -50
  204. package/src/lib/installer/index.js +0 -309
  205. package/src/lib/installer/index.spec.js +0 -83
  206. package/src/lib/installer/index.test.js +0 -545
  207. package/src/lib/logger/README.md +0 -424
  208. package/src/lib/logger/debug.js +0 -132
  209. package/src/lib/logger/debug.spec.js +0 -130
  210. package/src/lib/logger/debug.test.js +0 -128
  211. package/src/lib/logger/index.js +0 -228
  212. package/src/lib/logger/index.spec.js +0 -131
  213. package/src/lib/logger/index.test.js +0 -578
  214. package/src/lib/npm/README.md +0 -127
  215. package/src/lib/npm/index.js +0 -198
  216. package/src/lib/npm/index.spec.js +0 -60
  217. package/src/lib/npm/index.test.js +0 -355
  218. package/src/lib/pdf/engines.js +0 -46
  219. package/src/lib/pdf/index.test.js +0 -708
  220. package/src/lib/pdf/paged.test.js +0 -366
  221. package/src/lib/pdf/prince.test.js +0 -202
  222. package/src/lib/pdf/schema.js +0 -21
  223. package/src/lib/pdf/split.test.js +0 -445
  224. package/src/lib/platform.js +0 -95
  225. package/src/lib/process/manager.js +0 -110
  226. package/src/lib/process/manager.test.js +0 -55
  227. package/src/lib/project/build.js +0 -162
  228. package/src/lib/project/build.test.js +0 -275
  229. package/src/lib/project/config.js +0 -48
  230. package/src/lib/project/config.test.js +0 -134
  231. package/src/lib/project/detect.js +0 -47
  232. package/src/lib/project/detect.test.js +0 -157
  233. package/src/lib/project/index.js +0 -56
  234. package/src/lib/project/output-paths.js +0 -87
  235. package/src/lib/project/output-paths.test.js +0 -66
  236. package/src/lib/project/paths.js +0 -272
  237. package/src/lib/project/version.js +0 -110
  238. package/src/lib/project/version.test.js +0 -350
  239. package/src/lib/reporter/index.test.js +0 -862
  240. package/src/main.spec.js +0 -61
  241. package/src/main.test.js +0 -347
  242. package/src/validators/validate-data-files.js +0 -154
  243. package/src/validators/validate-data-files.test.js +0 -217
@@ -1,144 +0,0 @@
1
- /**
2
- * PDF output check
3
- *
4
- * Checks for PDF output files using the same path resolution logic as the
5
- * PDF generation command. Supports both default engine-named paths and
6
- * config-aware custom output paths.
7
- *
8
- * @module lib/doctor/checks/outputs/pdf-output
9
- */
10
- import fs from 'node:fs'
11
- import path from 'node:path'
12
- import createDebug from '#debug'
13
- import { getPdfOutputPaths } from '#lib/project/output-paths.js'
14
- import { loadProjectConfig } from '#lib/project/config.js'
15
- import config from '#lib/conf/config.js'
16
- import { getStatus } from '#lib/conf/build-status.js'
17
- import { DOCS_BASE_URL, resolveStaleThreshold } from '#lib/doctor/constants.js'
18
- import { formatDuration } from '#lib/doctor/formatDuration.js'
19
-
20
- const debug = createDebug('lib:doctor:pdf-output')
21
-
22
- /**
23
- * Load pdf config from the project's config.yaml
24
- *
25
- * Returns undefined if config cannot be loaded (not in a project, missing
26
- * config file, no pdf section). The caller falls back to engine defaults.
27
- *
28
- * @returns {Promise<Object|undefined>}
29
- */
30
- async function loadPdfConfig() {
31
- try {
32
- const projectConfig = await loadProjectConfig()
33
- return projectConfig.pdf
34
- } catch {
35
- debug('Could not load project config, using engine defaults only')
36
- return undefined
37
- }
38
- }
39
-
40
- /**
41
- * Check if PDF output exists and is up to date with _site
42
- *
43
- * PDF is generated from _site, so if _site is newer than the PDF,
44
- * the PDF is considered stale.
45
- *
46
- * Loads the project config to resolve config-aware PDF output paths,
47
- * matching the same resolution logic as `lib/pdf/index.js`.
48
- *
49
- * @returns {Promise<import('../../index.js').CheckResult>}
50
- */
51
- export async function checkPdfOutput() {
52
- const pdfConfig = await loadPdfConfig()
53
-
54
- // Get all possible PDF paths (config-aware + engine defaults)
55
- const candidatePaths = getPdfOutputPaths({ pdfConfig })
56
- debug('candidate PDF paths: %o', candidatePaths)
57
-
58
- // Find which PDF files actually exist
59
- const existingPdfs = candidatePaths.filter((p) => fs.existsSync(p))
60
-
61
- if (existingPdfs.length === 0) {
62
- debug('No PDF files found, checking stored pdf status')
63
-
64
- const status = getStatus(process.cwd(), 'pdf')
65
- if (status?.status === 'failed') {
66
- debug('Last pdf generation failed (stored status)')
67
- return {
68
- ok: false,
69
- message: 'Last PDF generation failed',
70
- remediation: `The last "quire pdf" run failed. Check the output for errors and try again.
71
- • Run "quire pdf --debug" for detailed error output`,
72
- docsUrl: `${DOCS_BASE_URL}/quire-commands/#pdf`,
73
- }
74
- }
75
-
76
- return {
77
- ok: true,
78
- level: 'na',
79
- message: 'No PDF output found',
80
- remediation: `Run "quire pdf" to generate a PDF.
81
- • If you already ran "quire pdf" and it failed, check the output for errors`,
82
- docsUrl: `${DOCS_BASE_URL}/quire-commands/#pdf`,
83
- }
84
- }
85
-
86
- // Use basenames for display
87
- const existingNames = existingPdfs.map((p) => path.basename(p))
88
- debug('found PDF files: %o', existingNames)
89
-
90
- // Check if _site exists
91
- if (!fs.existsSync('_site')) {
92
- debug('_site directory not found')
93
- return {
94
- ok: true,
95
- message: `${existingNames.join(', ')} exists (no _site to compare)`,
96
- }
97
- }
98
-
99
- // Get _site last modified time
100
- const { mtimeMs: siteLastModified } = fs.statSync('_site')
101
- debug('_site lastModified: %d', siteLastModified)
102
-
103
- // Check each PDF for staleness beyond the configured threshold
104
- const thresholdMs = resolveStaleThreshold(config.get('staleThreshold'))
105
- const staleFiles = []
106
- let oldestPdfLastModified = Infinity
107
-
108
- for (const pdfFile of existingPdfs) {
109
- const { mtimeMs: pdfLastModified } = fs.statSync(pdfFile)
110
- debug('%s lastModified: %d', path.basename(pdfFile), pdfLastModified)
111
-
112
- const staleDelta = siteLastModified - pdfLastModified
113
- if (staleDelta > thresholdMs) {
114
- staleFiles.push(pdfFile)
115
- if (pdfLastModified < oldestPdfLastModified) {
116
- oldestPdfLastModified = pdfLastModified
117
- }
118
- }
119
- }
120
-
121
- if (staleFiles.length > 0) {
122
- const staleDuration = formatDuration(siteLastModified - oldestPdfLastModified)
123
- const staleNames = staleFiles.map((p) => path.basename(p))
124
- const fileList = staleNames.join(', ')
125
- return {
126
- ok: false,
127
- level: 'warn',
128
- message: `${fileList} is ${staleDuration} older than _site`,
129
- remediation: `Your PDF may not reflect recent build changes.
130
- • Run "quire pdf" to regenerate the PDF
131
- • Or delete the old PDF files and run "quire pdf"`,
132
- docsUrl: `${DOCS_BASE_URL}/quire-commands/#pdf`,
133
- }
134
- }
135
-
136
- // All PDFs are up to date
137
- const fileList = existingNames.join(', ')
138
- return {
139
- ok: true,
140
- message: `${fileList} up to date`,
141
- }
142
- }
143
-
144
- export default checkPdfOutput
@@ -1,377 +0,0 @@
1
- import test from 'ava'
2
- import path from 'node:path'
3
- import sinon from 'sinon'
4
- import esmock from 'esmock'
5
-
6
- const TWO_MINUTES = 120000
7
- const TEN_MINUTES = 600000
8
- const ONE_HOUR = 3600000
9
- const TWO_HOURS = 7200000
10
-
11
- const configMock = { default: { get: () => 'HOURLY' } }
12
- const buildStatusMock = { getStatus: () => undefined }
13
-
14
- test.beforeEach((t) => {
15
- t.context.sandbox = sinon.createSandbox()
16
- })
17
-
18
- test.afterEach.always((t) => {
19
- t.context.sandbox.restore()
20
- })
21
-
22
- test('checkPdfOutput returns N/A when no PDF files exist', async (t) => {
23
- const { sandbox } = t.context
24
-
25
- const { checkPdfOutput } = await esmock('./pdf-output.js', {
26
- 'node:fs': {
27
- existsSync: sandbox.stub().returns(false),
28
- },
29
- '#lib/project/output-paths.js': {
30
- getPdfOutputPaths: () => ['pagedjs.pdf', 'prince.pdf'],
31
- },
32
- '#lib/project/config.js': {
33
- loadProjectConfig: async () => ({}),
34
- },
35
- '#lib/conf/config.js': configMock,
36
- '#lib/conf/build-status.js': buildStatusMock,
37
- })
38
-
39
- const result = await checkPdfOutput()
40
-
41
- t.true(result.ok)
42
- t.is(result.level, 'na', 'should return N/A level when no PDF output')
43
- t.regex(result.message, /No PDF output found/)
44
- })
45
-
46
- test('checkPdfOutput includes remediation when no output found', async (t) => {
47
- const { sandbox } = t.context
48
-
49
- const { checkPdfOutput } = await esmock('./pdf-output.js', {
50
- 'node:fs': {
51
- existsSync: sandbox.stub().returns(false),
52
- },
53
- '#lib/project/output-paths.js': {
54
- getPdfOutputPaths: () => ['pagedjs.pdf', 'prince.pdf'],
55
- },
56
- '#lib/project/config.js': {
57
- loadProjectConfig: async () => ({}),
58
- },
59
- '#lib/conf/config.js': configMock,
60
- '#lib/conf/build-status.js': buildStatusMock,
61
- })
62
-
63
- const result = await checkPdfOutput()
64
-
65
- t.truthy(result.remediation)
66
- t.regex(result.remediation, /quire pdf/)
67
- t.regex(result.remediation, /failed/)
68
- t.truthy(result.docsUrl)
69
- })
70
-
71
- test('checkPdfOutput returns failure when last PDF generation failed and no output exists', async (t) => {
72
- const { sandbox } = t.context
73
-
74
- const { checkPdfOutput } = await esmock('./pdf-output.js', {
75
- 'node:fs': {
76
- existsSync: sandbox.stub().returns(false),
77
- },
78
- '#lib/project/output-paths.js': {
79
- getPdfOutputPaths: () => ['pagedjs.pdf', 'prince.pdf'],
80
- },
81
- '#lib/project/config.js': {
82
- loadProjectConfig: async () => ({}),
83
- },
84
- '#lib/conf/config.js': configMock,
85
- '#lib/conf/build-status.js': {
86
- getStatus: () => ({ status: 'failed', timestamp: Date.now() }),
87
- },
88
- })
89
-
90
- const result = await checkPdfOutput()
91
-
92
- t.false(result.ok)
93
- t.is(result.level, undefined)
94
- t.regex(result.message, /Last PDF generation failed/)
95
- t.truthy(result.remediation)
96
- t.regex(result.remediation, /quire pdf --debug/)
97
- t.truthy(result.docsUrl)
98
- })
99
-
100
- test('checkPdfOutput returns ok when PDF exists but no _site', async (t) => {
101
- const { sandbox } = t.context
102
-
103
- const existsSync = sandbox.stub()
104
- existsSync.withArgs('pagedjs.pdf').returns(true)
105
- existsSync.withArgs('prince.pdf').returns(false)
106
- existsSync.withArgs('_site').returns(false)
107
-
108
- const { checkPdfOutput } = await esmock('./pdf-output.js', {
109
- 'node:fs': {
110
- existsSync,
111
- },
112
- '#lib/project/output-paths.js': {
113
- getPdfOutputPaths: () => ['pagedjs.pdf', 'prince.pdf'],
114
- },
115
- '#lib/project/config.js': {
116
- loadProjectConfig: async () => ({}),
117
- },
118
- '#lib/conf/config.js': configMock,
119
- })
120
-
121
- const result = await checkPdfOutput()
122
-
123
- t.true(result.ok)
124
- t.regex(result.message, /pagedjs\.pdf exists/)
125
- t.regex(result.message, /no _site to compare/)
126
- })
127
-
128
- test('checkPdfOutput returns ok when PDF is up to date', async (t) => {
129
- const { sandbox } = t.context
130
-
131
- const now = Date.now()
132
- const pdfTime = now // PDF is current
133
- const siteTime = now - TEN_MINUTES // _site is older
134
-
135
- const existsSync = sandbox.stub()
136
- existsSync.withArgs('pagedjs.pdf').returns(true)
137
- existsSync.withArgs('prince.pdf').returns(false)
138
- existsSync.withArgs('_site').returns(true)
139
-
140
- const statSync = sandbox.stub()
141
- statSync.withArgs('_site').returns({ mtimeMs: siteTime })
142
- statSync.withArgs('pagedjs.pdf').returns({ mtimeMs: pdfTime })
143
-
144
- const { checkPdfOutput } = await esmock('./pdf-output.js', {
145
- 'node:fs': {
146
- existsSync,
147
- statSync,
148
- },
149
- '#lib/project/output-paths.js': {
150
- getPdfOutputPaths: () => ['pagedjs.pdf', 'prince.pdf'],
151
- },
152
- '#lib/project/config.js': {
153
- loadProjectConfig: async () => ({}),
154
- },
155
- '#lib/conf/config.js': configMock,
156
- })
157
-
158
- const result = await checkPdfOutput()
159
-
160
- t.true(result.ok)
161
- t.regex(result.message, /pagedjs\.pdf up to date/)
162
- })
163
-
164
- test('checkPdfOutput returns warning when PDF is stale beyond threshold', async (t) => {
165
- const { sandbox } = t.context
166
-
167
- const pdfTime = Date.now() - TWO_HOURS // 2 hours ago
168
- const siteTime = Date.now() // now
169
-
170
- const existsSync = sandbox.stub()
171
- existsSync.withArgs('pagedjs.pdf').returns(true)
172
- existsSync.withArgs('prince.pdf').returns(false)
173
- existsSync.withArgs('_site').returns(true)
174
-
175
- const statSync = sandbox.stub()
176
- statSync.withArgs('_site').returns({ mtimeMs: siteTime })
177
- statSync.withArgs('pagedjs.pdf').returns({ mtimeMs: pdfTime })
178
-
179
- const { checkPdfOutput } = await esmock('./pdf-output.js', {
180
- 'node:fs': {
181
- existsSync,
182
- statSync,
183
- },
184
- '#lib/project/output-paths.js': {
185
- getPdfOutputPaths: () => ['pagedjs.pdf', 'prince.pdf'],
186
- },
187
- '#lib/project/config.js': {
188
- loadProjectConfig: async () => ({}),
189
- },
190
- '#lib/conf/config.js': configMock,
191
- })
192
-
193
- const result = await checkPdfOutput()
194
-
195
- t.false(result.ok)
196
- t.is(result.level, 'warn')
197
- t.regex(result.message, /pagedjs\.pdf/)
198
- t.regex(result.message, /older than _site/)
199
- t.truthy(result.remediation)
200
- t.truthy(result.docsUrl)
201
- })
202
-
203
- test('checkPdfOutput returns ok when PDF is stale but within threshold', async (t) => {
204
- const { sandbox } = t.context
205
-
206
- const pdfTime = Date.now() - TWO_MINUTES // 2 minutes ago
207
- const siteTime = Date.now()
208
-
209
- const existsSync = sandbox.stub()
210
- existsSync.withArgs('pagedjs.pdf').returns(true)
211
- existsSync.withArgs('prince.pdf').returns(false)
212
- existsSync.withArgs('_site').returns(true)
213
-
214
- const statSync = sandbox.stub()
215
- statSync.withArgs('_site').returns({ mtimeMs: siteTime })
216
- statSync.withArgs('pagedjs.pdf').returns({ mtimeMs: pdfTime })
217
-
218
- const { checkPdfOutput } = await esmock('./pdf-output.js', {
219
- 'node:fs': {
220
- existsSync,
221
- statSync,
222
- },
223
- '#lib/project/output-paths.js': {
224
- getPdfOutputPaths: () => ['pagedjs.pdf', 'prince.pdf'],
225
- },
226
- '#lib/project/config.js': {
227
- loadProjectConfig: async () => ({}),
228
- },
229
- '#lib/conf/config.js': configMock,
230
- })
231
-
232
- const result = await checkPdfOutput()
233
-
234
- t.true(result.ok)
235
- t.regex(result.message, /pagedjs\.pdf up to date/)
236
- })
237
-
238
- test('checkPdfOutput checks multiple PDF files', async (t) => {
239
- const { sandbox } = t.context
240
-
241
- const now = Date.now()
242
- const pdfTime = now
243
- const siteTime = now - TEN_MINUTES
244
-
245
- const existsSync = sandbox.stub()
246
- existsSync.withArgs('pagedjs.pdf').returns(true)
247
- existsSync.withArgs('prince.pdf').returns(true)
248
- existsSync.withArgs('_site').returns(true)
249
-
250
- const statSync = sandbox.stub()
251
- statSync.withArgs('_site').returns({ mtimeMs: siteTime })
252
- statSync.withArgs('pagedjs.pdf').returns({ mtimeMs: pdfTime })
253
- statSync.withArgs('prince.pdf').returns({ mtimeMs: pdfTime })
254
-
255
- const { checkPdfOutput } = await esmock('./pdf-output.js', {
256
- 'node:fs': {
257
- existsSync,
258
- statSync,
259
- },
260
- '#lib/project/output-paths.js': {
261
- getPdfOutputPaths: () => ['pagedjs.pdf', 'prince.pdf'],
262
- },
263
- '#lib/project/config.js': {
264
- loadProjectConfig: async () => ({}),
265
- },
266
- '#lib/conf/config.js': configMock,
267
- })
268
-
269
- const result = await checkPdfOutput()
270
-
271
- t.true(result.ok)
272
- t.regex(result.message, /pagedjs\.pdf/)
273
- t.regex(result.message, /prince\.pdf/)
274
- })
275
-
276
- test('checkPdfOutput includes remediation with pdf command', async (t) => {
277
- const { sandbox } = t.context
278
-
279
- const pdfTime = Date.now() - TWO_HOURS
280
- const siteTime = Date.now()
281
-
282
- const existsSync = sandbox.stub()
283
- existsSync.withArgs('pagedjs.pdf').returns(true)
284
- existsSync.withArgs('prince.pdf').returns(false)
285
- existsSync.withArgs('_site').returns(true)
286
-
287
- const statSync = sandbox.stub()
288
- statSync.withArgs('_site').returns({ mtimeMs: siteTime })
289
- statSync.withArgs('pagedjs.pdf').returns({ mtimeMs: pdfTime })
290
-
291
- const { checkPdfOutput } = await esmock('./pdf-output.js', {
292
- 'node:fs': {
293
- existsSync,
294
- statSync,
295
- },
296
- '#lib/project/output-paths.js': {
297
- getPdfOutputPaths: () => ['pagedjs.pdf', 'prince.pdf'],
298
- },
299
- '#lib/project/config.js': {
300
- loadProjectConfig: async () => ({}),
301
- },
302
- '#lib/conf/config.js': configMock,
303
- })
304
-
305
- const result = await checkPdfOutput()
306
-
307
- t.false(result.ok)
308
- t.regex(result.remediation, /quire pdf/)
309
- })
310
-
311
- test('checkPdfOutput loads project config to resolve config-aware paths', async (t) => {
312
- const { sandbox } = t.context
313
-
314
- const pdfConfig = { outputDir: 'pdf', filename: 'my-publication' }
315
- const configPath = path.join('_site', 'pdf', 'my-publication.pdf')
316
-
317
- const existsSync = sandbox.stub().returns(false)
318
- existsSync.withArgs(configPath).returns(true)
319
- existsSync.withArgs('_site').returns(true)
320
-
321
- const now = Date.now()
322
- const statSync = sandbox.stub()
323
- statSync.withArgs('_site').returns({ mtimeMs: now - TEN_MINUTES })
324
- statSync.withArgs(configPath).returns({ mtimeMs: now })
325
-
326
- const { checkPdfOutput } = await esmock('./pdf-output.js', {
327
- 'node:fs': {
328
- existsSync,
329
- statSync,
330
- },
331
- '#lib/project/output-paths.js': {
332
- getPdfOutputPaths: (opts) => {
333
- const paths = []
334
- if (opts.pdfConfig) {
335
- paths.push(configPath)
336
- }
337
- paths.push('pagedjs.pdf', 'prince.pdf')
338
- return paths
339
- },
340
- },
341
- '#lib/project/config.js': {
342
- loadProjectConfig: async () => ({ pdf: pdfConfig }),
343
- },
344
- '#lib/conf/config.js': configMock,
345
- })
346
-
347
- const result = await checkPdfOutput()
348
-
349
- t.true(result.ok)
350
- t.regex(result.message, /my-publication\.pdf up to date/)
351
- })
352
-
353
- test('checkPdfOutput falls back to engine defaults when config loading fails', async (t) => {
354
- const { sandbox } = t.context
355
-
356
- const { checkPdfOutput } = await esmock('./pdf-output.js', {
357
- 'node:fs': {
358
- existsSync: sandbox.stub().returns(false),
359
- },
360
- '#lib/project/output-paths.js': {
361
- getPdfOutputPaths: (opts) => {
362
- t.is(opts.pdfConfig, undefined, 'pdfConfig should be undefined when config fails')
363
- return ['pagedjs.pdf', 'prince.pdf']
364
- },
365
- },
366
- '#lib/project/config.js': {
367
- loadProjectConfig: async () => { throw new Error('No config.yaml') },
368
- },
369
- '#lib/conf/config.js': configMock,
370
- '#lib/conf/build-status.js': buildStatusMock,
371
- })
372
-
373
- const result = await checkPdfOutput()
374
-
375
- t.true(result.ok)
376
- t.is(result.level, 'na')
377
- })
@@ -1,122 +0,0 @@
1
- /**
2
- * Stale build check
3
- *
4
- * @module lib/doctor/checks/outputs/stale-build
5
- */
6
- import fs from 'node:fs'
7
- import path from 'node:path'
8
- import { SOURCE_DIRECTORIES } from '#lib/project/index.js'
9
- import config from '#lib/conf/config.js'
10
- import { getStatus } from '#lib/conf/build-status.js'
11
- import createDebug from '#debug'
12
- import { DOCS_BASE_URL, resolveStaleThreshold } from '#lib/doctor/constants.js'
13
- import { formatDuration } from '#lib/doctor/formatDuration.js'
14
-
15
- const debug = createDebug('lib:doctor:stale-build')
16
-
17
- /**
18
- * Get the latest modification time from files in a directory (recursive)
19
- * @param {string} dir - Directory to scan
20
- * @returns {number} - Latest modified timestamp in milliseconds, or 0 if directory doesn't exist
21
- */
22
- function getLatestModified(dir) {
23
- if (!fs.existsSync(dir)) {
24
- return 0
25
- }
26
-
27
- let newest = 0
28
-
29
- const scan = (currentDir) => {
30
- const entries = fs.readdirSync(currentDir, { withFileTypes: true })
31
- for (const entry of entries) {
32
- const fullPath = path.join(currentDir, entry.name)
33
- try {
34
- const { mtimeMs: lastModified } = fs.statSync(fullPath)
35
- if (lastModified > newest) {
36
- newest = lastModified
37
- }
38
- if (entry.isDirectory()) {
39
- scan(fullPath)
40
- }
41
- } catch {
42
- // Skip files we can't stat (permissions, etc.)
43
- }
44
- }
45
- }
46
-
47
- scan(dir)
48
- return newest
49
- }
50
-
51
- /**
52
- * Check if build output is stale (source files newer than _site)
53
- * @returns {import('../../index.js').CheckResult}
54
- */
55
- export function checkStaleBuild() {
56
- const siteDir = '_site'
57
-
58
- // Skip if not in a project or no build output exists
59
- if (!fs.existsSync(siteDir)) {
60
- debug('No _site directory found, checking stored build status')
61
-
62
- const status = getStatus(process.cwd(), 'build')
63
- if (status?.status === 'failed') {
64
- debug('Last build failed (stored status)')
65
- return {
66
- ok: false,
67
- message: 'Last build failed',
68
- remediation: `The last "quire build" run failed. Check the output for errors and try again.
69
- • Run "quire build --debug" for detailed error output`,
70
- docsUrl: `${DOCS_BASE_URL}/quire-commands/#preview-and-build`,
71
- }
72
- }
73
-
74
- return {
75
- ok: true,
76
- level: 'na',
77
- message: 'No build output found',
78
- remediation: `Run "quire build" to generate the site.
79
- • If you already ran "quire build" and it failed, check the output for errors`,
80
- docsUrl: `${DOCS_BASE_URL}/quire-commands/#preview-and-build`,
81
- }
82
- }
83
-
84
- // Get _site last modified time
85
- const { mtimeMs: siteLastModified } = fs.statSync(siteDir)
86
- debug('_site lastModified: %d', siteLastModified)
87
-
88
- // Find newest source file across all source directories
89
- let newestSourceLastModified = 0
90
- for (const dir of SOURCE_DIRECTORIES) {
91
- const lastModified = getLatestModified(dir)
92
- if (lastModified > newestSourceLastModified) {
93
- newestSourceLastModified = lastModified
94
- }
95
- }
96
- debug('Newest source lastModified: %d', newestSourceLastModified)
97
-
98
- // If source is newer than build by more than the stale threshold, warn
99
- const thresholdMs = resolveStaleThreshold(config.get('staleThreshold'))
100
- const staleDelta = newestSourceLastModified - siteLastModified
101
- debug('stale delta: %dms, threshold: %dms (%s)', staleDelta, thresholdMs, config.get('staleThreshold'))
102
-
103
- if (staleDelta > thresholdMs) {
104
- const staleDuration = formatDuration(staleDelta)
105
- return {
106
- ok: false,
107
- level: 'warn',
108
- message: `Build output is ${staleDuration} older than source files`,
109
- remediation: `Your build output may not reflect recent changes.
110
- • Run "quire build" to regenerate the site
111
- • Or run "quire preview" which auto-rebuilds on changes`,
112
- docsUrl: `${DOCS_BASE_URL}/quire-commands/#preview-and-build`,
113
- }
114
- }
115
-
116
- return {
117
- ok: true,
118
- message: 'Build output is up to date',
119
- }
120
- }
121
-
122
- export default checkStaleBuild