@thegetty/quire-cli 1.0.0-pre-release.7 → 1.0.0-pre-release.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@thegetty/quire-cli",
3
3
  "description": "Quire command-line interface",
4
- "version": "1.0.0-pre-release.7",
4
+ "version": "1.0.0-pre-release.8",
5
5
  "author": "Getty Digital",
6
6
  "license": "J Paul Getty Trust",
7
7
  "bugs": {
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "devDependencies": {
67
67
  "del-cli": "^5.0.0",
68
- "eslint": "^8.27.0"
68
+ "eslint": "^8.28.0"
69
69
  },
70
70
  "engines": {
71
71
  "node": ">=14.16"
@@ -1,5 +1,12 @@
1
1
  import fs from 'node:fs'
2
- import path from 'node:path'
2
+
3
+ const QUIRE_DOT_FILES = Object.freeze([
4
+ '.eleventy.js',
5
+ '.quire',
6
+ '.quire-11ty',
7
+ '.quire-version',
8
+ 'eleventy.config.js',
9
+ ])
3
10
 
4
11
  /**
5
12
  * Test if a directory is a Quire project root
@@ -8,11 +15,13 @@ import path from 'node:path'
8
15
  * a directory is a Quire project, testing a Quire project subdirectory will
9
16
  * return falsely negative result.
10
17
  *
18
+ * @todo refactor this to throw an Error NOTQUIRE
19
+ *
11
20
  * @param {String} dirpath path to a local directory
12
21
  * @return {Promise}
13
22
  */
14
23
  export function isQuire (dirpath) {
15
24
  return fs.readdirSync(dirpath)
16
- .includes((file) => file === '.eleventy.js' || file === '.quire.js')
25
+ .includes((file) => QUIRE_DOT_FILES.includes(file))
17
26
  }
18
27
 
@@ -0,0 +1,19 @@
1
+ import isQuire from '#helpers/is-quire.js'
2
+
3
+ /**
4
+ * Test current working directory is a Quire project directory
5
+ *
6
+ * @param {String} projectPath
7
+ * @return {Boolean}
8
+ */
9
+ export default (command) => {
10
+ const message = `[CLI] the '${command.name}' command must be run from a Quire project directory.`
11
+
12
+ return (projectPath) => {
13
+ if (!isQuire(process.cwd()) && !isQuire(projectPath)) {
14
+ if (command) console.error(message)
15
+ return false
16
+ }
17
+ return true
18
+ }
19
+ }
@@ -62,17 +62,20 @@ function getVersion(projectPath) {
62
62
  * (i.e `^1.0.0-pre-release.0` => `1.0.0-pre-release.2`) so this string-trimming
63
63
  * logic can be removed
64
64
  */
65
- function getVersionFromStarter(projectPath) {
65
+ async function getVersionFromStarter(projectPath) {
66
66
  const packageConfig = fs.readFileSync(path.join(projectPath, 'package.json'), { encoding:'utf8' })
67
67
  const { peerDependencies } = JSON.parse(packageConfig)
68
68
  const version = peerDependencies[PACKAGE_NAME]
69
- return version.substr(version.search(/\d/))
69
+ return version === 'latest'
70
+ ? await latest()
71
+ : version.substr(version.search(/\d/))
70
72
  }
71
73
 
72
74
  /**
73
75
  * Clone or copy a Quire starter project
74
76
  *
75
- * @param {String} starter A repository URL or path to local starter
77
+ * @param {String} starter A repository URL or an absolute path to local starter
78
+ * @TODO resolve both absolute and relative paths to local starter repositories
76
79
  * @param {String} projectPath Absolute system path to the project root
77
80
  *
78
81
  * @return {String} quireVersion A string indicating the current version
@@ -112,7 +115,7 @@ async function initStarter (starter, projectPath) {
112
115
  * Determine `quire-11ty` version required by the starter project
113
116
  * and write a `.quire` file with the semantic version string.
114
117
  */
115
- const quireVersion = getVersionFromStarter(projectPath) || await latest()
118
+ const quireVersion = await getVersionFromStarter(projectPath)
116
119
  setVersion(projectPath, quireVersion)
117
120
 
118
121
  // Re-initialize project directory as a new git repository
@@ -1,21 +0,0 @@
1
- // if (!commandExists('pagedjs-cli')) return
2
- // const opts = [
3
- // `--outline-tags 'h1'`,
4
- // `--output ${output}`,
5
- // ]
6
- // const { stderror, stdout } = execa('pagedjs-cli', [...opts, input])
7
-
8
- // console.info(`[CLI:lib/pdf] generating PDF using ${lib}`)
9
- // const Printer = await import('pagedjs-cli')
10
- /**
11
- * Configure the Paged.js Printer options
12
- * @see https://gitlab.coko.foundation/pagedjs/pagedjs-cli/-/blob/main/src/cli.js
13
- */
14
- // const printerOptions = { debug: options.debug || false }
15
- // const printer = new Printer(printerOptions)
16
- /**
17
- * Configure the Paged.js PDF options
18
- * @see
19
- */
20
- // const pdfOptions = {}
21
- // const pdfFile = await printer.pdf(input, pdfOptions)
@@ -1,7 +0,0 @@
1
- // if (!commandExists('prince')) return
2
- // const opts = [
3
- // `--outline-tags 'h1'`,
4
- // `--output ${output}`,
5
- // ]
6
- // console.info(`[CLI:lib/pdf] generating PDF using ${lib}`)
7
- // const { stderror, stdout } = execa('prince', [...opts, input])