@thegetty/quire-cli 1.0.0-rc.1 → 1.0.0-rc.10
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 +19 -1
- package/bin/cli.js +2 -2
- package/package.json +2 -2
- package/src/commands/README.md +28 -8
- package/src/commands/create.js +23 -7
- package/src/commands/info.js +125 -0
- package/src/lib/epub/index.js +3 -1
- package/src/lib/pdf/index.js +3 -1
- package/src/lib/quire/index.js +63 -53
package/CHANGELOG.md
CHANGED
|
@@ -18,6 +18,24 @@ Changelog entries are classified using the following labels:
|
|
|
18
18
|
|
|
19
19
|
- `Removed`: for deprecated features removed in this release
|
|
20
20
|
|
|
21
|
+
## [1.0.0-rc.10]
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
### Added
|
|
24
|
+
- Support semantic version ranges for `quire-11ty` in quire starter projects and the `--quire-version` option of the `quire new` command, and use the latest compatible `quire-11ty` version when creating and installing a new project.
|
|
23
25
|
|
|
26
|
+
## [1.0.0-rc.9]
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
- Update old `.quire` files when running `info` command on versions prior to `1.0.0-rc.8`
|
|
30
|
+
- Include `quire-cli` version used to generate project in `info` output
|
|
31
|
+
- Adds headings to `info` output
|
|
32
|
+
|
|
33
|
+
## [1.0.0-rc.8]
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
- Added `info` command to output package versions
|
|
37
|
+
|
|
38
|
+
## [1.0.0-rc.7]
|
|
39
|
+
|
|
40
|
+
### Added
|
|
41
|
+
- Added `new` command `--quire-path` option to support development with local version of `quire-11ty`
|
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: '
|
|
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.
|
|
4
|
+
"version": "1.0.0-rc.10",
|
|
5
5
|
"author": "Getty Digital",
|
|
6
6
|
"license": "SEE LICENSE IN https://github.com/thegetty/quire/blob/main/LICENSE",
|
|
7
7
|
"bugs": {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"conf": "^11.0.1",
|
|
52
52
|
"cross-env": "^7.0.3",
|
|
53
53
|
"del": "^7.0.0",
|
|
54
|
-
"epubjs-cli": "^0.1.
|
|
54
|
+
"epubjs-cli": "^0.1.3",
|
|
55
55
|
"execa": "^6.1.0",
|
|
56
56
|
"fs-extra": "^11.1.0",
|
|
57
57
|
"hosted-git-info": "^6.1.1",
|
package/src/commands/README.md
CHANGED
|
@@ -16,6 +16,14 @@ Build Quire publication EPUB format.
|
|
|
16
16
|
quire build epub
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
#### `info`
|
|
20
|
+
|
|
21
|
+
List `quire-11ty`, `quire-cli`, and starter package versions; use the `--debug` option to include node, npm, and os versions.
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
quire build info
|
|
25
|
+
```
|
|
26
|
+
|
|
19
27
|
#### `pdf`
|
|
20
28
|
|
|
21
29
|
Build Quire publication PDF format.
|
|
@@ -80,6 +88,26 @@ To create a new project from a starter template
|
|
|
80
88
|
quire new <path> <starter>
|
|
81
89
|
```
|
|
82
90
|
|
|
91
|
+
#### Specifying the `quire-11ty` version
|
|
92
|
+
|
|
93
|
+
When the `--quire` flag is used the new project will be started using the specified version of `quire-11ty`
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
quire new <path> <starter> --quire <version>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
##### Version identifiers
|
|
100
|
+
|
|
101
|
+
The `--quire` flag must be either a semantic version identifier or a npm distribution tag. For example:
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
quire new ./blargh --quire 1.0.0-rc.5
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
quire new ./blargh --quire latest
|
|
109
|
+
```
|
|
110
|
+
|
|
83
111
|
### `preview`
|
|
84
112
|
|
|
85
113
|
Build and server the Quire site in development mode.
|
|
@@ -134,14 +162,6 @@ To set the quire version globally use the `--global` command flag.
|
|
|
134
162
|
quire version 1.0.0 --global
|
|
135
163
|
```
|
|
136
164
|
|
|
137
|
-
#### `info`
|
|
138
|
-
|
|
139
|
-
Display the local and global `quire-11ty` version; this is the *default* subcommand (running `quire version` invokes the `info` subcommand).
|
|
140
|
-
|
|
141
|
-
```sh
|
|
142
|
-
quire version info
|
|
143
|
-
```
|
|
144
|
-
|
|
145
165
|
#### `install`
|
|
146
166
|
|
|
147
167
|
```sh
|
package/src/commands/create.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Command from '#src/Command.js'
|
|
2
|
+
import fs from 'fs-extra'
|
|
2
3
|
import { quire } from '#src/lib/quire/index.js'
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -22,8 +23,10 @@ export default class CreateCommand extends Command {
|
|
|
22
23
|
[ '[starter]', 'repository url or local path for a starter project' ],
|
|
23
24
|
],
|
|
24
25
|
options: [
|
|
25
|
-
[ '--
|
|
26
|
-
[ '--
|
|
26
|
+
[ '--quire-path <path>', 'local path to quire-11ty package' ],
|
|
27
|
+
[ '--quire-version <version>', 'quire-11ty version to install' ],
|
|
28
|
+
// [ '--eject', 'install quire-11ty into the project directory', true ],
|
|
29
|
+
[ '--debug', 'debug the `quire new` command', false ],
|
|
27
30
|
],
|
|
28
31
|
}
|
|
29
32
|
|
|
@@ -52,14 +55,27 @@ export default class CreateCommand extends Command {
|
|
|
52
55
|
// const starter = starters['default']
|
|
53
56
|
// `git clone starter path`
|
|
54
57
|
} else {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
/**
|
|
59
|
+
* @TODO test that `version` is compatible with the `requiredVersion`
|
|
60
|
+
* if version is incompatible or unknown
|
|
61
|
+
* - interactive mode prompt to continue
|
|
62
|
+
* - non-interactive mode throw an error and exit the process
|
|
63
|
+
*/
|
|
64
|
+
let quireVersion
|
|
65
|
+
try {
|
|
66
|
+
quireVersion = await quire.initStarter(starter, projectPath, options)
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error(error.message)
|
|
69
|
+
fs.removeSync(projectPath)
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
options.eject = true
|
|
58
74
|
|
|
59
75
|
if (options.eject) {
|
|
60
|
-
await quire.installInProject(projectPath,
|
|
76
|
+
await quire.installInProject(projectPath, quireVersion, options)
|
|
61
77
|
} else {
|
|
62
|
-
await quire.install(
|
|
78
|
+
await quire.install(options)
|
|
63
79
|
}
|
|
64
80
|
}
|
|
65
81
|
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import Command from '#src/Command.js'
|
|
2
|
+
import { execaCommand } from 'execa'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import os from 'node:os'
|
|
5
|
+
import path from 'path'
|
|
6
|
+
import testcwd from '#helpers/test-cwd.js'
|
|
7
|
+
|
|
8
|
+
const VERSION_FILE = '.quire'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Quire CLI `info` Command
|
|
12
|
+
*
|
|
13
|
+
* Runs the Eleventy `info` command to list the quire-cli, quire-11ty, node, and npm versions.
|
|
14
|
+
*
|
|
15
|
+
* @class InfoCommand
|
|
16
|
+
* @extends {Command}
|
|
17
|
+
*/
|
|
18
|
+
export default class InfoCommand extends Command {
|
|
19
|
+
static definition = {
|
|
20
|
+
name: 'info',
|
|
21
|
+
description: 'List Quire cli, quire-11ty, and node versions',
|
|
22
|
+
summary: 'list info',
|
|
23
|
+
version: '1.0.0',
|
|
24
|
+
args: [],
|
|
25
|
+
options: [['--debug', 'include os versions in output']],
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
super(InfoCommand.definition)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async action(options, command) {
|
|
33
|
+
if (options.debug) {
|
|
34
|
+
console.debug(
|
|
35
|
+
'[CLI] Command \'%s\' called with options %o',
|
|
36
|
+
this.name(),
|
|
37
|
+
options
|
|
38
|
+
)
|
|
39
|
+
} else {
|
|
40
|
+
console.debug('[CLI] Command \'%s\' called', this.name())
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let versionFile = fs.readFileSync(VERSION_FILE, { encoding: 'utf8' })
|
|
44
|
+
try {
|
|
45
|
+
versionFile = JSON.parse(versionFile)
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.warn(
|
|
48
|
+
`This project was generated with the quire-cli prior to version 1.0.0.rc-8. Updating the version file to the new format, though this project's version file will not contain specific starter version information.`
|
|
49
|
+
)
|
|
50
|
+
versionFile = { cli: '<=1.0.0.rc-7' }
|
|
51
|
+
fs.writeFileSync(VERSION_FILE, JSON.stringify(versionFile))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const { name: projectDirectory } = path.parse(process.cwd())
|
|
55
|
+
|
|
56
|
+
const versions = [
|
|
57
|
+
{
|
|
58
|
+
title: `[${projectDirectory}]`,
|
|
59
|
+
items: [
|
|
60
|
+
{
|
|
61
|
+
name: 'quire-cli',
|
|
62
|
+
get: () => versionFile.cli,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'quire-11ty',
|
|
66
|
+
get: () => {
|
|
67
|
+
const { version } = JSON.parse(fs.readFileSync('./package.json'))
|
|
68
|
+
return version
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'starter',
|
|
73
|
+
get: () => versionFile.starter,
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
title: '[System]',
|
|
79
|
+
items: [
|
|
80
|
+
{
|
|
81
|
+
name: 'quire-cli',
|
|
82
|
+
get: async () => {
|
|
83
|
+
const { stdout } = await execaCommand('quire --version')
|
|
84
|
+
return stdout
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
debug: true,
|
|
89
|
+
name: 'node',
|
|
90
|
+
get: () => process.version,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
debug: true,
|
|
94
|
+
name: 'npm',
|
|
95
|
+
get: async () => {
|
|
96
|
+
const { stdout } = await execaCommand('npm --version')
|
|
97
|
+
return stdout
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
debug: true,
|
|
102
|
+
name: 'os',
|
|
103
|
+
get: () => `${os.type()} ${os.release()}`,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Filter the command output based on `debug` settings
|
|
111
|
+
*/
|
|
112
|
+
versions.forEach(async ({ items, title }) => {
|
|
113
|
+
const versions = await Promise.all(
|
|
114
|
+
items
|
|
115
|
+
.filter(({ debug }) => !debug || (options.debug && debug))
|
|
116
|
+
.map(async ({ name, get }) => `${name} ${await get()}`)
|
|
117
|
+
)
|
|
118
|
+
console.info(`${title}\n ${versions.join('\n ')}`)
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
preAction(command) {
|
|
123
|
+
testcwd(command)
|
|
124
|
+
}
|
|
125
|
+
}
|
package/src/lib/epub/index.js
CHANGED
|
@@ -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
|
-
|
|
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 = {}
|
package/src/lib/pdf/index.js
CHANGED
|
@@ -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
|
-
|
|
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'
|
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 fetch from 'node-fetch'
|
|
6
7
|
import fs from 'fs-extra'
|
|
7
8
|
import git from '#src/lib/git/index.js'
|
|
8
9
|
import inv from 'install-npm-version'
|
|
10
|
+
import packageConfig from '#root/package.json' assert { type: 'json' }
|
|
9
11
|
import path from 'node:path'
|
|
10
12
|
import semver from 'semver'
|
|
11
13
|
|
|
@@ -48,25 +50,19 @@ function getVersion(projectPath) {
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
|
-
* Read the required `quire-11ty`
|
|
53
|
+
* Read the required `quire-11ty` and starter versions from starter `package.json` `peerDependencies`
|
|
52
54
|
*
|
|
53
55
|
* @param {String} projectPath Absolute system path to the project root
|
|
54
56
|
*
|
|
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
|
|
57
|
+
* @return {Object}
|
|
58
|
+
* @property {String} quire11tyVersion Latest compatible Quire-11ty semantic version
|
|
59
|
+
* @property {String} starterVersion Starter project version defined in the starter package.json
|
|
62
60
|
*/
|
|
63
|
-
async function
|
|
64
|
-
const
|
|
65
|
-
const { peerDependencies } = JSON.parse(
|
|
66
|
-
const
|
|
67
|
-
return
|
|
68
|
-
? await latest()
|
|
69
|
-
: version.substr(version.search(/\d/))
|
|
61
|
+
async function getVersionsFromStarter(projectPath) {
|
|
62
|
+
const projectPackageConfig = fs.readFileSync(path.join(projectPath, 'package.json'), { encoding:'utf8' })
|
|
63
|
+
const { peerDependencies, version: starterVersion } = JSON.parse(projectPackageConfig)
|
|
64
|
+
const quire11tyVersion = peerDependencies[PACKAGE_NAME]
|
|
65
|
+
return { quire11tyVersion, starterVersion }
|
|
70
66
|
}
|
|
71
67
|
|
|
72
68
|
/**
|
|
@@ -79,7 +75,7 @@ async function getVersionFromStarter(projectPath) {
|
|
|
79
75
|
* @return {String} quireVersion A string indicating the current version
|
|
80
76
|
* of quire being used with a new project
|
|
81
77
|
*/
|
|
82
|
-
async function initStarter (starter, projectPath) {
|
|
78
|
+
async function initStarter (starter, projectPath, options) {
|
|
83
79
|
projectPath = projectPath || cwd()
|
|
84
80
|
|
|
85
81
|
// ensure that the target path exists
|
|
@@ -110,12 +106,24 @@ async function initStarter (starter, projectPath) {
|
|
|
110
106
|
.catch((error) => console.error('[CLI:error] ', error))
|
|
111
107
|
|
|
112
108
|
/**
|
|
113
|
-
* Determine `quire-11ty` version
|
|
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, cli, starter name and version to 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,18 +143,19 @@ 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`, default to 'latest' version
|
|
151
|
+
*
|
|
152
|
+
* @TODO refactor this to be callable by the installInProject method
|
|
144
153
|
*
|
|
145
|
-
* @param {String} version Quire-11ty semantic version
|
|
146
154
|
* @param {Object} options options passed from `quire new` command
|
|
147
155
|
* @return {Promise}
|
|
148
156
|
*/
|
|
149
|
-
async function install(
|
|
157
|
+
async function install(options = {}) {
|
|
158
|
+
const version = options.quireVersion || 'latest'
|
|
150
159
|
console.debug(`[CLI:quire] installing quire-11ty@${version}`)
|
|
151
160
|
const absoluteInstallPath = path.join(__dirname, 'versions')
|
|
152
161
|
fs.ensureDirSync(absoluteInstallPath)
|
|
@@ -185,19 +194,23 @@ async function install(version, options={}) {
|
|
|
185
194
|
}
|
|
186
195
|
|
|
187
196
|
/**
|
|
188
|
-
* Install
|
|
197
|
+
* Install `quire-11ty` directly into a quire project
|
|
198
|
+
*
|
|
199
|
+
* @TODO refactor this to use the install method with pre and post-install hooks
|
|
200
|
+
* or steps to prepare the working directory and cleanup on error and completion
|
|
189
201
|
*
|
|
190
202
|
* @param {String} projectPath Absolute system path to the project root
|
|
191
|
-
* @param {String} version Quire-11ty semantic version
|
|
192
203
|
* @param {Object} options options passed from `quire new` command
|
|
193
204
|
* @return {Promise}
|
|
194
205
|
*/
|
|
195
|
-
async function installInProject(projectPath,
|
|
196
|
-
|
|
206
|
+
async function installInProject(projectPath, quireVersion, options = {}) {
|
|
207
|
+
const { quirePath } = options
|
|
208
|
+
const quire11tyPackage = fs.existsSync(quirePath) ? quirePath : `${PACKAGE_NAME}@${quireVersion}`
|
|
209
|
+
console.debug(`[CLI:quire] installing ${quire11tyPackage} into ${projectPath}`)
|
|
197
210
|
|
|
198
211
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
212
|
+
* Delete the starter project package configuration so that it can be replaced
|
|
213
|
+
* with the `@thegetty/quire-11ty` configuration
|
|
201
214
|
* @TODO If a user runs quire eject at a later date we may want to merge their
|
|
202
215
|
* package.json with the `quire-11ty` dev dependencies, scripts, etc
|
|
203
216
|
*/
|
|
@@ -220,7 +233,7 @@ async function installInProject(projectPath, version, options={}) {
|
|
|
220
233
|
Verbosity: options.debug ? 'Debug' : 'Silent',
|
|
221
234
|
WorkingDirectory: projectPath
|
|
222
235
|
}
|
|
223
|
-
await inv.Install(
|
|
236
|
+
await inv.Install(quire11tyPackage, installOptions)
|
|
224
237
|
|
|
225
238
|
// delete empty `node_modules` directory that `install-npm-version` creates
|
|
226
239
|
const invNodeModulesDir = path.join(projectPath, 'node_modules')
|
|
@@ -262,25 +275,27 @@ async function installInProject(projectPath, version, options={}) {
|
|
|
262
275
|
|
|
263
276
|
/**
|
|
264
277
|
* 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
|
-
*
|
|
278
|
+
* or the latest compatible version with the provided semantic version string
|
|
279
|
+
*
|
|
280
|
+
* @param {String} version A semantic version string, i.e `^1.0.0-pre-release.0`
|
|
281
|
+
*
|
|
279
282
|
* @return {String} `quire-11ty@latest` semantic version string
|
|
280
283
|
*/
|
|
281
|
-
async function latest() {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
+
async function latest(version) {
|
|
285
|
+
let quireVersion;
|
|
286
|
+
if (!version || version === 'latest') {
|
|
287
|
+
const { stdout } =
|
|
288
|
+
await execa('npm', ['view', PACKAGE_NAME, 'version'])
|
|
289
|
+
quireVersion = stdout
|
|
290
|
+
} else {
|
|
291
|
+
const response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}`)
|
|
292
|
+
const json = await response.json()
|
|
293
|
+
const versions = Object.keys(json.versions)
|
|
294
|
+
quireVersion = semver.maxSatisfying(versions, version)
|
|
295
|
+
}
|
|
296
|
+
if (!quireVersion) {
|
|
297
|
+
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.`)
|
|
298
|
+
}
|
|
284
299
|
return quireVersion
|
|
285
300
|
}
|
|
286
301
|
|
|
@@ -314,16 +329,11 @@ async function remove(version) {
|
|
|
314
329
|
/**
|
|
315
330
|
* Sets the quire-11ty version for a project
|
|
316
331
|
*
|
|
317
|
-
* @param {String} version
|
|
332
|
+
* @param {String} version a version identifier or distribution tag
|
|
318
333
|
*/
|
|
319
334
|
function setVersion(projectPath, version) {
|
|
320
|
-
if (!version) {
|
|
321
|
-
console.error('[CLI] no version specified')
|
|
322
|
-
}
|
|
323
335
|
const projectName = path.basename(projectPath)
|
|
324
336
|
console.info(`${projectName} set to use quire-11ty@${version}`)
|
|
325
|
-
const versionFilePath = path.join(projectPath, VERSION_FILE)
|
|
326
|
-
fs.writeFileSync(versionFilePath, version)
|
|
327
337
|
}
|
|
328
338
|
|
|
329
339
|
/**
|