@thegetty/quire-cli 1.0.0-rc.35 → 1.0.0-rc.37
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 +36 -0
- package/README.md +9 -0
- package/bin/cli.js +19 -1
- package/package.json +21 -8
- package/patches/README.md +19 -0
- package/patches/install-npm-version+1.0.9.patch +12119 -0
- package/schemas/objects.schema.json +12 -38
- package/schemas/publication.schema.json +0 -22
- package/schemas/references.schema.json +0 -1
- package/src/Command.js +26 -6
- package/src/Command.spec.js +99 -0
- package/src/commands/README.md +213 -122
- package/src/commands/build.js +37 -36
- package/src/commands/build.spec.js +113 -0
- package/src/commands/build.test.js +397 -0
- package/src/commands/clean.js +25 -19
- package/src/commands/clean.spec.js +108 -0
- package/src/commands/clean.test.js +260 -0
- package/src/commands/config.js +251 -0
- package/src/commands/config.spec.js +107 -0
- package/src/commands/config.test.js +715 -0
- package/src/commands/create.js +42 -14
- package/src/commands/create.spec.js +112 -0
- package/src/commands/create.test.js +415 -0
- package/src/commands/epub.js +59 -30
- package/src/commands/epub.spec.js +114 -0
- package/src/commands/epub.test.js +503 -0
- package/src/commands/index.js +9 -2
- package/src/commands/info.js +18 -24
- package/src/commands/info.spec.js +64 -0
- package/src/commands/info.test.js +415 -0
- package/src/commands/pdf.js +58 -84
- package/src/commands/pdf.spec.js +114 -0
- package/src/commands/pdf.test.js +464 -0
- package/src/commands/preview.js +32 -31
- package/src/commands/preview.spec.js +97 -0
- package/src/commands/preview.test.js +250 -0
- package/src/commands/use.js +56 -0
- package/src/commands/use.spec.js +61 -0
- package/src/commands/use.test.js +280 -0
- package/src/commands/validate.js +31 -19
- package/src/commands/validate.spec.js +82 -0
- package/src/commands/validate.test.js +234 -0
- package/src/commands/workflows.js +70 -0
- package/src/errors/build/build-failed-error.js +19 -0
- package/src/errors/build/config-field-missing-error.js +20 -0
- package/src/errors/build/config-file-not-found-error.js +20 -0
- package/src/errors/build/index.js +11 -0
- package/src/errors/index.js +48 -0
- package/src/errors/install/dependency-install-error.js +19 -0
- package/src/errors/install/directory-not-empty-error.js +25 -0
- package/src/errors/install/index.js +12 -0
- package/src/errors/install/invalid-path-error.js +31 -0
- package/src/errors/install/invalid-starter-error.js +27 -0
- package/src/errors/install/version-not-found-error.js +35 -0
- package/src/errors/output/epub-generation-error.js +19 -0
- package/src/errors/output/index.js +14 -0
- package/src/errors/output/invalid-epub-library-error.js +20 -0
- package/src/errors/output/invalid-pdf-library-error.js +20 -0
- package/src/errors/output/missing-build-output-error.js +21 -0
- package/src/errors/output/pdf-generation-error.js +24 -0
- package/src/errors/output/tool-not-found-error.js +37 -0
- package/src/errors/project/index.js +10 -0
- package/src/errors/project/not-in-project-error.js +20 -0
- package/src/errors/project/project-create-error.js +21 -0
- package/src/errors/quire-error.js +27 -0
- package/src/errors/validation/validation-error.js +20 -11
- package/src/helpers/clean.js +1 -1
- package/src/helpers/docs-url.js +32 -0
- package/src/helpers/test-cwd.js +5 -6
- package/src/helpers/test-cwd.test.js +192 -0
- package/src/helpers/which.js +10 -4
- package/src/lib/11ty/README.md +135 -19
- package/src/lib/11ty/api.js +196 -94
- package/src/lib/11ty/cli.js +91 -37
- package/src/lib/11ty/index.js +64 -5
- package/src/lib/11ty/index.test.js +655 -0
- package/src/lib/README.md +275 -0
- package/src/lib/commander/index.js +100 -0
- package/src/lib/commander/index.test.js +86 -0
- package/src/lib/commander/options.js +195 -0
- package/src/lib/commander/options.test.js +109 -0
- package/src/lib/conf/README.md +84 -73
- package/src/lib/conf/config.js +5 -3
- package/src/lib/conf/config.test.js +281 -0
- package/src/lib/conf/defaults.js +44 -0
- package/src/lib/conf/format.js +60 -0
- package/src/lib/conf/format.test.js +106 -0
- package/src/lib/conf/helpers.js +91 -0
- package/src/lib/conf/helpers.test.js +136 -0
- package/src/lib/conf/index.js +22 -0
- package/src/lib/conf/schema.js +53 -8
- package/src/lib/epub/README.md +133 -2
- package/src/lib/epub/engines.js +46 -0
- package/src/lib/epub/epub.js +36 -11
- package/src/lib/epub/index.js +111 -21
- package/src/lib/epub/index.test.js +518 -0
- package/src/lib/epub/pandoc.js +33 -4
- package/src/lib/epub/pandoc.test.js +122 -0
- package/src/lib/epub/schema.js +21 -0
- package/src/lib/error/README.md +170 -0
- package/src/lib/error/handler.js +107 -0
- package/src/lib/git/README.md +151 -2
- package/src/lib/git/index.js +217 -13
- package/src/lib/git/index.spec.js +80 -0
- package/src/lib/git/index.test.js +453 -0
- package/src/lib/installer/index.js +309 -0
- package/src/lib/installer/index.spec.js +83 -0
- package/src/lib/installer/index.test.js +545 -0
- package/src/lib/logger/README.md +424 -0
- package/src/lib/logger/debug.js +132 -0
- package/src/lib/logger/debug.spec.js +130 -0
- package/src/lib/logger/debug.test.js +128 -0
- package/src/lib/logger/index.js +228 -0
- package/src/lib/logger/index.spec.js +131 -0
- package/src/lib/logger/index.test.js +477 -0
- package/src/lib/npm/README.md +127 -0
- package/src/lib/npm/index.js +198 -0
- package/src/lib/npm/index.spec.js +60 -0
- package/src/lib/npm/index.test.js +355 -0
- package/src/lib/pdf/README.md +131 -0
- package/src/lib/pdf/engines.js +46 -0
- package/src/lib/pdf/index.js +124 -21
- package/src/lib/pdf/index.test.js +708 -0
- package/src/lib/pdf/paged.js +100 -52
- package/src/lib/pdf/paged.test.js +366 -0
- package/src/lib/pdf/prince.js +115 -37
- package/src/lib/pdf/prince.test.js +202 -0
- package/src/lib/pdf/schema.js +21 -0
- package/src/lib/pdf/split.js +61 -33
- package/src/lib/pdf/split.test.js +445 -0
- package/src/lib/process/manager.js +110 -0
- package/src/lib/process/manager.test.js +55 -0
- package/src/lib/project/build.js +143 -0
- package/src/lib/project/build.test.js +253 -0
- package/src/lib/project/config.js +48 -0
- package/src/lib/project/config.test.js +134 -0
- package/src/{helpers/is-quire.js → lib/project/detect.js} +5 -3
- package/src/lib/project/detect.test.js +157 -0
- package/src/lib/project/index.js +40 -0
- package/src/lib/project/paths.js +224 -0
- package/src/lib/project/version.js +110 -0
- package/src/lib/project/version.test.js +350 -0
- package/src/lib/reporter/README.md +211 -2
- package/src/lib/reporter/index.js +512 -0
- package/src/lib/reporter/index.test.js +593 -0
- package/src/main.js +134 -47
- package/src/main.spec.js +61 -0
- package/src/main.test.js +347 -0
- package/src/validators/utils.js +2 -1
- package/src/commands/conf.js +0 -43
- package/src/commands/version.js +0 -43
- package/src/lib/11ty/paths.js +0 -103
- package/src/lib/i18n/README.md +0 -3
- package/src/lib/i18n/config.js +0 -53
- package/src/lib/i18n/index.js +0 -43
- package/src/lib/i18n/localeService.js +0 -58
- package/src/lib/quire/README.md +0 -19
- package/src/lib/quire/index.js +0 -350
package/src/lib/README.md
CHANGED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# CLI Library Modules
|
|
2
|
+
|
|
3
|
+
This directory contains domain-specific modules that encapsulate the core functionality of the Quire CLI. Each module is designed around a single responsibility and provides a façade for its domain.
|
|
4
|
+
|
|
5
|
+
## Architecture Overview
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Commands Layer
|
|
9
|
+
┌─────────────────────────────────────────┐
|
|
10
|
+
│ build preview new pdf epub info │
|
|
11
|
+
└──────────────────┬──────────────────────┘
|
|
12
|
+
│
|
|
13
|
+
┌──────────────────┴──────────────────────┐
|
|
14
|
+
│ lib/ modules │
|
|
15
|
+
└─────────────────────────────────────────┘
|
|
16
|
+
|
|
17
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
18
|
+
│ Domain Modules │
|
|
19
|
+
│ ┌────────────┐ ┌──────────┐ ┌────────────┐ ┌─────────────┐ │
|
|
20
|
+
│ │ project/ │ │ 11ty/ │ │ pdf/ │ │ epub/ │ │
|
|
21
|
+
│ │ │ │ │ │ │ │ │ │
|
|
22
|
+
│ │ - paths │ │ - api │ │ - pagedjs │ │ - epubjs │ │
|
|
23
|
+
│ │ - config │ │ - cli │ │ - prince │ │ - pandoc │ │
|
|
24
|
+
│ │ - detect │ │ │ │ │ │ │ │
|
|
25
|
+
│ │ - version │ │ │ │ │ │ │ │
|
|
26
|
+
│ └────┬───────┘ └────┬─────┘ └────┬───────┘ └──────┬──────┘ │
|
|
27
|
+
└───────┼───────────────┼─────────────┼─────────────────┼─────────┘
|
|
28
|
+
│ │ │ │
|
|
29
|
+
│ ┌────────┴─────────────┴─────────────────┘
|
|
30
|
+
│ │
|
|
31
|
+
┌───────┴──────┴──────────────────────────────────────────────────┐
|
|
32
|
+
│ Installation Module │
|
|
33
|
+
│ ┌──────────────────────────────────────────────────────────┐ │
|
|
34
|
+
│ │ installer/ │ │
|
|
35
|
+
│ │ - initStarter (clone starter, setup project) │ │
|
|
36
|
+
│ │ - installInProject (install @thegetty/quire-11ty) │ │
|
|
37
|
+
│ │ - latest (resolve version from npm) │ │
|
|
38
|
+
│ │ - versions (list published versions) │ │
|
|
39
|
+
│ └──────────────────────────────────────────────────────────┘ │
|
|
40
|
+
└───────────────────────────────┬─────────────────────────────────┘
|
|
41
|
+
│
|
|
42
|
+
┌───────────────────────────────┴─────────────────────────────────┐
|
|
43
|
+
│ Infrastructure Modules │
|
|
44
|
+
│ ┌────────┐ ┌────────┐ ┌────────┐ ┌─────────┐ ┌──────────┐ │
|
|
45
|
+
│ │ npm/ │ │ git/ │ │ conf/ │ │ error/ │ │ logger/ │ │
|
|
46
|
+
│ │ │ │ │ │ │ │ │ │ │ │
|
|
47
|
+
│ └────────┘ └────────┘ └────────┘ └─────────┘ └──────────┘ │
|
|
48
|
+
│ ┌───────────┐ ┌───────────┐ │
|
|
49
|
+
│ │ reporter/ │ │ ui/ │ │
|
|
50
|
+
│ │ │ │ (prompt) │ │
|
|
51
|
+
│ └───────────┘ └───────────┘ │
|
|
52
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Module Reference
|
|
56
|
+
|
|
57
|
+
### Domain Modules
|
|
58
|
+
|
|
59
|
+
These modules encapsulate specific business domains of Quire.
|
|
60
|
+
|
|
61
|
+
#### `project/`
|
|
62
|
+
**Purpose:** Project-level concerns including paths, detection, configuration, and version management.
|
|
63
|
+
|
|
64
|
+
| Export | Description |
|
|
65
|
+
|--------|-------------|
|
|
66
|
+
| `paths` (default) | Singleton for path resolution |
|
|
67
|
+
| `Paths` | Class for custom path instances |
|
|
68
|
+
| `detect(dirpath)` | Check if directory is a Quire project |
|
|
69
|
+
| `loadProjectConfig(projectRoot?)` | Load and validate project config |
|
|
70
|
+
| `getVersion(projectPath?)` | Read `quire-11ty` version from project |
|
|
71
|
+
| `setVersion(version, projectPath?)` | Write `quire-11ty` version to project |
|
|
72
|
+
| `getVersionsFromStarter(projectPath)` | Read versions from starter package.json |
|
|
73
|
+
| `readVersionFile(projectPath)` | Read raw version file contents |
|
|
74
|
+
| `writeVersionFile(projectPath, info)` | Write version file contents |
|
|
75
|
+
|
|
76
|
+
**Dependencies:** `conf/`, `fs-extra`
|
|
77
|
+
|
|
78
|
+
#### `11ty/`
|
|
79
|
+
**Purpose:** Eleventy build system integration via API or CLI.
|
|
80
|
+
|
|
81
|
+
| Export | Description |
|
|
82
|
+
|--------|-------------|
|
|
83
|
+
| `api` | Programmatic Eleventy control |
|
|
84
|
+
| `cli` | CLI-based Eleventy execution |
|
|
85
|
+
| `paths` | Re-exported from `project/` |
|
|
86
|
+
| `Paths` | Re-exported from `project/` |
|
|
87
|
+
|
|
88
|
+
**Dependencies:** `project/`
|
|
89
|
+
|
|
90
|
+
#### `pdf/`
|
|
91
|
+
**Purpose:** PDF generation using Prince or Paged.js.
|
|
92
|
+
|
|
93
|
+
| Export | Description |
|
|
94
|
+
|--------|-------------|
|
|
95
|
+
| `default` | Factory returning configured PDF generator |
|
|
96
|
+
|
|
97
|
+
**Implementations:** `prince.js`, `paged.js`
|
|
98
|
+
|
|
99
|
+
**Dependencies:** `project/`
|
|
100
|
+
|
|
101
|
+
#### `epub/`
|
|
102
|
+
**Purpose:** EPUB generation using Pandoc.
|
|
103
|
+
|
|
104
|
+
| Export | Description |
|
|
105
|
+
|--------|-------------|
|
|
106
|
+
| `default` | EPUB generator façade |
|
|
107
|
+
|
|
108
|
+
**Dependencies:** `project/`
|
|
109
|
+
|
|
110
|
+
#### `installer/`
|
|
111
|
+
**Purpose:** Installation of `@thegetty/quire-11ty` into Quire projects.
|
|
112
|
+
|
|
113
|
+
| Export | Description |
|
|
114
|
+
|--------|-------------|
|
|
115
|
+
| `installer` | Object with all installer methods |
|
|
116
|
+
| `initStarter(starter, projectPath, options)` | Clone and setup starter project |
|
|
117
|
+
| `installInProject(projectPath, version, options)` | Install `@thegetty/quire-11ty` package |
|
|
118
|
+
| `latest(version?)` | Resolve version from npm registry |
|
|
119
|
+
| `versions()` | List all published `@thegetty/quire-11ty` versions |
|
|
120
|
+
|
|
121
|
+
**Dependencies:** `project/`, `npm/`, `git/`
|
|
122
|
+
|
|
123
|
+
### Infrastructure Modules
|
|
124
|
+
|
|
125
|
+
These modules provide cross-cutting concerns and external tool integrations.
|
|
126
|
+
|
|
127
|
+
#### `npm/`
|
|
128
|
+
**Purpose:** NPM operations façade.
|
|
129
|
+
|
|
130
|
+
| Export | Description |
|
|
131
|
+
|--------|-------------|
|
|
132
|
+
| `default` | Singleton npm façade |
|
|
133
|
+
| `init(cwd, options?)` | Run `npm init` |
|
|
134
|
+
| `install(cwd, options?)` | Run `npm install` |
|
|
135
|
+
| `pack(spec, dest, options?)` | Run `npm pack` |
|
|
136
|
+
| `cacheClean(cwd?)` | Run `npm cache clean` |
|
|
137
|
+
| `view(pkg, field?)` | Query package info |
|
|
138
|
+
| `show(pkg, field?)` | Query package versions |
|
|
139
|
+
| `version()` | Get npm version |
|
|
140
|
+
| `isAvailable()` | Check npm in PATH |
|
|
141
|
+
| `fetchFromRegistry(pkg)` | Direct registry API call |
|
|
142
|
+
| `getCompatibleVersion(pkg, range)` | Resolve semver range |
|
|
143
|
+
|
|
144
|
+
**Dependencies:** `execa`, `node-fetch`
|
|
145
|
+
|
|
146
|
+
#### `git/`
|
|
147
|
+
**Purpose:** Git operations via simple-git.
|
|
148
|
+
|
|
149
|
+
| Export | Description |
|
|
150
|
+
|--------|-------------|
|
|
151
|
+
| `default` | Configured simple-git instance |
|
|
152
|
+
|
|
153
|
+
**Dependencies:** `simple-git`
|
|
154
|
+
|
|
155
|
+
#### `conf/`
|
|
156
|
+
**Purpose:** CLI configuration persistence and schema-aware helpers.
|
|
157
|
+
|
|
158
|
+
| Export | Source | Description |
|
|
159
|
+
|--------|--------|-------------|
|
|
160
|
+
| `default` | `config.js` | `Conf` singleton instance |
|
|
161
|
+
| `isValidKey(key)` | `helpers.js` | Check if key exists in schema |
|
|
162
|
+
| `getValidKeys()` | `helpers.js` | Sorted array of all schema keys |
|
|
163
|
+
| `coerceValue(key, value)` | `helpers.js` | Coerce CLI string to schema type |
|
|
164
|
+
| `formatValidationError(key, value)` | `helpers.js` | Format error with enum/description hints |
|
|
165
|
+
| `getDefault(key)` | `helpers.js` | Get default value for a key |
|
|
166
|
+
| `getKeyDescription(key)` | `helpers.js` | Get schema description for a key |
|
|
167
|
+
| `formatSettings(store, options)` | `helpers.js` | Format all settings for display |
|
|
168
|
+
|
|
169
|
+
Uses a barrel export (`index.js`) rather than a wrapper class to keep pure helper functions separate from the stateful `Conf` singleton. This avoids circular dependencies with the logger module and keeps helpers directly testable without mocking.
|
|
170
|
+
|
|
171
|
+
**Dependencies:** `conf`
|
|
172
|
+
|
|
173
|
+
#### `logger.js`
|
|
174
|
+
**Purpose:** Logging abstraction.
|
|
175
|
+
|
|
176
|
+
| Export | Description |
|
|
177
|
+
|--------|-------------|
|
|
178
|
+
| `default` | Logger instance (loglevel) |
|
|
179
|
+
|
|
180
|
+
**Dependencies:** `loglevel`
|
|
181
|
+
|
|
182
|
+
#### `reporter/`
|
|
183
|
+
**Purpose:** Progress reporting for long-running operations.
|
|
184
|
+
|
|
185
|
+
| Export | Description |
|
|
186
|
+
|--------|-------------|
|
|
187
|
+
| `default` | Reporter façade |
|
|
188
|
+
|
|
189
|
+
#### `error/`
|
|
190
|
+
**Purpose:** Centralized error handling and formatting.
|
|
191
|
+
|
|
192
|
+
| Export | Description |
|
|
193
|
+
|--------|-------------|
|
|
194
|
+
| `formatError(error, options)` | Format error for display |
|
|
195
|
+
| `handleError(error, options)` | Handle single error (format, log, exit) |
|
|
196
|
+
| `handleErrors(errors, options)` | Handle multiple errors (batch validation) |
|
|
197
|
+
|
|
198
|
+
**Features:**
|
|
199
|
+
- Consistent error formatting with suggestion, docs URL, file path
|
|
200
|
+
- Debug mode shows error codes and stack traces
|
|
201
|
+
- Conditional `--debug` hint (controlled by `showDebugHint` property)
|
|
202
|
+
- Exit code management per error category
|
|
203
|
+
|
|
204
|
+
**Dependencies:** `logger/`
|
|
205
|
+
|
|
206
|
+
#### `ui/`
|
|
207
|
+
**Purpose:** Display and interactive prompt
|
|
208
|
+
|
|
209
|
+
_Future feature: Not yet impemented._
|
|
210
|
+
|
|
211
|
+
## Design Patterns
|
|
212
|
+
|
|
213
|
+
### Singleton façade
|
|
214
|
+
Most modules export a singleton instance as the default export:
|
|
215
|
+
```javascript
|
|
216
|
+
import npm from '#lib/npm/index.js'
|
|
217
|
+
await npm.install('/path/to/project')
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Optional Parameters with Defaults
|
|
221
|
+
Functions that operate on projects default to `cwd` when path not provided:
|
|
222
|
+
```javascript
|
|
223
|
+
// Uses current working directory
|
|
224
|
+
setVersion('1.0.0')
|
|
225
|
+
|
|
226
|
+
// Uses explicit path
|
|
227
|
+
setVersion('1.0.0', '/path/to/project')
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Re-exports for Convenience
|
|
231
|
+
Modules re-export commonly used dependencies:
|
|
232
|
+
```javascript
|
|
233
|
+
// 11ty/ re-exports paths from project/
|
|
234
|
+
import { paths } from '#lib/11ty/index.js'
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Import Aliases
|
|
238
|
+
|
|
239
|
+
Use these aliases for imports:
|
|
240
|
+
|
|
241
|
+
| Alias | Path |
|
|
242
|
+
|-------|------|
|
|
243
|
+
| `#lib/` | `src/lib/` |
|
|
244
|
+
| `#src/` | `src/` |
|
|
245
|
+
| `#helpers/` | `src/helpers/` |
|
|
246
|
+
|
|
247
|
+
Example:
|
|
248
|
+
```javascript
|
|
249
|
+
import npm from '#lib/npm/index.js'
|
|
250
|
+
import { installer } from '#lib/installer/index.js'
|
|
251
|
+
import paths, { loadProjectConfig } from '#lib/project/index.js'
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Testing
|
|
255
|
+
|
|
256
|
+
Each module has associated test files:
|
|
257
|
+
|
|
258
|
+
| Pattern | Purpose |
|
|
259
|
+
|---------|---------|
|
|
260
|
+
| `*.spec.js` | Unit tests (interface contracts) |
|
|
261
|
+
| `*.test.js` | Integration tests (with mocked dependencies) |
|
|
262
|
+
|
|
263
|
+
Tests use:
|
|
264
|
+
- **AVA** for test runner
|
|
265
|
+
- **esmock** for ESM module mocking
|
|
266
|
+
- **sinon** for stubs and spies
|
|
267
|
+
- **memfs** for in-memory filesystem
|
|
268
|
+
|
|
269
|
+
## Adding a New Module
|
|
270
|
+
|
|
271
|
+
1. Create directory: `lib/<module-name>/`
|
|
272
|
+
2. Create entry point: `index.js` with façade pattern
|
|
273
|
+
3. Export singleton or factory as default
|
|
274
|
+
4. Add tests: `index.spec.js` and/or `index.test.js`
|
|
275
|
+
5. Update this README with module documentation
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commander.js utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides helper functions for converting array-based definitions
|
|
5
|
+
* to Commander.js Argument and Option objects, plus shared option definitions.
|
|
6
|
+
*
|
|
7
|
+
* @module lib/commander
|
|
8
|
+
*/
|
|
9
|
+
import { Argument, Option } from 'commander'
|
|
10
|
+
|
|
11
|
+
// Re-export shared option definitions
|
|
12
|
+
export {
|
|
13
|
+
quietOption,
|
|
14
|
+
verboseOption,
|
|
15
|
+
debugOption,
|
|
16
|
+
outputModeOptions,
|
|
17
|
+
outputModeHelpText,
|
|
18
|
+
withOutputModes,
|
|
19
|
+
} from './options.js'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Convert array argument definition to Argument object
|
|
23
|
+
*
|
|
24
|
+
* @param {Array} entry - Argument definition array [name, description, { choices, default }]
|
|
25
|
+
* @returns {Argument} Commander Argument object
|
|
26
|
+
* @see https://github.com/tj/commander.js#more-configuration-1
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Required argument
|
|
30
|
+
* arrayToArgument(['<version>', 'quire-11ty version to use'])
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Optional argument with default
|
|
34
|
+
* arrayToArgument(['[starter]', 'starter template', { default: 'default' }])
|
|
35
|
+
*/
|
|
36
|
+
export function arrayToArgument(entry) {
|
|
37
|
+
const [name, description, config = {}] = entry
|
|
38
|
+
const argument = new Argument(name, description)
|
|
39
|
+
if (config.choices) argument.choices(config.choices)
|
|
40
|
+
if (config.default) argument.default(config.default)
|
|
41
|
+
return argument
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Convert array option definition to Option object
|
|
46
|
+
*
|
|
47
|
+
* Supports two array formats:
|
|
48
|
+
* - Separate flags: ['-s', '--long <value>', 'description', default, { choices, default }]
|
|
49
|
+
* - Combined flags: ['--long <value>', 'description', default, { choices, default }]
|
|
50
|
+
*
|
|
51
|
+
* @param {Array} entry - Option definition array
|
|
52
|
+
* @returns {Option} Commander Option object
|
|
53
|
+
* @see https://github.com/tj/commander.js/#options
|
|
54
|
+
* @see https://github.com/tj/commander.js/#more-configuration
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // Long-only option
|
|
58
|
+
* arrayToOption(['--debug', 'enable debug output'])
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* // Short and long flags
|
|
62
|
+
* arrayToOption(['-v', '--verbose', 'enable verbose output'])
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // Option with choices
|
|
66
|
+
* arrayToOption(['--lib <module>', 'library to use', { choices: ['a', 'b'], default: 'a' }])
|
|
67
|
+
*/
|
|
68
|
+
export function arrayToOption(entry) {
|
|
69
|
+
const lastElement = entry[entry.length - 1]
|
|
70
|
+
const configObj = typeof lastElement === 'object' && lastElement !== null ? lastElement : null
|
|
71
|
+
|
|
72
|
+
let flags, description, defaultValue
|
|
73
|
+
if (entry[0]?.startsWith('-') && entry[1]?.startsWith('--')) {
|
|
74
|
+
// Array has separate elements for short and long option flags
|
|
75
|
+
// @example ['-s', '--long <value>', 'desc', ...]
|
|
76
|
+
flags = `${entry[0]}, ${entry[1]}`
|
|
77
|
+
description = entry[2]
|
|
78
|
+
defaultValue = entry[3]
|
|
79
|
+
} else {
|
|
80
|
+
// Array has a single element with option flags
|
|
81
|
+
// @example ['--long <value>', 'desc', ...]
|
|
82
|
+
flags = entry[0]
|
|
83
|
+
description = entry[1]
|
|
84
|
+
defaultValue = entry[2]
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const option = new Option(flags, description)
|
|
88
|
+
|
|
89
|
+
if (configObj) {
|
|
90
|
+
if (configObj.choices) option.choices(configObj.choices)
|
|
91
|
+
if (configObj.conflicts) option.conflicts(configObj.conflicts)
|
|
92
|
+
if (configObj.default !== undefined) option.default(configObj.default)
|
|
93
|
+
if (configObj.hidden) option.hideHelp()
|
|
94
|
+
if (configObj.implies) option.implies(configObj.implies)
|
|
95
|
+
} else if (defaultValue !== undefined) {
|
|
96
|
+
option.default(defaultValue)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return option
|
|
100
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import test from 'ava'
|
|
2
|
+
import { Argument, Option } from 'commander'
|
|
3
|
+
import { arrayToArgument, arrayToOption } from './index.js'
|
|
4
|
+
|
|
5
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
6
|
+
// arrayToArgument tests
|
|
7
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
test('arrayToArgument creates Argument from basic array', (t) => {
|
|
10
|
+
const arg = arrayToArgument(['<version>', 'the version to use'])
|
|
11
|
+
|
|
12
|
+
t.true(arg instanceof Argument)
|
|
13
|
+
t.is(arg.name(), 'version')
|
|
14
|
+
t.is(arg.description, 'the version to use')
|
|
15
|
+
t.true(arg.required)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('arrayToArgument creates optional Argument', (t) => {
|
|
19
|
+
const arg = arrayToArgument(['[starter]', 'starter template'])
|
|
20
|
+
|
|
21
|
+
t.true(arg instanceof Argument)
|
|
22
|
+
t.is(arg.name(), 'starter')
|
|
23
|
+
t.false(arg.required)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('arrayToArgument applies choices from config', (t) => {
|
|
27
|
+
const arg = arrayToArgument(['<format>', 'output format', { choices: ['pdf', 'epub'] }])
|
|
28
|
+
|
|
29
|
+
t.true(arg instanceof Argument)
|
|
30
|
+
t.deepEqual(arg.argChoices, ['pdf', 'epub'])
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('arrayToArgument applies default from config', (t) => {
|
|
34
|
+
const arg = arrayToArgument(['[starter]', 'starter template', { default: 'default' }])
|
|
35
|
+
|
|
36
|
+
t.true(arg instanceof Argument)
|
|
37
|
+
t.is(arg.defaultValue, 'default')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
41
|
+
// arrayToOption tests
|
|
42
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
43
|
+
|
|
44
|
+
test('arrayToOption creates Option from combined flags', (t) => {
|
|
45
|
+
const opt = arrayToOption(['--debug', 'enable debug output'])
|
|
46
|
+
|
|
47
|
+
t.true(opt instanceof Option)
|
|
48
|
+
t.is(opt.long, '--debug')
|
|
49
|
+
t.is(opt.description, 'enable debug output')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('arrayToOption creates Option from separate short/long flags', (t) => {
|
|
53
|
+
const opt = arrayToOption(['-v', '--verbose', 'enable verbose output'])
|
|
54
|
+
|
|
55
|
+
t.true(opt instanceof Option)
|
|
56
|
+
t.is(opt.short, '-v')
|
|
57
|
+
t.is(opt.long, '--verbose')
|
|
58
|
+
t.is(opt.description, 'enable verbose output')
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('arrayToOption applies choices from config object', (t) => {
|
|
62
|
+
const opt = arrayToOption([
|
|
63
|
+
'--lib <module>',
|
|
64
|
+
'library to use',
|
|
65
|
+
{ choices: ['pagedjs', 'prince'], default: 'pagedjs' }
|
|
66
|
+
])
|
|
67
|
+
|
|
68
|
+
t.true(opt instanceof Option)
|
|
69
|
+
t.deepEqual(opt.argChoices, ['pagedjs', 'prince'])
|
|
70
|
+
t.is(opt.defaultValue, 'pagedjs')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('arrayToOption applies default from positional argument', (t) => {
|
|
74
|
+
const opt = arrayToOption(['--port <number>', 'port to use', 8080])
|
|
75
|
+
|
|
76
|
+
t.true(opt instanceof Option)
|
|
77
|
+
t.is(opt.defaultValue, 8080)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('arrayToOption handles option with value placeholder', (t) => {
|
|
81
|
+
const opt = arrayToOption(['--output <path>', 'output directory'])
|
|
82
|
+
|
|
83
|
+
t.true(opt instanceof Option)
|
|
84
|
+
t.is(opt.long, '--output')
|
|
85
|
+
t.true(opt.required) // option requires a value
|
|
86
|
+
})
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared option definitions for CLI commands
|
|
3
|
+
*
|
|
4
|
+
* Provides consistent option definitions that can be imported by commands.
|
|
5
|
+
* This ensures uniform help text, flags, and behavior across the CLI.
|
|
6
|
+
*
|
|
7
|
+
* ## Recommended Usage
|
|
8
|
+
*
|
|
9
|
+
* Use `withOutputModes()` to wrap your command definition:
|
|
10
|
+
*
|
|
11
|
+
* ```javascript
|
|
12
|
+
* import { withOutputModes } from '#lib/commander/index.js'
|
|
13
|
+
*
|
|
14
|
+
* export default class MyCommand extends Command {
|
|
15
|
+
* static definition = withOutputModes({
|
|
16
|
+
* name: 'my-command',
|
|
17
|
+
* description: 'Do something useful',
|
|
18
|
+
* helpText: `
|
|
19
|
+
* Examples:
|
|
20
|
+
* quire my-command --verbose
|
|
21
|
+
* `,
|
|
22
|
+
* options: [
|
|
23
|
+
* ['--custom', 'my custom option'],
|
|
24
|
+
* ],
|
|
25
|
+
* })
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* This automatically adds --quiet, --verbose, --debug options and prepends
|
|
30
|
+
* the standard output mode help text.
|
|
31
|
+
*
|
|
32
|
+
* ## Selective Options
|
|
33
|
+
*
|
|
34
|
+
* For commands that need only specific output options:
|
|
35
|
+
*
|
|
36
|
+
* ```javascript
|
|
37
|
+
* import { quietOption, verboseOption } from '#lib/commander/index.js'
|
|
38
|
+
*
|
|
39
|
+
* options: [
|
|
40
|
+
* quietOption,
|
|
41
|
+
* verboseOption,
|
|
42
|
+
* // No --debug for this command
|
|
43
|
+
* ]
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* ## Commander.js Boolean Negation
|
|
47
|
+
*
|
|
48
|
+
* Boolean options automatically support negation via Commander.js.
|
|
49
|
+
* For example, `--verbose` automatically supports `--no-verbose`.
|
|
50
|
+
*
|
|
51
|
+
* This enables the config fallback pattern:
|
|
52
|
+
* - `--verbose` → options.verbose = true
|
|
53
|
+
* - `--no-verbose` → options.verbose = false
|
|
54
|
+
* - (no flag) → options.verbose = undefined (falls back to config)
|
|
55
|
+
*
|
|
56
|
+
* @see https://github.com/tj/commander.js#other-option-types-negatable-boolean-and-booleanvalue
|
|
57
|
+
* @module lib/commander/options
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Quiet mode option - suppress progress output
|
|
62
|
+
*
|
|
63
|
+
* Use for CI/CD pipelines and automated scripts where spinner
|
|
64
|
+
* output would clutter logs. Exit codes still indicate success/failure.
|
|
65
|
+
*
|
|
66
|
+
* Conflicts with --verbose and --debug since quiet mode suppresses
|
|
67
|
+
* the output those modes would show.
|
|
68
|
+
*
|
|
69
|
+
* @type {Array}
|
|
70
|
+
*/
|
|
71
|
+
export const quietOption = [
|
|
72
|
+
'-q, --quiet', 'suppress progress output',
|
|
73
|
+
{ conflicts: ['verbose', 'debug'] }
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Verbose mode option - show detailed progress
|
|
78
|
+
*
|
|
79
|
+
* Shows additional information like file paths, timing data,
|
|
80
|
+
* and step-by-step progress. Useful when users want more
|
|
81
|
+
* visibility into what the CLI is doing.
|
|
82
|
+
*
|
|
83
|
+
* Respects config default: `quire settings set verbose true`
|
|
84
|
+
* Conflicts with --quiet since quiet mode suppresses output.
|
|
85
|
+
*
|
|
86
|
+
* @type {Array}
|
|
87
|
+
*/
|
|
88
|
+
export const verboseOption = [
|
|
89
|
+
'-v, --verbose', 'show detailed progress output',
|
|
90
|
+
{ conflicts: ['quiet'] }
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Progress option - hidden alias for --verbose
|
|
95
|
+
*
|
|
96
|
+
* Provides a familiar `--progress` flag as an alternative to `--verbose`.
|
|
97
|
+
* Many users expect `--progress` to show detailed output during long-running
|
|
98
|
+
* operations like builds and file deletions.
|
|
99
|
+
*
|
|
100
|
+
* Hidden from help output since --verbose is the canonical flag.
|
|
101
|
+
* Uses `implies` to set verbose=true when --progress is used.
|
|
102
|
+
*
|
|
103
|
+
* @type {Array}
|
|
104
|
+
*/
|
|
105
|
+
const progressOption = [
|
|
106
|
+
'--progress', 'show detailed progress (alias for --verbose)',
|
|
107
|
+
{ hidden: true, implies: { verbose: true } }
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Debug mode option - enable debug output
|
|
112
|
+
*
|
|
113
|
+
* Enables the DEBUG=quire:* namespace for internal logging.
|
|
114
|
+
* Outputs technical debugging information intended for developers
|
|
115
|
+
* and maintainers troubleshooting issues.
|
|
116
|
+
*
|
|
117
|
+
* Respects config default: `quire settings set debug true`
|
|
118
|
+
* Conflicts with --quiet since quiet mode suppresses output.
|
|
119
|
+
*
|
|
120
|
+
* @type {Array}
|
|
121
|
+
*/
|
|
122
|
+
export const debugOption = [
|
|
123
|
+
'--debug', 'enable debug output for troubleshooting',
|
|
124
|
+
{ conflicts: ['quiet'] }
|
|
125
|
+
]
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Standard output mode options (quiet, verbose, debug, progress)
|
|
129
|
+
*
|
|
130
|
+
* Most commands should include all three options for consistent UX.
|
|
131
|
+
* Spread this array into your command's options:
|
|
132
|
+
*
|
|
133
|
+
* ```javascript
|
|
134
|
+
* options: [
|
|
135
|
+
* ...outputModeOptions,
|
|
136
|
+
* ['--my-option', 'custom option'],
|
|
137
|
+
* ]
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @type {string[][]}
|
|
141
|
+
*/
|
|
142
|
+
export const outputModeOptions = [
|
|
143
|
+
quietOption,
|
|
144
|
+
verboseOption,
|
|
145
|
+
progressOption,
|
|
146
|
+
debugOption,
|
|
147
|
+
]
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Standard help text for output modes
|
|
151
|
+
*
|
|
152
|
+
* @type {string}
|
|
153
|
+
*/
|
|
154
|
+
export const outputModeHelpText = `Output Modes:
|
|
155
|
+
-q, --quiet Suppress progress output (for CI/scripts)
|
|
156
|
+
-v, --verbose Show detailed progress (paths, timing)
|
|
157
|
+
--progress Alias for --verbose
|
|
158
|
+
--debug Enable debug output for troubleshooting`
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Add output mode options to a command definition
|
|
162
|
+
*
|
|
163
|
+
* Injects --quiet, --verbose, --debug options and prepends the
|
|
164
|
+
* standard output mode help text to the command's helpText.
|
|
165
|
+
*
|
|
166
|
+
* @param {Object} definition - Command definition object
|
|
167
|
+
* @param {string} [definition.helpText] - Existing help text (output modes prepended)
|
|
168
|
+
* @param {Array} [definition.options] - Existing options (output modes appended)
|
|
169
|
+
* @returns {Object} Modified definition with output mode options
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* static definition = withOutputModes({
|
|
173
|
+
* name: 'build',
|
|
174
|
+
* description: 'Generate publication outputs',
|
|
175
|
+
* helpText: `
|
|
176
|
+
* Examples:
|
|
177
|
+
* quire build --verbose
|
|
178
|
+
* `,
|
|
179
|
+
* options: [
|
|
180
|
+
* ['--custom', 'my option'],
|
|
181
|
+
* ],
|
|
182
|
+
* })
|
|
183
|
+
*/
|
|
184
|
+
export function withOutputModes(definition) {
|
|
185
|
+
return {
|
|
186
|
+
...definition,
|
|
187
|
+
helpText: definition.helpText
|
|
188
|
+
? `\n${outputModeHelpText}\n${definition.helpText}`
|
|
189
|
+
: `\n${outputModeHelpText}`,
|
|
190
|
+
options: [
|
|
191
|
+
...(definition.options || []),
|
|
192
|
+
...outputModeOptions,
|
|
193
|
+
],
|
|
194
|
+
}
|
|
195
|
+
}
|