@thegetty/quire-cli 1.0.0-rc.2 → 1.0.0-rc.21
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 +93 -7
- package/README.md +14 -0
- package/bin/cli.js +21 -8
- package/package.json +16 -9
- package/patches/README.md +19 -0
- package/patches/install-npm-version+1.0.9.patch +12119 -0
- package/src/Command.js +14 -0
- package/src/LOGGING.md +16 -0
- package/src/commands/README.md +28 -8
- package/src/commands/conf.js +43 -0
- package/src/commands/config/config-get.js +35 -0
- package/src/commands/config/config-reset.js +34 -0
- package/src/commands/config/config-set.js +37 -0
- package/src/commands/create.js +25 -7
- package/src/commands/epub.js +1 -2
- package/src/commands/info.js +128 -0
- package/src/commands/pdf.js +59 -10
- package/src/helpers/clean.js +5 -0
- package/src/helpers/is-empty.js +4 -0
- package/src/helpers/is-quire.js +4 -0
- package/src/helpers/os-utils.js +4 -0
- package/src/helpers/test-cwd.js +4 -0
- package/src/helpers/which.js +4 -0
- package/src/lib/conf/README.md +104 -0
- package/src/lib/conf/config.js +42 -0
- package/src/lib/conf/defaults.js +37 -0
- package/src/lib/conf/migrations.js +11 -0
- package/src/lib/conf/schema.js +30 -0
- package/src/lib/epub/index.js +3 -1
- package/src/lib/pdf/README.md +11 -4
- package/src/lib/pdf/index.js +7 -5
- package/src/lib/pdf/paged.js +88 -9
- package/src/lib/pdf/pagedPlugin.js +49 -0
- package/src/lib/pdf/prince.js +78 -4
- package/src/lib/pdf/princePlugin.js +35 -0
- package/src/lib/pdf/split.js +61 -0
- package/src/lib/quire/index.js +68 -58
- package/src/main.js +26 -6
- package/src/lib/11ty/plugins/before.js +0 -16
- package/src/lib/config/README.md +0 -3
- package/src/lib/config/index.js +0 -1
- package/src/lib/quire/constants.js +0 -6
- package/src/lib/quire/project.js +0 -104
package/src/Command.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import config from '#src/lib/conf/config.js'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Command
|
|
3
5
|
* @abstract
|
|
@@ -12,6 +14,7 @@ export default class Command {
|
|
|
12
14
|
/**
|
|
13
15
|
* @typedef CommandDefinition
|
|
14
16
|
* @property {String} name
|
|
17
|
+
* @property {String} alias
|
|
15
18
|
* @property {Array<String>} aliases
|
|
16
19
|
* @property {String} descriptions
|
|
17
20
|
* @property {Array<CommandArgument>} args
|
|
@@ -24,6 +27,8 @@ export default class Command {
|
|
|
24
27
|
/**
|
|
25
28
|
* Constructs a new instance
|
|
26
29
|
*
|
|
30
|
+
* Nota bene: Only the first command alias is displayed in the help.
|
|
31
|
+
*
|
|
27
32
|
* @param {CommandDefinition} definition The definition
|
|
28
33
|
*/
|
|
29
34
|
constructor(definition) {
|
|
@@ -31,6 +36,15 @@ export default class Command {
|
|
|
31
36
|
throw new Error('Command is an *abstract* class')
|
|
32
37
|
}
|
|
33
38
|
|
|
39
|
+
this.config = config // quire-cli configuration
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Merge and deduplicate command definition alias and aliases
|
|
43
|
+
* Nota bene: Only the first command alias is displayed in the help.
|
|
44
|
+
*/
|
|
45
|
+
// let aliases = Array.isArray(definition.aliases) ? definition.aliases || []
|
|
46
|
+
// aliases = new Set([ definition.alias, ...aliases ])
|
|
47
|
+
|
|
34
48
|
this.name = definition.name
|
|
35
49
|
this.aliases = definition.aliases
|
|
36
50
|
this.description = definition.description
|
package/src/LOGGING.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
## Logging
|
|
3
|
+
|
|
4
|
+
- https://betterstack.com/community/guides/logging/nodejs-logging-best-practices/
|
|
5
|
+
|
|
6
|
+
### `debug-js`
|
|
7
|
+
- https://github.com/debug-js/debug
|
|
8
|
+
- https://github.com/commenthol/debug-level
|
|
9
|
+
|
|
10
|
+
### Pino
|
|
11
|
+
- https://betterstack.com/community/guides/logging/how-to-install-setup-and-use-pino-to-log-node-js-applications/
|
|
12
|
+
- https://github.com/pinojs/pino
|
|
13
|
+
|
|
14
|
+
### Winston
|
|
15
|
+
- https://betterstack.com/community/guides/logging/how-to-install-setup-and-use-winston-and-morgan-to-log-node-js-applications/
|
|
16
|
+
- https://github.com/winstonjs/winston
|
package/src/commands/README.md
CHANGED
|
@@ -16,6 +16,14 @@ Build Quire publication EPUB format.
|
|
|
16
16
|
quire build epub
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
#### `info`
|
|
20
|
+
|
|
21
|
+
List `quire-11ty`, `quire-cli`, and starter package versions; use the `--debug` option to include node, npm, and os versions.
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
quire build info
|
|
25
|
+
```
|
|
26
|
+
|
|
19
27
|
#### `pdf`
|
|
20
28
|
|
|
21
29
|
Build Quire publication PDF format.
|
|
@@ -80,6 +88,26 @@ To create a new project from a starter template
|
|
|
80
88
|
quire new <path> <starter>
|
|
81
89
|
```
|
|
82
90
|
|
|
91
|
+
#### Specifying the `quire-11ty` version
|
|
92
|
+
|
|
93
|
+
When the `--quire` flag is used the new project will be started using the specified version of `quire-11ty`
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
quire new <path> <starter> --quire <version>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
##### Version identifiers
|
|
100
|
+
|
|
101
|
+
The `--quire` flag must be either a semantic version identifier or a npm distribution tag. For example:
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
quire new ./blargh --quire 1.0.0-rc.5
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
quire new ./blargh --quire latest
|
|
109
|
+
```
|
|
110
|
+
|
|
83
111
|
### `preview`
|
|
84
112
|
|
|
85
113
|
Build and server the Quire site in development mode.
|
|
@@ -134,14 +162,6 @@ To set the quire version globally use the `--global` command flag.
|
|
|
134
162
|
quire version 1.0.0 --global
|
|
135
163
|
```
|
|
136
164
|
|
|
137
|
-
#### `info`
|
|
138
|
-
|
|
139
|
-
Display the local and global `quire-11ty` version; this is the *default* subcommand (running `quire version` invokes the `info` subcommand).
|
|
140
|
-
|
|
141
|
-
```sh
|
|
142
|
-
quire version info
|
|
143
|
-
```
|
|
144
|
-
|
|
145
165
|
#### `install`
|
|
146
166
|
|
|
147
167
|
```sh
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Command from '#src/Command.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Quire CLI `conf` Command
|
|
5
|
+
*
|
|
6
|
+
* @class ConfCommand
|
|
7
|
+
* @extends {Command}
|
|
8
|
+
*/
|
|
9
|
+
export default class ConfCommand extends Command {
|
|
10
|
+
static definition = {
|
|
11
|
+
name: 'conf',
|
|
12
|
+
aliases: ['config', 'configure'],
|
|
13
|
+
description: 'Manage the Quire CLI configuration.',
|
|
14
|
+
summary: 'read/write quire-cli configuration options',
|
|
15
|
+
version: '1.0.0',
|
|
16
|
+
options: [
|
|
17
|
+
[ '--debug', 'run command in debug mode' ],
|
|
18
|
+
],
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor() {
|
|
22
|
+
super(ConfCommand.definition)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {Object} options
|
|
27
|
+
* @return {Promise}
|
|
28
|
+
*/
|
|
29
|
+
async action(key, value, options = {}) {
|
|
30
|
+
if (options.debug) {
|
|
31
|
+
console.info('Command \'%s\' called with options %o', this.name(), options)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// this.outputHelp()
|
|
35
|
+
|
|
36
|
+
console.info('quire-cli configuration %s', this.config.path)
|
|
37
|
+
|
|
38
|
+
for (const [ key, value ] of Object.entries(this.config.store)) {
|
|
39
|
+
if (key.startsWith('__internal__') && !options.debug) continue
|
|
40
|
+
console.info('%s: %O', key, value)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Command from '#src/Command.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Quire CLI `config get` Command
|
|
5
|
+
*
|
|
6
|
+
* @class ConfigGetCommand
|
|
7
|
+
* @extends {Command}
|
|
8
|
+
*/
|
|
9
|
+
export default class ConfigGetCommand extends Command {
|
|
10
|
+
static definition = {
|
|
11
|
+
name: 'config-get',
|
|
12
|
+
description: 'Get the value of a Quire CLI configuration property',
|
|
13
|
+
summary: 'get a cli configuration property',
|
|
14
|
+
version: '1.0.0',
|
|
15
|
+
args: [
|
|
16
|
+
[ '[property]', 'configuration property' ]
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
constructor() {
|
|
21
|
+
super(ConfigGetCommand.definition)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {String} key
|
|
26
|
+
* @param {Object} options
|
|
27
|
+
* @return {Promise}
|
|
28
|
+
*/
|
|
29
|
+
async action(property, options = {}) {
|
|
30
|
+
for (const [ key, value ] of Object.entries(this.config.store)) {
|
|
31
|
+
if (key.startsWith('__internal__') && !options.debug) continue
|
|
32
|
+
console.info(`${key}: ${JSON.stringify(value, null, 2)}`)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Command from '#src/Command.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Quire CLI `config reset` Command
|
|
5
|
+
*
|
|
6
|
+
* @class ConfigResetCommand
|
|
7
|
+
* @extends {Command}
|
|
8
|
+
*/
|
|
9
|
+
export default class ConfigResetCommand extends Command {
|
|
10
|
+
static definition = {
|
|
11
|
+
name: 'config-reset',
|
|
12
|
+
description: 'Reset the Quire CLI configuration to the default',
|
|
13
|
+
summary: 'reset cli configuration properties to default values',
|
|
14
|
+
version: '1.0.0',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
constructor() {
|
|
18
|
+
super(ConfigResetCommand.definition)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @return {Promise}
|
|
23
|
+
*/
|
|
24
|
+
async action(options = {}) {
|
|
25
|
+
if (options.debug) {
|
|
26
|
+
console.info('Command \'%s\' called with options %o', this.name(), options)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
for (const [ key, value ] of Object.entries(this.config.store)) {
|
|
30
|
+
if (key.startsWith('__internal__') && !options.debug) continue
|
|
31
|
+
console.info(`${key}: ${JSON.stringify(value, null, 2)}`)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Command from '#src/Command.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Quire CLI `config set` Command
|
|
5
|
+
*
|
|
6
|
+
* @class ConfigCommand
|
|
7
|
+
* @extends {Command}
|
|
8
|
+
*/
|
|
9
|
+
export default class ConfigSetCommand extends Command {
|
|
10
|
+
static definition = {
|
|
11
|
+
name: 'config-set',
|
|
12
|
+
description: 'Set a Quire CLI configuration property',
|
|
13
|
+
summary: 'set a cli configuration property',
|
|
14
|
+
version: '1.0.0',
|
|
15
|
+
args: [
|
|
16
|
+
[ '[key]', 'configuration property key' ],
|
|
17
|
+
[ '[value]', 'configuration property value' ]
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor() {
|
|
22
|
+
super(ConfigSetCommand.definition)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {String} key
|
|
27
|
+
* @param {String} value
|
|
28
|
+
* @param {Object} options
|
|
29
|
+
* @return {Promise}
|
|
30
|
+
*/
|
|
31
|
+
async action(key, value, options = {}) {
|
|
32
|
+
for (const [ key, value ] of Object.entries(this.config.store)) {
|
|
33
|
+
if (key.startsWith('__internal__') && !options.debug) continue
|
|
34
|
+
console.info(`${key}: ${JSON.stringify(value, null, 2)}`)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/commands/create.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Command from '#src/Command.js'
|
|
2
|
+
import fs from 'fs-extra'
|
|
2
3
|
import { quire } from '#src/lib/quire/index.js'
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -22,8 +23,10 @@ export default class CreateCommand extends Command {
|
|
|
22
23
|
[ '[starter]', 'repository url or local path for a starter project' ],
|
|
23
24
|
],
|
|
24
25
|
options: [
|
|
25
|
-
[ '--
|
|
26
|
-
[ '--
|
|
26
|
+
[ '--quire-path <path>', 'local path to quire-11ty package' ],
|
|
27
|
+
[ '--quire-version <version>', 'quire-11ty version to install' ],
|
|
28
|
+
// [ '--eject', 'install quire-11ty into the project directory', true ],
|
|
29
|
+
[ '--debug', 'debug the `quire new` command', false ],
|
|
27
30
|
],
|
|
28
31
|
}
|
|
29
32
|
|
|
@@ -42,6 +45,8 @@ export default class CreateCommand extends Command {
|
|
|
42
45
|
console.info('Command \'%s\' called with options %o', CreateCommand.name, options)
|
|
43
46
|
}
|
|
44
47
|
|
|
48
|
+
starter = starter || this.config.get('projectTemplate')
|
|
49
|
+
|
|
45
50
|
if (!projectPath && !starter) {
|
|
46
51
|
// @TODO implement this case of interactively selecting starter templates
|
|
47
52
|
// from available subtrees in `lib/quire` module
|
|
@@ -52,14 +57,27 @@ export default class CreateCommand extends Command {
|
|
|
52
57
|
// const starter = starters['default']
|
|
53
58
|
// `git clone starter path`
|
|
54
59
|
} else {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
/**
|
|
61
|
+
* @TODO test that `version` is compatible with the `requiredVersion`
|
|
62
|
+
* if version is incompatible or unknown
|
|
63
|
+
* - interactive mode prompt to continue
|
|
64
|
+
* - non-interactive mode throw an error and exit the process
|
|
65
|
+
*/
|
|
66
|
+
let quireVersion
|
|
67
|
+
try {
|
|
68
|
+
quireVersion = await quire.initStarter(starter, projectPath, options)
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error(error.message)
|
|
71
|
+
fs.removeSync(projectPath)
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
options.eject = true
|
|
58
76
|
|
|
59
77
|
if (options.eject) {
|
|
60
|
-
await quire.installInProject(projectPath,
|
|
78
|
+
await quire.installInProject(projectPath, quireVersion, options)
|
|
61
79
|
} else {
|
|
62
|
-
await quire.install(
|
|
80
|
+
await quire.install(options)
|
|
63
81
|
}
|
|
64
82
|
}
|
|
65
83
|
}
|
package/src/commands/epub.js
CHANGED
|
@@ -55,8 +55,7 @@ export default class EpubCommand extends Command {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
* test if build site has already be run and output can be reused
|
|
59
|
-
* @todo
|
|
58
|
+
* @todo test if build site has already be run and output can be reused
|
|
60
59
|
*/
|
|
61
60
|
preAction(command) {
|
|
62
61
|
const options = command.opts()
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import Command from '#src/Command.js'
|
|
2
|
+
import { execaCommand } from 'execa'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import os from 'node:os'
|
|
5
|
+
import path from 'path'
|
|
6
|
+
import testcwd from '#helpers/test-cwd.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Quire CLI `info` Command
|
|
10
|
+
*
|
|
11
|
+
* Runs the Eleventy `info` command to list the quire-cli, quire-11ty, node, and npm versions.
|
|
12
|
+
*
|
|
13
|
+
* @class InfoCommand
|
|
14
|
+
* @extends {Command}
|
|
15
|
+
*/
|
|
16
|
+
export default class InfoCommand extends Command {
|
|
17
|
+
static definition = {
|
|
18
|
+
name: 'info',
|
|
19
|
+
description: 'List Quire cli, quire-11ty, and node versions',
|
|
20
|
+
summary: 'list info',
|
|
21
|
+
version: '1.0.0',
|
|
22
|
+
args: [],
|
|
23
|
+
options: [
|
|
24
|
+
['--debug', 'include os versions in output']
|
|
25
|
+
],
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
super(InfoCommand.definition)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async action(options, command) {
|
|
33
|
+
if (options.debug) {
|
|
34
|
+
console.debug(
|
|
35
|
+
'[CLI] Command \'%s\' called with options %o',
|
|
36
|
+
this.name(),
|
|
37
|
+
options
|
|
38
|
+
)
|
|
39
|
+
} else {
|
|
40
|
+
console.debug('[CLI] Command \'%s\' called', this.name())
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const versionFileName = this.config.get('versionFile')
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
// the quire version file is always local to the project root
|
|
47
|
+
let fileData = fs.readFileSync(versionFileName, { encoding: 'utf8' })
|
|
48
|
+
versionInfo = JSON.parse(fileData)
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.warn(
|
|
51
|
+
`This project was generated with the quire-cli prior to version 1.0.0.rc-8. Updating the version file to the new format, though this project's version file will not contain specific starter version information.`
|
|
52
|
+
)
|
|
53
|
+
versionInfo = { cli: '<=1.0.0.rc-7' }
|
|
54
|
+
fs.writeFileSync(versionFileName, JSON.stringify(versionInfo))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const { name: projectDirectory } = path.parse(process.cwd())
|
|
58
|
+
|
|
59
|
+
const versions = [
|
|
60
|
+
{
|
|
61
|
+
title: `[${projectDirectory}]`,
|
|
62
|
+
items: [
|
|
63
|
+
{
|
|
64
|
+
name: 'quire-cli',
|
|
65
|
+
get: () => versionInfo.cli,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'quire-11ty',
|
|
69
|
+
get: () => {
|
|
70
|
+
const { version } = JSON.parse(fs.readFileSync('./package.json'))
|
|
71
|
+
return version
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'starter',
|
|
76
|
+
get: () => versionInfo.starter,
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
title: '[System]',
|
|
82
|
+
items: [
|
|
83
|
+
{
|
|
84
|
+
name: 'quire-cli',
|
|
85
|
+
get: async () => {
|
|
86
|
+
const { stdout } = await execaCommand('quire --version')
|
|
87
|
+
return stdout
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
debug: true,
|
|
92
|
+
name: 'node',
|
|
93
|
+
get: () => process.version,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
debug: true,
|
|
97
|
+
name: 'npm',
|
|
98
|
+
get: async () => {
|
|
99
|
+
const { stdout } = await execaCommand('npm --version')
|
|
100
|
+
return stdout
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
debug: true,
|
|
105
|
+
name: 'os',
|
|
106
|
+
get: () => `${os.type()} ${os.release()}`,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Filter the command output based on `debug` settings
|
|
114
|
+
*/
|
|
115
|
+
versions.forEach(async ({ items, title }) => {
|
|
116
|
+
const versions = await Promise.all(
|
|
117
|
+
items
|
|
118
|
+
.filter(({ debug }) => !debug || (options.debug && debug))
|
|
119
|
+
.map(async ({ name, get }) => `${name} ${await get()}`)
|
|
120
|
+
)
|
|
121
|
+
console.info(`${title}\n ${versions.join('\n ')}`)
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
preAction(command) {
|
|
126
|
+
testcwd(command)
|
|
127
|
+
}
|
|
128
|
+
}
|
package/src/commands/pdf.js
CHANGED
|
@@ -1,10 +1,49 @@
|
|
|
1
|
-
import Command from '#src/Command.js'
|
|
2
1
|
import { paths, projectRoot } from '#lib/11ty/index.js'
|
|
2
|
+
import Command from '#src/Command.js'
|
|
3
3
|
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
|
-
|
|
7
|
+
import yaml from 'js-yaml'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @function loadConfig(path) - loads and validates quire config, returns an empty object if not found
|
|
11
|
+
*
|
|
12
|
+
* @param {path} string - file path to config file
|
|
13
|
+
*
|
|
14
|
+
* @return {Object|undefined} User configuration object or undefined
|
|
15
|
+
*
|
|
16
|
+
* @todo consider hardcoding a version check against .quire / project's package.json ver
|
|
17
|
+
*/
|
|
18
|
+
async function loadConfig(configPath) {
|
|
19
|
+
if (!fs.existsSync(configPath)) {
|
|
20
|
+
return undefined
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const data = fs.readFileSync(configPath)
|
|
24
|
+
let config = yaml.load(data)
|
|
25
|
+
|
|
26
|
+
// NB: Schemas and validators are specific to the 11ty version of the project being built
|
|
27
|
+
const schemaPath = path.join(projectRoot,'_plugins','schemas','config.json')
|
|
28
|
+
const validatorPath = path.join(projectRoot, '_plugins', 'globalData', 'validator.js')
|
|
29
|
+
|
|
30
|
+
if (fs.existsSync(schemaPath) && fs.existsSync(validatorPath)) {
|
|
31
|
+
|
|
32
|
+
const { validateUserConfig } = await import(validatorPath)
|
|
33
|
+
|
|
34
|
+
const schemaJSON = fs.readFileSync(schemaPath)
|
|
35
|
+
const schema = JSON.parse(schemaJSON)
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
config = validateUserConfig('config', config, { config: schema })
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error(error)
|
|
41
|
+
process.exit(1)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return config
|
|
46
|
+
}
|
|
8
47
|
|
|
9
48
|
/**
|
|
10
49
|
* Quire CLI `pdf` Command
|
|
@@ -41,22 +80,32 @@ export default class PDFCommand extends Command {
|
|
|
41
80
|
console.debug('[CLI] Command \'%s\' called with options %o', this.name(), options)
|
|
42
81
|
}
|
|
43
82
|
|
|
44
|
-
const
|
|
83
|
+
const publicationInput = path.join(projectRoot, paths.output, 'pdf.html')
|
|
84
|
+
const coversInput = path.join(projectRoot, paths.output, 'pdf-covers.html')
|
|
45
85
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
86
|
+
const quireConfig = await loadConfig(path.join(projectRoot,'content','_data','config.yaml'))
|
|
87
|
+
|
|
88
|
+
if (quireConfig === undefined) {
|
|
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?`)
|
|
90
|
+
process.exit(1)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!fs.existsSync(publicationInput)) {
|
|
94
|
+
console.error(`[quire pdf]: ERROR Unable to find PDF input at ${publicationInput}\nPlease first run the 'quire build' command.`)
|
|
95
|
+
process.exit(1)
|
|
49
96
|
}
|
|
50
97
|
|
|
51
|
-
const output =
|
|
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`)
|
|
52
101
|
|
|
53
|
-
const pdfLib = await libPdf(options.lib, {
|
|
54
|
-
await pdfLib(
|
|
102
|
+
const pdfLib = await libPdf(options.lib, { ...options, pdfConfig: quireConfig.pdf })
|
|
103
|
+
await pdfLib(publicationInput, coversInput, output)
|
|
55
104
|
|
|
56
105
|
try {
|
|
57
106
|
if (fs.existsSync(output) && options.open) open(output)
|
|
58
107
|
} catch (error) {
|
|
59
|
-
console.error(error)
|
|
108
|
+
console.error(`[quire pdf]: ERROR`,error)
|
|
60
109
|
process.exit(1)
|
|
61
110
|
}
|
|
62
111
|
}
|
package/src/helpers/clean.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A helper module for cleaning quire outputs
|
|
3
|
+
* @module clean
|
|
4
|
+
*/
|
|
1
5
|
import { deleteAsync } from 'del'
|
|
2
6
|
import path from 'node:path'
|
|
3
7
|
|
|
@@ -9,6 +13,7 @@ import path from 'node:path'
|
|
|
9
13
|
*/
|
|
10
14
|
export async function clean (projectRoot, paths, options = {}) {
|
|
11
15
|
const pathsToClean = [
|
|
16
|
+
path.join(projectRoot, '.11ty-vite'),
|
|
12
17
|
path.join(projectRoot, paths.epub),
|
|
13
18
|
path.join(projectRoot, paths.output),
|
|
14
19
|
path.join(projectRoot, '*.epub'),
|
package/src/helpers/is-empty.js
CHANGED
package/src/helpers/is-quire.js
CHANGED
package/src/helpers/os-utils.js
CHANGED
package/src/helpers/test-cwd.js
CHANGED