@thegetty/quire-cli 1.0.0-rc.37 → 1.0.0-rc.38

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 (85) hide show
  1. package/package.json +3 -2
  2. package/src/commands/build.js +13 -6
  3. package/src/commands/clean.js +10 -2
  4. package/src/commands/clean.spec.js +10 -0
  5. package/src/commands/clean.test.js +122 -0
  6. package/src/commands/config.js +3 -1
  7. package/src/commands/config.test.js +42 -1
  8. package/src/commands/doctor.js +251 -0
  9. package/src/commands/doctor.spec.js +115 -0
  10. package/src/commands/doctor.test.js +1409 -0
  11. package/src/commands/epub.js +9 -2
  12. package/src/commands/info.js +79 -71
  13. package/src/commands/info.spec.js +8 -0
  14. package/src/commands/info.test.js +173 -76
  15. package/src/commands/pdf.js +10 -3
  16. package/src/commands/validate.js +39 -7
  17. package/src/commands/validate.spec.js +8 -0
  18. package/src/commands/validate.test.js +144 -0
  19. package/src/lib/README.md +77 -22
  20. package/src/lib/conf/README.md +6 -0
  21. package/src/lib/conf/build-status.js +103 -0
  22. package/src/lib/conf/build-status.test.js +247 -0
  23. package/src/lib/conf/defaults.js +14 -0
  24. package/src/lib/conf/format.js +1 -1
  25. package/src/lib/conf/schema.js +46 -1
  26. package/src/lib/constants.js +28 -0
  27. package/src/lib/doctor/README.md +667 -0
  28. package/src/lib/doctor/checks/environment/cli-version.js +62 -0
  29. package/src/lib/doctor/checks/environment/cli-version.test.js +132 -0
  30. package/src/lib/doctor/checks/environment/git-available.js +77 -0
  31. package/src/lib/doctor/checks/environment/git-available.test.js +52 -0
  32. package/src/lib/doctor/checks/environment/index.js +13 -0
  33. package/src/lib/doctor/checks/environment/node-version.js +66 -0
  34. package/src/lib/doctor/checks/environment/node-version.test.js +17 -0
  35. package/src/lib/doctor/checks/environment/npm-available.js +66 -0
  36. package/src/lib/doctor/checks/environment/npm-available.test.js +52 -0
  37. package/src/lib/doctor/checks/environment/os-info.js +48 -0
  38. package/src/lib/doctor/checks/environment/os-info.test.js +81 -0
  39. package/src/lib/doctor/checks/environment/runtime-info.js +51 -0
  40. package/src/lib/doctor/checks/environment/runtime-info.test.js +132 -0
  41. package/src/lib/doctor/checks/outputs/epub-output.js +119 -0
  42. package/src/lib/doctor/checks/outputs/epub-output.test.js +277 -0
  43. package/src/lib/doctor/checks/outputs/index.js +10 -0
  44. package/src/lib/doctor/checks/outputs/pdf-output.js +144 -0
  45. package/src/lib/doctor/checks/outputs/pdf-output.test.js +377 -0
  46. package/src/lib/doctor/checks/outputs/stale-build.js +122 -0
  47. package/src/lib/doctor/checks/outputs/stale-build.test.js +282 -0
  48. package/src/lib/doctor/checks/project/data-files.js +56 -0
  49. package/src/lib/doctor/checks/project/data-files.test.js +125 -0
  50. package/src/lib/doctor/checks/project/dependencies.js +53 -0
  51. package/src/lib/doctor/checks/project/dependencies.test.js +71 -0
  52. package/src/lib/doctor/checks/project/index.js +11 -0
  53. package/src/lib/doctor/checks/project/quire-11ty.js +98 -0
  54. package/src/lib/doctor/checks/project/quire-11ty.test.js +170 -0
  55. package/src/lib/doctor/checks/project/quire-project.js +38 -0
  56. package/src/lib/doctor/checks/project/quire-project.test.js +47 -0
  57. package/src/lib/doctor/checks/tools/index.js +10 -0
  58. package/src/lib/doctor/checks/tools/pandoc-available.js +82 -0
  59. package/src/lib/doctor/checks/tools/pandoc-available.test.js +73 -0
  60. package/src/lib/doctor/checks/tools/prince-available.js +81 -0
  61. package/src/lib/doctor/checks/tools/prince-available.test.js +73 -0
  62. package/src/lib/doctor/constants.js +39 -0
  63. package/src/lib/doctor/formatDuration.js +108 -0
  64. package/src/lib/doctor/formatDuration.test.js +76 -0
  65. package/src/lib/doctor/formatters/human.js +257 -0
  66. package/src/lib/doctor/formatters/human.test.js +463 -0
  67. package/src/lib/doctor/formatters/index.js +8 -0
  68. package/src/lib/doctor/formatters/json.js +78 -0
  69. package/src/lib/doctor/formatters/json.test.js +174 -0
  70. package/src/lib/doctor/formatters/shared.js +129 -0
  71. package/src/lib/doctor/formatters/shared.test.js +194 -0
  72. package/src/lib/doctor/index.js +271 -0
  73. package/src/lib/doctor/index.test.js +797 -0
  74. package/src/lib/platform.js +95 -0
  75. package/src/lib/project/build.js +44 -25
  76. package/src/lib/project/build.test.js +30 -8
  77. package/src/lib/project/detect.js +16 -2
  78. package/src/lib/project/index.js +18 -2
  79. package/src/lib/project/output-paths.js +87 -0
  80. package/src/lib/project/output-paths.test.js +66 -0
  81. package/src/lib/project/paths.js +48 -0
  82. package/src/main.js +24 -2
  83. package/src/packageConfig.js +17 -0
  84. package/src/validators/validate-data-files.js +154 -0
  85. package/src/validators/validate-data-files.test.js +217 -0
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Platform detection utilities
3
+ *
4
+ * Provides OS detection and platform-specific helpers for the CLI.
5
+ *
6
+ * @module lib/platform
7
+ */
8
+ import os from 'node:os'
9
+
10
+ /**
11
+ * Platform identifiers
12
+ * @readonly
13
+ * @enum {string}
14
+ */
15
+ export const Platform = {
16
+ MACOS: 'macos',
17
+ WINDOWS: 'windows',
18
+ LINUX: 'linux',
19
+ UNKNOWN: 'unknown',
20
+ }
21
+
22
+ /**
23
+ * Get the current platform identifier
24
+ * @returns {string} Platform identifier (macos, windows, linux, or unknown)
25
+ */
26
+ export function getPlatform() {
27
+ switch (process.platform) {
28
+ case 'darwin':
29
+ return Platform.MACOS
30
+ case 'win32':
31
+ return Platform.WINDOWS
32
+ case 'linux':
33
+ return Platform.LINUX
34
+ default:
35
+ return Platform.UNKNOWN
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Get a human-readable platform name
41
+ * @returns {string} Human-readable OS name (e.g., "macOS 14.0", "Windows 11", "Linux")
42
+ */
43
+ export function getPlatformName() {
44
+ const platform = getPlatform()
45
+ const release = os.release()
46
+
47
+ switch (platform) {
48
+ case Platform.MACOS: {
49
+ // Darwin kernel version to macOS version mapping (approximate)
50
+ const majorVersion = parseInt(release.split('.')[0], 10)
51
+ // Darwin 23.x = macOS 14 (Sonoma), 22.x = macOS 13, etc.
52
+ const macOSVersion = majorVersion >= 20 ? majorVersion - 9 : majorVersion - 4
53
+ return `macOS ${macOSVersion >= 14 ? macOSVersion : release}`
54
+ }
55
+ case Platform.WINDOWS:
56
+ return `Windows (${release})`
57
+ case Platform.LINUX:
58
+ return `Linux (${release})`
59
+ default:
60
+ return `${process.platform} (${release})`
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Check if running on macOS
66
+ * @returns {boolean}
67
+ */
68
+ export function isMacOS() {
69
+ return process.platform === 'darwin'
70
+ }
71
+
72
+ /**
73
+ * Check if running on Windows
74
+ * @returns {boolean}
75
+ */
76
+ export function isWindows() {
77
+ return process.platform === 'win32'
78
+ }
79
+
80
+ /**
81
+ * Check if running on Linux
82
+ * @returns {boolean}
83
+ */
84
+ export function isLinux() {
85
+ return process.platform === 'linux'
86
+ }
87
+
88
+ export default {
89
+ Platform,
90
+ getPlatform,
91
+ getPlatformName,
92
+ isMacOS,
93
+ isWindows,
94
+ isLinux,
95
+ }
@@ -2,12 +2,15 @@
2
2
  * Build detection module
3
3
  *
4
4
  * Detects if build output exists and provides build status information.
5
+ * Uses shared output path resolution to ensure consistency with the
6
+ * doctor command and generation commands.
5
7
  *
6
8
  * @module lib/project/build
7
9
  */
8
10
  import fs from 'node:fs'
9
11
  import path from 'node:path'
10
12
  import paths from './paths.js'
13
+ import { getPdfOutputPaths, getEpubOutputPaths, getEpubBuildDir } from './output-paths.js'
11
14
 
12
15
  /**
13
16
  * Get build output information
@@ -17,45 +20,60 @@ import paths from './paths.js'
17
20
  */
18
21
  export function getBuildInfo(projectRoot = paths.getProjectRoot()) {
19
22
  const sitePath = path.join(projectRoot, '_site')
20
- const epubPath = path.join(projectRoot, '_epub')
21
- const pdfFiles = ['pagedjs.pdf', 'prince.pdf']
23
+ const epubBuildPath = getEpubBuildDir({ projectRoot })
22
24
 
23
25
  const info = {
24
26
  site: {
25
27
  exists: fs.existsSync(sitePath),
26
28
  path: sitePath,
27
- mtime: null,
29
+ lastModified: null,
28
30
  },
29
31
  epub: {
30
- exists: fs.existsSync(epubPath),
31
- path: epubPath,
32
- mtime: null,
32
+ exists: false,
33
+ paths: [],
34
+ buildDir: epubBuildPath,
35
+ buildDirExists: fs.existsSync(epubBuildPath),
36
+ lastModified: null,
33
37
  },
34
38
  pdf: {
35
39
  exists: false,
36
40
  paths: [],
37
- mtime: null,
41
+ lastModified: null,
38
42
  },
39
43
  }
40
44
 
41
- // Get modification times if directories exist
45
+ // Get last modified times if directories exist
42
46
  if (info.site.exists) {
43
- info.site.mtime = fs.statSync(sitePath).mtime
47
+ const { mtime: lastModified } = fs.statSync(sitePath)
48
+ info.site.lastModified = lastModified
44
49
  }
45
- if (info.epub.exists) {
46
- info.epub.mtime = fs.statSync(epubPath).mtime
50
+ if (info.epub.buildDirExists) {
51
+ const { mtime: lastModified } = fs.statSync(epubBuildPath)
52
+ info.epub.lastModified = lastModified
47
53
  }
48
54
 
49
- // Check for PDF files
50
- for (const file of pdfFiles) {
51
- const pdfPath = path.join(projectRoot, file)
55
+ // Check for EPUB files using shared path resolution
56
+ const epubPaths = getEpubOutputPaths({ projectRoot })
57
+ for (const epubPath of epubPaths) {
58
+ if (fs.existsSync(epubPath)) {
59
+ info.epub.exists = true
60
+ info.epub.paths.push(epubPath)
61
+ const { mtime: lastModified } = fs.statSync(epubPath)
62
+ if (!info.epub.lastModified || lastModified > info.epub.lastModified) {
63
+ info.epub.lastModified = lastModified
64
+ }
65
+ }
66
+ }
67
+
68
+ // Check for PDF files using shared path resolution
69
+ const pdfPaths = getPdfOutputPaths({ projectRoot })
70
+ for (const pdfPath of pdfPaths) {
52
71
  if (fs.existsSync(pdfPath)) {
53
72
  info.pdf.exists = true
54
73
  info.pdf.paths.push(pdfPath)
55
- // Use most recent mtime if multiple PDFs exist
56
- const mtime = fs.statSync(pdfPath).mtime
57
- if (!info.pdf.mtime || mtime > info.pdf.mtime) {
58
- info.pdf.mtime = mtime
74
+ const { mtime: lastModified } = fs.statSync(pdfPath)
75
+ if (!info.pdf.lastModified || lastModified > info.pdf.lastModified) {
76
+ info.pdf.lastModified = lastModified
59
77
  }
60
78
  }
61
79
  }
@@ -77,20 +95,21 @@ export function hasSiteOutput(projectRoot = paths.getProjectRoot()) {
77
95
  /**
78
96
  * Check if epub build output exists
79
97
  *
98
+ * Checks for the intermediate _epub build directory.
99
+ *
80
100
  * @param {string} [projectRoot] - Project root directory (defaults to cwd)
81
101
  * @returns {boolean} True if _epub directory exists
82
102
  */
83
103
  export function hasEpubOutput(projectRoot = paths.getProjectRoot()) {
84
- const epubPath = path.join(projectRoot, '_epub')
104
+ const epubPath = getEpubBuildDir({ projectRoot })
85
105
  return fs.existsSync(epubPath)
86
106
  }
87
107
 
88
108
  /**
89
109
  * Check if PDF output exists
90
110
  *
91
- * Checks for PDF output at common locations:
92
- * - Default library outputs: pagedjs.pdf, prince.pdf
93
- * - Specific library output when lib option provided
111
+ * Uses shared path resolution to check all possible PDF output locations,
112
+ * including config-aware custom paths and default engine-named paths.
94
113
  *
95
114
  * @param {Object} [options]
96
115
  * @param {string} [options.lib] - Specific library to check ('pagedjs' or 'prince')
@@ -105,9 +124,9 @@ export function hasPdfOutput(options = {}) {
105
124
  return fs.existsSync(pdfPath)
106
125
  }
107
126
 
108
- // Check for any common PDF output
109
- const pdfFiles = ['pagedjs.pdf', 'prince.pdf']
110
- return pdfFiles.some((file) => fs.existsSync(path.join(projectRoot, file)))
127
+ // Check all possible PDF output locations
128
+ const pdfPaths = getPdfOutputPaths({ projectRoot })
129
+ return pdfPaths.some((pdfPath) => fs.existsSync(pdfPath))
111
130
  }
112
131
 
113
132
  /**
@@ -84,6 +84,7 @@ test('getBuildInfo returns correct status for existing builds', async (t) => {
84
84
  vol.fromJSON({
85
85
  [memfsPath('_site', 'index.html')]: '<html></html>',
86
86
  [memfsPath('_epub', 'content.opf')]: '<package></package>',
87
+ [memfsPath('epubjs.epub')]: 'PK\x03\x04',
87
88
  [memfsPath('pagedjs.pdf')]: '%PDF-1.4',
88
89
  })
89
90
 
@@ -95,15 +96,17 @@ test('getBuildInfo returns correct status for existing builds', async (t) => {
95
96
 
96
97
  t.true(info.site.exists)
97
98
  t.is(info.site.path, nativePath('_site'))
98
- t.truthy(info.site.mtime)
99
+ t.truthy(info.site.lastModified)
99
100
 
100
101
  t.true(info.epub.exists)
101
- t.is(info.epub.path, nativePath('_epub'))
102
- t.truthy(info.epub.mtime)
102
+ t.true(info.epub.buildDirExists)
103
+ t.is(info.epub.buildDir, nativePath('_epub'))
104
+ t.true(info.epub.paths.includes(nativePath('epubjs.epub')))
105
+ t.truthy(info.epub.lastModified)
103
106
 
104
107
  t.true(info.pdf.exists)
105
108
  t.deepEqual(info.pdf.paths, [nativePath('pagedjs.pdf')])
106
- t.truthy(info.pdf.mtime)
109
+ t.truthy(info.pdf.lastModified)
107
110
  })
108
111
 
109
112
  test('getBuildInfo returns correct status for missing builds', async (t) => {
@@ -120,14 +123,15 @@ test('getBuildInfo returns correct status for missing builds', async (t) => {
120
123
  const info = getBuildInfo(testRoot)
121
124
 
122
125
  t.false(info.site.exists)
123
- t.is(info.site.mtime, null)
126
+ t.is(info.site.lastModified, null)
124
127
 
125
128
  t.false(info.epub.exists)
126
- t.is(info.epub.mtime, null)
129
+ t.false(info.epub.buildDirExists)
130
+ t.is(info.epub.lastModified, null)
127
131
 
128
132
  t.false(info.pdf.exists)
129
133
  t.deepEqual(info.pdf.paths, [])
130
- t.is(info.pdf.mtime, null)
134
+ t.is(info.pdf.lastModified, null)
131
135
  })
132
136
 
133
137
  test('getBuildInfo returns multiple PDF paths when both exist', async (t) => {
@@ -148,7 +152,25 @@ test('getBuildInfo returns multiple PDF paths when both exist', async (t) => {
148
152
  t.is(info.pdf.paths.length, 2)
149
153
  t.true(info.pdf.paths.includes(nativePath('pagedjs.pdf')))
150
154
  t.true(info.pdf.paths.includes(nativePath('prince.pdf')))
151
- t.truthy(info.pdf.mtime)
155
+ t.truthy(info.pdf.lastModified)
156
+ })
157
+
158
+ test('getBuildInfo detects epub build dir without .epub files', async (t) => {
159
+ const { vol } = t.context
160
+
161
+ vol.fromJSON({
162
+ [memfsPath('_epub', 'content.opf')]: '<package></package>',
163
+ })
164
+
165
+ const { getBuildInfo } = await esmock('./build.js', {
166
+ 'node:fs': createFsFromVolume(vol),
167
+ })
168
+
169
+ const info = getBuildInfo(testRoot)
170
+
171
+ t.false(info.epub.exists, 'no .epub files should mean exists is false')
172
+ t.true(info.epub.buildDirExists, '_epub directory should be detected')
173
+ t.truthy(info.epub.lastModified, 'lastModified from _epub dir should be present')
152
174
  })
153
175
 
154
176
  test('requireBuildOutput throws when site output missing', async (t) => {
@@ -7,7 +7,21 @@
7
7
  */
8
8
  import fs from 'node:fs'
9
9
 
10
- const QUIRE_DOT_FILES = Object.freeze([
10
+ /**
11
+ * Files that indicate a Quire project directory.
12
+ *
13
+ * These marker files are created by `quire new` or exist in Quire project templates.
14
+ * The presence of any one of these files indicates the directory is a Quire project root.
15
+ *
16
+ * @constant {ReadonlyArray<string>}
17
+ *
18
+ * @example
19
+ * // Check if a file is a project marker
20
+ * if (PROJECT_MARKERS.includes(filename)) {
21
+ * console.log('This is a Quire project root')
22
+ * }
23
+ */
24
+ export const PROJECT_MARKERS = Object.freeze([
11
25
  '.eleventy.js',
12
26
  '.quire',
13
27
  '.quire-11ty',
@@ -29,5 +43,5 @@ const QUIRE_DOT_FILES = Object.freeze([
29
43
  */
30
44
  export default function (dirpath) {
31
45
  return fs.readdirSync(dirpath)
32
- .find((entry) => QUIRE_DOT_FILES.includes(entry))
46
+ .find((entry) => PROJECT_MARKERS.includes(entry))
33
47
  }
@@ -4,8 +4,8 @@
4
4
  * Provides project-level concerns including paths, detection, configuration,
5
5
  * build status, and version management.
6
6
  */
7
- import paths, { Paths } from './paths.js'
8
- import detect from './detect.js'
7
+ import paths, { DATA_DIR, Paths, REQUIRED_DATA_FILES, SOURCE_DIRECTORIES } from './paths.js'
8
+ import detect, { PROJECT_MARKERS } from './detect.js'
9
9
  import { loadProjectConfig } from './config.js'
10
10
  import {
11
11
  getBuildInfo,
@@ -14,6 +14,13 @@ import {
14
14
  hasSiteOutput,
15
15
  requireBuildOutput,
16
16
  } from './build.js'
17
+ import {
18
+ getPdfOutputPaths,
19
+ getEpubOutputPaths,
20
+ getEpubBuildDir,
21
+ PDF_ENGINES,
22
+ EPUB_ENGINES,
23
+ } from './output-paths.js'
17
24
  import {
18
25
  getVersion,
19
26
  setVersion,
@@ -23,8 +30,17 @@ import {
23
30
  } from './version.js'
24
31
 
25
32
  export {
33
+ DATA_DIR,
34
+ EPUB_ENGINES,
35
+ PDF_ENGINES,
36
+ PROJECT_MARKERS,
37
+ REQUIRED_DATA_FILES,
38
+ SOURCE_DIRECTORIES,
26
39
  detect,
27
40
  getBuildInfo,
41
+ getEpubBuildDir,
42
+ getEpubOutputPaths,
43
+ getPdfOutputPaths,
28
44
  hasEpubOutput,
29
45
  hasPdfOutput,
30
46
  hasSiteOutput,
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Output path resolution module
3
+ *
4
+ * Centralizes knowledge of where PDF and EPUB output files are located.
5
+ * Used by the doctor command and build detection to find output artifacts
6
+ * using the same logic as the generation commands.
7
+ *
8
+ * @module lib/project/output-paths
9
+ */
10
+ import path from 'node:path'
11
+ import { ENGINES as PDF_ENGINES } from '#lib/pdf/schema.js'
12
+ import { ENGINES as EPUB_ENGINES } from '#lib/epub/schema.js'
13
+
14
+ export { PDF_ENGINES, EPUB_ENGINES }
15
+
16
+ /**
17
+ * Get all possible PDF output file paths for a project
18
+ *
19
+ * PDF output paths depend on configuration:
20
+ * - With config.pdf: `{outputDir}/{config.pdf.outputDir}/{config.pdf.filename}.pdf`
21
+ * - Without config (default): `{projectRoot}/{engine}.pdf`
22
+ *
23
+ * This reuses the same resolution logic as `lib/pdf/index.js#getOutputPath`.
24
+ *
25
+ * @param {Object} [options]
26
+ * @param {string} [options.projectRoot=process.cwd()] - Project root directory
27
+ * @param {string} [options.outputDir='_site'] - Build output directory (relative)
28
+ * @param {Object} [options.pdfConfig] - PDF config from config.yaml (config.pdf)
29
+ * @param {string} [options.pdfConfig.outputDir] - PDF output subdirectory
30
+ * @param {string} [options.pdfConfig.filename] - PDF filename (without extension)
31
+ * @returns {string[]} Array of absolute paths to check for PDF output
32
+ */
33
+ export function getPdfOutputPaths(options = {}) {
34
+ const {
35
+ projectRoot = process.cwd(),
36
+ outputDir = '_site',
37
+ pdfConfig,
38
+ } = options
39
+
40
+ const paths = []
41
+
42
+ if (pdfConfig && pdfConfig.outputDir && pdfConfig.filename) {
43
+ // Config-aware path: matches lib/pdf/index.js getOutputPath()
44
+ paths.push(
45
+ path.join(projectRoot, outputDir, pdfConfig.outputDir, `${pdfConfig.filename}.pdf`)
46
+ )
47
+ }
48
+
49
+ // Default engine-named paths (always check these as fallback)
50
+ for (const engine of PDF_ENGINES) {
51
+ paths.push(path.join(projectRoot, `${engine}.pdf`))
52
+ }
53
+
54
+ return paths
55
+ }
56
+
57
+ /**
58
+ * Get all possible EPUB output file paths for a project
59
+ *
60
+ * EPUB output is at `{projectRoot}/{engine}.epub` for each supported engine.
61
+ * The `_epub` directory is an intermediate build artifact, not the final output.
62
+ *
63
+ * This reuses the same resolution logic as `commands/epub.js`.
64
+ *
65
+ * @param {Object} [options]
66
+ * @param {string} [options.projectRoot=process.cwd()] - Project root directory
67
+ * @returns {string[]} Array of absolute paths to check for EPUB output
68
+ */
69
+ export function getEpubOutputPaths(options = {}) {
70
+ const { projectRoot = process.cwd() } = options
71
+
72
+ return EPUB_ENGINES.map(
73
+ (engine) => path.join(projectRoot, `${engine}.epub`)
74
+ )
75
+ }
76
+
77
+ /**
78
+ * Get the intermediate EPUB build directory path
79
+ *
80
+ * @param {Object} [options]
81
+ * @param {string} [options.projectRoot=process.cwd()] - Project root directory
82
+ * @returns {string} Absolute path to _epub directory
83
+ */
84
+ export function getEpubBuildDir(options = {}) {
85
+ const { projectRoot = process.cwd() } = options
86
+ return path.join(projectRoot, '_epub')
87
+ }
@@ -0,0 +1,66 @@
1
+ import test from 'ava'
2
+ import path from 'node:path'
3
+ import { getPdfOutputPaths, getEpubOutputPaths, getEpubBuildDir } from './output-paths.js'
4
+
5
+ const projectRoot = '/test-project'
6
+
7
+ test('getPdfOutputPaths returns default engine paths', (t) => {
8
+ const paths = getPdfOutputPaths({ projectRoot })
9
+
10
+ t.true(paths.includes(path.join(projectRoot, 'pagedjs.pdf')))
11
+ t.true(paths.includes(path.join(projectRoot, 'prince.pdf')))
12
+ })
13
+
14
+ test('getPdfOutputPaths includes config-aware path when pdfConfig provided', (t) => {
15
+ const pdfConfig = { outputDir: 'pdf', filename: 'my-publication' }
16
+ const paths = getPdfOutputPaths({ projectRoot, outputDir: '_site', pdfConfig })
17
+
18
+ // Config path should be first
19
+ t.is(paths[0], path.join(projectRoot, '_site', 'pdf', 'my-publication.pdf'))
20
+ // Default paths should still be present
21
+ t.true(paths.includes(path.join(projectRoot, 'pagedjs.pdf')))
22
+ t.true(paths.includes(path.join(projectRoot, 'prince.pdf')))
23
+ })
24
+
25
+ test('getPdfOutputPaths skips config path when pdfConfig is incomplete', (t) => {
26
+ // Missing filename
27
+ const paths = getPdfOutputPaths({ projectRoot, pdfConfig: { outputDir: 'pdf' } })
28
+
29
+ // Should only have default engine paths
30
+ t.is(paths.length, 2)
31
+ t.true(paths.includes(path.join(projectRoot, 'pagedjs.pdf')))
32
+ t.true(paths.includes(path.join(projectRoot, 'prince.pdf')))
33
+ })
34
+
35
+ test('getPdfOutputPaths uses cwd when no projectRoot provided', (t) => {
36
+ const paths = getPdfOutputPaths()
37
+
38
+ t.true(paths.includes(path.join(process.cwd(), 'pagedjs.pdf')))
39
+ t.true(paths.includes(path.join(process.cwd(), 'prince.pdf')))
40
+ })
41
+
42
+ test('getEpubOutputPaths returns default engine paths', (t) => {
43
+ const paths = getEpubOutputPaths({ projectRoot })
44
+
45
+ t.true(paths.includes(path.join(projectRoot, 'epubjs.epub')))
46
+ t.true(paths.includes(path.join(projectRoot, 'pandoc.epub')))
47
+ })
48
+
49
+ test('getEpubOutputPaths uses cwd when no projectRoot provided', (t) => {
50
+ const paths = getEpubOutputPaths()
51
+
52
+ t.true(paths.includes(path.join(process.cwd(), 'epubjs.epub')))
53
+ t.true(paths.includes(path.join(process.cwd(), 'pandoc.epub')))
54
+ })
55
+
56
+ test('getEpubBuildDir returns _epub path', (t) => {
57
+ const dir = getEpubBuildDir({ projectRoot })
58
+
59
+ t.is(dir, path.join(projectRoot, '_epub'))
60
+ })
61
+
62
+ test('getEpubBuildDir uses cwd when no projectRoot provided', (t) => {
63
+ const dir = getEpubBuildDir()
64
+
65
+ t.is(dir, path.join(process.cwd(), '_epub'))
66
+ })
@@ -5,6 +5,54 @@ import path from 'node:path'
5
5
  const __filename = fileURLToPath(import.meta.url)
6
6
  const __dirname = path.dirname(__filename)
7
7
 
8
+ /**
9
+ * Source directories that contain content for building.
10
+ *
11
+ * These directories are monitored for changes during preview and are used
12
+ * to determine if a build is stale. Changes to files in these directories
13
+ * indicate the site needs to be rebuilt.
14
+ *
15
+ * @constant {ReadonlyArray<string>}
16
+ *
17
+ * @example
18
+ * // Check all source directories for changes
19
+ * for (const dir of SOURCE_DIRECTORIES) {
20
+ * const mtime = getLatestMtime(dir)
21
+ * // ...
22
+ * }
23
+ */
24
+ export const SOURCE_DIRECTORIES = Object.freeze([
25
+ '_data',
26
+ '_includes',
27
+ '_layouts',
28
+ 'content',
29
+ 'static',
30
+ ])
31
+
32
+ /**
33
+ * Path to data files directory (relative to project root)
34
+ *
35
+ * Contains YAML configuration files for the publication:
36
+ * - publication.yaml - Publication metadata
37
+ * - config.yaml - Site configuration
38
+ * - figures.yaml - Figure definitions
39
+ * - objects.yaml - Object catalog entries
40
+ * - references.yaml - Bibliography entries
41
+ *
42
+ * @constant {string}
43
+ */
44
+ export const DATA_DIR = 'content/_data'
45
+
46
+ /**
47
+ * Required data files that must exist in a Quire project.
48
+ *
49
+ * These files are validated by the doctor command and the validate command.
50
+ * Missing required files will trigger a warning.
51
+ *
52
+ * @constant {ReadonlyArray<string>}
53
+ */
54
+ export const REQUIRED_DATA_FILES = Object.freeze(['publication.yaml'])
55
+
8
56
  /**
9
57
  * Project path configuration
10
58
  *
package/src/main.js CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  import commands from '#src/commands/index.js'
10
10
  import config from '#lib/conf/config.js'
11
11
  import { handleError } from '#lib/error/handler.js'
12
+ import reporter from '#lib/reporter/index.js'
12
13
  import { docsUrl, DOCS_BASE } from '#helpers/docs-url.js'
13
14
  import packageConfig from '#src/packageConfig.js'
14
15
  import { enableDebug } from '#lib/logger/debug.js'
@@ -93,6 +94,14 @@ program.hook('preAction', (thisCommand) => {
93
94
  }
94
95
  })
95
96
 
97
+ /**
98
+ * Stop the reporter after every command to clear any active setInterval timers
99
+ * (e.g. elapsed time display) that would otherwise keep the event loop alive.
100
+ */
101
+ program.hook('postAction', () => {
102
+ reporter.stop()
103
+ })
104
+
96
105
  /**
97
106
  * Register each command as a subcommand of this program
98
107
  * @see https://github.com/tj/commander.js?tab=readme-ov-file#automated-help
@@ -190,12 +199,25 @@ commands.forEach((command) => {
190
199
  })
191
200
  }
192
201
 
193
- // Wrap action in centralized error handler
194
- // Using apply() preserves `this` context for `this.debug` and `this.logger`
202
+ /**
203
+ * Wrap action in centralized error handler.
204
+ * Using apply() preserves `this` context for `this.debug` and `this.logger`.
205
+ *
206
+ * Nota bene: Commander passes subcommand-local opts as the options argument,
207
+ * but global options (--verbose, --quiet, --debug) defined on the parent
208
+ * program are only available via optsWithGlobals(). We replace the options
209
+ * argument with the merged set so action handlers see all options uniformly.
210
+ */
195
211
  subCommand.action(async (...args) => {
196
212
  try {
213
+ // Commander Command instance is the last element in args array
214
+ // @see https://github.com/tj/commander.js#action-handler
215
+ const cmd = args[args.length - 1]
216
+ const mergedOpts = cmd.optsWithGlobals()
217
+ args[args.length - 2] = mergedOpts
197
218
  await action.apply(command, args)
198
219
  } catch (error) {
220
+ reporter.stop()
199
221
  const { debug } = program.opts()
200
222
  handleError(error, { debug })
201
223
  }
@@ -1,6 +1,7 @@
1
1
  import { dirname } from 'node:path'
2
2
  import { fileURLToPath } from 'node:url'
3
3
  import { readPackageUpSync } from 'read-package-up'
4
+ import which from '#helpers/which.js'
4
5
 
5
6
  const __filename = fileURLToPath(import.meta.url)
6
7
  const __dirname = dirname(__filename)
@@ -12,4 +13,20 @@ const __dirname = dirname(__filename)
12
13
  */
13
14
  const { packageJson } = readPackageUpSync({ cwd: __dirname, normalize: true })
14
15
 
16
+ /**
17
+ * Resolve the full filesystem path to the quire CLI executable
18
+ *
19
+ * Uses the `which` helper to find the first `quire` executable in PATH.
20
+ * Returns null if the executable is not found.
21
+ *
22
+ * @returns {string|null} Absolute path to the quire executable, or null
23
+ */
24
+ export function binPath() {
25
+ try {
26
+ return which('quire')
27
+ } catch {
28
+ return null
29
+ }
30
+ }
31
+
15
32
  export default packageJson