-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstripDocPaths.ts
42 lines (37 loc) · 1.19 KB
/
stripDocPaths.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
import cliProgress from 'cli-progress';
import * as fs from 'fs';
import { map } from 'lodash/fp';
import * as path from 'path';
import recursiveReadDir from 'recursive-readdir';
import * as util from 'util';
const readFileAsync = util.promisify(fs.readFile);
const writeFileAsync = util.promisify(fs.writeFile);
/**
* Strip out local file paths which expose paths outside of the project directoy
* @param filename
*/
async function updatePaths(filename: string) {
const filepath = path.join(__dirname, filename);
const contents = await readFileAsync(filepath);
const updated = contents
.toString()
.replace(/(Defined in )(.*?)(node_modules.*:\d+)/g, '$1$3');
return writeFileAsync(filepath, updated);
}
async function stripPaths() {
const progress = new cliProgress.Bar({
format: 'Cleaning file paths [{bar}] {percentage}% {value}/{total}',
stopOnComplete: true,
});
const filenames = await recursiveReadDir('./docs');
progress.start(filenames.length, 0);
await Promise.all(
map(
filename => updatePaths(filename).then(() => progress.increment(1)),
filenames,
),
);
// tslint:disable-next-line:no-console
console.log('\nDone!');
}
stripPaths();