@thegetty/quire-cli 1.0.0-rc.12 → 1.0.0-rc.13
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 +17 -15
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
|
/**
|
|
@@ -17,27 +16,29 @@ import yaml from 'js-yaml'
|
|
|
17
16
|
*
|
|
18
17
|
* @return {Object|undefined} User configuration object or undefined
|
|
19
18
|
*/
|
|
20
|
-
function loadConfig(
|
|
21
|
-
if (!fs.existsSync(
|
|
19
|
+
async function loadConfig(configPath) {
|
|
20
|
+
if (!fs.existsSync(configPath)) {
|
|
22
21
|
return undefined
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
const data = fs.readFileSync(
|
|
24
|
+
const data = fs.readFileSync(configPath)
|
|
26
25
|
let config = yaml.load(data)
|
|
27
26
|
|
|
28
27
|
// NB: Schemas may be project specific so the CLI must loads from project root rather than package root
|
|
29
28
|
const schemaPath = path.join(projectRoot,'_plugins','schemas','config.json')
|
|
29
|
+
const validatorPlugin = path.join(projectRoot, '_plugins', 'globalData', 'validator.js')
|
|
30
|
+
|
|
31
|
+
const validateUserConfig = await import(validatorPlugin)
|
|
30
32
|
|
|
31
33
|
// TODO: Check the project version string for whether we should check the schema
|
|
32
34
|
if (fs.existsSync(schemaPath)) {
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const schema = JSON.parse(sch)
|
|
35
|
+
const schemaJSON = fs.readFileSync(schemaPath)
|
|
36
|
+
const schema = JSON.parse(schemaJSON)
|
|
36
37
|
|
|
37
38
|
try {
|
|
38
|
-
config = validateUserConfig('config',config,{config: schema})
|
|
39
|
-
} catch (
|
|
40
|
-
console.error(
|
|
39
|
+
config = validateUserConfig('config', config, { config: schema })
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error(error)
|
|
41
42
|
process.exit(1)
|
|
42
43
|
}
|
|
43
44
|
}
|
|
@@ -45,8 +46,6 @@ function loadConfig(confPath) {
|
|
|
45
46
|
return config
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
const quireConfig = loadConfig(path.join(projectRoot,'content','_data','config.yaml'))
|
|
49
|
-
|
|
50
49
|
/**
|
|
51
50
|
* Quire CLI `pdf` Command
|
|
52
51
|
*
|
|
@@ -74,7 +73,6 @@ export default class PDFCommand extends Command {
|
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
constructor() {
|
|
77
|
-
const config = loadConfig(path.join(projectRoot,'content','_data','config.yaml'))
|
|
78
76
|
super(PDFCommand.definition)
|
|
79
77
|
}
|
|
80
78
|
|
|
@@ -86,7 +84,9 @@ export default class PDFCommand extends Command {
|
|
|
86
84
|
const publicationInput = path.join(projectRoot, paths.output, 'pdf.html')
|
|
87
85
|
const coversInput = path.join(projectRoot, paths.output, 'pdf-covers.html')
|
|
88
86
|
|
|
89
|
-
|
|
87
|
+
const quireConfig = await loadConfig(path.join(projectRoot,'content','_data','config.yaml'))
|
|
88
|
+
|
|
89
|
+
if (quireConfig === undefined) {
|
|
90
90
|
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
91
|
process.exit(1)
|
|
92
92
|
}
|
|
@@ -96,7 +96,9 @@ export default class PDFCommand extends Command {
|
|
|
96
96
|
process.exit(1)
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
const output = quireConfig.pdf !== undefined
|
|
99
|
+
const output = quireConfig.pdf !== undefined
|
|
100
|
+
? path.join(paths.output, quireConfig.pdf.outputDir, `${quireConfig.pdf.filename}.pdf`)
|
|
101
|
+
: path.join(projectRoot, `${options.lib}.pdf`);
|
|
100
102
|
|
|
101
103
|
const pdfLib = await libPdf(options.lib, { ...options, pdfConfig: quireConfig.pdf })
|
|
102
104
|
await pdfLib(publicationInput, coversInput, output)
|