forked from ssb-junkyard/react-native-scuttlebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch-scuttlebot.js
68 lines (60 loc) · 2.26 KB
/
patch-scuttlebot.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var fs = require("fs");
var path = require("path");
var scuttlebotPathHere = path.join(__dirname, "./node_modules/scuttlebot");
var scuttlebotPathAbove = path.join(__dirname, "../scuttlebot");
var existsHere = fs.existsSync(scuttlebotPathHere);
var existsAbove = fs.existsSync(scuttlebotPathAbove);
if (existsHere) {
patchApidocsFile(scuttlebotPathHere);
}
if (existsAbove) {
patchApidocsFile(scuttlebotPathAbove);
}
if (!existsHere && !existsAbove) {
throw new Error("Cannot find file scuttlebot/lib/apidocs.js to patch");
}
function patchApidocsFile(scuttlebotPath) {
var apidocsPath = path.join(scuttlebotPath, "./lib/apidocs.js");
var prevContent = fs.readFileSync(apidocsPath, "utf-8");
var dirname = path.dirname(apidocsPath);
function readMarkdownCompileTime(relPath) {
return fs
.readFileSync(path.join(dirname, relPath), "utf-8")
.replace(/\`\`\`/g, "")
.replace(/\`/g, '"');
}
var nextContent = prevContent
.replace(
`fs.readFileSync(path.join(__dirname, '../api.md'), 'utf-8')`,
`\`${readMarkdownCompileTime("../api.md")}\``
)
.replace(
`fs.readFileSync(path.join(__dirname, '../plugins/block.md'), 'utf-8')`,
`\`${readMarkdownCompileTime("../plugins/block.md")}\``
)
.replace(
`fs.readFileSync(path.join(__dirname, '../plugins/friends.md'), 'utf-8')`,
`\`${readMarkdownCompileTime("../plugins/friends.md")}\``
)
.replace(
`fs.readFileSync(path.join(__dirname, '../plugins/gossip.md'), 'utf-8')`,
`\`${readMarkdownCompileTime("../plugins/gossip.md")}\``
)
.replace(
`fs.readFileSync(path.join(__dirname, '../plugins/invite.md'), 'utf-8')`,
`\`${readMarkdownCompileTime("../plugins/invite.md")}\``
)
.replace(
`fs.readFileSync(path.join(__dirname, '../plugins/plugins.md'), 'utf-8')`,
`\`${readMarkdownCompileTime("../plugins/plugins.md")}\``
)
.replace(
`fs.readFileSync(path.join(__dirname, '../plugins/private.md'), 'utf-8')`,
`\`${readMarkdownCompileTime("../plugins/private.md")}\``
)
.replace(
`fs.readFileSync(path.join(__dirname, '../plugins/replicate.md'), 'utf-8')`,
`\`${readMarkdownCompileTime("../plugins/replicate.md")}\``
);
fs.writeFileSync(apidocsPath, nextContent, "utf-8");
}