@thegetty/quire-cli 1.0.0-pre-release.12 → 1.0.0-pre-release.14

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,9 +1,9 @@
1
1
  {
2
2
  "name": "@thegetty/quire-cli",
3
3
  "description": "Quire command-line interface",
4
- "version": "1.0.0-pre-release.12",
4
+ "version": "1.0.0-pre-release.14",
5
5
  "author": "Getty Digital",
6
- "license": "J Paul Getty Trust",
6
+ "license": "SEE LICENSE IN https://github.com/thegetty/quire/blob/main/LICENSE",
7
7
  "bugs": {
8
8
  "url": "https://github.com/thegetty/quire/issues"
9
9
  },
@@ -1,6 +1,7 @@
1
1
  import Command from '#src/Command.js'
2
2
  import { api, cli, paths, projectRoot } from '#lib/11ty/index.js'
3
3
  import { clean } from '#helpers/clean.js'
4
+ import testcwd from '#helpers/test-cwd.js'
4
5
 
5
6
  /**
6
7
  * Quire CLI `build` Command
@@ -56,6 +57,8 @@ export default class BuildCommand extends Command {
56
57
  }
57
58
 
58
59
  preAction(command) {
60
+ testcwd(command)
61
+
59
62
  const options = command.opts()
60
63
  if (options.debug) {
61
64
  console.debug('[CLI] Calling \'build\' command pre-action with options', options)
@@ -1,6 +1,7 @@
1
1
  import Command from '#src/Command.js'
2
2
  import { clean } from '#helpers/clean.js'
3
3
  import { paths, projectRoot } from '#lib/11ty/index.js'
4
+ import testcwd from '#helpers/test-cwd.js'
4
5
 
5
6
  /**
6
7
  * Quire CLI `clean` Command
@@ -53,4 +54,8 @@ export default class CleanCommand extends Command {
53
54
 
54
55
  console.debug(`[CLI] ${message} ${deletedPaths}`)
55
56
  }
57
+
58
+ preAction(command) {
59
+ testcwd(command)
60
+ }
56
61
  }
@@ -1,5 +1,6 @@
1
1
  import Command from '#src/Command.js'
2
2
  import { api, cli, paths, projectRoot } from '#lib/11ty/index.js'
3
+ import testcwd from '#helpers/test-cwd.js'
3
4
 
4
5
  /**
5
6
  * Quire CLI `preview` Command
@@ -53,4 +54,8 @@ export default class PreviewCommand extends Command {
53
54
  api.serve(options)
54
55
  }
55
56
  }
57
+
58
+ preAction(command) {
59
+ testcwd(command)
60
+ }
56
61
  }
@@ -1,5 +1,7 @@
1
1
  import Command from '#src/Command.js'
2
+ import { paths, projectRoot } from '#lib/11ty/index.js'
2
3
  import * as quire from '#lib/quire/index.js'
4
+ import testcwd from '#helpers/test-cwd.js'
3
5
 
4
6
  /**
5
7
  * Quire CLI `version` Command
@@ -21,7 +23,7 @@ export default class VersionCommand extends Command {
21
23
  [ '<version>', 'the local quire version to use' ],
22
24
  ],
23
25
  options: [
24
- [ '-g', '--global', 'set the quire version globally' ],
26
+ // [ '-g', '--global', 'set the quire version globally' ],
25
27
  ],
26
28
  }
27
29
 
@@ -29,9 +31,13 @@ export default class VersionCommand extends Command {
29
31
  super(VersionCommand.definition)
30
32
  }
31
33
 
32
- async action(path, starter, options = {}) {
34
+ action(args, options = {}) {
33
35
  if (options.debug) {
34
36
  console.info('Command \'%s\' called with options %o', this.name, options)
35
37
  }
36
38
  }
39
+
40
+ preAction(command) {
41
+ testcwd(command)
42
+ }
37
43
  }
@@ -20,8 +20,8 @@ const QUIRE_DOT_FILES = Object.freeze([
20
20
  * @param {String} dirpath path to a local directory
21
21
  * @return {Promise}
22
22
  */
23
- export function isQuire (dirpath) {
23
+ export default function (dirpath) {
24
24
  return fs.readdirSync(dirpath)
25
- .includes((file) => QUIRE_DOT_FILES.includes(file))
25
+ .find((entry) => QUIRE_DOT_FILES.includes(entry))
26
26
  }
27
27
 
@@ -3,17 +3,13 @@ import isQuire from '#helpers/is-quire.js'
3
3
  /**
4
4
  * Test current working directory is a Quire project directory
5
5
  *
6
- * @param {String} projectPath
7
- * @return {Boolean}
6
+ * @param {Command} command the command from which testcwd was called
8
7
  */
9
8
  export default (command) => {
10
- const message = `[CLI] the '${command.name}' command must be run from a Quire project directory.`
9
+ const message = `[CLI] ${ command ? command.name() : '' } command must be run while in a Quire project directory. Use 'cd' to navigate to your project directory and re-run the 'quire ${ command ? command.name() : '' }' command.`
11
10
 
12
- return (projectPath) => {
13
- if (!isQuire(process.cwd()) && !isQuire(projectPath)) {
14
- if (command) console.error(message)
15
- return false
16
- }
17
- return true
11
+ if (!isQuire(process.cwd())) {
12
+ console.error(message)
13
+ process.exit(1)
18
14
  }
19
15
  }
@@ -23,15 +23,6 @@ const cliRoot = path.resolve(__dirname, path.join('..', '..'))
23
23
  const eleventyConfig = '.eleventy.js'
24
24
  const version = 'latest'
25
25
 
26
- // Test project directory for an eleventy configuration file
27
- const hasEleventyConfig = (dir) => {
28
- try {
29
- return fs.readdirSync(dir).includes(eleventyConfig)
30
- } catch (error) {
31
- throw new Error(`[CLI:11ty] Unable to read project directory for eleventy config ${error}`)
32
- }
33
- }
34
-
35
26
  export const projectRoot = process.cwd()
36
27
 
37
28
  const inputDir = path.join(projectRoot, 'content')
@@ -47,10 +38,49 @@ const libQuirePath = path.resolve(__dirname, path.join(cliRoot, 'lib', 'quire',
47
38
  * Nota bene: to get a relative path to the `eleventyRoot`,
48
39
  * for example when the version is specified is 'latest',
49
40
  * it must be set to the real path to the symlink target.
41
+ *
42
+ * @todo refactor how and *when* the eleventyRoot is determined:
43
+ * - we only need eleventyRoot for cli commands that run 11ty
44
+ * - paths module is a concern of the `quire` module
45
+ * - global quire-cli installation
46
+ * - local quire-cli installation
47
+ *
48
+ * For an excellent developer experience, the quire-11ty code should be
49
+ * installed into an `11ty` or `quire-11ty` directory in the `projectRoot`
50
+ * this will allow us to more easily manage symlinks for local development
51
+ * using unpublished `quire-11ty` code.
52
+ * @example
53
+ * ```sh
54
+ * blargh/
55
+ * .git/
56
+ * .gitignore
57
+ * .node-version
58
+ * .quire-version
59
+ * 11ty@ --> /Users/mph/Code/Getty/quire/packages/11ty
60
+ * content/
61
+ * CHANGELOG.md
62
+ * LICENSE
63
+ * README.md
64
+ * package.json
65
+ * package-lock.json
66
+ * ```
67
+ * Installing to a directory will allow more cleanly `eject` and `uneject`
68
+ * using a symlink or single directory `rm -rf`.
69
+ * Should the `11ty` directory be a dot directory to hide the complexity from
70
+ * users or should it be visible to be more explicit when project is ejected?
50
71
  */
51
- export const eleventyRoot = hasEleventyConfig(projectRoot)
52
- ? projectRoot
53
- : fs.realpathSync(libQuirePath)
72
+ const getEleventyRoot = () => {
73
+ // try {
74
+ // return fs.readdirSync(projectRoot).includes(eleventyConfig)
75
+ // ? projectRoot
76
+ // : fs.realpathSync(libQuirePath)
77
+ // } catch (error) {
78
+ // throw new Error(`[CLI:11ty] Unable to read project directory for eleventy config ${error}`)
79
+ // }
80
+ return projectRoot
81
+ }
82
+
83
+ export const eleventyRoot = getEleventyRoot()
54
84
 
55
85
  export default {
56
86
  config: path.join(eleventyRoot, '.eleventy.js'),
@@ -262,17 +262,21 @@ async function installInProject(projectPath, version, options={}) {
262
262
 
263
263
  /**
264
264
  * Retrieve latest published version of the `quire-11ty` package
265
+
266
+ * @todo refactor to programmatically return a specific version
267
+ * of `@thegetty/quire-11ty` from a semantic version string
268
+ * (i.e `^1.0.0-pre-release.0` => `1.0.0-pre-release.2`)
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
+ *
265
272
  * Nota bene: `npm view [<@scope>/]<name>[@<version>] version`
266
273
  * @see https://docs.npmjs.com/cli/v7/commands/npm-view
267
274
  * returns a list of versions that satisfy the `<version>` range specifier,
268
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`
269
278
  *
270
279
  * @return {String} `quire-11ty@latest` semantic version string
271
- *
272
- * @TODO refactor `latest()` function to programmatically return a specific
273
- * version of `@thegetty/quire-11ty` from a semantic version string
274
- * (i.e `^1.0.0-pre-release.0` => `1.0.0-pre-release.2`) so it may be used like:
275
- * await latest('^1.0.0-pre-release.0') => '1.0.0-pre-release.2'
276
280
  */
277
281
  async function latest() {
278
282
  const { stdout: quireVersion } =
package/LICENSE DELETED
@@ -1 +0,0 @@
1
- Copyright (c) 2022, J Paul Getty Trust.