-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathstellar_cli.mjs
60 lines (47 loc) · 1.68 KB
/
stellar_cli.mjs
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
48
49
50
51
52
53
54
55
56
57
58
59
60
import fs from "fs-extra";
import path from "path";
import {execSync} from "child_process";
import * as tar from 'tar'
import {finished} from "stream/promises";
import {Readable} from "stream"
const localArtifactPath = "./stellar-cli-artifacts"
// Remove the existing artifact if it exists
if (fs.existsSync(localArtifactPath)) {
console.log("Removing existing artifacts...");
fs.removeSync(localArtifactPath);
}
fs.mkdirSync(localArtifactPath)
const resp = await fetch("https://api.github.com/repos/stellar/stellar-cli/tags")
const json = await resp.json()
const latestVersion = json[0].name.replace("v", "")
const url = `https://github.com/stellar/stellar-cli/releases/download/v${latestVersion}/stellar-cli-${latestVersion}-docs-cookbook.tar.gz`
const blob = await fetch(url);
await finished(Readable.fromWeb(blob.body).pipe(
tar.x({
C: `${localArtifactPath}`,
z: true
}),
));
console.log("the latest version is", latestVersion.toString());
// Copy FULL_HELP_DOCS.md
const fullHelpDocsPath = path.join(localArtifactPath, "FULL_HELP_DOCS.md");
const fullHelpDocsContent = fs.readFileSync(fullHelpDocsPath, "utf8");
const modifiedContent = `---
sidebar_position: 30
description: This document contains the help content for the stellar command-line program.
---
${fullHelpDocsContent}
`;
fs.writeFileSync(
"src/helpers/stellarCli.ts",
`export const latestVersion = "${latestVersion}";`,
);
fs.writeFileSync(
"docs/tools/developer-tools/cli/stellar-cli.mdx",
modifiedContent,
);
fs.cpSync(path.join(localArtifactPath, "cookbook"), "docs/build/guides/cli", {
recursive: true,
});
execSync("yarn format:mdx");
console.log("All files processed successfully.");