@metamask-previews/platform-api-docs 0.1.0-preview-8bfa290fb → 0.2.0-preview-0a30e47

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.
Files changed (75) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/dist/cli.d.ts +3 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/{cli.mjs → cli.js} +10 -40
  5. package/dist/cli.js.map +1 -0
  6. package/dist/{extraction.d.cts → extraction.d.ts} +3 -13
  7. package/dist/extraction.d.ts.map +1 -0
  8. package/dist/{extraction.mjs → extraction.js} +3 -28
  9. package/dist/{extraction.cjs.map → extraction.js.map} +1 -1
  10. package/dist/{generate.d.cts → generate.d.ts} +2 -2
  11. package/dist/generate.d.ts.map +1 -0
  12. package/dist/{generate.mjs → generate.js} +111 -68
  13. package/dist/generate.js.map +1 -0
  14. package/dist/{markdown.d.cts → markdown.d.ts} +2 -2
  15. package/dist/markdown.d.ts.map +1 -0
  16. package/dist/{markdown.mjs → markdown.js} +1 -1
  17. package/dist/markdown.js.map +1 -0
  18. package/dist/{root-messenger-discovery.d.cts → root-messenger-discovery.d.ts} +2 -2
  19. package/dist/root-messenger-discovery.d.ts.map +1 -0
  20. package/dist/{root-messenger-discovery.mjs → root-messenger-discovery.js} +9 -30
  21. package/dist/root-messenger-discovery.js.map +1 -0
  22. package/dist/ts-project.d.ts +12 -0
  23. package/dist/ts-project.d.ts.map +1 -0
  24. package/dist/ts-project.js +29 -0
  25. package/dist/ts-project.js.map +1 -0
  26. package/dist/{types.d.cts → types.d.ts} +1 -1
  27. package/dist/types.d.ts.map +1 -0
  28. package/dist/types.js +2 -0
  29. package/dist/types.js.map +1 -0
  30. package/package.json +12 -9
  31. package/dist/cli.cjs +0 -328
  32. package/dist/cli.cjs.map +0 -1
  33. package/dist/cli.d.cts +0 -3
  34. package/dist/cli.d.cts.map +0 -1
  35. package/dist/cli.d.mts +0 -3
  36. package/dist/cli.d.mts.map +0 -1
  37. package/dist/cli.mjs.map +0 -1
  38. package/dist/discovery.cjs +0 -53
  39. package/dist/discovery.cjs.map +0 -1
  40. package/dist/discovery.d.cts +0 -22
  41. package/dist/discovery.d.cts.map +0 -1
  42. package/dist/discovery.d.mts +0 -22
  43. package/dist/discovery.d.mts.map +0 -1
  44. package/dist/discovery.mjs +0 -48
  45. package/dist/discovery.mjs.map +0 -1
  46. package/dist/extraction.cjs +0 -780
  47. package/dist/extraction.d.cts.map +0 -1
  48. package/dist/extraction.d.mts +0 -83
  49. package/dist/extraction.d.mts.map +0 -1
  50. package/dist/extraction.mjs.map +0 -1
  51. package/dist/generate.cjs +0 -462
  52. package/dist/generate.cjs.map +0 -1
  53. package/dist/generate.d.cts.map +0 -1
  54. package/dist/generate.d.mts +0 -70
  55. package/dist/generate.d.mts.map +0 -1
  56. package/dist/generate.mjs.map +0 -1
  57. package/dist/markdown.cjs +0 -239
  58. package/dist/markdown.cjs.map +0 -1
  59. package/dist/markdown.d.cts.map +0 -1
  60. package/dist/markdown.d.mts +0 -52
  61. package/dist/markdown.d.mts.map +0 -1
  62. package/dist/markdown.mjs.map +0 -1
  63. package/dist/root-messenger-discovery.cjs +0 -380
  64. package/dist/root-messenger-discovery.cjs.map +0 -1
  65. package/dist/root-messenger-discovery.d.cts.map +0 -1
  66. package/dist/root-messenger-discovery.d.mts +0 -61
  67. package/dist/root-messenger-discovery.d.mts.map +0 -1
  68. package/dist/root-messenger-discovery.mjs.map +0 -1
  69. package/dist/types.cjs +0 -3
  70. package/dist/types.cjs.map +0 -1
  71. package/dist/types.d.cts.map +0 -1
  72. package/dist/types.d.mts +0 -47
  73. package/dist/types.d.mts.map +0 -1
  74. package/dist/types.mjs +0 -2
  75. package/dist/types.mjs.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/platform-api-docs",
3
- "version": "0.1.0-preview-8bfa290fb",
3
+ "version": "0.2.0-preview-0a30e47",
4
4
  "description": "Produces documentation for the platform API, the set of actions and events available in the clients through the message bus",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -15,19 +15,22 @@
15
15
  "type": "git",
16
16
  "url": "https://github.com/MetaMask/core.git"
17
17
  },
18
- "bin": "./dist/cli.mjs",
18
+ "bin": "./dist/cli.js",
19
19
  "files": [
20
20
  "dist/",
21
21
  "site/"
22
22
  ],
23
+ "type": "module",
23
24
  "sideEffects": false,
24
25
  "publishConfig": {
25
26
  "access": "public",
26
27
  "registry": "https://registry.npmjs.org/"
27
28
  },
28
29
  "scripts": {
29
- "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
30
- "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
30
+ "build": "tsc --project tsconfig.build.json",
31
+ "build:all": "tsc --build tsconfig.build.json --verbose",
32
+ "build:clean": "yarn build:only-clean && yarn build",
33
+ "build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
31
34
  "changelog:update": "../../scripts/update-changelog.sh @metamask/platform-api-docs",
32
35
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/platform-api-docs",
33
36
  "cli": "tsx src/cli.ts",
@@ -49,7 +52,6 @@
49
52
  "@mdx-js/react": "^3.1.1",
50
53
  "@metamask/utils": "^11.12.0",
51
54
  "execa": "^5.0.0",
52
- "glob": "^13.0.6",
53
55
  "npm-which": "^3.0.1",
54
56
  "prism-react-renderer": "^2.4.1",
55
57
  "react": "^19.0.0",
@@ -59,19 +61,20 @@
59
61
  },
60
62
  "devDependencies": {
61
63
  "@metamask/auto-changelog": "^6.1.0",
62
- "@ts-bridge/cli": "^0.6.4",
63
64
  "@types/jest": "^30.0.0",
64
- "@types/node": "^16.18.54",
65
+ "@types/node": "^22.13.14",
65
66
  "@types/npm-which": "^3",
66
67
  "@types/react": "^19.0.0",
67
68
  "@types/yargs": "^17.0.32",
69
+ "@typescript/native": "npm:typescript@^7.0.2",
68
70
  "deepmerge": "^4.2.2",
69
71
  "jest": "^30.4.2",
72
+ "rimraf": "^5.0.5",
70
73
  "ts-jest": "^29.4.11",
71
74
  "tsx": "^4.20.5",
72
- "typescript": "~5.3.3"
75
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
73
76
  },
