@thegetty/quire-cli 1.0.0-rc.5 → 1.0.0-rc.7

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-rc.5",
4
+ "version": "1.0.0-rc.7",
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,10 @@ 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-path <path>', 'local path to quire-11ty package' ],
26
+ [ '--quire-version <version>', 'quire-11ty version to install', 'latest' ],
27
+ // [ '--eject', 'install quire-11ty into the project directory', true ],
28
+ [ '--debug', 'debug the `quire new` command', false ],
27
29
  ],
28
30
  }
29
31
 
@@ -52,14 +54,20 @@ export default class CreateCommand extends Command {
52
54
  // const starter = starters['default']
53
55
  // `git clone starter path`
54
56
  } 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
57
+ /**
58
+ * @TODO test that `version` is compatible with the `requiredVersion`
59
+ * if version is incompatible or unknown
60
+ * - interactive mode prompt to continue
61
+ * - non-interactive mode throw an error and exit the process
62
+ */
63
+ await quire.initStarter(starter, projectPath, options)
64
+
65
+ options.eject = true
58
66
 
59
67
  if (options.eject) {
60
- await quire.installInProject(projectPath, version, options)
68
+ await quire.installInProject(projectPath, options)
61
69
  } else {
62
- await quire.install(version, options)
70
+ await quire.install(options)
63
71
  }
64
72
  }
65
73
  }
@@ -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.quireVersion` overrides the version in starter
116
+ * project `package.json`.
115
117
  */
116
- const quireVersion = await getVersionFromStarter(projectPath)
118
+ const quireVersion = options.quireVersion || 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.quireVersion || '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,23 @@ 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={}) {
196
- console.debug(`[CLI:quire] installing quire-11ty@${version} into ${projectPath}`)
201
+ async function installInProject(projectPath, options = {}) {
202
+ const { quirePath, quireVersion } = options
203
+ const quire11tyPackage = fs.existsSync(quirePath) ? quirePath : `${PACKAGE_NAME}@${quireVersion}`
204
+ console.debug(`[CLI:quire] installing ${quire11tyPackage} into ${projectPath}`)
197
205
 
198
206
  /**
199
- * delete `package.json` from starter project, as it will be replaced with
200
- * `package.json` from `@thegetty/quire-11ty`
207
+ * Delete the starter project package configuration so that it can be replaced
208
+ * with the `@thegetty/quire-11ty` configuration
201
209
  * @TODO If a user runs quire eject at a later date we may want to merge their
202
210
  * package.json with the `quire-11ty` dev dependencies, scripts, etc
203
211
  */
@@ -220,7 +228,7 @@ async function installInProject(projectPath, version, options={}) {
220
228
  Verbosity: options.debug ? 'Debug' : 'Silent',
221
229
  WorkingDirectory: projectPath
222
230
  }
223
- await inv.Install(`${PACKAGE_NAME}@${version}`, installOptions)
231
+ await inv.Install(quire11tyPackage, installOptions)
224
232
 
225
233
  // delete empty `node_modules` directory that `install-npm-version` creates
226
234
  const invNodeModulesDir = path.join(projectPath, 'node_modules')
@@ -314,16 +322,16 @@ async function remove(version) {
314
322
  /**
315
323
  * Sets the quire-11ty version for a project
316
324
  *
317
- * @param {String} version Quire-11ty semantic version
325
+ * @param {String} version a version identifier or distribution tag
318
326
  */
319
327
  function setVersion(projectPath, version) {
320
328
  if (!version) {
321
329
  console.error('[CLI] no version specified')
330
+ return
322
331
  }
332
+ fs.writeFileSync(path.join(projectPath, VERSION_FILE), version)
323
333
  const projectName = path.basename(projectPath)
324
334
  console.info(`${projectName} set to use quire-11ty@${version}`)
325
- const versionFilePath = path.join(projectPath, VERSION_FILE)
326
- fs.writeFileSync(versionFilePath, version)
327
335
  }
328
336
 
329
337
  /**