@thegetty/quire-cli 1.0.0-rc.3 → 1.0.0-rc.31
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 +148 -7
- package/README.md +15 -0
- package/bin/cli.js +14 -8
- package/package.json +16 -10
- package/patches/.DS_Store +0 -0
- package/patches/README.md +19 -0
- package/patches/install-npm-version+1.0.9.patch +12119 -0
- package/src/.DS_Store +0 -0
- package/src/Command.js +14 -0
- package/src/commands/README.md +28 -8
- package/src/commands/conf.js +43 -0
- package/src/commands/create.js +22 -10
- package/src/commands/epub.js +1 -2
- package/src/commands/info.js +130 -0
- package/src/commands/pdf.js +60 -10
- package/src/helpers/.DS_Store +0 -0
- 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/11ty/cli.js +18 -2
- package/src/lib/conf/README.md +104 -0
- package/src/lib/conf/config.js +35 -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 +79 -4
- package/src/lib/pdf/princePlugin.js +35 -0
- package/src/lib/pdf/split.js +61 -0
- package/src/lib/quire/index.js +84 -141
- package/src/main.js +21 -6
- package/src/packageConfig.js +15 -0
- 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/.DS_Store
ADDED
|
Binary file
|
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/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
|
+
}
|
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,15 +57,22 @@ export default class CreateCommand extends Command {
|
|
|
52
57
|
// const starter = starters['default']
|
|
53
58
|
// `git clone starter path`
|
|
54
59
|
} else {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
|
63
73
|
}
|
|
74
|
+
|
|
75
|
+
await quire.installInProject(projectPath, quireVersion, options)
|
|
64
76
|
}
|
|
65
77
|
}
|
|
66
78
|
}
|
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,130 @@
|
|
|
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 'node: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
|
+
// Load filename from config with a default constraint if it doesn't exist
|
|
44
|
+
const versionFileName = this.config.get('versionFile')
|
|
45
|
+
let versionInfo = { cli: '<=1.0.0.rc-7' }
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const versionFileData = fs.readFileSync(versionFileName, { encoding: 'utf8' })
|
|
49
|
+
|
|
50
|
+
versionInfo = JSON.parse(versionFileData)
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.warn(
|
|
53
|
+
`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.`
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
fs.writeFileSync(versionFileName, JSON.stringify(versionInfo))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const { name: projectDirectory } = path.parse(process.cwd())
|
|
60
|
+
|
|
61
|
+
const versions = [
|
|
62
|
+
{
|
|
63
|
+
title: `[${projectDirectory}]`,
|
|
64
|
+
items: [
|
|
65
|
+
{
|
|
66
|
+
name: 'quire-cli',
|
|
67
|
+
get: () => versionInfo.cli,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'quire-11ty',
|
|
71
|
+
get: () => {
|
|
72
|
+
const { version } = JSON.parse(fs.readFileSync('./package.json'))
|
|
73
|
+
return version
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'starter',
|
|
78
|
+
get: () => versionInfo.starter,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
title: '[System]',
|
|
84
|
+
items: [
|
|
85
|
+
{
|
|
86
|
+
name: 'quire-cli',
|
|
87
|
+
get: async () => {
|
|
88
|
+
const { stdout } = await execaCommand('quire --version')
|
|
89
|
+
return stdout
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
debug: true,
|
|
94
|
+
name: 'node',
|
|
95
|
+
get: () => process.version,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
debug: true,
|
|
99
|
+
name: 'npm',
|
|
100
|
+
get: async () => {
|
|
101
|
+
const { stdout } = await execaCommand('npm --version')
|
|
102
|
+
return stdout
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
debug: true,
|
|
107
|
+
name: 'os',
|
|
108
|
+
get: () => `${os.type()} ${os.release()}`,
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
]
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Filter the command output based on `debug` settings
|
|
116
|
+
*/
|
|
117
|
+
versions.forEach(async ({ items, title }) => {
|
|
118
|
+
const versions = await Promise.all(
|
|
119
|
+
items
|
|
120
|
+
.filter(({ debug }) => !debug || (options.debug && debug))
|
|
121
|
+
.map(async ({ name, get }) => `${name} ${await get()}`)
|
|
122
|
+
)
|
|
123
|
+
console.info(`${title}\n ${versions.join('\n ')}`)
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
preAction(command) {
|
|
128
|
+
testcwd(command)
|
|
129
|
+
}
|
|
130
|
+
}
|
package/src/commands/pdf.js
CHANGED
|
@@ -1,10 +1,50 @@
|
|
|
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 { pathToFileURL } from 'node:url'
|
|
8
|
+
import yaml from 'js-yaml'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @function loadConfig(path) - loads and validates quire config, returns an empty object if not found
|
|
12
|
+
*
|
|
13
|
+
* @param {path} string - file path to config file
|
|
14
|
+
*
|
|
15
|
+
* @return {Object|undefined} User configuration object or undefined
|
|
16
|
+
*
|
|
17
|
+
* @todo consider hardcoding a version check against .quire / project's package.json ver
|
|
18
|
+
*/
|
|
19
|
+
async function loadConfig(configPath) {
|
|
20
|
+
if (!fs.existsSync(configPath)) {
|
|
21
|
+
return undefined
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const data = fs.readFileSync(configPath)
|
|
25
|
+
let config = yaml.load(data)
|
|
26
|
+
|
|
27
|
+
// NB: Schemas and validators are specific to the 11ty version of the project being built
|
|
28
|
+
const schemaPath = path.join(projectRoot,'_plugins','schemas','config.json')
|
|
29
|
+
const validatorPath = path.join(projectRoot, '_plugins', 'globalData', 'validator.js')
|
|
30
|
+
|
|
31
|
+
if (fs.existsSync(schemaPath) && fs.existsSync(validatorPath)) {
|
|
32
|
+
|
|
33
|
+
const { validateUserConfig } = await import(pathToFileURL(validatorPath))
|
|
34
|
+
|
|
35
|
+
const schemaJSON = fs.readFileSync(schemaPath)
|
|
36
|
+
const schema = JSON.parse(schemaJSON)
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
config = validateUserConfig('config', config, { config: schema })
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error(error)
|
|
42
|
+
process.exit(1)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return config
|
|
47
|
+
}
|
|
8
48
|
|
|
9
49
|
/**
|
|
10
50
|
* Quire CLI `pdf` Command
|
|
@@ -41,22 +81,32 @@ export default class PDFCommand extends Command {
|
|
|
41
81
|
console.debug('[CLI] Command \'%s\' called with options %o', this.name(), options)
|
|
42
82
|
}
|
|
43
83
|
|
|
44
|
-
const
|
|
84
|
+
const publicationInput = path.join(projectRoot, paths.output, 'pdf.html')
|
|
85
|
+
const coversInput = path.join(projectRoot, paths.output, 'pdf-covers.html')
|
|
45
86
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
87
|
+
const quireConfig = await loadConfig(path.join(projectRoot,'content','_data','config.yaml'))
|
|
88
|
+
|
|
89
|
+
if (quireConfig === undefined) {
|
|
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
|
+
process.exit(1)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!fs.existsSync(publicationInput)) {
|
|
95
|
+
console.error(`[quire pdf]: ERROR Unable to find PDF input at ${publicationInput}\nPlease first run the 'quire build' command.`)
|
|
96
|
+
process.exit(1)
|
|
49
97
|
}
|
|
50
98
|
|
|
51
|
-
const output =
|
|
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`)
|
|
52
102
|
|
|
53
|
-
const pdfLib = await libPdf(options.lib, {
|
|
54
|
-
await pdfLib(
|
|
103
|
+
const pdfLib = await libPdf(options.lib, { ...options, pdfConfig: quireConfig.pdf })
|
|
104
|
+
await pdfLib(publicationInput, coversInput, output)
|
|
55
105
|
|
|
56
106
|
try {
|
|
57
107
|
if (fs.existsSync(output) && options.open) open(output)
|
|
58
108
|
} catch (error) {
|
|
59
|
-
console.error(error)
|
|
109
|
+
console.error(`[quire pdf]: ERROR`,error)
|
|
60
110
|
process.exit(1)
|
|
61
111
|
}
|
|
62
112
|
}
|
|
Binary file
|
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
package/src/helpers/which.js
CHANGED
package/src/lib/11ty/cli.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execa } from 'execa'
|
|
2
|
+
import fs from 'node:fs'
|
|
2
3
|
import path from 'node:path'
|
|
3
4
|
import paths, { eleventyRoot, projectRoot } from './paths.js'
|
|
4
5
|
|
|
@@ -17,9 +18,24 @@ const factory = (options = {}) => {
|
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Use the version of Eleventy installed to `lib/quire/versions`
|
|
21
|
+
*
|
|
22
|
+
* NB: in eleventy v3 the CLI extension (".cjs") is load-bearing but v2 is simply ".js"
|
|
23
|
+
*
|
|
20
24
|
*/
|
|
21
|
-
const
|
|
22
|
-
|
|
25
|
+
const eleventyModuleDir = path.join(eleventyRoot, 'node_modules', '@11ty', 'eleventy')
|
|
26
|
+
const packagePath = path.join(eleventyModuleDir,'package.json')
|
|
27
|
+
|
|
28
|
+
const pack = JSON.parse(fs.readFileSync(packagePath))
|
|
29
|
+
|
|
30
|
+
const { version } = pack
|
|
31
|
+
|
|
32
|
+
const eleventyMajorVer = version.split('.').at(0)
|
|
33
|
+
|
|
34
|
+
let eleventy = path.join(eleventyModuleDir,'cmd.cjs')
|
|
35
|
+
|
|
36
|
+
if ( Number(eleventyMajorVer) < 3 ) {
|
|
37
|
+
eleventy = path.join(eleventyModuleDir,'cmd.js')
|
|
38
|
+
}
|
|
23
39
|
|
|
24
40
|
const command = [
|
|
25
41
|
eleventy,
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
## CLI Configuration Manager
|
|
2
|
+
|
|
3
|
+
This `quire-cli/lib/config` module manages reading and writing (persisting) options for the Quire CLI using the [`conf`](https://github.com/sindresorhus/conf) package.
|
|
4
|
+
|
|
5
|
+
`conf` stores the config in the system default [user config directory](https://github.com/sindresorhus/env-paths#pathsconfig). For example, on macOS, the config file will be stored in the `~/Library/Preferences/@thegetty/quire-cli` directory.
|
|
6
|
+
|
|
7
|
+
> Changes are written to disk atomically, so if the process crashes during a write, it will not corrupt the existing config.
|
|
8
|
+
|
|
9
|
+
### Configuration
|
|
10
|
+
|
|
11
|
+
`logLevel` The default logging level for the Quire CLI output; default `'info'`.
|
|
12
|
+
|
|
13
|
+
`projectTemplate` A default project starter template to use when creating new projects; default `'quire-starter-default'`.
|
|
14
|
+
|
|
15
|
+
`quirePath` The relative path to `quire-11ty` installed in the project directory; default `./11ty`. When set to `null`, `quire-11ty` is installed to the CLI `lib/quire/versions/<version>/` directory.
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
❯ quire config quire-path '.'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`quireVersion` The default version of `quire-11ty` to install when creating new Quire projects; default `'latest'`.
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
❯ quire config quire-version '1.0.0'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`telemetry` Send anonymous data about Quire usage; default `false`.
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
❯ quire config telemetry --enabled
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
❯ quire config telemetry --disabled
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`updateChannels` A list of distribution tags to use when checking for version updates; default `['latest']`. To show notifications for pre-releases version updates include `'pre-release'` in the array of channels. This can be set using the configuration `--pre-release` command flag.
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
❯ quire config update-channels
|
|
41
|
+
Quire configured to check for updates tagged 'latest'
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
❯ quire config update-channels --add 'pre-release'
|
|
46
|
+
Quire configured to check for updates tagged 'latest', 'pre-release'
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
❯ quire config update-channels --rm 'pre-release'
|
|
51
|
+
Quire configured to check for updates tagged 'latest'
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`updateInterval` Interval at which to check for updates to the Quire CLI and project's `quire-11ty` version; default `'DAILY'`.
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
❯ quire config update-interval
|
|
58
|
+
Quire configured to check for updates DAILY
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
❯ quire config update-interval WEEKLY
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`versionFile ['.quire-version']` The default file name for the `quire-11ty` version file.
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
❯ quire config version-file '.blargh'
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Quire CLI `config` Command
|
|
72
|
+
|
|
73
|
+
Running the `config` command without any arguments will start an interactive prompt to configure Quire.
|
|
74
|
+
|
|
75
|
+
To view an individual configuration value and its default value use:
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
❯ quire config [key]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
To view the current `logLevel` setting for example:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
❯ quire config logLevel
|
|
85
|
+
loglevel: 'debug' (default 'info')
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
To set an individual configuration value, use the `set` argument:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
❯ quire config set <key> <value>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
To reset *all* keys to their default values, use the `reset` argument:
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
❯ quire config reset
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
To reset an individual key to its default value:
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
❯ quire config reset [key]
|
|
104
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Conf from 'conf'
|
|
2
|
+
import defaults from './defaults.js'
|
|
3
|
+
import migrations from './migrations.js'
|
|
4
|
+
import packageConfig from '#src/packageConfig.js'
|
|
5
|
+
import schema from './schema.js'
|
|
6
|
+
|
|
7
|
+
const { name, version } = packageConfig
|
|
8
|
+
|
|
9
|
+
const beforeEachMigration = (store, context) => {
|
|
10
|
+
const { fromVersion, toVersion } = context
|
|
11
|
+
console.info(`quire-cli migrating config from ${fromVersion} → ${toVersion}`)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create quire-cli configuration instance
|
|
16
|
+
* @see https://github.com/sindresorhus/conf#confoptions
|
|
17
|
+
*
|
|
18
|
+
* @todo support yaml configuration files
|
|
19
|
+
* https://github.com/sindresorhus/conf?tab=readme-ov-file#can-i-use-yaml-or-another-serialization-format
|
|
20
|
+
*
|
|
21
|
+
* @type {Conf}
|
|
22
|
+
*/
|
|
23
|
+
const config = new Conf({
|
|
24
|
+
beforeEachMigration,
|
|
25
|
+
clearInvalidConfig: true,
|
|
26
|
+
defaults,
|
|
27
|
+
migrations,
|
|
28
|
+
projectName: name,
|
|
29
|
+
projectSuffix: '',
|
|
30
|
+
projectVersion: version,
|
|
31
|
+
schema,
|
|
32
|
+
watch: true,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
export default config
|