@metamask-previews/platform-api-docs 0.0.0-preview-1275d0fda

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 (62) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE +6 -0
  3. package/LICENSE.APACHE2 +201 -0
  4. package/LICENSE.MIT +21 -0
  5. package/README.md +39 -0
  6. package/dist/cli.cjs +214 -0
  7. package/dist/cli.cjs.map +1 -0
  8. package/dist/cli.d.cts +3 -0
  9. package/dist/cli.d.cts.map +1 -0
  10. package/dist/cli.d.mts +3 -0
  11. package/dist/cli.d.mts.map +1 -0
  12. package/dist/cli.mjs +212 -0
  13. package/dist/cli.mjs.map +1 -0
  14. package/dist/discovery.cjs +53 -0
  15. package/dist/discovery.cjs.map +1 -0
  16. package/dist/discovery.d.cts +22 -0
  17. package/dist/discovery.d.cts.map +1 -0
  18. package/dist/discovery.d.mts +22 -0
  19. package/dist/discovery.d.mts.map +1 -0
  20. package/dist/discovery.mjs +48 -0
  21. package/dist/discovery.mjs.map +1 -0
  22. package/dist/extraction.cjs +745 -0
  23. package/dist/extraction.cjs.map +1 -0
  24. package/dist/extraction.d.cts +40 -0
  25. package/dist/extraction.d.cts.map +1 -0
  26. package/dist/extraction.d.mts +40 -0
  27. package/dist/extraction.d.mts.map +1 -0
  28. package/dist/extraction.mjs +716 -0
  29. package/dist/extraction.mjs.map +1 -0
  30. package/dist/generate.cjs +373 -0
  31. package/dist/generate.cjs.map +1 -0
  32. package/dist/generate.d.cts +37 -0
  33. package/dist/generate.d.cts.map +1 -0
  34. package/dist/generate.d.mts +37 -0
  35. package/dist/generate.d.mts.map +1 -0
  36. package/dist/generate.mjs +346 -0
  37. package/dist/generate.mjs.map +1 -0
  38. package/dist/markdown.cjs +239 -0
  39. package/dist/markdown.cjs.map +1 -0
  40. package/dist/markdown.d.cts +52 -0
  41. package/dist/markdown.d.cts.map +1 -0
  42. package/dist/markdown.d.mts +52 -0
  43. package/dist/markdown.d.mts.map +1 -0
  44. package/dist/markdown.mjs +232 -0
  45. package/dist/markdown.mjs.map +1 -0
  46. package/dist/types.cjs +3 -0
  47. package/dist/types.cjs.map +1 -0
  48. package/dist/types.d.cts +63 -0
  49. package/dist/types.d.cts.map +1 -0
  50. package/dist/types.d.mts +63 -0
  51. package/dist/types.d.mts.map +1 -0
  52. package/dist/types.mjs +2 -0
  53. package/dist/types.mjs.map +1 -0
  54. package/package.json +75 -0
  55. package/site/docusaurus.config.ts +103 -0
  56. package/site/src/css/custom.css +336 -0
  57. package/site/static/fonts/MM-Sans/MM_Sans_Mono-Regular.woff2 +0 -0
  58. package/site/static/img/favicons/favicon-96x96.png +0 -0
  59. package/site/static/img/metamask-fox.svg +12 -0
  60. package/site/static/img/metamask-logo-dark.svg +3 -0
  61. package/site/static/img/metamask-logo.svg +3 -0
  62. package/site/tsconfig.json +13 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+
