-
Notifications
You must be signed in to change notification settings - Fork 1
/
patch.ts
28 lines (23 loc) · 1.08 KB
/
patch.ts
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
import { readFileSync, writeFileSync } from "fs";
console.log("applying patch...");
let file = readFileSync("./src/index.ts", "utf8");
file = file.replace(/([a-z|A-Z|\d]): ([a-z|A-Z|\d]+) \| undefined/g, "$1?: $2");
file = file.replace(
/Conversation\[\]|RemovedComment\[\]/g,
"(Conversation | RemovedComment)[]"
);
file = file.replace(
"axios.create();\n",
"axios.create();\n\nthis.instance.defaults.transformResponse = [];\n"
);
file = file.replace(
'threads && threads.forEach(item => { url_ += "threads=" + encodeURIComponent("" + item) + "&"; });',
'url_ += "threads=" + JSON.stringify(threads) + "&";'
);
file = file.concat(`export type CommentContent = HTMLComment | PollComment`);
file = file.replace(/Comment2/g, "CommentContent");
file = file.replace("export interface HTMLComment {", 'export interface HTMLComment { type: HTMLCommentType, html: string ')
const reqFolOpt =
/([a-z|A-Z|\d]+)\?: ([a-z|A-Z|\d]+) ?, ?([a-z|A-Z|\d]+): ([a-z|A-Z|\d]+)/g;
while (reqFolOpt.test(file)) file = file.replace(reqFolOpt, "$3: $4, $1?: $2");
writeFileSync("src/index.ts", file);