-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathcopy-generated-service-docs.ts
70 lines (65 loc) · 1.67 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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 =
`---` +
`\n` +
`title: ${file.replace('.md', '')}` +
`\n` +
`slug: /chat/docs/sdk/angular/services/${file.replace('.md', '')}/` +
`\n` +
`---` +
'\n\n' +
data
.replace(`# Class: ${file.replace('.md', '')}`, '')
.replace(
/\b(?!README)(\w+)\.md\b/g,
'/chat/docs/sdk/angular/services/$1'
)
.replace(/•\s/g, '')
.replace(/▸\s/g, '')
.replace('<T\\>', '')
.replace('\\', '');
fs.writeFile(`${sourcePath}/${file}`, result, 'utf8', (err: any) => {
if (err) {
throw err;
}
fs.copyFile(
`${sourcePath}/${file}`,
`${serviceDocsTargetPath}/${file}`,
(err: any) => {
if (err) {
throw err;
}
}
);
});
});
});
});