@openpkg-ts/cli 0.10.0 → 0.11.1
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/dist/index.js +61 -8
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -13,12 +13,14 @@ import {
|
|
|
13
13
|
getAvailableVersions,
|
|
14
14
|
getValidationErrors,
|
|
15
15
|
listExports,
|
|
16
|
+
loadConfig,
|
|
17
|
+
mergeConfig,
|
|
16
18
|
recommendSemverBump
|
|
17
19
|
} from "@openpkg-ts/sdk";
|
|
18
20
|
var HELP = `openpkg - extract TypeScript API specs and generate docs
|
|
19
21
|
|
|
20
22
|
Usage:
|
|
21
|
-
openpkg spec <entry.ts> [-o spec.json]
|
|
23
|
+
openpkg spec <entry.ts> [-o spec.json] [--follow-external <pkg,...>]
|
|
22
24
|
openpkg docs <entry.ts | spec.json> [-f md|html|json] [-o out]
|
|
23
25
|
openpkg list <entry.ts> [--json]
|
|
24
26
|
openpkg validate <spec.json>
|
|
@@ -32,11 +34,20 @@ Commands:
|
|
|
32
34
|
diff Compare two spec files and recommend a semver bump
|
|
33
35
|
|
|
34
36
|
Options:
|
|
35
|
-
-o, --output
|
|
36
|
-
-f, --format
|
|
37
|
-
--json
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
-o, --output Write to file instead of stdout
|
|
38
|
+
-f, --format docs output format: md (default), html, json
|
|
39
|
+
--json list/diff output as JSON
|
|
40
|
+
--follow-external Expand types from these packages (comma-separated,
|
|
41
|
+
globs ok: "@ai-sdk/*"). Default: stub externals.
|
|
42
|
+
--follow-external-all Expand every external package (use with care)
|
|
43
|
+
--only Only extract these exports (comma-separated, * ok)
|
|
44
|
+
--ignore Ignore these exports (comma-separated, * ok)
|
|
45
|
+
-h, --help Show this help
|
|
46
|
+
-v, --version Show version
|
|
47
|
+
|
|
48
|
+
Config: reads openpkg.config.json (or package.json "openpkg" field) from the
|
|
49
|
+
cwd. Flags override the file. Example openpkg.config.json:
|
|
50
|
+
{ "followExternal": ["@acme/payment-kit", "@ai-sdk/*"] }
|
|
40
51
|
`;
|
|
41
52
|
function fail(message) {
|
|
42
53
|
console.error(`error: ${message}`);
|
|
@@ -65,17 +76,59 @@ function reportDiagnostics(diagnostics) {
|
|
|
65
76
|
process.exit(1);
|
|
66
77
|
}
|
|
67
78
|
}
|
|
79
|
+
function toList(value) {
|
|
80
|
+
if (!value)
|
|
81
|
+
return;
|
|
82
|
+
const items = value.split(",").map((s) => s.trim()).filter(Boolean);
|
|
83
|
+
return items.length > 0 ? items : undefined;
|
|
84
|
+
}
|
|
85
|
+
function reportStubbedExternals(spec) {
|
|
86
|
+
const counts = new Map;
|
|
87
|
+
for (const t of spec.types ?? []) {
|
|
88
|
+
if (!t.external)
|
|
89
|
+
continue;
|
|
90
|
+
const pkg = t.schema?.["x-ts-package"];
|
|
91
|
+
const key = typeof pkg === "string" ? pkg : "(unknown origin)";
|
|
92
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
93
|
+
}
|
|
94
|
+
if (counts.size === 0)
|
|
95
|
+
return;
|
|
96
|
+
const summary = [...counts.entries()].sort((a, b) => b[1] - a[1]).map(([pkg, n]) => `${pkg} (${n})`).join(", ");
|
|
97
|
+
console.error(`external types stubbed from: ${summary}`);
|
|
98
|
+
console.error(" → add package names to followExternal (config or --follow-external) to expand them");
|
|
99
|
+
}
|
|
68
100
|
async function specCommand(args) {
|
|
69
101
|
const { values, positionals } = parseArgs({
|
|
70
102
|
args,
|
|
71
|
-
options: {
|
|
103
|
+
options: {
|
|
104
|
+
output: { type: "string", short: "o" },
|
|
105
|
+
"follow-external": { type: "string" },
|
|
106
|
+
"follow-external-all": { type: "boolean" },
|
|
107
|
+
only: { type: "string" },
|
|
108
|
+
ignore: { type: "string" }
|
|
109
|
+
},
|
|
72
110
|
allowPositionals: true
|
|
73
111
|
});
|
|
74
112
|
const entryFile = positionals[0];
|
|
75
113
|
if (!entryFile)
|
|
76
114
|
fail("spec requires an entry file (openpkg spec src/index.ts)");
|
|
77
|
-
const
|
|
115
|
+
const fileConfig = loadConfig(process.cwd());
|
|
116
|
+
const cliConfig = {
|
|
117
|
+
followExternal: values["follow-external-all"] ? true : toList(values["follow-external"]),
|
|
118
|
+
only: toList(values.only),
|
|
119
|
+
ignore: toList(values.ignore)
|
|
120
|
+
};
|
|
121
|
+
const config = mergeConfig(fileConfig, cliConfig);
|
|
122
|
+
const { spec, diagnostics } = await extractSpec({
|
|
123
|
+
entryFile,
|
|
124
|
+
followExternal: config.followExternal,
|
|
125
|
+
only: config.only,
|
|
126
|
+
ignore: config.ignore,
|
|
127
|
+
externals: config.externals
|
|
128
|
+
});
|
|
78
129
|
reportDiagnostics(diagnostics);
|
|
130
|
+
if (!config.followExternal)
|
|
131
|
+
reportStubbedExternals(spec);
|
|
79
132
|
write(JSON.stringify(spec, null, 2), values.output);
|
|
80
133
|
}
|
|
81
134
|
async function docsCommand(args) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "CLI for OpenPkg - extract TypeScript API specs and generate docs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openpkg",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"test": "bun test"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@openpkg-ts/sdk": "^0.
|
|
38
|
+
"@openpkg-ts/sdk": "^0.49.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/bun": "latest",
|