Docs: CLI README update (#3058)

This commit is contained in:
Ben Guidarelli 2023-06-13 09:21:25 -04:00 committed by GitHub
parent 6b85c08b53
commit 88ddb1d9e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1108 additions and 21 deletions

View File

@ -246,7 +246,10 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: "16"
- run: cd clients/js && make test
- run: |
cd clients/js && make test
make docs
git diff --name-only --exit-code && echo "✅ Generated CLI docs match committed docs" || (echo "❌ Generated CLI docs differs from committed CLI docs, run \`make docs\` and commit the result" >&2 && exit 1)
# Verify wormhole chain unit tests
wormchain:

View File

@ -28,5 +28,8 @@ test: build
node build/main.js --version > /dev/null
./run_parse_tests
docs:
npm run docs
clean:
rm -rf build node_modules

File diff suppressed because it is too large Load Diff

View File

@ -17,6 +17,7 @@
"start": "npm run build && node ./build/main.js",
"build": "esbuild src/main.ts --bundle --outfile=build/main.js --minify --platform=node --target=node16",
"check": "tsc --noEmit",
"docs":"npx tsx src/doc.ts",
"prepublishOnly": "npm run check",
"test": "echo \"Error: no test specified\" && exit 1"
},

68
clients/js/src/doc.ts Normal file
View File

@ -0,0 +1,68 @@
import * as fs from "fs";
import yargs from "yargs";
// Side effects are here to trigger before the afflicted libraries' on-import warnings can be emitted.
// It is also imported so that it can side-effect without being tree-shaken.
import "./side-effects";
// https://github.com/yargs/yargs/blob/main/docs/advanced.md#example-command-hierarchy-using-indexmjs
import * as aptos from "./cmds/aptos";
import * as editVaa from "./cmds/editVaa";
import * as evm from "./cmds/evm";
import * as generate from "./cmds/generate";
import * as info from "./cmds/info";
import * as near from "./cmds/near";
import * as parse from "./cmds/parse";
import * as recover from "./cmds/recover";
import * as submit from "./cmds/submit";
import * as sui from "./cmds/sui";
import * as verifyVaa from "./cmds/verifyVaa";
const MD_TAG = "<!--CLI_USAGE-->";
async function getHelpText(name: string, cmd: any): Promise<string> {
return await cmd.builder(yargs).scriptName(`worm ${cmd.command}`).getHelp();
}
(async function () {
const cmds = [
aptos,
editVaa,
evm,
generate,
info,
near,
parse,
recover,
submit,
sui,
verifyVaa,
];
const helpOutputs: Buffer[] = [];
for (const [name, cmd] of Object.entries(cmds)) {
const helpText = await getHelpText(name, cmd);
helpOutputs.push(Buffer.from(`
<details>
<summary> ${cmd.command} </summary>
\`\`\`sh
${helpText}
\`\`\`
</details>
`))
}
const f = fs.readFileSync("README.md");
const startIdx = f.indexOf(MD_TAG, 0);
const stopIdx = f.indexOf(MD_TAG, startIdx + 1);
const head = f.subarray(0, startIdx + MD_TAG.length);
const tail = f.subarray(stopIdx, f.length);
const content = Buffer.concat([head, ...helpOutputs, tail])
fs.writeFileSync("README.md", content.toString())
})();