@driftdev/cli 0.35.0
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/LICENSE +21 -0
- package/README.md +212 -0
- package/dist/config/index.d.ts +9 -0
- package/dist/config/index.js +108 -0
- package/dist/drift.js +179161 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Ryan Waits
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# @driftdev/cli
|
|
2
|
+
|
|
3
|
+
Command-line interface for documentation coverage analysis and drift detection. Ships as the `drift` binary.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add -g @driftdev/cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Full scan: coverage + lint + prose drift + health
|
|
15
|
+
drift scan
|
|
16
|
+
|
|
17
|
+
# Check documentation coverage
|
|
18
|
+
drift coverage
|
|
19
|
+
|
|
20
|
+
# Find JSDoc accuracy issues
|
|
21
|
+
drift lint
|
|
22
|
+
|
|
23
|
+
# Validate @example blocks
|
|
24
|
+
drift examples
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Entry auto-detects from `package.json` — works in any TypeScript project.
|
|
28
|
+
|
|
29
|
+
## Commands
|
|
30
|
+
|
|
31
|
+
### Composed
|
|
32
|
+
|
|
33
|
+
| Command | Description |
|
|
34
|
+
|---------|-------------|
|
|
35
|
+
| `drift scan [entry]` | Coverage + lint + prose drift + health in one pass |
|
|
36
|
+
| `drift health [entry]` | Documentation health score (default command) |
|
|
37
|
+
| `drift ci` | CI checks on changed packages with PR comments |
|
|
38
|
+
|
|
39
|
+
### Analysis
|
|
40
|
+
|
|
41
|
+
| Command | Description |
|
|
42
|
+
|---------|-------------|
|
|
43
|
+
| `drift coverage [entry]` | Documentation coverage score |
|
|
44
|
+
| `drift lint [entry]` | Cross-reference JSDoc vs code signatures |
|
|
45
|
+
| `drift examples [entry]` | Validate @example blocks (presence, typecheck, run) |
|
|
46
|
+
|
|
47
|
+
### Extraction
|
|
48
|
+
|
|
49
|
+
| Command | Description |
|
|
50
|
+
|---------|-------------|
|
|
51
|
+
| `drift extract [entry]` | Extract full API spec as JSON |
|
|
52
|
+
| `drift list [entry]` | List all exports with kinds |
|
|
53
|
+
| `drift get <name> [entry]` | Inspect single export detail + types |
|
|
54
|
+
|
|
55
|
+
### Spec Operations
|
|
56
|
+
|
|
57
|
+
| Command | Description |
|
|
58
|
+
|---------|-------------|
|
|
59
|
+
| `drift validate <spec>` | Validate a spec file |
|
|
60
|
+
| `drift filter <spec>` | Filter exports by kind, search, tag |
|
|
61
|
+
|
|
62
|
+
### Comparison
|
|
63
|
+
|
|
64
|
+
| Command | Description |
|
|
65
|
+
|---------|-------------|
|
|
66
|
+
| `drift diff <old> <new>` | What changed between two specs |
|
|
67
|
+
| `drift breaking <old> <new>` | Detect breaking changes |
|
|
68
|
+
| `drift semver <old> <new>` | Recommend semver bump |
|
|
69
|
+
| `drift changelog <old> <new>` | Generate changelog |
|
|
70
|
+
|
|
71
|
+
### Setup & Plumbing
|
|
72
|
+
|
|
73
|
+
| Command | Description |
|
|
74
|
+
|---------|-------------|
|
|
75
|
+
| `drift init` | Create configuration file |
|
|
76
|
+
| `drift config` | Manage config (list, get, set) |
|
|
77
|
+
| `drift context` | Generate agent context file |
|
|
78
|
+
| `drift report` | Documentation trends from history |
|
|
79
|
+
| `drift release` | Pre-release documentation audit |
|
|
80
|
+
| `drift cache` | Cache management (clear, status) |
|
|
81
|
+
|
|
82
|
+
### Discovery
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Machine-readable list of all commands + flags
|
|
86
|
+
drift --capabilities
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Global Options
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
--json Force JSON output (default when piped)
|
|
93
|
+
--human Force human-readable output (default in terminal)
|
|
94
|
+
--config <path> Path to drift config file
|
|
95
|
+
--cwd <dir> Run as if started in <dir>
|
|
96
|
+
--no-cache Bypass spec cache
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## scan
|
|
100
|
+
|
|
101
|
+
Run coverage + lint + prose drift + health in one pass.
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
drift scan # single package
|
|
105
|
+
drift scan --min 80 # fail if health below 80%
|
|
106
|
+
drift scan --all # all workspace packages
|
|
107
|
+
drift scan --all --private # include private packages
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## lint
|
|
111
|
+
|
|
112
|
+
Cross-reference JSDoc against code signatures. Detects 15 drift types across 4 categories (structural, semantic, example, prose). Prose detection scans markdown files for broken import references.
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
drift lint # single package
|
|
116
|
+
drift lint --all # all workspace packages
|
|
117
|
+
drift lint --json # JSON output with filePath/line
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## coverage
|
|
121
|
+
|
|
122
|
+
Documentation coverage score.
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
drift coverage # single package
|
|
126
|
+
drift coverage --min 80 # fail if below 80%
|
|
127
|
+
drift coverage --all # all workspace packages
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## health
|
|
131
|
+
|
|
132
|
+
Weighted health score: completeness (coverage) + accuracy (lint).
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
drift health # default command (bare `drift`)
|
|
136
|
+
drift health --min 80
|
|
137
|
+
drift health --all
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## examples
|
|
141
|
+
|
|
142
|
+
Validate @example blocks.
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
drift examples # presence check
|
|
146
|
+
drift examples --typecheck # type-check examples
|
|
147
|
+
drift examples --run # execute examples
|
|
148
|
+
drift examples --min 50 # fail if example coverage below 50%
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## ci
|
|
152
|
+
|
|
153
|
+
CI checks with GitHub integration: PR comments, step summaries, history tracking.
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
drift ci # check changed packages
|
|
157
|
+
drift ci --all # check all packages
|
|
158
|
+
drift ci --private # include private packages
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Generates `~/.drift/projects/<slug>/context.md` — machine-readable project state for agents.
|
|
162
|
+
|
|
163
|
+
## Configuration
|
|
164
|
+
|
|
165
|
+
### drift.config.json
|
|
166
|
+
|
|
167
|
+
```json
|
|
168
|
+
{
|
|
169
|
+
"entry": "src/index.ts",
|
|
170
|
+
"coverage": {
|
|
171
|
+
"min": 80,
|
|
172
|
+
"ratchet": true
|
|
173
|
+
},
|
|
174
|
+
"lint": true,
|
|
175
|
+
"docs": {
|
|
176
|
+
"include": ["README.md", "docs/**/*.md"],
|
|
177
|
+
"exclude": ["node_modules/**"]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
See [Configuration docs](../../docs/configuration.md) for all keys and `drift config` commands.
|
|
183
|
+
|
|
184
|
+
## Output Format
|
|
185
|
+
|
|
186
|
+
All commands return structured JSON when piped or with `--json`:
|
|
187
|
+
|
|
188
|
+
```json
|
|
189
|
+
{
|
|
190
|
+
"ok": true,
|
|
191
|
+
"data": { "score": 88, "documented": 243, "total": 275 },
|
|
192
|
+
"meta": { "command": "coverage", "duration": 1234, "version": "0.34.3" }
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Human-readable output in terminal by default, or with `--human`.
|
|
197
|
+
|
|
198
|
+
## Monorepo Support
|
|
199
|
+
|
|
200
|
+
All analysis commands support `--all` for workspace batch mode:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
drift scan --all # scan all packages
|
|
204
|
+
drift coverage --all # coverage per package
|
|
205
|
+
drift lint --all # lint per package
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Auto-detects workspace globs from `package.json`.
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DocCovConfig as DocCovConfig2, DocCovConfigInput, DocsConfig } from "@driftdev/sdk";
|
|
2
|
+
import { DocCovConfig } from "@driftdev/sdk";
|
|
3
|
+
declare const DRIFT_CONFIG_FILENAMES: readonly ["drift.config.ts", "drift.config.mts", "drift.config.js", "drift.config.mjs"];
|
|
4
|
+
interface LoadedDriftTsConfig extends DocCovConfig {
|
|
5
|
+
filePath: string;
|
|
6
|
+
}
|
|
7
|
+
declare const loadDriftTsConfig: (cwd: string) => Promise<LoadedDriftTsConfig | null>;
|
|
8
|
+
declare const defineConfig: (config: DocCovConfigInput) => DocCovConfigInput;
|
|
9
|
+
export { loadDriftTsConfig, defineConfig, LoadedDriftTsConfig, DocsConfig, DocCovConfigInput, DocCovConfig2 as DocCovConfig, DRIFT_CONFIG_FILENAMES };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
set: (newValue) => all[name] = () => newValue
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
29
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
30
|
+
|
|
31
|
+
// src/config/drift-ts-config.ts
|
|
32
|
+
import { access } from "node:fs/promises";
|
|
33
|
+
import path from "node:path";
|
|
34
|
+
import { pathToFileURL } from "node:url";
|
|
35
|
+
import { docCovConfigSchema, normalizeConfig } from "@driftdev/sdk";
|
|
36
|
+
var DRIFT_CONFIG_FILENAMES = [
|
|
37
|
+
"drift.config.ts",
|
|
38
|
+
"drift.config.mts",
|
|
39
|
+
"drift.config.js",
|
|
40
|
+
"drift.config.mjs"
|
|
41
|
+
];
|
|
42
|
+
var fileExists = async (filePath) => {
|
|
43
|
+
try {
|
|
44
|
+
await access(filePath);
|
|
45
|
+
return true;
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var findConfigFile = async (cwd) => {
|
|
51
|
+
let current = path.resolve(cwd);
|
|
52
|
+
const { root } = path.parse(current);
|
|
53
|
+
while (true) {
|
|
54
|
+
for (const candidate of DRIFT_CONFIG_FILENAMES) {
|
|
55
|
+
const candidatePath = path.join(current, candidate);
|
|
56
|
+
if (await fileExists(candidatePath)) {
|
|
57
|
+
return candidatePath;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (current === root) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
current = path.dirname(current);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var importConfigModule = async (absolutePath) => {
|
|
67
|
+
const fileUrl = pathToFileURL(absolutePath);
|
|
68
|
+
fileUrl.searchParams.set("t", Date.now().toString());
|
|
69
|
+
const module = await import(fileUrl.href);
|
|
70
|
+
return module?.default ?? module?.config ?? module;
|
|
71
|
+
};
|
|
72
|
+
var formatIssues = (issues) => issues.map((issue) => `- ${issue}`).join(`
|
|
73
|
+
`);
|
|
74
|
+
var loadDriftTsConfig = async (cwd) => {
|
|
75
|
+
const configPath = await findConfigFile(cwd);
|
|
76
|
+
if (!configPath) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
let rawConfig;
|
|
80
|
+
try {
|
|
81
|
+
rawConfig = await importConfigModule(configPath);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
84
|
+
throw new Error(`Failed to load drift config at ${configPath}: ${message}`);
|
|
85
|
+
}
|
|
86
|
+
const parsed = docCovConfigSchema.safeParse(rawConfig);
|
|
87
|
+
if (!parsed.success) {
|
|
88
|
+
const issues = parsed.error.issues.map((issue) => {
|
|
89
|
+
const pathLabel = issue.path.length > 0 ? issue.path.join(".") : "(root)";
|
|
90
|
+
return `${pathLabel}: ${issue.message}`;
|
|
91
|
+
});
|
|
92
|
+
throw new Error(`Invalid drift configuration at ${configPath}.
|
|
93
|
+
${formatIssues(issues)}`);
|
|
94
|
+
}
|
|
95
|
+
const normalized = normalizeConfig(parsed.data);
|
|
96
|
+
return {
|
|
97
|
+
filePath: configPath,
|
|
98
|
+
...normalized
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// src/config/index.ts
|
|
103
|
+
var defineConfig = (config) => config;
|
|
104
|
+
export {
|
|
105
|
+
loadDriftTsConfig,
|
|
106
|
+
defineConfig,
|
|
107
|
+
DRIFT_CONFIG_FILENAMES
|
|
108
|
+
};
|