-
Notifications
You must be signed in to change notification settings - Fork 32
/
copy-generated-service-docs.ts
55 lines (50 loc) · 1.24 KB
/
copy-generated-service-docs.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
53
54
55
const fs = require('fs');
const sourcePath = 'temp-service-docs/classes';
const serviceDocsTargetPath = process.argv[2];
// remove docs from the source folder
fs.readdir(serviceDocsTargetPath, (err: any, files: string[]) => {
if (err) {
throw err;
}
files.forEach((file) => {
if (file !== '_category_.json') {
try {
fs.unlinkSync(`${serviceDocsTargetPath}/${file}`);
} catch (err: any) {
throw err;
}
}
});
});
// copy generated files
fs.readdir(sourcePath, (err: any, files: string[]) => {
if (err) {
throw err;
}
files.forEach((file) => {
fs.readFile(`${sourcePath}/${file}`, 'utf8', (err: any, data: string) => {
if (err) {
throw err;
}
// Remove the thre prefix from the title
const result = data
.replace(/# Class:/g, '#')
.replace('<T\\>', '')
.replace('\\', '');
fs.writeFile(`${sourcePath}/${file}`, result, 'utf8', (err: any) => {
if (err) {
throw err;
}
fs.copyFile(
`${sourcePath}/${file}`,
`${serviceDocsTargetPath}/${file}x`,
(err: any) => {
if (err) {
throw err;
}
}
);
});
});
});
});