@metamask-previews/platform-api-docs 0.1.0-preview-8bfa290fb → 0.2.0-preview-97d6b86c0
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 +10 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/{cli.mjs → cli.js} +10 -40
- package/dist/cli.js.map +1 -0
- package/dist/{extraction.d.cts → extraction.d.ts} +3 -13
- package/dist/extraction.d.ts.map +1 -0
- package/dist/{extraction.mjs → extraction.js} +3 -28
- package/dist/{extraction.cjs.map → extraction.js.map} +1 -1
- package/dist/{generate.d.cts → generate.d.ts} +2 -2
- package/dist/generate.d.ts.map +1 -0
- package/dist/{generate.mjs → generate.js} +111 -68
- package/dist/generate.js.map +1 -0
- package/dist/{markdown.d.cts → markdown.d.ts} +2 -2
- package/dist/markdown.d.ts.map +1 -0
- package/dist/{markdown.mjs → markdown.js} +1 -1
- package/dist/markdown.js.map +1 -0
- package/dist/{root-messenger-discovery.d.cts → root-messenger-discovery.d.ts} +2 -2
- package/dist/root-messenger-discovery.d.ts.map +1 -0
- package/dist/{root-messenger-discovery.mjs → root-messenger-discovery.js} +9 -30
- package/dist/root-messenger-discovery.js.map +1 -0
- package/dist/ts-project.d.ts +12 -0
- package/dist/ts-project.d.ts.map +1 -0
- package/dist/ts-project.js +29 -0
- package/dist/ts-project.js.map +1 -0
- package/dist/{types.d.cts → types.d.ts} +1 -1
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +12 -9
- package/dist/cli.cjs +0 -328
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.cts +0 -3
- package/dist/cli.d.cts.map +0 -1
- package/dist/cli.d.mts +0 -3
- package/dist/cli.d.mts.map +0 -1
- package/dist/cli.mjs.map +0 -1
- package/dist/discovery.cjs +0 -53
- package/dist/discovery.cjs.map +0 -1
- package/dist/discovery.d.cts +0 -22
- package/dist/discovery.d.cts.map +0 -1
- package/dist/discovery.d.mts +0 -22
- package/dist/discovery.d.mts.map +0 -1
- package/dist/discovery.mjs +0 -48
- package/dist/discovery.mjs.map +0 -1
- package/dist/extraction.cjs +0 -780
- package/dist/extraction.d.cts.map +0 -1
- package/dist/extraction.d.mts +0 -83
- package/dist/extraction.d.mts.map +0 -1
- package/dist/extraction.mjs.map +0 -1
- package/dist/generate.cjs +0 -462
- package/dist/generate.cjs.map +0 -1
- package/dist/generate.d.cts.map +0 -1
- package/dist/generate.d.mts +0 -70
- package/dist/generate.d.mts.map +0 -1
- package/dist/generate.mjs.map +0 -1
- package/dist/markdown.cjs +0 -239
- package/dist/markdown.cjs.map +0 -1
- package/dist/markdown.d.cts.map +0 -1
- package/dist/markdown.d.mts +0 -52
- package/dist/markdown.d.mts.map +0 -1
- package/dist/markdown.mjs.map +0 -1
- package/dist/root-messenger-discovery.cjs +0 -380
- package/dist/root-messenger-discovery.cjs.map +0 -1
- package/dist/root-messenger-discovery.d.cts.map +0 -1
- package/dist/root-messenger-discovery.d.mts +0 -61
- package/dist/root-messenger-discovery.d.mts.map +0 -1
- package/dist/root-messenger-discovery.mjs.map +0 -1
- package/dist/types.cjs +0 -3
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts +0 -47
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs +0 -2
- package/dist/types.mjs.map +0 -1
package/dist/generate.cjs
DELETED
|
@@ -1,462 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.generate = exports.resolveRepoUrl = void 0;
|
|
27
|
-
const node_1 = require("@metamask/utils/node");
|
|
28
|
-
const node_child_process_1 = require("node:child_process");
|
|
29
|
-
const fs = __importStar(require("node:fs/promises"));
|
|
30
|
-
const path = __importStar(require("node:path"));
|
|
31
|
-
const node_util_1 = require("node:util");
|
|
32
|
-
const discovery_js_1 = require("./discovery.cjs");
|
|
33
|
-
const extraction_js_1 = require("./extraction.cjs");
|
|
34
|
-
const markdown_js_1 = require("./markdown.cjs");
|
|
35
|
-
const root_messenger_discovery_js_1 = require("./root-messenger-discovery.cjs");
|
|
36
|
-
/** How many skipped capability types to name before summarizing the rest. */
|
|
37
|
-
const MAX_SKIPPED_SHOWN = 10;
|
|
38
|
-
/**
|
|
39
|
-
* Compute a deduplication score for a messenger item, preferring items with
|
|
40
|
-
* JSDoc and from the "home" package whose name matches the namespace.
|
|
41
|
-
*
|
|
42
|
-
* @param item - The messenger item to score.
|
|
43
|
-
* @returns A numeric score (higher is better).
|
|
44
|
-
*/
|
|
45
|
-
function deduplicationScore(item) {
|
|
46
|
-
const jsDocScore = item.jsDoc ? 2 : 0;
|
|
47
|
-
const namespacePrefix = item.typeString
|
|
48
|
-
.split(':')[0]
|
|
49
|
-
.replace(/(?:Controller|Service)$/u, '')
|
|
50
|
-
.toLowerCase();
|
|
51
|
-
const homeScore = namespacePrefix.length > 0 &&
|
|
52
|
-
item.sourceFile.toLowerCase().includes(namespacePrefix)
|
|
53
|
-
? 1
|
|
54
|
-
: 0;
|
|
55
|
-
return jsDocScore + homeScore;
|
|
56
|
-
}
|
|
57
|
-
const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
|
|
58
|
-
/**
|
|
59
|
-
* Resolve the default branch of a project's `origin` remote by reading the
|
|
60
|
-
* symbolic ref `refs/remotes/origin/HEAD`. Falls back to `main` if the
|
|
61
|
-
* symbolic ref isn't set (e.g. in shallow CI clones).
|
|
62
|
-
*
|
|
63
|
-
* @param projectPath - Absolute path to the project root.
|
|
64
|
-
* @returns The default branch name (e.g. "main", "master", "develop").
|
|
65
|
-
*/
|
|
66
|
-
async function resolveDefaultBranch(projectPath) {
|
|
67
|
-
try {
|
|
68
|
-
const { stdout } = await execFileAsync('git', ['symbolic-ref', '--short', 'refs/remotes/origin/HEAD'], { cwd: projectPath });
|
|
69
|
-
// stdout looks like "origin/main"; strip the leading "origin/".
|
|
70
|
-
const trimmed = stdout.trim();
|
|
71
|
-
const slash = trimmed.indexOf('/');
|
|
72
|
-
return slash === -1
|
|
73
|
-
? // istanbul ignore next: defensive — `symbolic-ref --short` always
|
|
74
|
-
// returns `origin/<branch>` when the symbolic ref is set; this
|
|
75
|
-
// fallback only matters if git's output format ever changes.
|
|
76
|
-
trimmed || 'main'
|
|
77
|
-
: trimmed.slice(slash + 1);
|
|
78
|
-
}
|
|
79
|
-
catch {
|
|
80
|
-
return 'main';
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Resolve the bare GitHub repository URL for a project by reading its
|
|
85
|
-
* `origin` remote.
|
|
86
|
-
*
|
|
87
|
-
* @param projectPath - Absolute path to the project root.
|
|
88
|
-
* @returns A URL like "https://github.com/Owner/Repo" or null when the remote
|
|
89
|
-
* isn't a GitHub URL or can't be read.
|
|
90
|
-
*/
|
|
91
|
-
async function resolveRepoUrl(projectPath) {
|
|
92
|
-
try {
|
|
93
|
-
const { stdout: remoteRaw } = await execFileAsync('git', ['remote', 'get-url', 'origin'], { cwd: projectPath });
|
|
94
|
-
const remote = remoteRaw.trim();
|
|
95
|
-
// Parse owner/repo from SSH or HTTPS remote URLs
|
|
96
|
-
// Handles aliases like github.com-Org used in SSH configs
|
|
97
|
-
const match = remote.match(/github\.com[^:/]*[:/]([^/]+\/[^/]+?)(?:\.git)?$/u);
|
|
98
|
-
if (!match) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
return `https://github.com/${match[1]}`;
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.resolveRepoUrl = resolveRepoUrl;
|
|
108
|
-
/**
|
|
109
|
-
* Resolve the GitHub blob base URL used for per-line source links.
|
|
110
|
-
*
|
|
111
|
-
* Prefers the documented commit SHA when one is available so the links point
|
|
112
|
-
* at the exact revision the docs were generated from; falls back to the
|
|
113
|
-
* default branch otherwise.
|
|
114
|
-
*
|
|
115
|
-
* @param projectPath - Absolute path to the project root.
|
|
116
|
-
* @param commitSha - Optional commit SHA to use as the ref. When null, the
|
|
117
|
-
* default branch is used instead.
|
|
118
|
-
* @returns A base URL like "https://github.com/Owner/Repo/blob/<ref>/" or null.
|
|
119
|
-
*/
|
|
120
|
-
async function resolveRepoBaseUrl(projectPath, commitSha) {
|
|
121
|
-
const repoUrl = await resolveRepoUrl(projectPath);
|
|
122
|
-
if (!repoUrl) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
const ref = commitSha ?? (await resolveDefaultBranch(projectPath));
|
|
126
|
-
return `${repoUrl}/blob/${ref}/`;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Discover which configured source locations actually exist on disk.
|
|
130
|
-
*
|
|
131
|
-
* @param projectPath - The project root path.
|
|
132
|
-
* @param scanDirs - User-configured scan directories relative to projectPath.
|
|
133
|
-
* @returns A ScanSources object describing the locations to scan.
|
|
134
|
-
*/
|
|
135
|
-
async function discoverScanSources(projectPath, scanDirs) {
|
|
136
|
-
const existingScanDirs = [];
|
|
137
|
-
for (const dir of scanDirs) {
|
|
138
|
-
if (await (0, node_1.directoryExists)(path.join(projectPath, dir))) {
|
|
139
|
-
existingScanDirs.push(dir);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
const packagesDir = path.join(projectPath, 'packages');
|
|
143
|
-
const nodeModulesDir = path.join(projectPath, 'node_modules', '@metamask');
|
|
144
|
-
return {
|
|
145
|
-
scanDirs: existingScanDirs,
|
|
146
|
-
packagesDir: (await (0, node_1.directoryExists)(packagesDir)) ? packagesDir : null,
|
|
147
|
-
nodeModulesDir: (await (0, node_1.directoryExists)(nodeModulesDir))
|
|
148
|
-
? nodeModulesDir
|
|
149
|
-
: null,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Log a human-readable description of which source locations will be scanned.
|
|
154
|
-
*
|
|
155
|
-
* @param sources - The resolved scan sources.
|
|
156
|
-
*/
|
|
157
|
-
function logScanPlan(sources) {
|
|
158
|
-
const summary = [];
|
|
159
|
-
for (const dir of sources.scanDirs) {
|
|
160
|
-
summary.push(`${dir}/ (.ts)`);
|
|
161
|
-
}
|
|
162
|
-
if (sources.packagesDir) {
|
|
163
|
-
summary.push('packages/*/src (.ts)');
|
|
164
|
-
}
|
|
165
|
-
if (sources.nodeModulesDir) {
|
|
166
|
-
summary.push('node_modules/@metamask/*/dist (.d.cts)');
|
|
167
|
-
}
|
|
168
|
-
console.log(`Scanning ${summary.join(', ')} for Messenger action/event types...`);
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Run extraction against every file in a single directory, logging and
|
|
172
|
-
* swallowing per-file failures. All files are added to the shared `project`
|
|
173
|
-
* up front so the type checker can resolve cross-file references when the
|
|
174
|
-
* walker descends into imported types.
|
|
175
|
-
*
|
|
176
|
-
* @param project - The shared ts-morph project.
|
|
177
|
-
* @param directory - The directory to scan.
|
|
178
|
-
* @param projectPath - The project root, used for relative path display.
|
|
179
|
-
* @param findFiles - The function used to enumerate files in the directory.
|
|
180
|
-
* @returns The list of extracted messenger items.
|
|
181
|
-
*/
|
|
182
|
-
async function extractFromDirectory(project, directory, projectPath, findFiles) {
|
|
183
|
-
const items = [];
|
|
184
|
-
const files = await findFiles(directory);
|
|
185
|
-
for (const file of files) {
|
|
186
|
-
try {
|
|
187
|
-
const sourceFile = project.getSourceFile(file) ?? project.addSourceFileAtPath(file);
|
|
188
|
-
items.push(...(0, extraction_js_1.extractFromSourceFile)(sourceFile, projectPath));
|
|
189
|
-
}
|
|
190
|
-
catch (error) {
|
|
191
|
-
console.warn(`Warning: failed to parse ${path.relative(projectPath, file)}`);
|
|
192
|
-
console.warn(error);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return items;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Enumerate the subdirectories of a parent directory that match the expected
|
|
199
|
-
* layout (e.g., `packages/*/src` or `node_modules/@metamask/*/dist`), keeping
|
|
200
|
-
* only those that actually exist.
|
|
201
|
-
*
|
|
202
|
-
* @param parentDir - The parent directory to enumerate.
|
|
203
|
-
* @param subPath - The trailing path component appended to each entry.
|
|
204
|
-
* @param includeSymlinks - Whether to include symbolic links (true for
|
|
205
|
-
* node_modules where workspaces are symlinked).
|
|
206
|
-
* @returns The list of absolute paths to existing target subdirectories.
|
|
207
|
-
*/
|
|
208
|
-
async function listTargetSubdirectories(parentDir, subPath, includeSymlinks) {
|
|
209
|
-
const entries = await fs.readdir(parentDir, { withFileTypes: true });
|
|
210
|
-
const candidates = entries
|
|
211
|
-
.filter((entry) => entry.isDirectory() || (includeSymlinks && entry.isSymbolicLink()))
|
|
212
|
-
.map((entry) => path.join(parentDir, entry.name, subPath));
|
|
213
|
-
const existing = [];
|
|
214
|
-
for (const candidate of candidates) {
|
|
215
|
-
if (await (0, node_1.directoryExists)(candidate)) {
|
|
216
|
-
existing.push(candidate);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
return existing;
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Scan every source location described by `sources` and return all extracted
|
|
223
|
-
* messenger items. A single ts-morph Project is shared across every file so
|
|
224
|
-
* the type checker can resolve cross-file references (e.g. a `*Messenger`
|
|
225
|
-
* declaration in one file walking through an imported umbrella union into
|
|
226
|
-
* an auto-generated `*-method-action-types.ts` sibling).
|
|
227
|
-
*
|
|
228
|
-
* @param projectPath - The project root path.
|
|
229
|
-
* @param sources - The set of source locations to scan.
|
|
230
|
-
* @returns A flat list of all extracted messenger items.
|
|
231
|
-
*/
|
|
232
|
-
async function scanSources(projectPath, sources) {
|
|
233
|
-
const project = (0, extraction_js_1.createExtractionProject)();
|
|
234
|
-
const allItems = [];
|
|
235
|
-
for (const dir of sources.scanDirs) {
|
|
236
|
-
allItems.push(...(await extractFromDirectory(project, path.join(projectPath, dir), projectPath, discovery_js_1.findTsFiles)));
|
|
237
|
-
}
|
|
238
|
-
if (sources.packagesDir) {
|
|
239
|
-
const srcDirs = await listTargetSubdirectories(sources.packagesDir, 'src', false);
|
|
240
|
-
for (const srcDir of srcDirs) {
|
|
241
|
-
allItems.push(...(await extractFromDirectory(project, srcDir, projectPath, discovery_js_1.findTsFiles)));
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
if (sources.nodeModulesDir) {
|
|
245
|
-
const distDirs = await listTargetSubdirectories(sources.nodeModulesDir, 'dist', true);
|
|
246
|
-
for (const distDir of distDirs) {
|
|
247
|
-
allItems.push(...(await extractFromDirectory(project, distDir, projectPath, discovery_js_1.findDtsFiles)));
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return allItems;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Replace a previously-seen item in its existing namespace group with a
|
|
254
|
-
* higher-scoring duplicate. Handles the case where the duplicate is a
|
|
255
|
-
* different kind (action vs event) by moving it between lists.
|
|
256
|
-
*
|
|
257
|
-
* @param byNamespace - Map of namespace to its group.
|
|
258
|
-
* @param previous - The previously stored item.
|
|
259
|
-
* @param replacement - The new item to replace it with.
|
|
260
|
-
*/
|
|
261
|
-
function replaceDuplicateInGroup(byNamespace, previous, replacement) {
|
|
262
|
-
const namespace = replacement.typeString.split(':')[0];
|
|
263
|
-
const group = byNamespace.get(namespace);
|
|
264
|
-
// istanbul ignore next: `previous` and `replacement` have the same
|
|
265
|
-
// typeString, so they share a namespace, and we always insert the
|
|
266
|
-
// namespace into `byNamespace` before recording the original entry.
|
|
267
|
-
if (!group) {
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
const previousList = previous.kind === 'action' ? group.actions : group.events;
|
|
271
|
-
const index = previousList.indexOf(previous);
|
|
272
|
-
// istanbul ignore next: `previous` was added to its kind's list by
|
|
273
|
-
// `groupByNamespace` before being recorded in `seen`, so it is always
|
|
274
|
-
// present when we look it up here.
|
|
275
|
-
if (index === -1) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
if (previous.kind === replacement.kind) {
|
|
279
|
-
previousList[index] = replacement;
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
previousList.splice(index, 1);
|
|
283
|
-
const newList = replacement.kind === 'action' ? group.actions : group.events;
|
|
284
|
-
newList.push(replacement);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Group items by namespace, deduplicating duplicate typeStrings using
|
|
289
|
-
* `deduplicationScore`. Returns groups sorted alphabetically by namespace,
|
|
290
|
-
* with each group's items sorted alphabetically by typeString.
|
|
291
|
-
*
|
|
292
|
-
* @param items - The full list of extracted items.
|
|
293
|
-
* @returns The deduplicated and sorted namespace groups.
|
|
294
|
-
*/
|
|
295
|
-
function groupByNamespace(items) {
|
|
296
|
-
const byNamespace = new Map();
|
|
297
|
-
const seen = new Map();
|
|
298
|
-
for (const item of items) {
|
|
299
|
-
const existing = seen.get(item.typeString);
|
|
300
|
-
if (existing) {
|
|
301
|
-
if (deduplicationScore(item) <= deduplicationScore(existing)) {
|
|
302
|
-
continue;
|
|
303
|
-
}
|
|
304
|
-
replaceDuplicateInGroup(byNamespace, existing, item);
|
|
305
|
-
seen.set(item.typeString, item);
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
seen.set(item.typeString, item);
|
|
309
|
-
const namespace = item.typeString.split(':')[0];
|
|
310
|
-
let group = byNamespace.get(namespace);
|
|
311
|
-
if (!group) {
|
|
312
|
-
group = { namespace, actions: [], events: [] };
|
|
313
|
-
byNamespace.set(namespace, group);
|
|
314
|
-
}
|
|
315
|
-
if (item.kind === 'action') {
|
|
316
|
-
group.actions.push(item);
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
group.events.push(item);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
const namespaces = Array.from(byNamespace.values()).sort((a, b) => a.namespace.localeCompare(b.namespace));
|
|
323
|
-
for (const ns of namespaces) {
|
|
324
|
-
ns.actions.sort((a, b) => a.typeString.localeCompare(b.typeString));
|
|
325
|
-
ns.events.sort((a, b) => a.typeString.localeCompare(b.typeString));
|
|
326
|
-
}
|
|
327
|
-
return namespaces;
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Write generated docs (namespace pages, index page, sidebars) to disk,
|
|
331
|
-
* replacing any existing `docs/` directory.
|
|
332
|
-
*
|
|
333
|
-
* @param namespaces - The grouped namespaces to render.
|
|
334
|
-
* @param outputDir - The root output directory.
|
|
335
|
-
* @param repoBaseUrl - GitHub blob base URL for source links, or null.
|
|
336
|
-
* @param indexOptions - Options stamped on the index page header.
|
|
337
|
-
* @param indexOptions.projectLabel - Short label identifying the project.
|
|
338
|
-
* @param indexOptions.commitSha - Git commit SHA the docs were generated from.
|
|
339
|
-
* @returns Promise that resolves once all files are written.
|
|
340
|
-
*/
|
|
341
|
-
async function writeOutput(namespaces, outputDir, repoBaseUrl, indexOptions) {
|
|
342
|
-
const docsDir = path.join(outputDir, 'docs');
|
|
343
|
-
if (await (0, node_1.directoryExists)(docsDir)) {
|
|
344
|
-
await fs.rm(docsDir, { recursive: true });
|
|
345
|
-
}
|
|
346
|
-
await fs.mkdir(docsDir, { recursive: true });
|
|
347
|
-
for (const ns of namespaces) {
|
|
348
|
-
const nsDir = path.join(docsDir, ns.namespace);
|
|
349
|
-
await fs.mkdir(nsDir, { recursive: true });
|
|
350
|
-
if (ns.actions.length > 0) {
|
|
351
|
-
await fs.writeFile(path.join(nsDir, 'actions.md'), (0, markdown_js_1.generateNamespacePage)(ns, 'action', repoBaseUrl));
|
|
352
|
-
}
|
|
353
|
-
if (ns.events.length > 0) {
|
|
354
|
-
await fs.writeFile(path.join(nsDir, 'events.md'), (0, markdown_js_1.generateNamespacePage)(ns, 'event', repoBaseUrl));
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
await fs.writeFile(path.join(docsDir, 'index.md'), (0, markdown_js_1.generateIndexPage)(namespaces, indexOptions));
|
|
358
|
-
await fs.writeFile(path.join(outputDir, 'sidebars.ts'), (0, markdown_js_1.generateSidebars)(namespaces));
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Collect capabilities by scanning the project's files.
|
|
362
|
-
*
|
|
363
|
-
* @param projectPath - The project root path.
|
|
364
|
-
* @param scanDirs - Directories (relative to projectPath) to scan.
|
|
365
|
-
* @returns The extracted capabilities.
|
|
366
|
-
* @throws If the project has no scannable directories at all.
|
|
367
|
-
*/
|
|
368
|
-
async function collectByScanning(projectPath, scanDirs) {
|
|
369
|
-
const sources = await discoverScanSources(projectPath, scanDirs);
|
|
370
|
-
if (sources.scanDirs.length === 0 &&
|
|
371
|
-
!sources.packagesDir &&
|
|
372
|
-
!sources.nodeModulesDir) {
|
|
373
|
-
throw new Error(`No scannable directories found in ${projectPath}. ` +
|
|
374
|
-
`Looked for: ${scanDirs.join(', ')}, packages/, node_modules/@metamask/`);
|
|
375
|
-
}
|
|
376
|
-
logScanPlan(sources);
|
|
377
|
-
return await scanSources(projectPath, sources);
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Using the project's root messenger capability collection types as
|
|
381
|
-
* entrypoints, collect the constituent individual capability types and package
|
|
382
|
-
* them so that they can be displayed within the documentation site.
|
|
383
|
-
*
|
|
384
|
-
* @param projectPath - The project root path.
|
|
385
|
-
* @param options - The root-messenger strategy options.
|
|
386
|
-
* @returns The extracted capabilities.
|
|
387
|
-
*/
|
|
388
|
-
function collectFromRootMessengerCapabilities(projectPath, options) {
|
|
389
|
-
const { rootActions, rootEvents } = options;
|
|
390
|
-
console.log(`Resolving actions from ${rootActions.filePath}#${rootActions.typeName} ` +
|
|
391
|
-
`and events from ${rootEvents.filePath}#${rootEvents.typeName}...`);
|
|
392
|
-
const { capabilityPackets, skippedCapabilities } = (0, root_messenger_discovery_js_1.discoverFromRootMessengerCapabilitiesTypes)({
|
|
393
|
-
projectPath,
|
|
394
|
-
rootActionsTypeReference: rootActions,
|
|
395
|
-
rootEventsTypeReference: rootEvents,
|
|
396
|
-
});
|
|
397
|
-
// Report rather than drop silently: a jump in any of these usually means the
|
|
398
|
-
// project changed how it declares its capabilities.
|
|
399
|
-
warnSkipped('declared inline, with no name to document', skippedCapabilities.unnamedCapabilities);
|
|
400
|
-
warnSkipped('whose shape could not be read', skippedCapabilities.unextractableCapabilities);
|
|
401
|
-
// If both capability collection types resolve to nothing, it's always a
|
|
402
|
-
// misconfiguration (a wrong type name, or imports that didn't resolve).
|
|
403
|
-
// Failing here matters because generation would otherwise replace an existing
|
|
404
|
-
// docs directory with an empty one and exit successfully.
|
|
405
|
-
if (capabilityPackets.length === 0) {
|
|
406
|
-
throw new Error(`No messenger actions or events found in ` +
|
|
407
|
-
`${rootActions.filePath}#${rootActions.typeName} or ` +
|
|
408
|
-
`${rootEvents.filePath}#${rootEvents.typeName}. ` +
|
|
409
|
-
`Check that these types name the collections carrying every ` +
|
|
410
|
-
`capability, and that their imports resolve.`);
|
|
411
|
-
}
|
|
412
|
-
return capabilityPackets;
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Warn about capability types that couldn't be documented, naming them so the
|
|
416
|
-
* warning is actionable.
|
|
417
|
-
*
|
|
418
|
-
* @param description - Why they were skipped, as a noun phrase.
|
|
419
|
-
* @param labels - Labels identifying each skipped type.
|
|
420
|
-
*/
|
|
421
|
-
function warnSkipped(description, labels) {
|
|
422
|
-
if (labels.length === 0) {
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
const shown = labels.slice(0, MAX_SKIPPED_SHOWN);
|
|
426
|
-
const remaining = labels.length - shown.length;
|
|
427
|
-
console.warn(`Warning: skipped ${labels.length} capability ` +
|
|
428
|
-
`${labels.length === 1 ? 'type' : 'types'} ${description}: ` +
|
|
429
|
-
`${shown.join(', ')}${remaining > 0 ? `, and ${remaining} more` : ''}`);
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Scan a project for messenger action/event types and generate documentation.
|
|
433
|
-
*
|
|
434
|
-
* @param options - Generation options.
|
|
435
|
-
* @returns A promise resolving to counts of generated namespaces, actions, and events.
|
|
436
|
-
*/
|
|
437
|
-
async function generate(options) {
|
|
438
|
-
const { projectPath, outputDir, projectLabel, commitSha } = options;
|
|
439
|
-
const allItems = options.strategy === 'root-messenger'
|
|
440
|
-
? collectFromRootMessengerCapabilities(projectPath, options)
|
|
441
|
-
: await collectByScanning(projectPath, options.scanDirs);
|
|
442
|
-
console.log(`Found ${allItems.length} messenger ${allItems.length === 1 ? 'item' : 'items'} total.`);
|
|
443
|
-
const namespaces = groupByNamespace(allItems);
|
|
444
|
-
const repoBaseUrl = await resolveRepoBaseUrl(projectPath, commitSha ?? null);
|
|
445
|
-
await writeOutput(namespaces, outputDir, repoBaseUrl, {
|
|
446
|
-
projectLabel,
|
|
447
|
-
commitSha,
|
|
448
|
-
});
|
|
449
|
-
const totalActions = namespaces.reduce((sum, ns) => sum + ns.actions.length, 0);
|
|
450
|
-
const totalEvents = namespaces.reduce((sum, ns) => sum + ns.events.length, 0);
|
|
451
|
-
console.log(`Generated docs for ${namespaces.length} ${namespaces.length === 1 ? 'namespace' : 'namespaces'}.`);
|
|
452
|
-
console.log(` Actions: ${totalActions}`);
|
|
453
|
-
console.log(` Events: ${totalEvents}`);
|
|
454
|
-
console.log(`Output: ${path.join(outputDir, 'docs')}/`);
|
|
455
|
-
return {
|
|
456
|
-
namespaces: namespaces.length,
|
|
457
|
-
actions: totalActions,
|
|
458
|
-
events: totalEvents,
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
exports.generate = generate;
|
|
462
|
-
//# sourceMappingURL=generate.cjs.map
|
package/dist/generate.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.cjs","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAuD;AACvD,2DAA8C;AAC9C,qDAAuC;AACvC,gDAAkC;AAClC,yCAAsC;AAGtC,kDAA2D;AAC3D,oDAGyB;AACzB,gDAIuB;AAEvB,gFAA2F;AAG3F,6EAA6E;AAC7E,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAsE7B;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,IAA+B;IACzD,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,MAAM,eAAe,GAAG,IAAI,CAAC,UAAU;SACpC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;SACb,OAAO,CAAC,0BAA0B,EAAE,E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AAG,CAAC,cAAc,YAAY,EAAE,CAAC,CAAC;IAC1C,OAAO,CAAC,GAAG,CAAC,aAAa,WAAW,EAAE,CAAC,CAAC;IACxC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAExD,OAAO;QACL,UAAU,EAAE,UAAU,CAAC,MAAM;QAC7B,OAAO,EAAE,YAAY;QACrB,MAAM,EAAE,WAAW;KACpB,CAAC;AACJ,CAAC;AAxCD,4BAwCC","sourcesContent":["import { directoryExists } from '@metamask/utils/node';\nimport { execFile } from 'node:child_process';\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { promisify } from 'node:util';\nimport type { Project } from 'ts-morph';\n\nimport { findDtsFiles, findTsFiles } from './discovery.js';\nimport {\n createExtractionProject,\n extractFromSourceFile,\n} from './extraction.js';\nimport {\n generateIndexPage,\n generateNamespacePage,\n generateSidebars,\n} from './markdown.js';\nimport type { RootCapabilitiesTypeReference } from './root-messenger-discovery.js';\nimport { discoverFromRootMessengerCapabilitiesTypes } from './root-messenger-discovery.js';\nimport type { MessengerCapabilityPacket, NamespaceGroup } from './types.js';\n\n/** How many skipped capability types to name before summarizing the rest. */\nconst MAX_SKIPPED_SHOWN = 10;\n\n/**\n * Options for the `scan` strategy, which reads every `*Messenger` type alias\n * in every file it can find. Used when no single messenger aggregates every\n * capability.\n */\ntype ScanStrategyOptions = {\n /** The selected strategy. */\n strategy: 'scan';\n /** Directories, relative to the project root, to scan. */\n scanDirs: string[];\n};\n\n/**\n * Options for the `root-messenger` strategy, which walks the types a\n * project declares for its root messenger capabilities instead of scanning the\n * entire repo. Used when one messenger carries every action and event.\n */\ntype RootMessengerStrategyOptions = {\n /** The selected strategy. */\n strategy: 'root-messenger';\n /** The root messenger actions type reference. */\n rootActions: RootCapabilitiesTypeReference;\n /** The root messenger events type reference. */\n rootEvents: RootCapabilitiesTypeReference;\n};\n\n/**\n * Options for the generate function.\n */\nexport type GenerateOptions = {\n /** Absolute path to the project to scan. */\n projectPath: string;\n /** Absolute path to the output directory for generated docs. */\n outputDir: string;\n /**\n * Short label identifying the project the docs were generated from (e.g.\n * \"Core\", \"Extension\"). Stamped in the index page title.\n */\n projectLabel?: string | null;\n /**\n * Git commit SHA the docs were generated from. Stamped in the index page\n * intro so engineers know how current the site is.\n */\n commitSha?: string | null;\n} & (ScanStrategyOptions | RootMessengerStrategyOptions);\n\n/**\n * Result returned by the generate function.\n */\nexport type GenerateResult = {\n namespaces: number;\n actions: number;\n events: number;\n};\n\n/**\n * The set of directories available to scan for messenger types, resolved from\n * the project's filesystem layout.\n */\ntype ScanSources = {\n /** User-configured scan dirs that exist on disk (relative to projectPath). */\n scanDirs: string[];\n /** Absolute path to `packages/` if it exists, otherwise null. */\n packagesDir: string | null;\n /** Absolute path to `node_modules/@metamask/` if it exists, otherwise null. */\n nodeModulesDir: string | null;\n};\n\n/**\n * Compute a deduplication score for a messenger item, preferring items with\n * JSDoc and from the \"home\" package whose name matches the namespace.\n *\n * @param item - The messenger item to score.\n * @returns A numeric score (higher is better).\n */\nfunction deduplicationScore(item: MessengerCapabilityPacket): number {\n const jsDocScore = item.jsDoc ? 2 : 0;\n const namespacePrefix = item.typeString\n .split(':')[0]\n .replace(/(?:Controller|Service)$/u, '')\n .toLowerCase();\n const homeScore =\n namespacePrefix.length > 0 &&\n item.sourceFile.toLowerCase().includes(namespacePrefix)\n ? 1\n : 0;\n return jsDocScore + homeScore;\n}\n\nconst execFileAsync = promisify(execFile);\n\n/**\n * Resolve the default branch of a project's `origin` remote by reading the\n * symbolic ref `refs/remotes/origin/HEAD`. Falls back to `main` if the\n * symbolic ref isn't set (e.g. in shallow CI clones).\n *\n * @param projectPath - Absolute path to the project root.\n * @returns The default branch name (e.g. \"main\", \"master\", \"develop\").\n */\nasync function resolveDefaultBranch(projectPath: string): Promise<string> {\n try {\n const { stdout } = await execFileAsync(\n 'git',\n ['symbolic-ref', '--short', 'refs/remotes/origin/HEAD'],\n { cwd: projectPath },\n );\n // stdout looks like \"origin/main\"; strip the leading \"origin/\".\n const trimmed = stdout.trim();\n const slash = trimmed.indexOf('/');\n return slash === -1\n ? // istanbul ignore next: defensive — `symbolic-ref --short` always\n // returns `origin/<branch>` when the symbolic ref is set; this\n // fallback only matters if git's output format ever changes.\n trimmed || 'main'\n : trimmed.slice(slash + 1);\n } catch {\n return 'main';\n }\n}\n\n/**\n * Resolve the bare GitHub repository URL for a project by reading its\n * `origin` remote.\n *\n * @param projectPath - Absolute path to the project root.\n * @returns A URL like \"https://github.com/Owner/Repo\" or null when the remote\n * isn't a GitHub URL or can't be read.\n */\nexport async function resolveRepoUrl(\n projectPath: string,\n): Promise<string | null> {\n try {\n const { stdout: remoteRaw } = await execFileAsync(\n 'git',\n ['remote', 'get-url', 'origin'],\n { cwd: projectPath },\n );\n\n const remote = remoteRaw.trim();\n\n // Parse owner/repo from SSH or HTTPS remote URLs\n // Handles aliases like github.com-Org used in SSH configs\n const match = remote.match(\n /github\\.com[^:/]*[:/]([^/]+\\/[^/]+?)(?:\\.git)?$/u,\n );\n if (!match) {\n return null;\n }\n\n return `https://github.com/${match[1]}`;\n } catch {\n return null;\n }\n}\n\n/**\n * Resolve the GitHub blob base URL used for per-line source links.\n *\n * Prefers the documented commit SHA when one is available so the links point\n * at the exact revision the docs were generated from; falls back to the\n * default branch otherwise.\n *\n * @param projectPath - Absolute path to the project root.\n * @param commitSha - Optional commit SHA to use as the ref. When null, the\n * default branch is used instead.\n * @returns A base URL like \"https://github.com/Owner/Repo/blob/<ref>/\" or null.\n */\nasync function resolveRepoBaseUrl(\n projectPath: string,\n commitSha: string | null,\n): Promise<string | null> {\n const repoUrl = await resolveRepoUrl(projectPath);\n if (!repoUrl) {\n return null;\n }\n const ref = commitSha ?? (await resolveDefaultBranch(projectPath));\n return `${repoUrl}/blob/${ref}/`;\n}\n\n/**\n * Discover which configured source locations actually exist on disk.\n *\n * @param projectPath - The project root path.\n * @param scanDirs - User-configured scan directories relative to projectPath.\n * @returns A ScanSources object describing the locations to scan.\n */\nasync function discoverScanSources(\n projectPath: string,\n scanDirs: string[],\n): Promise<ScanSources> {\n const existingScanDirs: string[] = [];\n for (const dir of scanDirs) {\n if (await directoryExists(path.join(projectPath, dir))) {\n existingScanDirs.push(dir);\n }\n }\n\n const packagesDir = path.join(projectPath, 'packages');\n const nodeModulesDir = path.join(projectPath, 'node_modules', '@metamask');\n\n return {\n scanDirs: existingScanDirs,\n packagesDir: (await directoryExists(packagesDir)) ? packagesDir : null,\n nodeModulesDir: (await directoryExists(nodeModulesDir))\n ? nodeModulesDir\n : null,\n };\n}\n\n/**\n * Log a human-readable description of which source locations will be scanned.\n *\n * @param sources - The resolved scan sources.\n */\nfunction logScanPlan(sources: ScanSources): void {\n const summary: string[] = [];\n for (const dir of sources.scanDirs) {\n summary.push(`${dir}/ (.ts)`);\n }\n if (sources.packagesDir) {\n summary.push('packages/*/src (.ts)');\n }\n if (sources.nodeModulesDir) {\n summary.push('node_modules/@metamask/*/dist (.d.cts)');\n }\n console.log(\n `Scanning ${summary.join(', ')} for Messenger action/event types...`,\n );\n}\n\n/**\n * Run extraction against every file in a single directory, logging and\n * swallowing per-file failures. All files are added to the shared `project`\n * up front so the type checker can resolve cross-file references when the\n * walker descends into imported types.\n *\n * @param project - The shared ts-morph project.\n * @param directory - The directory to scan.\n * @param projectPath - The project root, used for relative path display.\n * @param findFiles - The function used to enumerate files in the directory.\n * @returns The list of extracted messenger items.\n */\nasync function extractFromDirectory(\n project: Project,\n directory: string,\n projectPath: string,\n findFiles: (dir: string) => Promise<string[]>,\n): Promise<MessengerCapabilityPacket[]> {\n const items: MessengerCapabilityPacket[] = [];\n const files = await findFiles(directory);\n for (const file of files) {\n try {\n const sourceFile =\n project.getSourceFile(file) ?? project.addSourceFileAtPath(file);\n items.push(...extractFromSourceFile(sourceFile, projectPath));\n } catch (error) {\n console.warn(\n `Warning: failed to parse ${path.relative(projectPath, file)}`,\n );\n console.warn(error);\n }\n }\n return items;\n}\n\n/**\n * Enumerate the subdirectories of a parent directory that match the expected\n * layout (e.g., `packages/*/src` or `node_modules/@metamask/*/dist`), keeping\n * only those that actually exist.\n *\n * @param parentDir - The parent directory to enumerate.\n * @param subPath - The trailing path component appended to each entry.\n * @param includeSymlinks - Whether to include symbolic links (true for\n * node_modules where workspaces are symlinked).\n * @returns The list of absolute paths to existing target subdirectories.\n */\nasync function listTargetSubdirectories(\n parentDir: string,\n subPath: string,\n includeSymlinks: boolean,\n): Promise<string[]> {\n const entries = await fs.readdir(parentDir, { withFileTypes: true });\n const candidates = entries\n .filter(\n (entry) =>\n entry.isDirectory() || (includeSymlinks && entry.isSymbolicLink()),\n )\n .map((entry) => path.join(parentDir, entry.name, subPath));\n\n const existing: string[] = [];\n for (const candidate of candidates) {\n if (await directoryExists(candidate)) {\n existing.push(candidate);\n }\n }\n return existing;\n}\n\n/**\n * Scan every source location described by `sources` and return all extracted\n * messenger items. A single ts-morph Project is shared across every file so\n * the type checker can resolve cross-file references (e.g. a `*Messenger`\n * declaration in one file walking through an imported umbrella union into\n * an auto-generated `*-method-action-types.ts` sibling).\n *\n * @param projectPath - The project root path.\n * @param sources - The set of source locations to scan.\n * @returns A flat list of all extracted messenger items.\n */\nasync function scanSources(\n projectPath: string,\n sources: ScanSources,\n): Promise<MessengerCapabilityPacket[]> {\n const project = createExtractionProject();\n const allItems: MessengerCapabilityPacket[] = [];\n\n for (const dir of sources.scanDirs) {\n allItems.push(\n ...(await extractFromDirectory(\n project,\n path.join(projectPath, dir),\n projectPath,\n findTsFiles,\n )),\n );\n }\n\n if (sources.packagesDir) {\n const srcDirs = await listTargetSubdirectories(\n sources.packagesDir,\n 'src',\n false,\n );\n for (const srcDir of srcDirs) {\n allItems.push(\n ...(await extractFromDirectory(\n project,\n srcDir,\n projectPath,\n findTsFiles,\n )),\n );\n }\n }\n\n if (sources.nodeModulesDir) {\n const distDirs = await listTargetSubdirectories(\n sources.nodeModulesDir,\n 'dist',\n true,\n );\n for (const distDir of distDirs) {\n allItems.push(\n ...(await extractFromDirectory(\n project,\n distDir,\n projectPath,\n findDtsFiles,\n )),\n );\n }\n }\n\n return allItems;\n}\n\n/**\n * Replace a previously-seen item in its existing namespace group with a\n * higher-scoring duplicate. Handles the case where the duplicate is a\n * different kind (action vs event) by moving it between lists.\n *\n * @param byNamespace - Map of namespace to its group.\n * @param previous - The previously stored item.\n * @param replacement - The new item to replace it with.\n */\nfunction replaceDuplicateInGroup(\n byNamespace: Map<string, NamespaceGroup>,\n previous: MessengerCapabilityPacket,\n replacement: MessengerCapabilityPacket,\n): void {\n const namespace = replacement.typeString.split(':')[0];\n const group = byNamespace.get(namespace);\n // istanbul ignore next: `previous` and `replacement` have the same\n // typeString, so they share a namespace, and we always insert the\n // namespace into `byNamespace` before recording the original entry.\n if (!group) {\n return;\n }\n const previousList =\n previous.kind === 'action' ? group.actions : group.events;\n const index = previousList.indexOf(previous);\n // istanbul ignore next: `previous` was added to its kind's list by\n // `groupByNamespace` before being recorded in `seen`, so it is always\n // present when we look it up here.\n if (index === -1) {\n return;\n }\n if (previous.kind === replacement.kind) {\n previousList[index] = replacement;\n } else {\n previousList.splice(index, 1);\n const newList =\n replacement.kind === 'action' ? group.actions : group.events;\n newList.push(replacement);\n }\n}\n\n/**\n * Group items by namespace, deduplicating duplicate typeStrings using\n * `deduplicationScore`. Returns groups sorted alphabetically by namespace,\n * with each group's items sorted alphabetically by typeString.\n *\n * @param items - The full list of extracted items.\n * @returns The deduplicated and sorted namespace groups.\n */\nfunction groupByNamespace(\n items: MessengerCapabilityPacket[],\n): NamespaceGroup[] {\n const byNamespace = new Map<string, NamespaceGroup>();\n const seen = new Map<string, MessengerCapabilityPacket>();\n\n for (const item of items) {\n const existing = seen.get(item.typeString);\n if (existing) {\n if (deduplicationScore(item) <= deduplicationScore(existing)) {\n continue;\n }\n replaceDuplicateInGroup(byNamespace, existing, item);\n seen.set(item.typeString, item);\n continue;\n }\n\n seen.set(item.typeString, item);\n const namespace = item.typeString.split(':')[0];\n let group = byNamespace.get(namespace);\n if (!group) {\n group = { namespace, actions: [], events: [] };\n byNamespace.set(namespace, group);\n }\n if (item.kind === 'action') {\n group.actions.push(item);\n } else {\n group.events.push(item);\n }\n }\n\n const namespaces = Array.from(byNamespace.values()).sort((a, b) =>\n a.namespace.localeCompare(b.namespace),\n );\n\n for (const ns of namespaces) {\n ns.actions.sort((a, b) => a.typeString.localeCompare(b.typeString));\n ns.events.sort((a, b) => a.typeString.localeCompare(b.typeString));\n }\n\n return namespaces;\n}\n\n/**\n * Write generated docs (namespace pages, index page, sidebars) to disk,\n * replacing any existing `docs/` directory.\n *\n * @param namespaces - The grouped namespaces to render.\n * @param outputDir - The root output directory.\n * @param repoBaseUrl - GitHub blob base URL for source links, or null.\n * @param indexOptions - Options stamped on the index page header.\n * @param indexOptions.projectLabel - Short label identifying the project.\n * @param indexOptions.commitSha - Git commit SHA the docs were generated from.\n * @returns Promise that resolves once all files are written.\n */\nasync function writeOutput(\n namespaces: NamespaceGroup[],\n outputDir: string,\n repoBaseUrl: string | null,\n indexOptions: {\n projectLabel?: string | null;\n commitSha?: string | null;\n },\n): Promise<void> {\n const docsDir = path.join(outputDir, 'docs');\n\n if (await directoryExists(docsDir)) {\n await fs.rm(docsDir, { recursive: true });\n }\n await fs.mkdir(docsDir, { recursive: true });\n\n for (const ns of namespaces) {\n const nsDir = path.join(docsDir, ns.namespace);\n await fs.mkdir(nsDir, { recursive: true });\n\n if (ns.actions.length > 0) {\n await fs.writeFile(\n path.join(nsDir, 'actions.md'),\n generateNamespacePage(ns, 'action', repoBaseUrl),\n );\n }\n\n if (ns.events.length > 0) {\n await fs.writeFile(\n path.join(nsDir, 'events.md'),\n generateNamespacePage(ns, 'event', repoBaseUrl),\n );\n }\n }\n\n await fs.writeFile(\n path.join(docsDir, 'index.md'),\n generateIndexPage(namespaces, indexOptions),\n );\n\n await fs.writeFile(\n path.join(outputDir, 'sidebars.ts'),\n generateSidebars(namespaces),\n );\n}\n\n/**\n * Collect capabilities by scanning the project's files.\n *\n * @param projectPath - The project root path.\n * @param scanDirs - Directories (relative to projectPath) to scan.\n * @returns The extracted capabilities.\n * @throws If the project has no scannable directories at all.\n */\nasync function collectByScanning(\n projectPath: string,\n scanDirs: string[],\n): Promise<MessengerCapabilityPacket[]> {\n const sources = await discoverScanSources(projectPath, scanDirs);\n\n if (\n sources.scanDirs.length === 0 &&\n !sources.packagesDir &&\n !sources.nodeModulesDir\n ) {\n throw new Error(\n `No scannable directories found in ${projectPath}. ` +\n `Looked for: ${scanDirs.join(', ')}, packages/, node_modules/@metamask/`,\n );\n }\n\n logScanPlan(sources);\n\n return await scanSources(projectPath, sources);\n}\n\n/**\n * Using the project's root messenger capability collection types as\n * entrypoints, collect the constituent individual capability types and package\n * them so that they can be displayed within the documentation site.\n *\n * @param projectPath - The project root path.\n * @param options - The root-messenger strategy options.\n * @returns The extracted capabilities.\n */\nfunction collectFromRootMessengerCapabilities(\n projectPath: string,\n options: RootMessengerStrategyOptions,\n): MessengerCapabilityPacket[] {\n const { rootActions, rootEvents } = options;\n\n console.log(\n `Resolving actions from ${rootActions.filePath}#${rootActions.typeName} ` +\n `and events from ${rootEvents.filePath}#${rootEvents.typeName}...`,\n );\n\n const { capabilityPackets, skippedCapabilities } =\n discoverFromRootMessengerCapabilitiesTypes({\n projectPath,\n rootActionsTypeReference: rootActions,\n rootEventsTypeReference: rootEvents,\n });\n\n // Report rather than drop silently: a jump in any of these usually means the\n // project changed how it declares its capabilities.\n warnSkipped(\n 'declared inline, with no name to document',\n skippedCapabilities.unnamedCapabilities,\n );\n warnSkipped(\n 'whose shape could not be read',\n skippedCapabilities.unextractableCapabilities,\n );\n\n // If both capability collection types resolve to nothing, it's always a\n // misconfiguration (a wrong type name, or imports that didn't resolve).\n // Failing here matters because generation would otherwise replace an existing\n // docs directory with an empty one and exit successfully.\n if (capabilityPackets.length === 0) {\n throw new Error(\n `No messenger actions or events found in ` +\n `${rootActions.filePath}#${rootActions.typeName} or ` +\n `${rootEvents.filePath}#${rootEvents.typeName}. ` +\n `Check that these types name the collections carrying every ` +\n `capability, and that their imports resolve.`,\n );\n }\n\n return capabilityPackets;\n}\n\n/**\n * Warn about capability types that couldn't be documented, naming them so the\n * warning is actionable.\n *\n * @param description - Why they were skipped, as a noun phrase.\n * @param labels - Labels identifying each skipped type.\n */\nfunction warnSkipped(description: string, labels: string[]): void {\n if (labels.length === 0) {\n return;\n }\n\n const shown = labels.slice(0, MAX_SKIPPED_SHOWN);\n const remaining = labels.length - shown.length;\n console.warn(\n `Warning: skipped ${labels.length} capability ` +\n `${labels.length === 1 ? 'type' : 'types'} ${description}: ` +\n `${shown.join(', ')}${remaining > 0 ? `, and ${remaining} more` : ''}`,\n );\n}\n\n/**\n * Scan a project for messenger action/event types and generate documentation.\n *\n * @param options - Generation options.\n * @returns A promise resolving to counts of generated namespaces, actions, and events.\n */\nexport async function generate(\n options: GenerateOptions,\n): Promise<GenerateResult> {\n const { projectPath, outputDir, projectLabel, commitSha } = options;\n\n const allItems =\n options.strategy === 'root-messenger'\n ? collectFromRootMessengerCapabilities(projectPath, options)\n : await collectByScanning(projectPath, options.scanDirs);\n\n console.log(\n `Found ${allItems.length} messenger ${allItems.length === 1 ? 'item' : 'items'} total.`,\n );\n\n const namespaces = groupByNamespace(allItems);\n const repoBaseUrl = await resolveRepoBaseUrl(projectPath, commitSha ?? null);\n\n await writeOutput(namespaces, outputDir, repoBaseUrl, {\n projectLabel,\n commitSha,\n });\n\n const totalActions = namespaces.reduce(\n (sum, ns) => sum + ns.actions.length,\n 0,\n );\n const totalEvents = namespaces.reduce((sum, ns) => sum + ns.events.length, 0);\n\n console.log(\n `Generated docs for ${namespaces.length} ${namespaces.length === 1 ? 'namespace' : 'namespaces'}.`,\n );\n console.log(` Actions: ${totalActions}`);\n console.log(` Events: ${totalEvents}`);\n console.log(`Output: ${path.join(outputDir, 'docs')}/`);\n\n return {\n namespaces: namespaces.length,\n actions: totalActions,\n events: totalEvents,\n };\n}\n"]}
|
package/dist/generate.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.cts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,6BAA6B,EAAE,uCAAsC;AAOnF;;;;GAIG;AACH,KAAK,mBAAmB,GAAG;IACzB,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF;;;;GAIG;AACH,KAAK,4BAA4B,GAAG;IAClC,6BAA6B;IAC7B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,iDAAiD;IACjD,WAAW,EAAE,6BAA6B,CAAC;IAC3C,gDAAgD;IAChD,UAAU,EAAE,6BAA6B,CAAC;CAC3C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,GAAG,CAAC,mBAAmB,GAAG,4BAA4B,CAAC,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAmEF;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAuBxB;AAqdD;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,cAAc,CAAC,CAsCzB"}
|
package/dist/generate.d.mts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { RootCapabilitiesTypeReference } from "./root-messenger-discovery.mjs";
|
|
2
|
-
/**
|
|
3
|
-
* Options for the `scan` strategy, which reads every `*Messenger` type alias
|
|
4
|
-
* in every file it can find. Used when no single messenger aggregates every
|
|
5
|
-
* capability.
|
|
6
|
-
*/
|
|
7
|
-
type ScanStrategyOptions = {
|
|
8
|
-
/** The selected strategy. */
|
|
9
|
-
strategy: 'scan';
|
|
10
|
-
/** Directories, relative to the project root, to scan. */
|
|
11
|
-
scanDirs: string[];
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Options for the `root-messenger` strategy, which walks the types a
|
|
15
|
-
* project declares for its root messenger capabilities instead of scanning the
|
|
16
|
-
* entire repo. Used when one messenger carries every action and event.
|
|
17
|
-
*/
|
|
18
|
-
type RootMessengerStrategyOptions = {
|
|
19
|
-
/** The selected strategy. */
|
|
20
|
-
strategy: 'root-messenger';
|
|
21
|
-
/** The root messenger actions type reference. */
|
|
22
|
-
rootActions: RootCapabilitiesTypeReference;
|
|
23
|
-
/** The root messenger events type reference. */
|
|
24
|
-
rootEvents: RootCapabilitiesTypeReference;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Options for the generate function.
|
|
28
|
-
*/
|
|
29
|
-
export type GenerateOptions = {
|
|
30
|
-
/** Absolute path to the project to scan. */
|
|
31
|
-
projectPath: string;
|
|
32
|
-
/** Absolute path to the output directory for generated docs. */
|
|
33
|
-
outputDir: string;
|
|
34
|
-
/**
|
|
35
|
-
* Short label identifying the project the docs were generated from (e.g.
|
|
36
|
-
* "Core", "Extension"). Stamped in the index page title.
|
|
37
|
-
*/
|
|
38
|
-
projectLabel?: string | null;
|
|
39
|
-
/**
|
|
40
|
-
* Git commit SHA the docs were generated from. Stamped in the index page
|
|
41
|
-
* intro so engineers know how current the site is.
|
|
42
|
-
*/
|
|
43
|
-
commitSha?: string | null;
|
|
44
|
-
} & (ScanStrategyOptions | RootMessengerStrategyOptions);
|
|
45
|
-
/**
|
|
46
|
-
* Result returned by the generate function.
|
|
47
|
-
*/
|
|
48
|
-
export type GenerateResult = {
|
|
49
|
-
namespaces: number;
|
|
50
|
-
actions: number;
|
|
51
|
-
events: number;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Resolve the bare GitHub repository URL for a project by reading its
|
|
55
|
-
* `origin` remote.
|
|
56
|
-
*
|
|
57
|
-
* @param projectPath - Absolute path to the project root.
|
|
58
|
-
* @returns A URL like "https://github.com/Owner/Repo" or null when the remote
|
|
59
|
-
* isn't a GitHub URL or can't be read.
|
|
60
|
-
*/
|
|
61
|
-
export declare function resolveRepoUrl(projectPath: string): Promise<string | null>;
|
|
62
|
-
/**
|
|
63
|
-
* Scan a project for messenger action/event types and generate documentation.
|
|
64
|
-
*
|
|
65
|
-
* @param options - Generation options.
|
|
66
|
-
* @returns A promise resolving to counts of generated namespaces, actions, and events.
|
|
67
|
-
*/
|
|
68
|
-
export declare function generate(options: GenerateOptions): Promise<GenerateResult>;
|
|
69
|
-
export {};
|
|
70
|
-
//# sourceMappingURL=generate.d.mts.map
|
package/dist/generate.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.mts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,6BAA6B,EAAE,uCAAsC;AAOnF;;;;GAIG;AACH,KAAK,mBAAmB,GAAG;IACzB,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF;;;;GAIG;AACH,KAAK,4BAA4B,GAAG;IAClC,6BAA6B;IAC7B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,iDAAiD;IACjD,WAAW,EAAE,6BAA6B,CAAC;IAC3C,gDAAgD;IAChD,UAAU,EAAE,6BAA6B,CAAC;CAC3C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,GAAG,CAAC,mBAAmB,GAAG,4BAA4B,CAAC,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAmEF;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAuBxB;AAqdD;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,cAAc,CAAC,CAsCzB"}
|