74
77
  "engines": {
75
- "node": "^18.18 || >=20"
78
+ "node": "^22.14.0 || ^24"
76
79
  }
77
80
  }
package/dist/cli.cjs DELETED
@@ -1,328 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- var __importDefault = (this && this.__importDefault) || function (mod) {
27
- return (mod && mod.__esModule) ? mod : { "default": mod };
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- const execa_1 = __importDefault(require("execa/index.js"));
31
- const fs = __importStar(require("node:fs/promises"));
32
- const path = __importStar(require("node:path"));
33
- const npm_which_1 = __importDefault(require("npm-which"));
34
- const yargs_1 = __importDefault(require("yargs"));
35
- const generate_js_1 = require("./generate.cjs");
36
- const root_messenger_discovery_js_1 = require("./root-messenger-discovery.cjs");
37
- /**
38
- * Locate the Docusaurus binary in this package's `node_modules/.bin`. Using
39
- * `npm-which` lets the lookup track wherever the installed Docusaurus puts
40
- * its binary, so a future Docusaurus upgrade can't break this path.
41
- *
42
- * @returns Absolute path to the `docusaurus` executable.
43
- */
44
- function resolveDocusaurus() {
45
- return (0, npm_which_1.default)(__dirname).sync('docusaurus');
46
- }
47
- /**
48
- * Run a Docusaurus command.
49
- *
50
- * @param command - The docusaurus command (start, build, serve).
51
- * @param cwd - The site directory.
52
- * @param extraEnv - Extra environment variables passed through to the
53
- * Docusaurus process (e.g. `DOCS_PROJECT_LABEL`, `DOCS_COMMIT_SHA`,
54
- * `DOCS_REPO_URL`).
55
- */
56
- async function runDocusaurus(command, cwd, extraEnv = {}) {
57
- await (0, execa_1.default)(resolveDocusaurus(), [command], {
58
- cwd,
59
- stdio: 'inherit',
60
- env: { ...process.env, ...extraEnv },
61
- });
62
- }
63
- /**
64
- * Copy site files into the output directory, skipping `node_modules`, `docs`,
65
- * and `tsconfig.json`. `docs` is owned by the doc generator and shouldn't be
66
- * carried over from the source `site/` directory. `tsconfig.json` extends the
67
- * monorepo's `tsconfig.base.json` via a relative path that only resolves from
68
- * the source location — it's there for IDE / lint inheritance, not for
69
- * Docusaurus, which uses `jiti` and doesn't consult the tsconfig at runtime.
70
- *
71
- * @param outDir - The output directory to set up.
72
- */
73
- async function setupSite(outDir) {
74
- const packageDir = path.resolve(__dirname, '..');
75
- const siteDir = path.join(packageDir, 'site');
76
- const packageNodeModules = path.join(packageDir, 'node_modules');
77
- const skip = new Set(['node_modules', 'docs', 'tsconfig.json']);
78
- console.log(`\nSetting up Docusaurus site in ${outDir}...`);
79
- // `fs.cp` has been available since Node 16.7 and only got the "stable"
80
- // marker in 22.3 — it's functional throughout our supported Node range
81
- // (`^18.18 || >=20`), even though the linter flags the older versions.
82
- // eslint-disable-next-line n/no-unsupported-features/node-builtins
83
- await fs.cp(siteDir, outDir, {
84
- recursive: true,
85
- filter: (source) => !skip.has(path.basename(source)),
86
- });
87
- // Symlink this package's `node_modules` into the output so the copied
88
- // `docusaurus.config.ts` and the rest of Docusaurus's bundling pipeline can
89
- // resolve their deps the same way they do in the source tree. Without it,
90
- // Node's resolver walks up from the output and can't reach our nested deps
91
- // when the package is installed as a regular dependency by an external
92
- // consumer (e.g. `metamask-extension`, `metamask-mobile`).
93
- const linkPath = path.join(outDir, 'node_modules');
94
- try {
95
- // `'junction'` works cross-platform (POSIX ignores it; Windows uses it
96
- // without admin) — `'dir'` would require admin on Windows.
97
- await fs.symlink(packageNodeModules, linkPath, 'junction');
98
- }
99
- catch (error) {
100
- if (error.code !== 'EEXIST') {
101
- throw error;
102
- }
103
- }
104
- // Write a minimal package.json so Docusaurus doesn't warn about a missing one
105
- const pkgJsonPath = path.join(outDir, 'package.json');
106
- try {
107
- await fs.access(pkgJsonPath);
108
- }
109
- catch {
110
- await fs.writeFile(pkgJsonPath, JSON.stringify({ name: 'platform-api-docs-site', private: true }, null, 2));
111
- }
112
- }
113
- /**
114
- * Resolve the short Git commit SHA the docs are being generated from.
115
- * Returns null when the project isn't a git repo or git isn't available.
116
- *
117
- * @param projectPath - The project root path.
118
- * @returns The short SHA, or null on failure.
119
- */
120
- async function resolveCommitSha(projectPath) {
121
- try {
122
- const { stdout } = await (0, execa_1.default)('git', ['rev-parse', '--short', 'HEAD'], {
123
- cwd: projectPath,
124
- });
125
- const trimmed = stdout.trim();
126
- return trimmed.length > 0 ? trimmed : null;
127
- }
128
- catch {
129
- return null;
130
- }
131
- }
132
- /**
133
- * Reject flag combinations that don't make sense, so a mistaken invocation
134
- * fails instead of silently producing docs built the wrong way.
135
- *
136
- * Flags belonging to the strategy that wasn't selected are errors rather than
137
- * ignored. Used as a yargs `.check`, so failures print alongside usage.
138
- *
139
- * @param argv - The parsed arguments.
140
- * @param argv.strategy - The selected discovery strategy.
141
- * @param argv.rootActions - The parsed root actions type reference.
142
- * @param argv.rootEvents - The parsed root events type reference.
143
- * @param argv.scanDir - The additional directories to scan.
144
- * @returns True when the combination is valid.
145
- */
146
- function checkStrategyArgs({ strategy, rootActions, rootEvents, scanDir = [], }) {
147
- if (strategy !== 'root-messenger') {
148
- if (rootActions !== undefined || rootEvents !== undefined) {
149
- throw new Error('--root-actions and --root-events only apply to --strategy root-messenger.');
150
- }
151
- return { strategy: 'scan', scanDir };
152
- }
153
- if (rootActions === undefined || rootEvents === undefined) {
154
- throw new Error('--strategy root-messenger requires both --root-actions and --root-events, ' +
155
- 'each written as "<file>#<TypeName>".');
156
- }
157
- if (scanDir.length > 0) {
158
- throw new Error('--scan-dir only applies to --strategy scan; --strategy root-messenger reads ' +
159
- 'only the files named by --root-actions and --root-events.');
160
- }
161
- return { strategy, rootActions, rootEvents };
162
- }
163
- /**
164
- * Parse and validate CLI arguments.
165
- *
166
- * @param argumentsForParsing - Arguments to parse, excluding the Node and
167
- * script paths.
168
- * @returns Parsed arguments, discriminated by discovery strategy.
169
- */
170
- async function parseArguments(argumentsForParsing = process.argv.slice(2)) {
171
- const argv = await (0, yargs_1.default)(argumentsForParsing)
172
- .command('$0 [project-path]', 'Produces documentation for the platform API, the set of actions and events available in clients through the message bus.', (yargsInstance) => {
173
- yargsInstance.positional('project-path', {
174
- type: 'string',
175
- description: 'Path to the project to scan',
176
- default: '.',
177
- });
178
- })
179
- .option('build', {
180
- type: 'boolean',
181
- description: 'Generate platform API docs and build a production-ready site',
182
- default: false,
183
- })
184
- .option('serve', {
185
- type: 'boolean',
186
- description: 'Generate platform API docs and serve a production-ready site',
187
- default: false,
188
- })
189
- .option('dev', {
190
- type: 'boolean',
191
- description: 'Generate platform API docs and serve a development-only site',
192
- default: false,
193
- })
194
- .option('strategy', {
195
- type: 'string',
196
- description: 'How to find messenger actions and events. "scan" parses every source and declaration file looking for messenger types. "root-messenger" instead resolves the two types the project declares for its root messenger',
197
- default: 'scan',
198
- })
199
- .choices('strategy', ['scan', 'root-messenger'])
200
- .option('root-actions', {
201
- type: 'string',
202
- coerce: root_messenger_discovery_js_1.parseRootCapabilitiesTypeReference,
203
- description: 'Type aliasing the union of every action on the root messenger, written as "<file>#<TypeName>" (required with --strategy root-messenger)',
204
- })
205
- .option('root-events', {
206
- type: 'string',
207
- coerce: root_messenger_discovery_js_1.parseRootCapabilitiesTypeReference,
208
- description: 'Type aliasing the union of every event on the root messenger, written as "<file>#<TypeName>" (required with --strategy root-messenger)',
209
- })
210
- .option('scan-dir', {
211
- type: 'array',
212
- string: true,
213
- description: 'Additional directories within the project to scan for messenger actions and events (note: may be specified multiple times)',
214
- default: [],
215
- })
216
- .option('output', {
217
- type: 'string',
218
- description: 'Output directory',
219
- })
220
- .option('project-label', {
221
- type: 'string',
222
- description: 'Short label identifying the project (e.g. "Core", "Extension") — stamped on the site title and headings',
223
- })
224
- .option('site-url', {
225
- type: 'string',
226
- description: 'Absolute URL the built site will be served from, e.g. https://metamask.github.io',
227
- })
228
- .option('site-base-url', {
229
- type: 'string',
230
- description: 'Path prefix the built site will be served under, e.g. /core/platform-api/',
231
- })
232
- .help()
233
- .parse();
234
- const strategyArguments = checkStrategyArgs(argv);
235
- const projectPath = argv['project-path'];
236
- if (typeof projectPath !== 'string') {
237
- throw new Error('Expected --project-path to be a string.');
238
- }
239
- return {
240
- build: argv.build,
241
- serve: argv.serve,
242
- dev: argv.dev,
243
- 'project-path': projectPath,
244
- output: argv.output,
245
- 'project-label': argv['project-label'],
246
- 'site-url': argv['site-url'],
247
- 'site-base-url': argv['site-base-url'],
248
- ...strategyArguments,
249
- };
250
- }
251
- /**
252
- * Main CLI entry point.
253
- */
254
- async function main() {
255
- const argv = await parseArguments();
256
- const resolvedProjectPath = path.resolve(argv['project-path']);
257
- const resolvedOutputDir = path.resolve(argv.output ?? path.join(resolvedProjectPath, '.platform-api-docs'));
258
- const projectLabel = argv['project-label'] && argv['project-label'].length > 0
259
- ? argv['project-label']
260
- : null;
261
- const commitSha = await resolveCommitSha(resolvedProjectPath);
262
- const repoUrl = await (0, generate_js_1.resolveRepoUrl)(resolvedProjectPath);
263
- // Step 1: Generate docs
264
- if (argv.strategy === 'root-messenger') {
265
- await (0, generate_js_1.generate)({
266
- projectPath: resolvedProjectPath,
267
- outputDir: resolvedOutputDir,
268
- projectLabel,
269
- commitSha,
270
- strategy: 'root-messenger',
271
- rootActions: argv.rootActions,
272
- rootEvents: argv.rootEvents,
273
- });
274
- }
275
- else {
276
- const scanDirs = ['src', ...argv.scanDir].filter((dir, index, dirs) => dirs.indexOf(dir) === index);
277
- await (0, generate_js_1.generate)({
278
- projectPath: resolvedProjectPath,
279
- outputDir: resolvedOutputDir,
280
- projectLabel,
281
- commitSha,
282
- strategy: 'scan',
283
- scanDirs,
284
- });
285
- }
286
- // Step 2: If --build, --serve, or --dev, set up and run Docusaurus
287
- if (argv.build || argv.serve || argv.dev) {
288
- await setupSite(resolvedOutputDir);
289
- // Translate CLI flags into the environment variables Docusaurus's
290
- // config reads. Keeping the CLI surface flag-only means consumers
291
- // (workflow files, package.json scripts) don't have to know how the
292
- // values are plumbed through to Docusaurus.
293
- const docusaurusEnv = {};
294
- if (projectLabel) {
295
- docusaurusEnv.DOCS_PROJECT_LABEL = projectLabel;
296
- }
297
- if (commitSha) {
298
- docusaurusEnv.DOCS_COMMIT_SHA = commitSha;
299
- }
300
- if (repoUrl) {
301
- docusaurusEnv.DOCS_REPO_URL = repoUrl;
302
- }
303
- if (typeof argv['site-url'] === 'string' && argv['site-url'].length > 0) {
304
- docusaurusEnv.DOCS_URL = argv['site-url'];
305
- }
306
- if (typeof argv['site-base-url'] === 'string' &&
307
- argv['site-base-url'].length > 0) {
308
- docusaurusEnv.DOCS_BASE_URL = argv['site-base-url'];
309
- }
310
- if (argv.dev) {
311
- console.log('\nStarting dev server...');
312
- await runDocusaurus('start', resolvedOutputDir, docusaurusEnv);
313
- }
314
- else if (argv.build || argv.serve) {
315
- console.log('\nBuilding static site...');
316
- await runDocusaurus('build', resolvedOutputDir, docusaurusEnv);
317
- if (argv.serve) {
318
- console.log('\nServing static site...');
319
- await runDocusaurus('serve', resolvedOutputDir, docusaurusEnv);
320
- }
321
- }
322
- }
323
- }
324
- main().catch((error) => {
325
- console.error(error);
326
- process.exitCode = 1;
327
- });
328
- //# sourceMappingURL=cli.cjs.map
package/dist/cli.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.cjs","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,2DAA0B;AAC1B,qDAAuC;AACvC,gDAAkC;AAClC,0DAAiC;AACjC,kDAA0B;AAE1B,gDAAyD;AAEzD,gFAAmF;AAoDnF;;;;;;GAMG;AACH,SAAS,iBAAiB;IACxB,OAAO,IAAA,mBAAQ,EAAC,SAAS,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAChD,CAAC;AAED;;;;;;;;GAQG;AACH,KAAK,UAAU,aAAa,CAC1B,OAAe,EACf,GAAW,EACX,WAAmC,EAAE;IAErC,MAAM,IAAA,eAAK,EAAC,iBAAiB,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE;QAC1C,GAAG;QACH,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE;KACrC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;GASG;AACH,KAAK,UAAU,SAAS,CAAC,MAAc;IACrC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC9C,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACjE,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;IAEhE,OAAO,CAAC,GAAG,CAAC,mCAAmC,MAAM,KAAK,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OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport execa from 'execa';\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport npmWhich from 'npm-which';\nimport yargs from 'yargs';\n\nimport { generate, resolveRepoUrl } from './generate.js';\nimport type { RootCapabilitiesTypeReference } from './root-messenger-discovery.js';\nimport { parseRootCapabilitiesTypeReference } from './root-messenger-discovery.js';\n\n/**\n * Arguments shared by both discovery strategies.\n */\ntype CommonArguments = {\n /** Whether to build the generated site. */\n build: boolean;\n /** Whether to serve the production build. */\n serve: boolean;\n /** Whether to serve the development site. */\n dev: boolean;\n /** Path to the project being documented. */\n 'project-path': string;\n /** Directory where generated documentation is written. */\n output?: string;\n /** Label displayed in the generated documentation. */\n 'project-label'?: string;\n /** URL where the generated site is served. */\n 'site-url'?: string;\n /** Base path where the generated site is served. */\n 'site-base-url'?: string;\n};\n\n/**\n * Arguments for the strategy that scans configured source directories.\n */\ntype ScanStrategyArguments = {\n /** The selected strategy. */\n strategy: 'scan';\n /** Directories, relative to the project root, to scan. */\n scanDir: string[];\n};\n\n/**\n * Arguments for the strategy that resolves a root messenger's type unions.\n */\ntype RootMessengerStrategyArguments = {\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 * Parsed CLI arguments, discriminated by the selected discovery strategy.\n */\ntype ParsedArguments = CommonArguments &\n (ScanStrategyArguments | RootMessengerStrategyArguments);\n\n/**\n * Locate the Docusaurus binary in this package's `node_modules/.bin`. Using\n * `npm-which` lets the lookup track wherever the installed Docusaurus puts\n * its binary, so a future Docusaurus upgrade can't break this path.\n *\n * @returns Absolute path to the `docusaurus` executable.\n */\nfunction resolveDocusaurus(): string {\n return npmWhich(__dirname).sync('docusaurus');\n}\n\n/**\n * Run a Docusaurus command.\n *\n * @param command - The docusaurus command (start, build, serve).\n * @param cwd - The site directory.\n * @param extraEnv - Extra environment variables passed through to the\n * Docusaurus process (e.g. `DOCS_PROJECT_LABEL`, `DOCS_COMMIT_SHA`,\n * `DOCS_REPO_URL`).\n */\nasync function runDocusaurus(\n command: string,\n cwd: string,\n extraEnv: Record<string, string> = {},\n): Promise<void> {\n await execa(resolveDocusaurus(), [command], {\n cwd,\n stdio: 'inherit',\n env: { ...process.env, ...extraEnv },\n });\n}\n\n/**\n * Copy site files into the output directory, skipping `node_modules`, `docs`,\n * and `tsconfig.json`. `docs` is owned by the doc generator and shouldn't be\n * carried over from the source `site/` directory. `tsconfig.json` extends the\n * monorepo's `tsconfig.base.json` via a relative path that only resolves from\n * the source location — it's there for IDE / lint inheritance, not for\n * Docusaurus, which uses `jiti` and doesn't consult the tsconfig at runtime.\n *\n * @param outDir - The output directory to set up.\n */\nasync function setupSite(outDir: string): Promise<void> {\n const packageDir = path.resolve(__dirname, '..');\n const siteDir = path.join(packageDir, 'site');\n const packageNodeModules = path.join(packageDir, 'node_modules');\n const skip = new Set(['node_modules', 'docs', 'tsconfig.json']);\n\n console.log(`\\nSetting up Docusaurus site in ${outDir}...`);\n\n // `fs.cp` has been available since Node 16.7 and only got the \"stable\"\n // marker in 22.3 — it's functional throughout our supported Node range\n // (`^18.18 || >=20`), even though the linter flags the older versions.\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n await fs.cp(siteDir, outDir, {\n recursive: true,\n filter: (source) => !skip.has(path.basename(source)),\n });\n\n // Symlink this package's `node_modules` into the output so the copied\n // `docusaurus.config.ts` and the rest of Docusaurus's bundling pipeline can\n // resolve their deps the same way they do in the source tree. Without it,\n // Node's resolver walks up from the output and can't reach our nested deps\n // when the package is installed as a regular dependency by an external\n // consumer (e.g. `metamask-extension`, `metamask-mobile`).\n const linkPath = path.join(outDir, 'node_modules');\n try {\n // `'junction'` works cross-platform (POSIX ignores it; Windows uses it\n // without admin) — `'dir'` would require admin on Windows.\n await fs.symlink(packageNodeModules, linkPath, 'junction');\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'EEXIST') {\n throw error;\n }\n }\n\n // Write a minimal package.json so Docusaurus doesn't warn about a missing one\n const pkgJsonPath = path.join(outDir, 'package.json');\n try {\n await fs.access(pkgJsonPath);\n } catch {\n await fs.writeFile(\n pkgJsonPath,\n JSON.stringify(\n { name: 'platform-api-docs-site', private: true },\n null,\n 2,\n ),\n );\n }\n}\n\n/**\n * Resolve the short Git commit SHA the docs are being generated from.\n * Returns null when the project isn't a git repo or git isn't available.\n *\n * @param projectPath - The project root path.\n * @returns The short SHA, or null on failure.\n */\nasync function resolveCommitSha(projectPath: string): Promise<string | null> {\n try {\n const { stdout } = await execa('git', ['rev-parse', '--short', 'HEAD'], {\n cwd: projectPath,\n });\n const trimmed = stdout.trim();\n return trimmed.length > 0 ? trimmed : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Reject flag combinations that don't make sense, so a mistaken invocation\n * fails instead of silently producing docs built the wrong way.\n *\n * Flags belonging to the strategy that wasn't selected are errors rather than\n * ignored. Used as a yargs `.check`, so failures print alongside usage.\n *\n * @param argv - The parsed arguments.\n * @param argv.strategy - The selected discovery strategy.\n * @param argv.rootActions - The parsed root actions type reference.\n * @param argv.rootEvents - The parsed root events type reference.\n * @param argv.scanDir - The additional directories to scan.\n * @returns True when the combination is valid.\n */\nfunction checkStrategyArgs({\n strategy,\n rootActions,\n rootEvents,\n scanDir = [],\n}: {\n strategy?: 'root-messenger' | 'scan';\n rootActions?: RootCapabilitiesTypeReference;\n rootEvents?: RootCapabilitiesTypeReference;\n scanDir?: string[];\n}): ScanStrategyArguments | RootMessengerStrategyArguments {\n if (strategy !== 'root-messenger') {\n if (rootActions !== undefined || rootEvents !== undefined) {\n throw new Error(\n '--root-actions and --root-events only apply to --strategy root-messenger.',\n );\n }\n return { strategy: 'scan', scanDir };\n }\n\n if (rootActions === undefined || rootEvents === undefined) {\n throw new Error(\n '--strategy root-messenger requires both --root-actions and --root-events, ' +\n 'each written as \"<file>#<TypeName>\".',\n );\n }\n if (scanDir.length > 0) {\n throw new Error(\n '--scan-dir only applies to --strategy scan; --strategy root-messenger reads ' +\n 'only the files named by --root-actions and --root-events.',\n );\n }\n\n return { strategy, rootActions, rootEvents };\n}\n\n/**\n * Parse and validate CLI arguments.\n *\n * @param argumentsForParsing - Arguments to parse, excluding the Node and\n * script paths.\n * @returns Parsed arguments, discriminated by discovery strategy.\n */\nasync function parseArguments(\n argumentsForParsing: string[] = process.argv.slice(2),\n): Promise<ParsedArguments> {\n const argv = await yargs(argumentsForParsing)\n .command(\n '$0 [project-path]',\n 'Produces documentation for the platform API, the set of actions and events available in clients through the message bus.',\n (yargsInstance) => {\n yargsInstance.positional('project-path', {\n type: 'string',\n description: 'Path to the project to scan',\n default: '.',\n });\n },\n )\n .option('build', {\n type: 'boolean',\n description:\n 'Generate platform API docs and build a production-ready site',\n default: false,\n })\n .option('serve', {\n type: 'boolean',\n description:\n 'Generate platform API docs and serve a production-ready site',\n default: false,\n })\n .option('dev', {\n type: 'boolean',\n description:\n 'Generate platform API docs and serve a development-only site',\n default: false,\n })\n .option('strategy', {\n type: 'string',\n description:\n 'How to find messenger actions and events. \"scan\" parses every source and declaration file looking for messenger types. \"root-messenger\" instead resolves the two types the project declares for its root messenger',\n default: 'scan',\n })\n .choices('strategy', ['scan', 'root-messenger'] as const)\n .option('root-actions', {\n type: 'string',\n coerce: parseRootCapabilitiesTypeReference,\n description:\n 'Type aliasing the union of every action on the root messenger, written as \"<file>#<TypeName>\" (required with --strategy root-messenger)',\n })\n .option('root-events', {\n type: 'string',\n coerce: parseRootCapabilitiesTypeReference,\n description:\n 'Type aliasing the union of every event on the root messenger, written as \"<file>#<TypeName>\" (required with --strategy root-messenger)',\n })\n .option('scan-dir', {\n type: 'array',\n string: true,\n description:\n 'Additional directories within the project to scan for messenger actions and events (note: may be specified multiple times)',\n default: [],\n })\n .option('output', {\n type: 'string',\n description: 'Output directory',\n })\n .option('project-label', {\n type: 'string',\n description:\n 'Short label identifying the project (e.g. \"Core\", \"Extension\") — stamped on the site title and headings',\n })\n .option('site-url', {\n type: 'string',\n description:\n 'Absolute URL the built site will be served from, e.g. https://metamask.github.io',\n })\n .option('site-base-url', {\n type: 'string',\n description:\n 'Path prefix the built site will be served under, e.g. /core/platform-api/',\n })\n .help()\n .parse();\n\n const strategyArguments = checkStrategyArgs(argv);\n\n const projectPath = argv['project-path'];\n if (typeof projectPath !== 'string') {\n throw new Error('Expected --project-path to be a string.');\n }\n\n return {\n build: argv.build,\n serve: argv.serve,\n dev: argv.dev,\n 'project-path': projectPath,\n output: argv.output,\n 'project-label': argv['project-label'],\n 'site-url': argv['site-url'],\n 'site-base-url': argv['site-base-url'],\n ...strategyArguments,\n };\n}\n\n/**\n * Main CLI entry point.\n */\nasync function main(): Promise<void> {\n const argv = await parseArguments();\n\n const resolvedProjectPath = path.resolve(argv['project-path']);\n const resolvedOutputDir = path.resolve(\n argv.output ?? path.join(resolvedProjectPath, '.platform-api-docs'),\n );\n const projectLabel =\n argv['project-label'] && argv['project-label'].length > 0\n ? argv['project-label']\n : null;\n const commitSha = await resolveCommitSha(resolvedProjectPath);\n const repoUrl = await resolveRepoUrl(resolvedProjectPath);\n\n // Step 1: Generate docs\n if (argv.strategy === 'root-messenger') {\n await generate({\n projectPath: resolvedProjectPath,\n outputDir: resolvedOutputDir,\n projectLabel,\n commitSha,\n strategy: 'root-messenger',\n rootActions: argv.rootActions,\n rootEvents: argv.rootEvents,\n });\n } else {\n const scanDirs = ['src', ...argv.scanDir].filter(\n (dir, index, dirs) => dirs.indexOf(dir) === index,\n );\n\n await generate({\n projectPath: resolvedProjectPath,\n outputDir: resolvedOutputDir,\n projectLabel,\n commitSha,\n strategy: 'scan',\n scanDirs,\n });\n }\n\n // Step 2: If --build, --serve, or --dev, set up and run Docusaurus\n if (argv.build || argv.serve || argv.dev) {\n await setupSite(resolvedOutputDir);\n\n // Translate CLI flags into the environment variables Docusaurus's\n // config reads. Keeping the CLI surface flag-only means consumers\n // (workflow files, package.json scripts) don't have to know how the\n // values are plumbed through to Docusaurus.\n const docusaurusEnv: Record<string, string> = {};\n if (projectLabel) {\n docusaurusEnv.DOCS_PROJECT_LABEL = projectLabel;\n }\n if (commitSha) {\n docusaurusEnv.DOCS_COMMIT_SHA = commitSha;\n }\n if (repoUrl) {\n docusaurusEnv.DOCS_REPO_URL = repoUrl;\n }\n if (typeof argv['site-url'] === 'string' && argv['site-url'].length > 0) {\n docusaurusEnv.DOCS_URL = argv['site-url'];\n }\n if (\n typeof argv['site-base-url'] === 'string' &&\n argv['site-base-url'].length > 0\n ) {\n docusaurusEnv.DOCS_BASE_URL = argv['site-base-url'];\n }\n\n if (argv.dev) {\n console.log('\\nStarting dev server...');\n await runDocusaurus('start', resolvedOutputDir, docusaurusEnv);\n } else if (argv.build || argv.serve) {\n console.log('\\nBuilding static site...');\n await runDocusaurus('build', resolvedOutputDir, docusaurusEnv);\n\n if (argv.serve) {\n console.log('\\nServing static site...');\n await runDocusaurus('serve', resolvedOutputDir, docusaurusEnv);\n }\n }\n }\n}\n\nmain().catch((error) => {\n console.error(error);\n process.exitCode = 1;\n});\n"]}
package/dist/cli.d.cts DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=cli.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.cts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.d.mts DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=cli.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.mts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.mjs","sourceRo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bin/env node\n\nimport execa from 'execa';\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport npmWhich from 'npm-which';\nimport yargs from 'yargs';\n\nimport { generate, resolveRepoUrl } from './generate.js';\nimport type { RootCapabilitiesTypeReference } from './root-messenger-discovery.js';\nimport { parseRootCapabilitiesTypeReference } from './root-messenger-discovery.js';\n\n/**\n * Arguments shared by both discovery strategies.\n */\ntype CommonArguments = {\n /** Whether to build the generated site. */\n build: boolean;\n /** Whether to serve the production build. */\n serve: boolean;\n /** Whether to serve the development site. */\n dev: boolean;\n /** Path to the project being documented. */\n 'project-path': string;\n /** Directory where generated documentation is written. */\n output?: string;\n /** Label displayed in the generated documentation. */\n 'project-label'?: string;\n /** URL where the generated site is served. */\n 'site-url'?: string;\n /** Base path where the generated site is served. */\n 'site-base-url'?: string;\n};\n\n/**\n * Arguments for the strategy that scans configured source directories.\n */\ntype ScanStrategyArguments = {\n /** The selected strategy. */\n strategy: 'scan';\n /** Directories, relative to the project root, to scan. */\n scanDir: string[];\n};\n\n/**\n * Arguments for the strategy that resolves a root messenger's type unions.\n */\ntype RootMessengerStrategyArguments = {\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 * Parsed CLI arguments, discriminated by the selected discovery strategy.\n */\ntype ParsedArguments = CommonArguments &\n (ScanStrategyArguments | RootMessengerStrategyArguments);\n\n/**\n * Locate the Docusaurus binary in this package's `node_modules/.bin`. Using\n * `npm-which` lets the lookup track wherever the installed Docusaurus puts\n * its binary, so a future Docusaurus upgrade can't break this path.\n *\n * @returns Absolute path to the `docusaurus` executable.\n */\nfunction resolveDocusaurus(): string {\n return npmWhich(__dirname).sync('docusaurus');\n}\n\n/**\n * Run a Docusaurus command.\n *\n * @param command - The docusaurus command (start, build, serve).\n * @param cwd - The site directory.\n * @param extraEnv - Extra environment variables passed through to the\n * Docusaurus process (e.g. `DOCS_PROJECT_LABEL`, `DOCS_COMMIT_SHA`,\n * `DOCS_REPO_URL`).\n */\nasync function runDocusaurus(\n command: string,\n cwd: string,\n extraEnv: Record<string, string> = {},\n): Promise<void> {\n await execa(resolveDocusaurus(), [command], {\n cwd,\n stdio: 'inherit',\n env: { ...process.env, ...extraEnv },\n });\n}\n\n/**\n * Copy site files into the output directory, skipping `node_modules`, `docs`,\n * and `tsconfig.json`. `docs` is owned by the doc generator and shouldn't be\n * carried over from the source `site/` directory. `tsconfig.json` extends the\n * monorepo's `tsconfig.base.json` via a relative path that only resolves from\n * the source location — it's there for IDE / lint inheritance, not for\n * Docusaurus, which uses `jiti` and doesn't consult the tsconfig at runtime.\n *\n * @param outDir - The output directory to set up.\n */\nasync function setupSite(outDir: string): Promise<void> {\n const packageDir = path.resolve(__dirname, '..');\n const siteDir = path.join(packageDir, 'site');\n const packageNodeModules = path.join(packageDir, 'node_modules');\n const skip = new Set(['node_modules', 'docs', 'tsconfig.json']);\n\n console.log(`\\nSetting up Docusaurus site in ${outDir}...`);\n\n // `fs.cp` has been available since Node 16.7 and only got the \"stable\"\n // marker in 22.3 — it's functional throughout our supported Node range\n // (`^18.18 || >=20`), even though the linter flags the older versions.\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n await fs.cp(siteDir, outDir, {\n recursive: true,\n filter: (source) => !skip.has(path.basename(source)),\n });\n\n // Symlink this package's `node_modules` into the output so the copied\n // `docusaurus.config.ts` and the rest of Docusaurus's bundling pipeline can\n // resolve their deps the same way they do in the source tree. Without it,\n // Node's resolver walks up from the output and can't reach our nested deps\n // when the package is installed as a regular dependency by an external\n // consumer (e.g. `metamask-extension`, `metamask-mobile`).\n const linkPath = path.join(outDir, 'node_modules');\n try {\n // `'junction'` works cross-platform (POSIX ignores it; Windows uses it\n // without admin) — `'dir'` would require admin on Windows.\n await fs.symlink(packageNodeModules, linkPath, 'junction');\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'EEXIST') {\n throw error;\n }\n }\n\n // Write a minimal package.json so Docusaurus doesn't warn about a missing one\n const pkgJsonPath = path.join(outDir, 'package.json');\n try {\n await fs.access(pkgJsonPath);\n } catch {\n await fs.writeFile(\n pkgJsonPath,\n JSON.stringify(\n { name: 'platform-api-docs-site', private: true },\n null,\n 2,\n ),\n );\n }\n}\n\n/**\n * Resolve the short Git commit SHA the docs are being generated from.\n * Returns null when the project isn't a git repo or git isn't available.\n *\n * @param projectPath - The project root path.\n * @returns The short SHA, or null on failure.\n */\nasync function resolveCommitSha(projectPath: string): Promise<string | null> {\n try {\n const { stdout } = await execa('git', ['rev-parse', '--short', 'HEAD'], {\n cwd: projectPath,\n });\n const trimmed = stdout.trim();\n return trimmed.length > 0 ? trimmed : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Reject flag combinations that don't make sense, so a mistaken invocation\n * fails instead of silently producing docs built the wrong way.\n *\n * Flags belonging to the strategy that wasn't selected are errors rather than\n * ignored. Used as a yargs `.check`, so failures print alongside usage.\n *\n * @param argv - The parsed arguments.\n * @param argv.strategy - The selected discovery strategy.\n * @param argv.rootActions - The parsed root actions type reference.\n * @param argv.rootEvents - The parsed root events type reference.\n * @param argv.scanDir - The additional directories to scan.\n * @returns True when the combination is valid.\n */\nfunction checkStrategyArgs({\n strategy,\n rootActions,\n rootEvents,\n scanDir = [],\n}: {\n strategy?: 'root-messenger' | 'scan';\n rootActions?: RootCapabilitiesTypeReference;\n rootEvents?: RootCapabilitiesTypeReference;\n scanDir?: string[];\n}): ScanStrategyArguments | RootMessengerStrategyArguments {\n if (strategy !== 'root-messenger') {\n if (rootActions !== undefined || rootEvents !== undefined) {\n throw new Error(\n '--root-actions and --root-events only apply to --strategy root-messenger.',\n );\n }\n return { strategy: 'scan', scanDir };\n }\n\n if (rootActions === undefined || rootEvents === undefined) {\n throw new Error(\n '--strategy root-messenger requires both --root-actions and --root-events, ' +\n 'each written as \"<file>#<TypeName>\".',\n );\n }\n if (scanDir.length > 0) {\n throw new Error(\n '--scan-dir only applies to --strategy scan; --strategy root-messenger reads ' +\n 'only the files named by --root-actions and --root-events.',\n );\n }\n\n return { strategy, rootActions, rootEvents };\n}\n\n/**\n * Parse and validate CLI arguments.\n *\n * @param argumentsForParsing - Arguments to parse, excluding the Node and\n * script paths.\n * @returns Parsed arguments, discriminated by discovery strategy.\n */\nasync function parseArguments(\n argumentsForParsing: string[] = process.argv.slice(2),\n): Promise<ParsedArguments> {\n const argv = await yargs(argumentsForParsing)\n .command(\n '$0 [project-path]',\n 'Produces documentation for the platform API, the set of actions and events available in clients through the message bus.',\n (yargsInstance) => {\n yargsInstance.positional('project-path', {\n type: 'string',\n description: 'Path to the project to scan',\n default: '.',\n });\n },\n )\n .option('build', {\n type: 'boolean',\n description:\n 'Generate platform API docs and build a production-ready site',\n default: false,\n })\n .option('serve', {\n type: 'boolean',\n description:\n 'Generate platform API docs and serve a production-ready site',\n default: false,\n })\n .option('dev', {\n type: 'boolean',\n description:\n 'Generate platform API docs and serve a development-only site',\n default: false,\n })\n .option('strategy', {\n type: 'string',\n description:\n 'How to find messenger actions and events. \"scan\" parses every source and declaration file looking for messenger types. \"root-messenger\" instead resolves the two types the project declares for its root messenger',\n default: 'scan',\n })\n .choices('strategy', ['scan', 'root-messenger'] as const)\n .option('root-actions', {\n type: 'string',\n coerce: parseRootCapabilitiesTypeReference,\n description:\n 'Type aliasing the union of every action on the root messenger, written as \"<file>#<TypeName>\" (required with --strategy root-messenger)',\n })\n .option('root-events', {\n type: 'string',\n coerce: parseRootCapabilitiesTypeReference,\n description:\n 'Type aliasing the union of every event on the root messenger, written as \"<file>#<TypeName>\" (required with --strategy root-messenger)',\n })\n .option('scan-dir', {\n type: 'array',\n string: true,\n description:\n 'Additional directories within the project to scan for messenger actions and events (note: may be specified multiple times)',\n default: [],\n })\n .option('output', {\n type: 'string',\n description: 'Output directory',\n })\n .option('project-label', {\n type: 'string',\n description:\n 'Short label identifying the project (e.g. \"Core\", \"Extension\") — stamped on the site title and headings',\n })\n .option('site-url', {\n type: 'string',\n description:\n 'Absolute URL the built site will be served from, e.g. https://metamask.github.io',\n })\n .option('site-base-url', {\n type: 'string',\n description:\n 'Path prefix the built site will be served under, e.g. /core/platform-api/',\n })\n .help()\n .parse();\n\n const strategyArguments = checkStrategyArgs(argv);\n\n const projectPath = argv['project-path'];\n if (typeof projectPath !== 'string') {\n throw new Error('Expected --project-path to be a string.');\n }\n\n return {\n build: argv.build,\n serve: argv.serve,\n dev: argv.dev,\n 'project-path': projectPath,\n output: argv.output,\n 'project-label': argv['project-label'],\n 'site-url': argv['site-url'],\n 'site-base-url': argv['site-base-url'],\n ...strategyArguments,\n };\n}\n\n/**\n * Main CLI entry point.\n */\nasync function main(): Promise<void> {\n const argv = await parseArguments();\n\n const resolvedProjectPath = path.resolve(argv['project-path']);\n const resolvedOutputDir = path.resolve(\n argv.output ?? path.join(resolvedProjectPath, '.platform-api-docs'),\n );\n const projectLabel =\n argv['project-label'] && argv['project-label'].length > 0\n ? argv['project-label']\n : null;\n const commitSha = await resolveCommitSha(resolvedProjectPath);\n const repoUrl = await resolveRepoUrl(resolvedProjectPath);\n\n // Step 1: Generate docs\n if (argv.strategy === 'root-messenger') {\n await generate({\n projectPath: resolvedProjectPath,\n outputDir: resolvedOutputDir,\n projectLabel,\n commitSha,\n strategy: 'root-messenger',\n rootActions: argv.rootActions,\n rootEvents: argv.rootEvents,\n });\n } else {\n const scanDirs = ['src', ...argv.scanDir].filter(\n (dir, index, dirs) => dirs.indexOf(dir) === index,\n );\n\n await generate({\n projectPath: resolvedProjectPath,\n outputDir: resolvedOutputDir,\n projectLabel,\n commitSha,\n strategy: 'scan',\n scanDirs,\n });\n }\n\n // Step 2: If --build, --serve, or --dev, set up and run Docusaurus\n if (argv.build || argv.serve || argv.dev) {\n await setupSite(resolvedOutputDir);\n\n // Translate CLI flags into the environment variables Docusaurus's\n // config reads. Keeping the CLI surface flag-only means consumers\n // (workflow files, package.json scripts) don't have to know how the\n // values are plumbed through to Docusaurus.\n const docusaurusEnv: Record<string, string> = {};\n if (projectLabel) {\n docusaurusEnv.DOCS_PROJECT_LABEL = projectLabel;\n }\n if (commitSha) {\n docusaurusEnv.DOCS_COMMIT_SHA = commitSha;\n }\n if (repoUrl) {\n docusaurusEnv.DOCS_REPO_URL = repoUrl;\n }\n if (typeof argv['site-url'] === 'string' && argv['site-url'].length > 0) {\n docusaurusEnv.DOCS_URL = argv['site-url'];\n }\n if (\n typeof argv['site-base-url'] === 'string' &&\n argv['site-base-url'].length > 0\n ) {\n docusaurusEnv.DOCS_BASE_URL = argv['site-base-url'];\n }\n\n if (argv.dev) {\n console.log('\\nStarting dev server...');\n await runDocusaurus('start', resolvedOutputDir, docusaurusEnv);\n } else if (argv.build || argv.serve) {\n console.log('\\nBuilding static site...');\n await runDocusaurus('build', resolvedOutputDir, docusaurusEnv);\n\n if (argv.serve) {\n console.log('\\nServing static site...');\n await runDocusaurus('serve', resolvedOutputDir, docusaurusEnv);\n }\n }\n }\n}\n\nmain().catch((error) => {\n console.error(error);\n process.exitCode = 1;\n});\n"]}
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findDtsFiles = exports.findTsFiles = void 0;
4
- const glob_1 = require("glob");
5
- /**
6
- * Find all non-test TypeScript source files in a directory.
7
- * Skips node_modules, dist, test directories, and declaration files.
8
- *
9
- * Results are sorted lexicographically so that downstream consumers
10
- * (extraction, deduplication, output ordering) behave deterministically
11
- * across filesystems.
12
- *
13
- * @param dir - The directory to search.
14
- * @returns A promise that resolves to a sorted array of absolute file paths.
15
- */
16
- async function findTsFiles(dir) {
17
- const matches = await (0, glob_1.glob)('**/*.ts', {
18
- cwd: dir,
19
- absolute: true,
20
- ignore: [
21
- '**/node_modules/**',
22
- '**/dist/**',
23
- '**/__tests__/**',
24
- '**/tests/**',
25
- '**/test/**',
26
- '**/__mocks__/**',
27
- '**/*.test.ts',
28
- '**/*.test-d.ts',
29
- '**/*.spec.ts',
30
- '**/*.d.ts',
31
- ],
32
- });
33
- return matches.sort();
34
- }
35
- exports.findTsFiles = findTsFiles;
36
- /**
37
- * Find all `.d.cts` declaration files in a directory.
38
- * Skips nested node_modules subdirectories. See {@link findTsFiles} for the
39
- * note about sorting.
40
- *
41
- * @param dir - The directory to search.
42
- * @returns A promise that resolves to a sorted array of absolute file paths.
43
- */
44
- async function findDtsFiles(dir) {
45
- const matches = await (0, glob_1.glob)('**/*.d.cts', {
46
- cwd: dir,
47
- absolute: true,
48
- ignore: ['**/node_modules/**'],
49
- });
50
- return matches.sort();
51
- }
52
- exports.findDtsFiles = findDtsFiles;
53
- //# sourceMappingURL=discovery.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"discovery.cjs","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAE5B;;;;;;;;;;GAUG;AACI,KAAK,UAAU,WAAW,CAAC,GAAW;IAC3C,MAAM,OAAO,GAAG,MAAM,IAAA,WAAI,EAAC,SAAS,EAAE;QACpC,GAAG,EAAE,GAAG;QACR,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE;YACN,oBAAoB;YACpB,YAAY;YACZ,iBAAiB;YACjB,aAAa;YACb,YAAY;YACZ,iBAAiB;YACjB,cAAc;YACd,gBAAgB;YAChB,cAAc;YACd,WAAW;SACZ;KACF,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;AACxB,CAAC;AAlBD,kCAkBC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,YAAY,CAAC,GAAW;IAC5C,MAAM,OAAO,GAAG,MAAM,IAAA,WAAI,EAAC,YAAY,EAAE;QACvC,GAAG,EAAE,GAAG;QACR,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,CAAC,oBAAoB,CAAC;KAC/B,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;AACxB,CAAC;AAPD,oCAOC","sourcesContent":["import { glob } from 'glob';\n\n/**\n * Find all non-test TypeScript source files in a directory.\n * Skips node_modules, dist, test directories, and declaration files.\n *\n * Results are sorted lexicographically so that downstream consumers\n * (extraction, deduplication, output ordering) behave deterministically\n * across filesystems.\n *\n * @param dir - The directory to search.\n * @returns A promise that resolves to a sorted array of absolute file paths.\n */\nexport async function findTsFiles(dir: string): Promise<string[]> {\n const matches = await glob('**/*.ts', {\n cwd: dir,\n absolute: true,\n ignore: [\n '**/node_modules/**',\n '**/dist/**',\n '**/__tests__/**',\n '**/tests/**',\n '**/test/**',\n '**/__mocks__/**',\n '**/*.test.ts',\n '**/*.test-d.ts',\n '**/*.spec.ts',\n '**/*.d.ts',\n ],\n });\n return matches.sort();\n}\n\n/**\n * Find all `.d.cts` declaration files in a directory.\n * Skips nested node_modules subdirectories. See {@link findTsFiles} for the\n * note about sorting.\n *\n * @param dir - The directory to search.\n * @returns A promise that resolves to a sorted array of absolute file paths.\n */\nexport async function findDtsFiles(dir: string): Promise<string[]> {\n const matches = await glob('**/*.d.cts', {\n cwd: dir,\n absolute: true,\n ignore: ['**/node_modules/**'],\n });\n return matches.sort();\n}\n"]}
@@ -1,22 +0,0 @@
1
- /**
2
- * Find all non-test TypeScript source files in a directory.
3
- * Skips node_modules, dist, test directories, and declaration files.
4
- *
5
- * Results are sorted lexicographically so that downstream consumers
6
- * (extraction, deduplication, output ordering) behave deterministically
7
- * across filesystems.
8
- *
9
- * @param dir - The directory to search.
10
- * @returns A promise that resolves to a sorted array of absolute file paths.
11
- */
12
- export declare function findTsFiles(dir: string): Promise<string[]>;
13
- /**
14
- * Find all `.d.cts` declaration files in a directory.
15
- * Skips nested node_modules subdirectories. See {@link findTsFiles} for the
16
- * note about sorting.
17
- *
18
- * @param dir - The directory to search.
19
- * @returns A promise that resolves to a sorted array of absolute file paths.
20
- */
21
- export declare function findDtsFiles(dir: string): Promise<string[]>;
22
- //# sourceMappingURL=discovery.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"discovery.d.cts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAkBhE;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAOjE"}
@@ -1,22 +0,0 @@
1
- /**
2
- * Find all non-test TypeScript source files in a directory.
3
- * Skips node_modules, dist, test directories, and declaration files.
4
- *
5
- * Results are sorted lexicographically so that downstream consumers
6
- * (extraction, deduplication, output ordering) behave deterministically
7
- * across filesystems.
8
- *
9
- * @param dir - The directory to search.
10
- * @returns A promise that resolves to a sorted array of absolute file paths.
11
- */
12
- export declare function findTsFiles(dir: string): Promise<string[]>;
13
- /**
14
- * Find all `.d.cts` declaration files in a directory.
15
- * Skips nested node_modules subdirectories. See {@link findTsFiles} for the
16
- * note about sorting.
17
- *
18
- * @param dir - The directory to search.
19
- * @returns A promise that resolves to a sorted array of absolute file paths.
20
- */
21
- export declare function findDtsFiles(dir: string): Promise<string[]>;
22
- //# sourceMappingURL=discovery.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"discovery.d.mts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAkBhE;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAOjE"}