12
+ - Initial release of the platform-api-docs package ([#8012](https://github.com/MetaMask/core/pull/8012))
13
+
14
+ [Unreleased]: https://github.com/MetaMask/core/
package/LICENSE ADDED
@@ -0,0 +1,6 @@
1
+ This project is licensed under either of
2
+
3
+ * MIT license ([LICENSE.MIT](LICENSE.MIT))
4
+ * Apache License, Version 2.0 ([LICENSE.APACHE2](LICENSE.APACHE2))
5
+
6
+ at your option.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 MetaMask
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/LICENSE.MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 MetaMask
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # `@metamask/platform-api-docs`
2
+
3
+ Produces documentation for the platform API, the set of actions and events available in clients through the message bus.
4
+
5
+ When run within a project (such as `metamask-extension` or `metamask-mobile`), this tool looks for messenger action and event types declared within TypeScript source and declaration files within MetaMask NPM packages. It extracts all of the JSDoc from these actions and events, then outputs them into a searchable Docusaurus site.
6
+
7
+ ## Installation
8
+
9
+ 1. Add this package as a dependency (`yarn add --dev @metamask/platform-api-docs` or `npm install --save-dev @metamask/platform-api-docs`).
10
+ 2. Add a script to your project's `package.json`. For example:
11
+ ```json
12
+ {
13
+ "scripts": {
14
+ "docs:platform-api:build": "platform-api-docs --build --project-label MyProject"
15
+ }
16
+ }
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ platform-api-docs [project-path] [options]
23
+
24
+ Arguments:
25
+ project-path Path to the project to scan (default: current directory)
26
+
27
+ Options:
28
+ --build Generate docs and build static site
29
+ --serve Generate docs, build, and serve static site
30
+ --dev Generate docs and start dev server with hot reload
31
+ --scan-dir <dir> Extra source directory to scan (repeatable)
32
+ --output <dir> Output directory (default: <project-path>/.platform-api-docs)
33
+ --project-label <label> Short label identifying the project (e.g. "Core", "Extension")
34
+ --help Show this help message
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
package/dist/cli.cjs ADDED
@@ -0,0 +1,214 @@
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_1 = require("./generate.cjs");
36
+ /**
37
+ * Locate the Docusaurus binary in this package's `node_modules/.bin`. Using
38
+ * `npm-which` lets the lookup track wherever the installed Docusaurus puts
39
+ * its binary, so a future Docusaurus upgrade can't break this path.
40
+ *
41
+ * @returns Absolute path to the `docusaurus` executable.
42
+ */
43
+ function resolveDocusaurus() {
44
+ return (0, npm_which_1.default)(__dirname).sync('docusaurus');
45
+ }
46
+ /**
47
+ * Run a Docusaurus command.
48
+ *
49
+ * @param command - The docusaurus command (start, build, serve).
50
+ * @param cwd - The site directory.
51
+ * @param extraEnv - Extra environment variables passed through to the
52
+ * Docusaurus process (e.g. `DOCS_PROJECT_LABEL`, `DOCS_COMMIT_SHA`).
53
+ */
54
+ async function runDocusaurus(command, cwd, extraEnv = {}) {
55
+ await (0, execa_1.default)(resolveDocusaurus(), [command], {
56
+ cwd,
57
+ stdio: 'inherit',
58
+ env: { ...process.env, ...extraEnv },
59
+ });
60
+ }
61
+ /**
62
+ * Copy site files into the output directory, skipping `node_modules` and
63
+ * `docs` (the latter is owned by the doc generator and shouldn't be carried
64
+ * over from the source `site/` directory).
65
+ *
66
+ * @param outDir - The output directory to set up.
67
+ */
68
+ async function setupSite(outDir) {
69
+ const siteDir = path.resolve(__dirname, '..', 'site');
70
+ const skip = new Set(['node_modules', 'docs']);
71
+ console.log(`\nSetting up Docusaurus site in ${outDir}...`);
72
+ // `fs.cp` has been available since Node 16.7 and only got the "stable"
73
+ // marker in 22.3 — it's functional throughout our supported Node range
74
+ // (`^18.18 || >=20`), even though the linter flags the older versions.
75
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins
76
+ await fs.cp(siteDir, outDir, {
77
+ recursive: true,
78
+ filter: (source) => !skip.has(path.basename(source)),
79
+ });
80
+ // Write a minimal package.json so Docusaurus doesn't warn about a missing one
81
+ const pkgJsonPath = path.join(outDir, 'package.json');
82
+ try {
83
+ await fs.access(pkgJsonPath);
84
+ }
85
+ catch {
86
+ await fs.writeFile(pkgJsonPath, JSON.stringify({ name: 'platform-api-docs-site', private: true }, null, 2));
87
+ }
88
+ }
89
+ /**
90
+ * Resolve the short Git commit SHA the docs are being generated from.
91
+ * Returns null when the project isn't a git repo or git isn't available.
92
+ *
93
+ * @param projectPath - The project root path.
94
+ * @returns The short SHA, or null on failure.
95
+ */
96
+ async function resolveCommitSha(projectPath) {
97
+ try {
98
+ const { stdout } = await (0, execa_1.default)('git', ['rev-parse', '--short', 'HEAD'], {
99
+ cwd: projectPath,
100
+ });
101
+ const trimmed = stdout.trim();
102
+ return trimmed.length > 0 ? trimmed : null;
103
+ }
104
+ catch {
105
+ return null;
106
+ }
107
+ }
108
+ /**
109
+ * Main CLI entry point.
110
+ */
111
+ async function main() {
112
+ const argv = await (0, yargs_1.default)(process.argv.slice(2))
113
+ .command('$0 [project-path]', 'Produces documentation for the platform API, the set of actions and events available in clients through the message bus.', (yargsInstance) => {
114
+ yargsInstance.positional('project-path', {
115
+ type: 'string',
116
+ description: 'Path to the project to scan',
117
+ default: '.',
118
+ });
119
+ })
120
+ .option('build', {
121
+ type: 'boolean',
122
+ description: 'Generate platform API docs and build a production-ready site',
123
+ default: false,
124
+ })
125
+ .option('serve', {
126
+ type: 'boolean',
127
+ description: 'Generate platform API docs and serve a production-ready site',
128
+ default: false,
129
+ })
130
+ .option('dev', {
131
+ type: 'boolean',
132
+ description: 'Generate platform API docs and serve a development-only site',
133
+ default: false,
134
+ })
135
+ .option('scan-dir', {
136
+ type: 'string',
137
+ array: true,
138
+ description: 'Additional directories within the project to scan for messenger actions and events (note: may be specified multiple times)',
139
+ default: [],
140
+ })
141
+ .option('output', {
142
+ type: 'string',
143
+ description: 'Output directory',
144
+ })
145
+ .option('project-label', {
146
+ type: 'string',
147
+ description: 'Short label identifying the project (e.g. "Core", "Extension") — stamped on the site title and headings',
148
+ })
149
+ .option('site-url', {
150
+ type: 'string',
151
+ description: 'Absolute URL the built site will be served from, e.g. https://metamask.github.io',
152
+ })
153
+ .option('site-base-url', {
154
+ type: 'string',
155
+ description: 'Path prefix the built site will be served under, e.g. /core/platform-api/',
156
+ })
157
+ .help().argv;
158
+ const projectPathArg = argv['project-path'];
159
+ const resolvedProjectPath = path.resolve(typeof projectPathArg === 'string' ? projectPathArg : '.');
160
+ const resolvedOutputDir = path.resolve(argv.output ?? path.join(resolvedProjectPath, '.platform-api-docs'));
161
+ const scanDirs = ['src', ...argv['scan-dir']].filter((dir, index, dirs) => dirs.indexOf(dir) === index);
162
+ const projectLabel = typeof argv['project-label'] === 'string' &&
163
+ argv['project-label'].length > 0
164
+ ? argv['project-label']
165
+ : null;
166
+ const commitSha = await resolveCommitSha(resolvedProjectPath);
167
+ // Step 1: Generate docs
168
+ await (0, generate_1.generate)({
169
+ projectPath: resolvedProjectPath,
170
+ outputDir: resolvedOutputDir,
171
+ scanDirs,
172
+ projectLabel,
173
+ commitSha,
174
+ });
175
+ // Step 2: If --build, --serve, or --dev, set up and run Docusaurus
176
+ if (argv.build || argv.serve || argv.dev) {
177
+ await setupSite(resolvedOutputDir);
178
+ // Translate CLI flags into the environment variables Docusaurus's
179
+ // config reads. Keeping the CLI surface flag-only means consumers
180
+ // (workflow files, package.json scripts) don't have to know how the
181
+ // values are plumbed through to Docusaurus.
182
+ const docusaurusEnv = {};
183
+ if (projectLabel) {
184
+ docusaurusEnv.DOCS_PROJECT_LABEL = projectLabel;
185
+ }
186
+ if (commitSha) {
187
+ docusaurusEnv.DOCS_COMMIT_SHA = commitSha;
188
+ }
189
+ if (typeof argv['site-url'] === 'string' && argv['site-url'].length > 0) {
190
+ docusaurusEnv.DOCS_URL = argv['site-url'];
191
+ }
192
+ if (typeof argv['site-base-url'] === 'string' &&
193
+ argv['site-base-url'].length > 0) {
194
+ docusaurusEnv.DOCS_BASE_URL = argv['site-base-url'];
195
+ }
196
+ if (argv.dev) {
197
+ console.log('\nStarting dev server...');
198
+ await runDocusaurus('start', resolvedOutputDir, docusaurusEnv);
199
+ }
200
+ else if (argv.build || argv.serve) {
201
+ console.log('\nBuilding static site...');
202
+ await runDocusaurus('build', resolvedOutputDir, docusaurusEnv);
203
+ if (argv.serve) {
204
+ console.log('\nServing static site...');
205
+ await runDocusaurus('serve', resolvedOutputDir, docusaurusEnv);
206
+ }
207
+ }
208
+ }
209
+ }
210
+ main().catch((error) => {
211
+ console.error(error);
212
+ process.exitCode = 1;
213
+ });
214
+ //# sourceMappingURL=cli.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.cjs","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,2DAA0B;AAC1B,qDAAuC;AACvC,gDAAkC;AAClC,0DAAiC;AACjC,kDAA0B;AAE1B,6CAAsC;AAEtC;;;;;;GAMG;AACH,SAAS,iBAAiB;IACxB,OAAO,IAAA,mBAAQ,EAAC,SAAS,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAChD,CAAC;AAED;;;;;;;GAOG;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;;;;;;GAMG;AACH,KAAK,UAAU,SAAS,CAAC,MAAc;IACrC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACtD,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC;IAE/C,OAAO,CAAC,GAAG,CAAC,mCAAmC,MAAM,KAAK,CAAC,CAAC;IAE5D,uEAAuE;IACvE,uEAAuE;IACvE,uEAAuE;IACvE,m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AI,CAAC,UAAU,CAAC,KAAK,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxE,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;QAC5C,CAAC;QACD,IACE,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,QAAQ;YACzC,IAAI,CAAC,eAAe,CAAC,CAAC,MAAM,GAAG,CAAC,EAChC,CAAC;YACD,aAAa,CAAC,aAAa,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC;QACtD,CAAC;QAED,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;YACxC,MAAM,aAAa,CAAC,OAAO,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC;QACjE,CAAC;aAAM,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACpC,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;YACzC,MAAM,aAAa,CAAC,OAAO,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC;YAE/D,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;gBACxC,MAAM,aAAa,CAAC,OAAO,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC;YACjE,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,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 } from './generate';\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 */\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` and\n * `docs` (the latter is owned by the doc generator and shouldn't be carried\n * over from the source `site/` directory).\n *\n * @param outDir - The output directory to set up.\n */\nasync function setupSite(outDir: string): Promise<void> {\n const siteDir = path.resolve(__dirname, '..', 'site');\n const skip = new Set(['node_modules', 'docs']);\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 // 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 * Main CLI entry point.\n */\nasync function main(): Promise<void> {\n const argv = await yargs(process.argv.slice(2))\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('scan-dir', {\n type: 'string',\n array: true,\n description:\n 'Additional directories within the project to scan for messenger actions and events (note: may be specified multiple times)',\n default: [] as string[],\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().argv;\n\n const projectPathArg = argv['project-path'];\n const resolvedProjectPath = path.resolve(\n typeof projectPathArg === 'string' ? projectPathArg : '.',\n );\n const resolvedOutputDir = path.resolve(\n argv.output ?? path.join(resolvedProjectPath, '.platform-api-docs'),\n );\n const scanDirs = ['src', ...argv['scan-dir']].filter(\n (dir, index, dirs) => dirs.indexOf(dir) === index,\n );\n const projectLabel =\n typeof argv['project-label'] === 'string' &&\n argv['project-label'].length > 0\n ? argv['project-label']\n : null;\n const commitSha = await resolveCommitSha(resolvedProjectPath);\n\n // Step 1: Generate docs\n await generate({\n projectPath: resolvedProjectPath,\n outputDir: resolvedOutputDir,\n scanDirs,\n projectLabel,\n commitSha,\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 (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 ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.cts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.d.mts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.mts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}