@thegetty/quire-cli 1.0.0-pre-release.2 → 1.0.0-pre-release.4
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/README.md +7 -0
- package/package.json +2 -2
- package/scripts/postinstall.js +27 -0
- package/src/lib/11ty/api.js +56 -4
- package/src/lib/11ty/cli.js +24 -15
package/README.md
CHANGED
|
@@ -9,3 +9,10 @@ The `quire-cli` implements the [command pattern](https://en.wikipedia.org/wiki/C
|
|
|
9
9
|
```sh
|
|
10
10
|
npx quire-cli --help
|
|
11
11
|
```
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
#### Microsoft Windows
|
|
15
|
+
|
|
16
|
+
https://learnshareit.com/how-to-solve-nodemon-ps1-cannot-be-loaded-because-running-scripts-is-disabled-on-this-system-in-nodejs/
|
|
17
|
+
|
|
18
|
+
See [Microsoft About Execution Policies](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.3)
|
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.
|
|
4
|
+
"version": "1.0.0-pre-release.4",
|
|
5
5
|
"author": "Getty Digital",
|
|
6
6
|
"license": "J Paul Getty Trust",
|
|
7
7
|
"bugs": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"type": "module",
|
|
20
20
|
"files": [
|
|
21
21
|
"bin/",
|
|
22
|
+
"scripts",
|
|
22
23
|
"src/",
|
|
23
24
|
"CHANGELOG.md",
|
|
24
25
|
"LICENSE",
|
|
@@ -35,7 +36,6 @@
|
|
|
35
36
|
"scripts": {
|
|
36
37
|
"lint": "eslint src --ext .js",
|
|
37
38
|
"lint:fix": "npm run lint -- --fix",
|
|
38
|
-
"postinstall": "node scripts/postinstall.js",
|
|
39
39
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
40
40
|
},
|
|
41
41
|
"imports": {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node --no-warnings
|
|
2
|
+
import chalk from 'chalk'
|
|
3
|
+
|
|
4
|
+
// @todo use an i18n string for the documentation url
|
|
5
|
+
const docsUrl = 'https://quire.getty.edu/docs/quire-cli/'
|
|
6
|
+
|
|
7
|
+
const showSuccessMessage = () => {
|
|
8
|
+
const heading = chalk.inverse.green('Success!')
|
|
9
|
+
const messsage = chalk.magenta(
|
|
10
|
+
'Quire CLI installed! Please visit ',
|
|
11
|
+
chalk.underline(docsUrl),
|
|
12
|
+
' for more information.'
|
|
13
|
+
)
|
|
14
|
+
console.log(heading, messsage)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// check if the cli is a global installation of quire-cli
|
|
19
|
+
const npmArgs = JSON.parse(process.env['npm_config_argv'])
|
|
20
|
+
if (npmArgs.cooked && npmArgs.cooked.includes('--global')) {
|
|
21
|
+
showSuccessMessage()
|
|
22
|
+
// @todo run `quire-cli --help` on success
|
|
23
|
+
// cli('--help')
|
|
24
|
+
}
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error('postinstall', error)
|
|
27
|
+
}
|
package/src/lib/11ty/api.js
CHANGED
|
@@ -8,7 +8,7 @@ import paths, { eleventyRoot, projectRoot } from './paths.js'
|
|
|
8
8
|
* @param {Object} options Eleventy configuration options
|
|
9
9
|
* @return {Eleventy} A configured instance of Eleventy
|
|
10
10
|
*/
|
|
11
|
-
const factory = async (options) => {
|
|
11
|
+
const factory = async (options = {}) => {
|
|
12
12
|
const { config, input, output } = paths
|
|
13
13
|
|
|
14
14
|
console.info(`[CLI:11ty] projectRoot ${projectRoot}`)
|
|
@@ -20,13 +20,61 @@ const factory = async (options) => {
|
|
|
20
20
|
*/
|
|
21
21
|
const { default: Eleventy } = await import(path.join(eleventyRoot, 'node_modules', '@11ty', 'eleventy', 'src', 'Eleventy.js'))
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Set Eleventy passthrough copy options
|
|
25
|
+
* @see https://www.11ty.dev/docs/copy/#advanced-options
|
|
26
|
+
* @see https://github.com/timkendrick/recursive-copy
|
|
27
|
+
*/
|
|
28
|
+
const copyOptions = {
|
|
29
|
+
debug: options.debug || false,
|
|
30
|
+
expand: true,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get an instance of the runtime of eleventy.
|
|
35
|
+
* @see https://github.com/11ty/eleventy/blob/src/Eleventy.js
|
|
36
|
+
*
|
|
37
|
+
* @param {String} input Path from which to read content templates
|
|
38
|
+
* @param {String} output Path where rendered files will be written
|
|
39
|
+
* @param {Object} options Options are merged with the Eleventy UserConfig
|
|
40
|
+
* @param {Object} config An eleventy configurtion object
|
|
41
|
+
*
|
|
42
|
+
* @returns {module:11ty/eleventy/Eleventy~Eleventy}
|
|
43
|
+
*/
|
|
44
|
+
const eleventy = new Eleventy(input, output, {
|
|
24
45
|
config: (eleventyConfig) => {
|
|
25
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Override addPassthroughCopy to use _absolute_ system paths.
|
|
48
|
+
* @see https://www.11ty.dev/docs/copy/#passthrough-file-copy
|
|
49
|
+
* Nota bene: Eleventy addPassthroughCopy assumes paths are _relative_
|
|
50
|
+
* to the `config` file however the quire-cli separates 11ty from the
|
|
51
|
+
* project directory (`input`) and needs to use absolute system paths.
|
|
52
|
+
*/
|
|
53
|
+
const addPassthroughCopy = eleventyConfig.addPassthroughCopy.bind(eleventyConfig)
|
|
54
|
+
eleventyConfig.addPassthroughCopy = (entry) => {
|
|
55
|
+
if (typeof entry === 'string') {
|
|
56
|
+
const filePath = path.resolve(entry) //path.join(projectRoot, file)
|
|
57
|
+
// console.debug('[11ty:API] passthrough copy %s', filePath)
|
|
58
|
+
return addPassthroughCopy(filePath, copyOptions)
|
|
59
|
+
} else {
|
|
60
|
+
// console.debug('[11ty:API] passthrough copy %o', entry)
|
|
61
|
+
entry = Object.fromEntries(
|
|
62
|
+
Object.entries(entry).map(([ src, dest ]) => {
|
|
63
|
+
return [ path.join(eleventyRoot, src), path.resolve(dest) ]
|
|
64
|
+
})
|
|
65
|
+
)
|
|
66
|
+
// console.debug('[11ty:API] passthrough copy %o', entry)
|
|
67
|
+
return addPassthroughCopy(entry, copyOptions)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return eleventyConfig
|
|
26
71
|
},
|
|
27
72
|
configPath: options.config || config,
|
|
28
73
|
quietMode: options.quiet || false,
|
|
74
|
+
// source: 'script',
|
|
29
75
|
})
|
|
76
|
+
|
|
77
|
+
return eleventy
|
|
30
78
|
}
|
|
31
79
|
|
|
32
80
|
/**
|
|
@@ -44,6 +92,9 @@ export default {
|
|
|
44
92
|
if (options.debug) process.env.DEBUG = 'Eleventy*'
|
|
45
93
|
|
|
46
94
|
const eleventy = await factory(options)
|
|
95
|
+
|
|
96
|
+
eleventy.setDryRun(options.dryrun)
|
|
97
|
+
|
|
47
98
|
await eleventy.executeBuild()
|
|
48
99
|
},
|
|
49
100
|
serve: async (options = {}) => {
|
|
@@ -52,6 +103,7 @@ export default {
|
|
|
52
103
|
if (options.debug) process.env.DEBUG = 'Eleventy*'
|
|
53
104
|
|
|
54
105
|
const eleventy = await factory(options)
|
|
55
|
-
|
|
106
|
+
|
|
107
|
+
await eleventy.serve(options.port)
|
|
56
108
|
}
|
|
57
109
|
}
|
package/src/lib/11ty/cli.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { execa } from 'execa'
|
|
2
|
-
import { fileURLToPath } from 'node:url'
|
|
3
2
|
import path from 'node:path'
|
|
4
|
-
import paths, { projectRoot } from './paths.js'
|
|
3
|
+
import paths, { eleventyRoot, projectRoot } from './paths.js'
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* A factory function to configure an Eleventy CLI command
|
|
@@ -9,20 +8,31 @@ import paths, { projectRoot } from './paths.js'
|
|
|
9
8
|
* @param {Object} options Eleventy configuration options
|
|
10
9
|
* @return {Array} Eleventy CLI options
|
|
11
10
|
*/
|
|
12
|
-
const factory = () => {
|
|
11
|
+
const factory = (options = {}) => {
|
|
13
12
|
const { config, input, output } = paths
|
|
14
13
|
|
|
15
14
|
console.info(`[CLI:11ty] projectRoot ${projectRoot}`)
|
|
16
15
|
|
|
17
16
|
console.debug('[CLI:11ty] %o', paths)
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Use the version of Eleventy installed to `lib/quire/versions`
|
|
20
|
+
*/
|
|
21
|
+
const eleventy =
|
|
22
|
+
path.join(eleventyRoot, 'node_modules', '@11ty', 'eleventy', 'cmd.js')
|
|
23
|
+
|
|
24
|
+
const command = [
|
|
25
|
+
eleventy,
|
|
21
26
|
`--config=${config}`,
|
|
22
27
|
`--input=${input}`,
|
|
23
28
|
`--output=${output}`,
|
|
24
29
|
`--incremental`,
|
|
25
30
|
]
|
|
31
|
+
|
|
32
|
+
if (options.quiet) command.push('--quiet')
|
|
33
|
+
if (options.verbose) command.push('--verbose')
|
|
34
|
+
|
|
35
|
+
return command
|
|
26
36
|
}
|
|
27
37
|
|
|
28
38
|
/**
|
|
@@ -33,7 +43,7 @@ export default {
|
|
|
33
43
|
build: async (options = {}) => {
|
|
34
44
|
console.info('[CLI:11ty] running eleventy build')
|
|
35
45
|
|
|
36
|
-
const
|
|
46
|
+
const eleventyCommand = factory()
|
|
37
47
|
|
|
38
48
|
/**
|
|
39
49
|
* Set execa environment variables
|
|
@@ -42,10 +52,10 @@ export default {
|
|
|
42
52
|
const execaEnv = {}
|
|
43
53
|
|
|
44
54
|
if (options.debug) execaEnv.DEBUG = 'Eleventy*'
|
|
45
|
-
if (options.dryRun) eleventyOptions.push('--dryrun')
|
|
46
|
-
if (options.quiet) eleventyOptions.push('--quiet')
|
|
47
55
|
|
|
48
|
-
|
|
56
|
+
if (options.dryRun) eleventyCommand.push('--dryrun')
|
|
57
|
+
|
|
58
|
+
await execa('node', eleventyCommand, {
|
|
49
59
|
all: true,
|
|
50
60
|
cwd: projectRoot,
|
|
51
61
|
env: execaEnv,
|
|
@@ -56,9 +66,9 @@ export default {
|
|
|
56
66
|
serve: async (options = {}) => {
|
|
57
67
|
console.info(`[CLI:11ty] running eleventy serve`)
|
|
58
68
|
|
|
59
|
-
const
|
|
69
|
+
const eleventyCommand = factory(options)
|
|
60
70
|
|
|
61
|
-
|
|
71
|
+
eleventyCommand.push('--serve')
|
|
62
72
|
|
|
63
73
|
/**
|
|
64
74
|
* Set execa environment variables
|
|
@@ -67,11 +77,10 @@ export default {
|
|
|
67
77
|
const execaEnv = {}
|
|
68
78
|
|
|
69
79
|
if (options.debug) execaEnv.DEBUG = 'Eleventy*'
|
|
70
|
-
if (options.port) eleventyOptions.push(`--port=${options.port}`)
|
|
71
|
-
if (options.quiet) eleventyOptions.push('--quiet')
|
|
72
|
-
if (options.verbose) eleventyOptions.push('--verbose')
|
|
73
80
|
|
|
74
|
-
|
|
81
|
+
if (options.port) eleventyCommand.push(`--port=${options.port}`)
|
|
82
|
+
|
|
83
|
+
await execa('node', eleventyCommand, {
|
|
75
84
|
all: true,
|
|
76
85
|
cwd: projectRoot,
|
|
77
86
|
env: execaEnv,
|