@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/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 config from '#lib/conf/config.js'
|
|
7
|
+
import fetch from 'node-fetch'
|
|
6
8
|
import fs from 'fs-extra'
|
|
7
|
-
import git from '#
|
|
8
|
-
import
|
|
9
|
+
import git from '#lib/git/index.js'
|
|
10
|
+
import packageConfig from '#src/packageConfig.js'
|
|
9
11
|
import path from 'node:path'
|
|
10
12
|
import semver from 'semver'
|
|
11
13
|
|
|
@@ -15,17 +17,19 @@ const __dirname = path.dirname(__filename)
|
|
|
15
17
|
// Version install path is relative to process working directory
|
|
16
18
|
const INSTALL_PATH = path.join('src', 'lib', 'quire', 'versions')
|
|
17
19
|
const PACKAGE_NAME = '@thegetty/quire-11ty'
|
|
18
|
-
|
|
20
|
+
|
|
21
|
+
const QUIRE_VERSION = config.get('quireVersion')
|
|
22
|
+
const VERSION_FILE = config.get('versionFile')
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
|
-
* Return an absolute path to an installed
|
|
25
|
+
* Return an absolute path to an installed quire-11ty version
|
|
22
26
|
*
|
|
23
|
-
* @return {String} path to installed
|
|
27
|
+
* @return {String} path to installed quire-11ty version
|
|
24
28
|
*/
|
|
25
|
-
function getPath(version=
|
|
26
|
-
const absolutePath = path.relative('/',
|
|
29
|
+
function getPath(version=QUIRE_VERSION) {
|
|
30
|
+
const absolutePath = path.relative('/', path.join(INSTALL_PATH, version))
|
|
27
31
|
if (!fs.existsSync(absolutePath)) {
|
|
28
|
-
console.error(`[CLI:quire]
|
|
32
|
+
console.error(`[CLI:quire] quire-11ty@${version} is not installed`)
|
|
29
33
|
return null
|
|
30
34
|
}
|
|
31
35
|
console.debug(`[CLI:quire] %s`, absolutePath)
|
|
@@ -33,7 +37,7 @@ function getPath(version='latest') {
|
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
/**
|
|
36
|
-
* Read the required
|
|
40
|
+
* Read the required quire-11ty version for the quire version file
|
|
37
41
|
*
|
|
38
42
|
* @param {String} projectPath Absolute system path to the project root
|
|
39
43
|
*
|
|
@@ -48,25 +52,19 @@ function getVersion(projectPath) {
|
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
/**
|
|
51
|
-
* Read
|
|
55
|
+
* Read required quire-11ty and starter versions from starter peerDependencies
|
|
52
56
|
*
|
|
53
57
|
* @param {String} projectPath Absolute system path to the project root
|
|
54
58
|
*
|
|
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
|
|
59
|
+
* @return {Object}
|
|
60
|
+
* @property {String} quire11tyVersion Latest compatible Quire-11ty semantic version
|
|
61
|
+
* @property {String} starterVersion Starter project version defined in the starter package.json
|
|
62
62
|
*/
|
|
63
|
-
async function
|
|
64
|
-
const
|
|
65
|
-
const { peerDependencies } = JSON.parse(
|
|
66
|
-
const
|
|
67
|
-
return
|
|
68
|
-
? await latest()
|
|
69
|
-
: version.substr(version.search(/\d/))
|
|
63
|
+
async function getVersionsFromStarter(projectPath) {
|
|
64
|
+
const projectPackageConfig = fs.readFileSync(path.join(projectPath, 'package.json'), { encoding:'utf8' })
|
|
65
|
+
const { peerDependencies, version: starterVersion } = JSON.parse(projectPackageConfig)
|
|
66
|
+
const quire11tyVersion = peerDependencies[PACKAGE_NAME]
|
|
67
|
+
return { quire11tyVersion, starterVersion }
|
|
70
68
|
}
|
|
71
69
|
|
|
72
70
|
/**
|
|
@@ -79,7 +77,7 @@ async function getVersionFromStarter(projectPath) {
|
|
|
79
77
|
* @return {String} quireVersion A string indicating the current version
|
|
80
78
|
* of quire being used with a new project
|
|
81
79
|
*/
|
|
82
|
-
async function initStarter (starter, projectPath) {
|
|
80
|
+
async function initStarter (starter, projectPath, options) {
|
|
83
81
|
projectPath = projectPath || cwd()
|
|
84
82
|
|
|
85
83
|
// ensure that the target path exists
|
|
@@ -93,11 +91,9 @@ async function initStarter (starter, projectPath) {
|
|
|
93
91
|
return
|
|
94
92
|
}
|
|
95
93
|
|
|
96
|
-
starter = starter || 'https://github.com/thegetty/quire-starter-default'
|
|
97
|
-
|
|
98
94
|
console.debug('[CLI:quire] init-starter',
|
|
99
|
-
`\n project
|
|
100
|
-
`\n starter:
|
|
95
|
+
`\n project: ${path.join(__dirname, projectPath)}`,
|
|
96
|
+
`\n starter: ${starter}`
|
|
101
97
|
)
|
|
102
98
|
|
|
103
99
|
/**
|
|
@@ -110,12 +106,24 @@ async function initStarter (starter, projectPath) {
|
|
|
110
106
|
.catch((error) => console.error('[CLI:error] ', error))
|
|
111
107
|
|
|
112
108
|
/**
|
|
113
|
-
* Determine
|
|
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, quire-cli, starter versions to the 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,69 +143,28 @@ 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` directly into a quire project
|
|
144
151
|
*
|
|
145
|
-
* @
|
|
146
|
-
*
|
|
147
|
-
* @return {Promise}
|
|
148
|
-
*/
|
|
149
|
-
async function install(version, options={}) {
|
|
150
|
-
console.debug(`[CLI:quire] installing quire-11ty@${version}`)
|
|
151
|
-
const absoluteInstallPath = path.join(__dirname, 'versions')
|
|
152
|
-
fs.ensureDirSync(absoluteInstallPath)
|
|
153
|
-
/**
|
|
154
|
-
* `Destination` is relative to `node_modules` of the working-directory
|
|
155
|
-
* so we have included a relative path to parent directory in order to
|
|
156
|
-
* install versions to a different local path.
|
|
157
|
-
* @see https://github.com/scott-lin/install-npm-version
|
|
158
|
-
*/
|
|
159
|
-
const installOptions = {
|
|
160
|
-
Destination: path.join('..', version),
|
|
161
|
-
Debug: false,
|
|
162
|
-
Overwrite: options.force || options.overwrite || false,
|
|
163
|
-
Verbosity: options.debug ? 'Debug' : 'Silent',
|
|
164
|
-
WorkingDirectory: absoluteInstallPath
|
|
165
|
-
}
|
|
166
|
-
await inv.Install(`${PACKAGE_NAME}@${version}`, installOptions)
|
|
167
|
-
|
|
168
|
-
// delete empty `node_modules` directory that `install-npm-version` creates
|
|
169
|
-
const invNodeModulesDir = path.join(absoluteInstallPath, 'node_modules')
|
|
170
|
-
if (fs.existsSync(invNodeModulesDir)) fs.rmdir(invNodeModulesDir)
|
|
171
|
-
|
|
172
|
-
symlinkLatest()
|
|
173
|
-
|
|
174
|
-
console.debug('[CLI:quire] installing dev dependencies')
|
|
175
|
-
/**
|
|
176
|
-
* Manually install necessary dev dependencies to run 11ty;
|
|
177
|
-
* these must be `devDependencies` so that they are not bundled into
|
|
178
|
-
* the final `_site` package when running `quire build`
|
|
179
|
-
*/
|
|
180
|
-
const currentWorkingDirectory = cwd()
|
|
181
|
-
const versionDir = path.join(absoluteInstallPath, version)
|
|
182
|
-
chdir(versionDir)
|
|
183
|
-
await execaCommand('npm cache clean --force')
|
|
184
|
-
await execaCommand('npm install --save-dev')
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Install a specific version of `quire-11ty` directly into a quire project
|
|
152
|
+
* @TODO refactor this to use the install method with pre and post-install hooks
|
|
153
|
+
* or steps to prepare the working directory and cleanup on error and completion
|
|
189
154
|
*
|
|
190
155
|
* @param {String} projectPath Absolute system path to the project root
|
|
191
|
-
* @param {String} version Quire-11ty semantic version
|
|
192
156
|
* @param {Object} options options passed from `quire new` command
|
|
193
157
|
* @return {Promise}
|
|
194
158
|
*/
|
|
195
|
-
async function installInProject(projectPath,
|
|
196
|
-
|
|
159
|
+
async function installInProject(projectPath, quireVersion, options = {}) {
|
|
160
|
+
const { quirePath } = options
|
|
161
|
+
const quire11tyPackage = `${PACKAGE_NAME}@${quireVersion}`
|
|
162
|
+
|
|
163
|
+
console.debug(`[CLI:quire] installing ${quire11tyPackage} into ${projectPath}`)
|
|
197
164
|
|
|
198
165
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
166
|
+
* Delete the starter project package configuration so that it can be replaced
|
|
167
|
+
* with the `@thegetty/quire-11ty` configuration
|
|
201
168
|
* @TODO If a user runs quire eject at a later date we may want to merge their
|
|
202
169
|
* package.json with the `quire-11ty` dev dependencies, scripts, etc
|
|
203
170
|
*/
|
|
@@ -207,27 +174,21 @@ async function installInProject(projectPath, version, options={}) {
|
|
|
207
174
|
.catch((error) => console.error('[CLI:error] ', error))
|
|
208
175
|
|
|
209
176
|
const temp11tyDirectory = '.temp'
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
Debug: false,
|
|
219
|
-
Overwrite: options.force || options.overwrite || false,
|
|
220
|
-
Verbosity: options.debug ? 'Debug' : 'Silent',
|
|
221
|
-
WorkingDirectory: projectPath
|
|
222
|
-
}
|
|
223
|
-
await inv.Install(`${PACKAGE_NAME}@${version}`, installOptions)
|
|
177
|
+
const tempDir = path.join(projectPath,temp11tyDirectory)
|
|
178
|
+
fs.mkdirSync(tempDir)
|
|
179
|
+
|
|
180
|
+
// Copy if passed a path and it exists, otherwise attempt to download the tarball for this pathspec
|
|
181
|
+
if (fs.existsSync(quirePath)) {
|
|
182
|
+
fs.copySync(quirePath, tempDir)
|
|
183
|
+
} else {
|
|
184
|
+
await execaCommand(`npm pack ${ options.debug ? '--debug' : '--quiet' } ${quire11tyPackage}`)
|
|
224
185
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
186
|
+
// Extract only the package dir from the tar bar and strip it from the extracted path
|
|
187
|
+
await execaCommand(`tar -xzf thegetty-quire-11ty-${quireVersion}.tgz -C ${tempDir} --strip-components=1 package/`)
|
|
188
|
+
}
|
|
228
189
|
|
|
229
|
-
// Copy
|
|
230
|
-
fs.copySync(
|
|
190
|
+
// Copy `.temp` to projectPath
|
|
191
|
+
fs.copySync(tempDir, projectPath)
|
|
231
192
|
|
|
232
193
|
console.debug('[CLI:quire] installing dev dependencies into quire project')
|
|
233
194
|
/**
|
|
@@ -245,7 +206,7 @@ async function installInProject(projectPath, version, options={}) {
|
|
|
245
206
|
}
|
|
246
207
|
|
|
247
208
|
const eleventyFilesToCommit = fs
|
|
248
|
-
.readdirSync(
|
|
209
|
+
.readdirSync(tempDir)
|
|
249
210
|
.filter((filePath) => filePath !== 'node_modules')
|
|
250
211
|
|
|
251
212
|
eleventyFilesToCommit.push('package-lock.json')
|
|
@@ -262,25 +223,27 @@ async function installInProject(projectPath, version, options={}) {
|
|
|
262
223
|
|
|
263
224
|
/**
|
|
264
225
|
* 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
|
-
*
|
|
226
|
+
* or the latest compatible version with the provided semantic version string
|
|
227
|
+
*
|
|
228
|
+
* @param {String} version A semantic version string, i.e `^1.0.0-pre-release.0`
|
|
229
|
+
*
|
|
279
230
|
* @return {String} `quire-11ty@latest` semantic version string
|
|
280
231
|
*/
|
|
281
|
-
async function latest() {
|
|
282
|
-
|
|
283
|
-
|
|
232
|
+
async function latest(version) {
|
|
233
|
+
let quireVersion;
|
|
234
|
+
if (!version || version === 'latest') {
|
|
235
|
+
const { stdout } =
|
|
236
|
+
await execa('npm', ['view', PACKAGE_NAME, 'version'])
|
|
237
|
+
quireVersion = stdout
|
|
238
|
+
} else {
|
|
239
|
+
const response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}`)
|
|
240
|
+
const json = await response.json()
|
|
241
|
+
const versions = Object.keys(json.versions)
|
|
242
|
+
quireVersion = semver.maxSatisfying(versions, version)
|
|
243
|
+
}
|
|
244
|
+
if (!quireVersion) {
|
|
245
|
+
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.`)
|
|
246
|
+
}
|
|
284
247
|
return quireVersion
|
|
285
248
|
}
|
|
286
249
|
|
|
@@ -314,16 +277,11 @@ async function remove(version) {
|
|
|
314
277
|
/**
|
|
315
278
|
* Sets the quire-11ty version for a project
|
|
316
279
|
*
|
|
317
|
-
* @param {String} version
|
|
280
|
+
* @param {String} version a version identifier or distribution tag
|
|
318
281
|
*/
|
|
319
282
|
function setVersion(projectPath, version) {
|
|
320
|
-
if (!version) {
|
|
321
|
-
console.error('[CLI] no version specified')
|
|
322
|
-
}
|
|
323
283
|
const projectName = path.basename(projectPath)
|
|
324
284
|
console.info(`${projectName} set to use quire-11ty@${version}`)
|
|
325
|
-
const versionFilePath = path.join(projectPath, VERSION_FILE)
|
|
326
|
-
fs.writeFileSync(versionFilePath, version)
|
|
327
285
|
}
|
|
328
286
|
|
|
329
287
|
/**
|
|
@@ -370,19 +328,6 @@ function symlinkLatest() {
|
|
|
370
328
|
return fs.symlinkSync(target, source, type)
|
|
371
329
|
}
|
|
372
330
|
|
|
373
|
-
/**
|
|
374
|
-
* Tests if a `quire-11ty` version is already installed
|
|
375
|
-
* and installs the version if it is not already installed.
|
|
376
|
-
*
|
|
377
|
-
* @param {String} version `quire-11ty` semantic version
|
|
378
|
-
*/
|
|
379
|
-
function testVersion(version) {
|
|
380
|
-
version ||= getVersion()
|
|
381
|
-
if (!versions.includes(version)) {
|
|
382
|
-
install(version)
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
331
|
/**
|
|
387
332
|
* Get an array of published `quire-11ty` package versions
|
|
388
333
|
*
|
|
@@ -396,12 +341,10 @@ export const quire = {
|
|
|
396
341
|
getPath,
|
|
397
342
|
getVersion,
|
|
398
343
|
initStarter,
|
|
399
|
-
install,
|
|
400
344
|
installInProject,
|
|
401
345
|
latest,
|
|
402
346
|
list,
|
|
403
347
|
remove,
|
|
404
348
|
setVersion,
|
|
405
|
-
testVersion,
|
|
406
349
|
versions,
|
|
407
350
|
}
|
package/src/main.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Argument, Command, Option } from 'commander'
|
|
2
|
-
import commands from '
|
|
3
|
-
import
|
|
2
|
+
import commands from '#src/commands/index.js'
|
|
3
|
+
import config from '#lib/conf/config.js'
|
|
4
|
+
import packageConfig from '#src/packageConfig.js'
|
|
5
|
+
|
|
6
|
+
const { version } = packageConfig
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* Quire CLI implements the command pattern.
|
|
@@ -12,9 +15,9 @@ import packageConfig from '../package.json' assert { type: 'json' }
|
|
|
12
15
|
const program = new Command()
|
|
13
16
|
|
|
14
17
|
program
|
|
15
|
-
.name('quire
|
|
18
|
+
.name('quire')
|
|
16
19
|
.description('Quire command-line interface')
|
|
17
|
-
.version(
|
|
20
|
+
.version(version, '-v, --version', 'output quire version number')
|
|
18
21
|
.configureHelp({
|
|
19
22
|
helpWidth: 80,
|
|
20
23
|
sortOptions: false,
|
|
@@ -23,9 +26,12 @@ program
|
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* Register each command as a subcommand of this program
|
|
29
|
+
*
|
|
30
|
+
* @todo refactor command definition to allow for per-command custom help text
|
|
31
|
+
* @see https://github.com/tj/commander.js?tab=readme-ov-file#automated-help
|
|
26
32
|
*/
|
|
27
33
|
commands.forEach((command) => {
|
|
28
|
-
const { action, aliases, args, description, name, options } = command
|
|
34
|
+
const { action, alias, aliases, args, description, name, options } = command
|
|
29
35
|
|
|
30
36
|
const subCommand = program
|
|
31
37
|
.command(name)
|
|
@@ -33,8 +39,12 @@ commands.forEach((command) => {
|
|
|
33
39
|
.addHelpCommand()
|
|
34
40
|
.showHelpAfterError()
|
|
35
41
|
|
|
42
|
+
if (alias instanceof String) {
|
|
43
|
+
subCommand.alias(alias)
|
|
44
|
+
}
|
|
45
|
+
|
|
36
46
|
if (Array.isArray(aliases)) {
|
|
37
|
-
|
|
47
|
+
subCommand.aliases(aliases)
|
|
38
48
|
}
|
|
39
49
|
|
|
40
50
|
/**
|
|
@@ -103,6 +113,11 @@ commands.forEach((command) => {
|
|
|
103
113
|
|
|
104
114
|
// subCommand.action((args) => action.apply(command, args))
|
|
105
115
|
subCommand.action(action)
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Inject the CLI configuration into commands
|
|
119
|
+
*/
|
|
120
|
+
subCommand.config = config
|
|
106
121
|
})
|
|
107
122
|
|
|
108
123
|
/**
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { dirname } from 'node:path'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import { readPackageUpSync } from 'read-package-up'
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
6
|
+
const __dirname = dirname(__filename)
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Nota bene: current working directory will be that from which cli commands
|
|
10
|
+
* are being, readPackageUpSync is passed the directory of this module as the
|
|
11
|
+
* starting path to search for the quire-cli package config file.
|
|
12
|
+
*/
|
|
13
|
+
const { packageJson } = readPackageUpSync({ cwd: __dirname, normalize: true })
|
|
14
|
+
|
|
15
|
+
export default packageJson
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* { item_description }
|
|
3
|
-
*/
|
|
4
|
-
module.export = (eleventyConfig) => {
|
|
5
|
-
/**
|
|
6
|
-
* The `eleventy.before` event runs every time Eleventy starts building,
|
|
7
|
-
* it will run before the start of each stand-alone build, as well as
|
|
8
|
-
* each time building starts as either part of `--watch` or `--serve`.
|
|
9
|
-
* @see https://www.11ty.dev/docs/events/#eleventy.before
|
|
10
|
-
*/
|
|
11
|
-
eleventyConfig.on('eleventy.before', async () => {
|
|
12
|
-
console.debug('[11ty] before build')
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
return eleventyConfig
|
|
16
|
-
}
|
package/src/lib/config/README.md
DELETED
package/src/lib/config/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import semver from 'semver'
|
package/src/lib/quire/project.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { CONSTANT } from 'constants.js'
|
|
2
|
-
import fs from 'fs-extra'
|
|
3
|
-
import path from 'node:path'
|
|
4
|
-
|
|
5
|
-
const { PACKAGE_NAME } = CONSTANT
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Read the required `quire-11ty` version from starter `package.json` `peerDependencies`
|
|
9
|
-
*
|
|
10
|
-
* @param {String} projectPath Absolute system path to the project root
|
|
11
|
-
*
|
|
12
|
-
* @return {String} version Quire-11ty semantic version with caret or other
|
|
13
|
-
* comparators trimmed off the beginning
|
|
14
|
-
*
|
|
15
|
-
* @TODO refactor `latest()` function to programmatically return a specific
|
|
16
|
-
* version of `@thegetty/quire-11ty` from a semantic version string
|
|
17
|
-
* (i.e `^1.0.0-pre-release.0` => `1.0.0-pre-release.2`) so this string-trimming
|
|
18
|
-
* logic can be removed
|
|
19
|
-
*/
|
|
20
|
-
async function getVersion(projectPath) {
|
|
21
|
-
const packageConfig = fs.readFileSync(path.join(projectPath, 'package.json'), { encoding:'utf8' })
|
|
22
|
-
const { peerDependencies } = JSON.parse(packageConfig)
|
|
23
|
-
const version = peerDependencies[PACKAGE_NAME]
|
|
24
|
-
return version === 'latest'
|
|
25
|
-
? await latest()
|
|
26
|
-
: version.substr(version.search(/\d/))
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Clone or copy a Quire starter project
|
|
31
|
-
*
|
|
32
|
-
* @param {String} starter A repository URL or an absolute path to local starter
|
|
33
|
-
* @TODO resolve both absolute and relative paths to local starter repositories
|
|
34
|
-
* @param {String} projectPath Absolute system path to the project root
|
|
35
|
-
*
|
|
36
|
-
* @return {String} quireVersion A string indicating the current version
|
|
37
|
-
* of quire being used with a new project
|
|
38
|
-
*/
|
|
39
|
-
async function init (starter, projectPath) {
|
|
40
|
-
projectPath = projectPath || cwd()
|
|
41
|
-
|
|
42
|
-
// ensure that the target path exists
|
|
43
|
-
fs.ensureDirSync(projectPath)
|
|
44
|
-
|
|
45
|
-
// if the target directory exists it must be empty
|
|
46
|
-
if (!isEmpty(projectPath)) {
|
|
47
|
-
const location = projectPath === '.' ? 'the current directory' : projectPath
|
|
48
|
-
console.error(`[CLI] cannot create a starter project in ${location} because it is not empty`)
|
|
49
|
-
// @TODO cleanup directories from failed new command
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
starter = starter || 'https://github.com/thegetty/quire-starter-default'
|
|
54
|
-
|
|
55
|
-
console.debug('[CLI:quire] init-starter',
|
|
56
|
-
`\n project root: "${projectPath}"`,
|
|
57
|
-
`\n starter: "${starter}"`
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Clone starter project repository
|
|
62
|
-
* @todo pipe `git clone` status to stdout for better UX
|
|
63
|
-
*/
|
|
64
|
-
await git
|
|
65
|
-
.cwd(projectPath)
|
|
66
|
-
.clone(starter, '.')
|
|
67
|
-
.catch((error) => console.error('[CLI:error] ', error))
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Determine `quire-11ty` version required by the starter project
|
|
71
|
-
* and write a `.quire` file with the semantic version string.
|
|
72
|
-
*/
|
|
73
|
-
const quireVersion = await getVersion(projectPath)
|
|
74
|
-
setVersion(projectPath, quireVersion)
|
|
75
|
-
|
|
76
|
-
// Re-initialize project directory as a new git repository
|
|
77
|
-
await fs.remove(path.join(projectPath, '.git'))
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Remove the starter repository package config file
|
|
81
|
-
* and create a new package config for the project
|
|
82
|
-
* (this is necessary for Eleventy to resolve project paths)
|
|
83
|
-
* @todo allow interactive init using a custom questionnaire
|
|
84
|
-
* @see https://docs.npmjs.com/creating-a-package-json-file#customizing-the-packagejson-questionnaire
|
|
85
|
-
*/
|
|
86
|
-
await fs.remove(path.join(projectPath, 'package.json'))
|
|
87
|
-
await execaCommand('npm init --yes', { cwd: projectPath })
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Create an initial commit of files in new repository
|
|
91
|
-
* @todo use a localized string for the commit message
|
|
92
|
-
*/
|
|
93
|
-
const projectFiles = fs.readdirSync(projectPath)
|
|
94
|
-
await git.init().add(projectFiles).commit('Initial Commit')
|
|
95
|
-
|
|
96
|
-
return quireVersion
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Update quire-11ty
|
|
101
|
-
*
|
|
102
|
-
* @return {Promise} { description_of_the_return_value }
|
|
103
|
-
*/
|
|
104
|
-
async function update () {}
|