forked from tauri-apps/rustdocusaurus
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
50 lines (42 loc) · 1.4 KB
/
main.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
48
49
50
const explore = require("./actions/explore");
const extract = require("./actions/extract");
const transform = require("./actions/transform");
const save = require("./actions/save");
const util = require("util");
const { readFile } = require("fs").promises;
const exec = util.promisify(require("child_process").exec);
const getCleanedResult = (result) => result.stdout.replace("\n", "");
const getRepositoryInfo = async (path) => {
const repoOwnership = getCleanedResult(
await exec("git remote get-url origin", { cwd: path }),
)
.match(/(?:https:\/\/github.com\/|git@github\.com:)(.*)/)[1]
.replace(".git", "")
.split("/");
return {
revision: getCleanedResult(
await exec("git rev-parse --short HEAD", { cwd: path }),
),
owner: repoOwnership[0],
project: repoOwnership[1],
};
};
const getAllCrates = async (originPath) => {
return JSON.parse(
(await readFile(originPath + "crates.js", "utf8"))
.replace("window.ALL_CRATES = ", "")
.replace(";", ""),
);
};
const transformDocs = async (cratePath, originPath, targetPath) => {
const crateName = cratePath.split("/").pop();
const repositoryInfo = await getRepositoryInfo(cratePath);
const docs = await explore(cratePath);
const contents = await extract(docs);
const results = await transform(contents, crateName, repositoryInfo);
await save(results, originPath, targetPath, crateName);
return results;
};
module.exports = {
transformDocs,
};