@thegetty/quire-cli 1.0.0-rc.12 → 1.0.0-rc.14
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/package.json +1 -1
- package/src/commands/pdf.js +21 -20
package/package.json
CHANGED
package/src/commands/pdf.js
CHANGED
|
@@ -4,7 +4,6 @@ import fs from 'fs-extra'
|
|
|
4
4
|
import libPdf from '#lib/pdf/index.js'
|
|
5
5
|
import open from 'open'
|
|
6
6
|
import path from 'node:path'
|
|
7
|
-
import { validateUserConfig } from '../../../11ty/_plugins/globalData/validator.js'
|
|
8
7
|
import yaml from 'js-yaml'
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -12,32 +11,33 @@ import yaml from 'js-yaml'
|
|
|
12
11
|
*
|
|
13
12
|
* @param {path} string - file path to config file
|
|
14
13
|
*
|
|
15
|
-
* @todo refactor loading configs to a separate module,
|
|
16
|
-
* which uses the same validator(s) as the build proceess
|
|
17
|
-
*
|
|
18
14
|
* @return {Object|undefined} User configuration object or undefined
|
|
15
|
+
*
|
|
16
|
+
* @todo consider hardcoding a version check against .quire / project's package.json ver
|
|
19
17
|
*/
|
|
20
|
-
function loadConfig(
|
|
21
|
-
if (!fs.existsSync(
|
|
18
|
+
async function loadConfig(configPath) {
|
|
19
|
+
if (!fs.existsSync(configPath)) {
|
|
22
20
|
return undefined
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
const data = fs.readFileSync(
|
|
23
|
+
const data = fs.readFileSync(configPath)
|
|
26
24
|
let config = yaml.load(data)
|
|
27
25
|
|
|
28
|
-
// NB: Schemas
|
|
26
|
+
// NB: Schemas and validators are specific to the 11ty version of the project being built
|
|
29
27
|
const schemaPath = path.join(projectRoot,'_plugins','schemas','config.json')
|
|
28
|
+
const validatorPath = path.join(projectRoot, '_plugins', 'globalData', 'validator.js')
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
if (fs.existsSync(schemaPath)) {
|
|
30
|
+
if (fs.existsSync(schemaPath) && fs.existsSync(validatorPath)) {
|
|
33
31
|
|
|
34
|
-
const
|
|
35
|
-
|
|
32
|
+
const { validateUserConfig } = await import(validatorPath)
|
|
33
|
+
|
|
34
|
+
const schemaJSON = fs.readFileSync(schemaPath)
|
|
35
|
+
const schema = JSON.parse(schemaJSON)
|
|
36
36
|
|
|
37
37
|
try {
|
|
38
|
-
config = validateUserConfig('config',config,{config: schema})
|
|
39
|
-
} catch (
|
|
40
|
-
console.error(
|
|
38
|
+
config = validateUserConfig('config', config, { config: schema })
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error(error)
|
|
41
41
|
process.exit(1)
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -45,8 +45,6 @@ function loadConfig(confPath) {
|
|
|
45
45
|
return config
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const quireConfig = loadConfig(path.join(projectRoot,'content','_data','config.yaml'))
|
|
49
|
-
|
|
50
48
|
/**
|
|
51
49
|
* Quire CLI `pdf` Command
|
|
52
50
|
*
|
|
@@ -74,7 +72,6 @@ export default class PDFCommand extends Command {
|
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
constructor() {
|
|
77
|
-
const config = loadConfig(path.join(projectRoot,'content','_data','config.yaml'))
|
|
78
75
|
super(PDFCommand.definition)
|
|
79
76
|
}
|
|
80
77
|
|
|
@@ -86,7 +83,9 @@ export default class PDFCommand extends Command {
|
|
|
86
83
|
const publicationInput = path.join(projectRoot, paths.output, 'pdf.html')
|
|
87
84
|
const coversInput = path.join(projectRoot, paths.output, 'pdf-covers.html')
|
|
88
85
|
|
|
89
|
-
|
|
86
|
+
const quireConfig = await loadConfig(path.join(projectRoot,'content','_data','config.yaml'))
|
|
87
|
+
|
|
88
|
+
if (quireConfig === undefined) {
|
|
90
89
|
console.error(`[quire pdf]: ERROR Unable to find a configuration file at ${path.join(projectRoot,'content','_data','config.yaml')}\nIs the command being run in a quire project?`)
|
|
91
90
|
process.exit(1)
|
|
92
91
|
}
|
|
@@ -96,7 +95,9 @@ export default class PDFCommand extends Command {
|
|
|
96
95
|
process.exit(1)
|
|
97
96
|
}
|
|
98
97
|
|
|
99
|
-
const output = quireConfig.pdf !== undefined
|
|
98
|
+
const output = quireConfig.pdf !== undefined
|
|
99
|
+
? path.join(paths.output, quireConfig.pdf.outputDir, `${quireConfig.pdf.filename}.pdf`)
|
|
100
|
+
: path.join(projectRoot, `${options.lib}.pdf`)
|
|
100
101
|
|
|
101
102
|
const pdfLib = await libPdf(options.lib, { ...options, pdfConfig: quireConfig.pdf })
|
|
102
103
|
await pdfLib(publicationInput, coversInput, output)
|