forked from hirosystems/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-cli-ref.js
executable file
·47 lines (34 loc) · 1.49 KB
/
update-cli-ref.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env node
/*
Before running this command, you should first update the cli-reference.json file with the Stacks CLI:
stx docs > src/_data/cli-reference.json
*/
const fs = require("fs");
const path = require("path");
var argv = require("yargs/yargs")(process.argv.slice(2))
.usage("Usage: $0 <json_file> [options]")
.default({ o: "./", f: "_commands.md" })
.demandCommand(1)
.alias("o", "outdir")
.describe("o", "output directory")
.alias("f", "filename")
.describe("f", "output file name")
.help("h")
.alias("h", "help").argv;
const content = JSON.parse(fs.readFileSync(argv._[0]));
var markdown =
"[//]: # (THIS IS AN AUTOMATICALLY GENERATED FILE, DO NOT EDIT BY HAND)\n\n";
content.forEach((entry) => {
const { command, group, usage, args } = entry;
markdown = `${markdown}### ${command}\n\n**Group:** ${group}\n\n${usage}\n\n| Name | Type | Value |\n|-|-|-|\n`;
args.forEach((arg) => {
const { name, type, value } = arg;
markdown = `${markdown}| \`${name}\` | \`${type}\` | \`${value}\` |\n`;
});
markdown = `${markdown}\n`;
});
// FIXME: this is a temporary workaround to add MDXv3 relevant escaping (see docs#566)
// A proper fix would require either updating @stacks/cli directly, or preferably,
// moving to a local build process that doesn't depend on @stacks/cli.
markdown = markdown.replace("{GAIA_URL_PREFIX}/{ADDRESS}/profile.json", "`{GAIA_URL_PREFIX}/{ADDRESS}/profile.json`");
fs.writeFileSync(path.resolve(argv.o, argv.f), markdown, { flag: "w+" });