@thegetty/quire-cli 1.0.0-rc.3 → 1.0.0-rc.6

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/bin/cli.js CHANGED
@@ -20,12 +20,12 @@ const INTERVAL = Object.freeze({
20
20
  * @todo user configuration of choosen update interval
21
21
  */
22
22
  const notifier = updateNotifier({
23
- distTag: 'rc',
23
+ distTag: 'latest',
24
24
  pkg: packageConfig,
25
25
  updateCheckInterval: INTERVAL.DAILY,
26
26
  })
27
27
 
28
- notifier.notify()
28
+ notifier.notify({ defer: false })
29
29
 
30
30
  /**
31
31
  * Run the cli program
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-rc.3",
4
+ "version": "1.0.0-rc.6",
5
5
  "author": "Getty Digital",
6
6
  "license": "SEE LICENSE IN https://github.com/thegetty/quire/blob/main/LICENSE",
7
7
  "bugs": {
@@ -80,6 +80,26 @@ To create a new project from a starter template
80
80
  quire new <path> <starter>
81
81
  ```
82
82
 
83
+ #### Specifying the `quire-11ty` version
84
+
85
+ When the `--quire` flag is used the new project will be started using the specified version of `quire-11ty`
86
+
87
+ ```sh
88
+ quire new <path> <starter> --quire <version>
89
+ ```
90
+
91
+ ##### Version identifiers
92
+
93
+ The `--quire` flag must be either a semantic version identifier or a npm distribution tag. For example:
94
+
95
+ ```sh
96
+ quire new ./blargh --quire 1.0.0-rc.5
97
+ ```
98
+
99
+ ```sh
100
+ quire new ./blargh --quire latest
101
+ ```
102
+
83
103
  ### `preview`
84
104
 
85
105
  Build and server the Quire site in development mode.
@@ -22,8 +22,9 @@ export default class CreateCommand extends Command {
22
22
  [ '[starter]', 'repository url or local path for a starter project' ],
23
23
  ],
24
24
  options: [
25
- [ '--debug', 'debug the `quire new` command' ],
26
- [ '--eject', 'install quire-11ty into the project directory', 'true' ],
25
+ [ '--quire <version>', 'quire-11ty version to install', 'latest' ],
26
+ // [ '--eject', 'install quire-11ty into the project directory', true ],
27
+ [ '--debug', 'debug the `quire new` command', false ],
27
28
  ],
28
29
  }
29
30
 
@@ -52,14 +53,20 @@ export default class CreateCommand extends Command {
52
53
  // const starter = starters['default']
53
54
  // `git clone starter path`
54
55
  } else {
55
- const version = await quire.initStarter(starter, projectPath)
56
- // @TODO we will want to abstract the test for emptiness to prevent further install steps on error
57
- if (!version) return
56
+ /**
57
+ * @TODO test that `version` is compatible with the `requiredVersion`
58
+ * if version is incompatible or unknown
59
+ * - interactive mode prompt to continue
60
+ * - non-interactive mode throw an error and exit the process
61
+ */
62
+ await quire.initStarter(starter, projectPath, options)
63
+
64
+ options.eject = true
58
65
 
59
66
  if (options.eject) {
60
- await quire.installInProject(projectPath, version, options)
67
+ await quire.installInProject(projectPath, options)
61
68
  } else {
62
- await quire.install(version, options)
69
+ await quire.install(options)
63
70
  }
64
71
  }
65
72
  }
