@thegetty/quire-cli 1.0.0-rc.0 → 1.0.0-rc.10
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 +19 -1
- package/bin/cli.js +3 -3
- package/package.json +12 -13
- package/src/commands/README.md +34 -54
- package/src/commands/create.js +23 -7
- package/src/commands/epub.js +2 -2
- package/src/commands/info.js +125 -0
- package/src/commands/pdf.js +2 -2
- package/src/commands/preview.js +1 -1
- package/src/lib/11ty/api.js +4 -5
- package/src/lib/11ty/cli.js +3 -3
- package/src/lib/epub/epub.js +22 -4
- package/src/lib/epub/index.js +16 -12
- package/src/lib/epub/pandoc.js +1 -1
- package/src/lib/pdf/index.js +16 -12
- package/src/lib/pdf/paged.js +30 -1
- package/src/lib/pdf/prince.js +6 -0
- package/src/lib/quire/index.js +63 -53
- package/src/main.js +1 -1
- package/src/lib/11ty/README.html +0 -1089
- package/src/lib/telemetry/README.md +0 -0
package/src/lib/pdf/paged.js
CHANGED
|
@@ -13,10 +13,30 @@ export default async (input, output, options = {}) => {
|
|
|
13
13
|
const printerOptions = {
|
|
14
14
|
allowLocal: true,
|
|
15
15
|
debug: options.debug || false,
|
|
16
|
+
enableWarnings: options.debug || false,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (options.debug) {
|
|
20
|
+
const optionsOutput = JSON.stringify(printerOptions, null, 2)
|
|
21
|
+
console.debug(`[CLI:lib/pdf/pagedjs] Printer options\n${optionsOutput}`)
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
const printer = new Printer(printerOptions)
|
|
19
25
|
|
|
26
|
+
printer.on('page', (page) => {
|
|
27
|
+
if (page.position === 0) {
|
|
28
|
+
console.info(`[CLI:lib/pdf/pagedjs] loaded`)
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
printer.on('rendered', (msg) => {
|
|
33
|
+
console.info(`[CLI:lib/pdf/pagedjs] ${msg}`)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
printer.on('postprocessing', () => {
|
|
37
|
+
console.info(`[CLI:lib/pdf/pagedjs] post-processing`)
|
|
38
|
+
})
|
|
39
|
+
|
|
20
40
|
/**
|
|
21
41
|
* Configure the Paged.js PDF options
|
|
22
42
|
* @see
|
|
@@ -28,13 +48,22 @@ export default async (input, output, options = {}) => {
|
|
|
28
48
|
outlineTags: options.outlineTags || ['h1'],
|
|
29
49
|
}
|
|
30
50
|
|
|
51
|
+
if (options.debug) {
|
|
52
|
+
const optionsOutput = JSON.stringify(pdfOptions, null, 2)
|
|
53
|
+
console.debug(`[CLI:lib/pdf/pagedjs] PDF options\n${optionsOutput}`)
|
|
54
|
+
}
|
|
55
|
+
|
|
31
56
|
try {
|
|
32
57
|
console.info(`[CLI:lib/pdf/pagedjs] printing ${input}`)
|
|
58
|
+
|
|
33
59
|
const file = await printer.pdf(input, pdfOptions)
|
|
34
60
|
.catch((error) => console.error(error))
|
|
35
61
|
|
|
62
|
+
printer.close()
|
|
63
|
+
|
|
36
64
|
if (file && output) {
|
|
37
|
-
fs.writeFile(output, file
|
|
65
|
+
await fs.promises.writeFile(output, file)
|
|
66
|
+
.catch((error) => console.error(error))
|
|
38
67
|
}
|
|
39
68
|
} catch (ERR_FILE_NOT_FOUND) {
|
|
40
69
|
console.error(`[CLI:lib/pdf/pagedjs] file not found ${input}`)
|
package/src/lib/pdf/prince.js
CHANGED
|
@@ -8,10 +8,16 @@ import which from '#helpers/which.js'
|
|
|
8
8
|
export default async (input, output, options = {}) => {
|
|
9
9
|
which('prince')
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* @see https://www.princexml.com/doc/command-line/#options
|
|
13
|
+
*/
|
|
11
14
|
const cmdOptions = [
|
|
12
15
|
`--output=${output}`,
|
|
13
16
|
]
|
|
14
17
|
|
|
18
|
+
if (options.debug) cmdOptions.push('--debug')
|
|
19
|
+
if (options.verbose) cmdOptions.push('--verbose')
|
|
20
|
+
|
|
15
21
|
const { stderror, stdout } = await execa('prince', [...cmdOptions, input])
|
|
16
22
|
return { stderror, stdout }
|
|
17
23
|
}
|
package/src/lib/quire/index.js
CHANGED
|
@@ -3,9 +3,11 @@ import { chdir, cwd } from 'node:process'
|
|
|
3
3
|
import { execa, execaCommand } from 'execa'
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
5
|
import { isEmpty } from '#helpers/is-empty.js'
|
|
6
|
+
import fetch from 'node-fetch'
|
|
6
7
|
import fs from 'fs-extra'
|
|
7
8
|
import git from '#src/lib/git/index.js'
|
|
8
9
|
import inv from 'install-npm-version'
|
|
10
|
+
import packageConfig from '#root/package.json' assert { type: 'json' }
|
|
9
11
|
import path from 'node:path'
|
|
10
12
|
import semver from 'semver'
|
|
11
13
|
|
|
@@ -48,25 +50,19 @@ function getVersion(projectPath) {
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
|
-
* Read the required `quire-11ty`
|
|
53
|
+
* Read the required `quire-11ty` and starter versions from starter `package.json` `peerDependencies`
|
|
52
54
|
*
|
|
53
55
|
* @param {String} projectPath Absolute system path to the project root
|
|
54
56
|
*
|
|
55
|
-
* @return {
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* @TODO refactor `latest()` function to programmatically return a specific
|
|
59
|
-
* version of `@thegetty/quire-11ty` from a semantic version string
|
|
60
|
-
* (i.e `^1.0.0-pre-release.0` => `1.0.0-pre-release.2`) so this string-trimming
|
|
61
|
-
* logic can be removed
|
|
57
|
+
* @return {Object}
|
|
58
|
+
* @property {String} quire11tyVersion Latest compatible Quire-11ty semantic version
|
|
59
|
+
* @property {String} starterVersion Starter project version defined in the starter package.json
|
|
62
60
|
*/
|
|
63
|
-
async function
|
|
64
|
-
const
|
|
65
|
-
const { peerDependencies } = JSON.parse(
|
|
66
|
-
const
|
|
67
|
-
return
|
|
68
|
-
? await latest()
|
|
69
|
-
: version.substr(version.search(/\d/))
|
|
61
|
+
async function getVersionsFromStarter(projectPath) {
|
|
62
|
+
const projectPackageConfig = fs.readFileSync(path.join(projectPath, 'package.json'), { encoding:'utf8' })
|
|
63
|
+
const { peerDependencies, version: starterVersion } = JSON.parse(projectPackageConfig)
|
|
64
|
+
const quire11tyVersion = peerDependencies[PACKAGE_NAME]
|
|
65
|
+
return { quire11tyVersion, starterVersion }
|
|
70
66
|
}
|
|
71
67
|
|
|
72
68
|
/**
|
|
@@ -79,7 +75,7 @@ async function getVersionFromStarter(projectPath) {
|
|
|
79
75
|
* @return {String} quireVersion A string indicating the current version
|
|
80
76
|
* of quire being used with a new project
|
|
81
77
|
*/
|
|
82
|
-
async function initStarter (starter, projectPath) {
|
|
78
|
+
async function initStarter (starter, projectPath, options) {
|
|
83
79
|
projectPath = projectPath || cwd()
|
|
84
80
|
|
|
85
81
|
// ensure that the target path exists
|
|
@@ -110,12 +106,24 @@ async function initStarter (starter, projectPath) {
|
|
|
110
106
|
.catch((error) => console.error('[CLI:error] ', error))
|
|
111
107
|
|
|
112
108
|
/**
|
|
113
|
-
* Determine `quire-11ty` version
|
|
114
|
-
*
|
|
109
|
+
* Determine the `quire-11ty` version to use in the new project,
|
|
110
|
+
* from the `quireVersion` option or as required by the starter project.
|
|
111
|
+
*
|
|
112
|
+
* Uses `latest` to get the latest semantic version compatible with version ranges
|
|
115
113
|
*/
|
|
116
|
-
const
|
|
114
|
+
const { quire11tyVersion, starterVersion } = await getVersionsFromStarter(projectPath)
|
|
115
|
+
const quireVersion = await latest(options.quireVersion || quire11tyVersion)
|
|
117
116
|
setVersion(projectPath, quireVersion)
|
|
118
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Write quire-11ty, cli, starter name and version to VERSION_FILE
|
|
120
|
+
*/
|
|
121
|
+
const versionInfo = {
|
|
122
|
+
cli: packageConfig.version,
|
|
123
|
+
starter: `${starter}@${starterVersion}`,
|
|
124
|
+
}
|
|
125
|
+
fs.writeFileSync(path.join(projectPath, VERSION_FILE), JSON.stringify(versionInfo))
|
|
126
|
+
|
|
119
127
|
// Re-initialize project directory as a new git repository
|
|
120
128
|
await fs.remove(path.join(projectPath, '.git'))
|
|
121
129
|
|
|
@@ -135,18 +143,19 @@ async function initStarter (starter, projectPath) {
|
|
|
135
143
|
*/
|
|
136
144
|
const projectFiles = fs.readdirSync(projectPath)
|
|
137
145
|
await git.init().add(projectFiles).commit('Initial Commit')
|
|
138
|
-
|
|
139
146
|
return quireVersion
|
|
140
147
|
}
|
|
141
148
|
|
|
142
149
|
/**
|
|
143
|
-
* Install
|
|
150
|
+
* Install `quire-11ty`, default to 'latest' version
|
|
151
|
+
*
|
|
152
|
+
* @TODO refactor this to be callable by the installInProject method
|
|
144
153
|
*
|
|
145
|
-
* @param {String} version Quire-11ty semantic version
|
|
146
154
|
* @param {Object} options options passed from `quire new` command
|
|
147
155
|
* @return {Promise}
|
|
148
156
|
*/
|
|
149
|
-
async function install(
|
|
157
|
+
async function install(options = {}) {
|
|
158
|
+
const version = options.quireVersion || 'latest'
|
|
150
159
|
console.debug(`[CLI:quire] installing quire-11ty@${version}`)
|
|
151
160
|
const absoluteInstallPath = path.join(__dirname, 'versions')
|
|
152
161
|
fs.ensureDirSync(absoluteInstallPath)
|
|
@@ -185,19 +194,23 @@ async function install(version, options={}) {
|
|
|
185
194
|
}
|
|
186
195
|
|
|
187
196
|
/**
|
|
188
|
-
* Install
|
|
197
|
+
* Install `quire-11ty` directly into a quire project
|
|
198
|
+
*
|
|
199
|
+
* @TODO refactor this to use the install method with pre and post-install hooks
|
|
200
|
+
* or steps to prepare the working directory and cleanup on error and completion
|
|
189
201
|
*
|
|
190
202
|
* @param {String} projectPath Absolute system path to the project root
|
|
191
|
-
* @param {String} version Quire-11ty semantic version
|
|
192
203
|
* @param {Object} options options passed from `quire new` command
|
|
193
204
|
* @return {Promise}
|
|
194
205
|
*/
|
|
195
|
-
async function installInProject(projectPath,
|
|
196
|
-
|
|
206
|
+
async function installInProject(projectPath, quireVersion, options = {}) {
|
|
207
|
+
const { quirePath } = options
|
|
208
|
+
const quire11tyPackage = fs.existsSync(quirePath) ? quirePath : `${PACKAGE_NAME}@${quireVersion}`
|
|
209
|
+
console.debug(`[CLI:quire] installing ${quire11tyPackage} into ${projectPath}`)
|
|
197
210
|
|
|
198
211
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
212
|
+
* Delete the starter project package configuration so that it can be replaced
|
|
213
|
+
* with the `@thegetty/quire-11ty` configuration
|
|
201
214
|
* @TODO If a user runs quire eject at a later date we may want to merge their
|
|
202
215
|
* package.json with the `quire-11ty` dev dependencies, scripts, etc
|
|
203
216
|
*/
|
|
@@ -220,7 +233,7 @@ async function installInProject(projectPath, version, options={}) {
|
|
|
220
233
|
Verbosity: options.debug ? 'Debug' : 'Silent',
|
|
221
234
|
WorkingDirectory: projectPath
|
|
222
235
|
}
|
|
223
|
-
await inv.Install(
|
|
236
|
+
await inv.Install(quire11tyPackage, installOptions)
|
|
224
237
|
|
|
225
238
|
// delete empty `node_modules` directory that `install-npm-version` creates
|
|
226
239
|
const invNodeModulesDir = path.join(projectPath, 'node_modules')
|
|
@@ -262,25 +275,27 @@ async function installInProject(projectPath, version, options={}) {
|
|
|
262
275
|
|
|
263
276
|
/**
|
|
264
277
|
* Retrieve latest published version of the `quire-11ty` package
|
|
265
|
-
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* so that the latest function may be used like:
|
|
270
|
-
* await latest('^1.0.0-pre-release.0') => '1.0.0-pre-release.2'
|
|
271
|
-
*
|
|
272
|
-
* Nota bene: `npm view [<@scope>/]<name>[@<version>] version`
|
|
273
|
-
* @see https://docs.npmjs.com/cli/v7/commands/npm-view
|
|
274
|
-
* returns a list of versions that satisfy the `<version>` range specifier,
|
|
275
|
-
* piping this to execa `stdout` we get only the last line of output.
|
|
276
|
-
* @todo use [`parse-columns`](https://github.com/sindresorhus/parse-columns)
|
|
277
|
-
* to parse the column formated list of versions returned by `npm view`
|
|
278
|
-
*
|
|
278
|
+
* or the latest compatible version with the provided semantic version string
|
|
279
|
+
*
|
|
280
|
+
* @param {String} version A semantic version string, i.e `^1.0.0-pre-release.0`
|
|
281
|
+
*
|
|
279
282
|
* @return {String} `quire-11ty@latest` semantic version string
|
|
280
283
|
*/
|
|
281
|
-
async function latest() {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
+
async function latest(version) {
|
|
285
|
+
let quireVersion;
|
|
286
|
+
if (!version || version === 'latest') {
|
|
287
|
+
const { stdout } =
|
|
288
|
+
await execa('npm', ['view', PACKAGE_NAME, 'version'])
|
|
289
|
+
quireVersion = stdout
|
|
290
|
+
} else {
|
|
291
|
+
const response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}`)
|
|
292
|
+
const json = await response.json()
|
|
293
|
+
const versions = Object.keys(json.versions)
|
|
294
|
+
quireVersion = semver.maxSatisfying(versions, version)
|
|
295
|
+
}
|
|
296
|
+
if (!quireVersion) {
|
|
297
|
+
throw new Error(`[CLI:quire] Sorry, we couldn't find a version of quire-11ty compatible with the version "${version}". You can set the quire-11ty version in the starter project's package.json or specify a version when running \`quire new\` with the \`--quire-version\` flag. You can run \`npm view @thegetty/quire-11ty versions\` to view all versions.`)
|
|
298
|
+
}
|
|
284
299
|
return quireVersion
|
|
285
300
|
}
|
|
286
301
|
|
|
@@ -314,16 +329,11 @@ async function remove(version) {
|
|
|
314
329
|
/**
|
|
315
330
|
* Sets the quire-11ty version for a project
|
|
316
331
|
*
|
|
317
|
-
* @param {String} version
|
|
332
|
+
* @param {String} version a version identifier or distribution tag
|
|
318
333
|
*/
|
|
319
334
|
function setVersion(projectPath, version) {
|
|
320
|
-
if (!version) {
|
|
321
|
-
console.error('[CLI] no version specified')
|
|
322
|
-
}
|
|
323
335
|
const projectName = path.basename(projectPath)
|
|
324
336
|
console.info(`${projectName} set to use quire-11ty@${version}`)
|
|
325
|
-
const versionFilePath = path.join(projectPath, VERSION_FILE)
|
|
326
|
-
fs.writeFileSync(versionFilePath, version)
|
|
327
337
|
}
|
|
328
338
|
|
|
329
339
|
/**
|
package/src/main.js
CHANGED
|
@@ -14,7 +14,7 @@ const program = new Command()
|
|
|
14
14
|
program
|
|
15
15
|
.name('quire-cli')
|
|
16
16
|
.description('Quire command-line interface')
|
|
17
|
-
.version(packageConfig.version)
|
|
17
|
+
.version(packageConfig.version, '-v, --version', 'output quire version number')
|
|
18
18
|
.configureHelp({
|
|
19
19
|
helpWidth: 80,
|
|
20
20
|
sortOptions: false,
|