-
Notifications
You must be signed in to change notification settings - Fork 39
/
utils.ts
52 lines (42 loc) · 1.9 KB
/
utils.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"use strict";
import { readFile, unlink, writeFile } from "fs";
const common: string[] = ["*gz", "*log", "*tmp", "*txt", ".gitignore", ".npmignore", ".nyc_output", "coverage", "node_modules", ""];
const git: string[] = ["index.d.ts", "index.js"];
const npm: string[] = [".*", "index.ts", "test", "tsconfig.json", "tslint.json", "utils.ts"];
const readme: (err: Error, data: string) => void = (err, data) => {
if(err) return process.stderr.write(`Error reading README.md: ${err.message}`);
const input = data.split("\n");
readFile("index.d.ts", "utf8", (err: Error, data: string) => {
if(err) return process.stderr.write(`Error reading index.d.ts: ${err.message}`);
const output = [];
let begin: boolean, end: boolean;
input.map((line: string) => {
if(begin) {
if(end) output.push(line);
else if(line === "```") {
output.push(line);
end = true;
}
}
if(! begin) {
output.push(line);
if(line === "```typescript") {
let first: boolean, interf: boolean;
begin = true;
data.split("\n").map((line: string) => {
if(! first) return (first = true);
if(interf) return (interf = ! line.match(/}$/));
if(line.match(/interface Chunk/) || line.match(/interface Opts/)) return (interf = true);
if(line.match(/class RotatingFileStream/)) interf = ((line = line.replace("{", "{}")) as unknown) as boolean;
if(! line.match(/Callback/) && ! line.match(/export \{}/)) output.push(line.replace(" ", " "));
});
output.pop();
}
}
});
writeFile("README.md", output.join("\n"), () => {});
});
};
if(process.argv[2] === "clean") unlink("index.js", (): void => unlink("index.d.ts", (): void => {}));
if(process.argv[2] === "ignore") writeFile(".gitignore", git.concat(common).join("\n"), (): void => writeFile(".npmignore", npm.concat(common).join("\n"), (): void => {}));
if(process.argv[2] === "readme") readFile("README.md", "utf8", readme);