@@ -11,7 +11,9 @@ const __dirname = path.dirname(__filename)
11
11
  export default async (name = 'epubjs', options = {}) => {
12
12
  const lib = { name, options, path }
13
13
 
14
- switch (lib.toLowerCase()) {
14
+ const normalizedName = name.replace(/[-_.\s]/g, '').toLowerCase()
15
+
16
+ switch (normalizedName) {
15
17
  case 'epubjs': {
16
18
  lib.name = 'Epub.js'
17
19
  lib.options = {}
@@ -11,7 +11,9 @@ const __dirname = path.dirname(__filename)
11
11
  export default async (name = 'pagedjs', options = {}) => {
12
12
  const lib = { name, options, path }
13
13
 
14
- switch (name.toLowerCase()) {
14
+ const normalizedName = name.replace(/[-_.\s]/g, '').toLowerCase()
15
+
16
+ switch (normalizedName) {
15
17
  case 'paged':
16
18
  case 'pagedjs': {
17
19
  lib.name = 'Paged.js'
@@ -79,7 +79,7 @@ async function getVersionFromStarter(projectPath) {
79
79
  * @return {String} quireVersion A string indicating the current version
80
80
  * of quire being used with a new project
81
81
  */
82
- async function initStarter (starter, projectPath) {
82
+ async function initStarter (starter, projectPath, options) {
83
83
  projectPath = projectPath || cwd()
84
84
 
85
85
  // ensure that the target path exists
@@ -110,10 +110,12 @@ async function initStarter (starter, projectPath) {
110
110
  .catch((error) => console.error('[CLI:error] ', error))
111
111
 
112
112
  /**
113
- * Determine `quire-11ty` version required by the starter project
114
- * and write a `.quire` file with the semantic version string.
113
+ * Determine `quire-11ty` version required by the starter project.
114
+ *
115
+ * A version specified in `options.quire` overrides the version in starter
116
+ * project `package.json`.
115
117
  */
116
- const quireVersion = await getVersionFromStarter(projectPath)
118
+ const quireVersion = options.quire || await getVersionFromStarter(projectPath)
117
119
  setVersion(projectPath, quireVersion)
118
120
 
119
121
  // Re-initialize project directory as a new git repository
@@ -140,13 +142,15 @@ async function initStarter (starter, projectPath) {
140
142
  }
141
143
 
142
144
  /**
143
- * Install a specific version of `quire-11ty`
145
+ * Install `quire-11ty`, default to 'latest' version
146
+ *
147
+ * @TODO refactor this to be callable by the installInProject method
144
148
  *
145
- * @param {String} version Quire-11ty semantic version
146
149
  * @param {Object} options options passed from `quire new` command
147
150
  * @return {Promise}
148
151
  */
149
- async function install(version, options={}) {
152
+ async function install(options = {}) {
153
+ const version = options.quire || 'latest'
150
154
  console.debug(`[CLI:quire] installing quire-11ty@${version}`)
151
155
  const absoluteInstallPath = path.join(__dirname, 'versions')
152
156
  fs.ensureDirSync(absoluteInstallPath)
@@ -185,19 +189,22 @@ async function install(version, options={}) {
185
189
  }
186
190
 
187
191
  /**
188
- * Install a specific version of `quire-11ty` directly into a quire project
192
+ * Install `quire-11ty` directly into a quire project
193
+ *
194
+ * @TODO refactor this to use the install method with pre and post-install hooks
195
+ * or steps to prepare the working directory and cleanup on error and completion
189
196
  *
190
197
  * @param {String} projectPath Absolute system path to the project root
191
- * @param {String} version Quire-11ty semantic version
192
198
  * @param {Object} options options passed from `quire new` command
193
199
  * @return {Promise}
194
200
  */
195
- async function installInProject(projectPath, version, options={}) {
201
+ async function installInProject(projectPath, options = {}) {
202
+ const version = options.quire || 'latest'
196
203
  console.debug(`[CLI:quire] installing quire-11ty@${version} into ${projectPath}`)
197
204
 
198
205
  /**
199
- * delete `package.json` from starter project, as it will be replaced with
200
- * `package.json` from `@thegetty/quire-11ty`
206
+ * Delete the starter project package configuration so that it can be replaced
207
+ * with the `@thegetty/quire-11ty` configuration
201
208
  * @TODO If a user runs quire eject at a later date we may want to merge their
202
209
  * package.json with the `quire-11ty` dev dependencies, scripts, etc
203
210
  */
@@ -314,16 +321,16 @@ async function remove(version) {
314
321
  /**
315
322
  * Sets the quire-11ty version for a project
316
323
  *
317
- * @param {String} version Quire-11ty semantic version
324
+ * @param {String} version a version identifier or distribution tag
318
325
  */
319
326
  function setVersion(projectPath, version) {
320
327
  if (!version) {
321
328
  console.error('[CLI] no version specified')
329
+ return
322
330
  }
331
+ fs.writeFileSync(path.join(projectPath, VERSION_FILE), version)
323
332
  const projectName = path.basename(projectPath)
324
333
  console.info(`${projectName} set to use quire-11ty@${version}`)
325
- const versionFilePath = path.join(projectPath, VERSION_FILE)
326
- fs.writeFileSync(versionFilePath, version)
327
334
  }
328
335
 
329
336
  /**
@@ -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
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * Quire constants
3
- */
4
- export const CONSTANTS = Object.freeze({
5
- PACKAGE_NAME: '@thegetty/quire-11ty'
6
- })
@@ -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 () {}