forked from surveyjs/survey-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dts_cleaner.js
26 lines (26 loc) · 753 Bytes
/
dts_cleaner.js
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
'use strict';
const fs = require('fs');
var path = 'packages/survey-pdf/survey.pdf.d.ts';
var modules = new Set();
var lines = fs.readFileSync(path, 'utf-8').split('\n');
fs.unlinkSync(path);
lines.forEach((line) => {
var reg = /(import\s*){(.*)}(.*)/;
var res = line.match(reg);
if (!res) {
fs.appendFileSync(path, line + '\n');
return;
}
var sp = res[2].split(/,\s*/);
var imp_part = '';
for (var s in sp) {
var mdl = sp[s].trim();
if (!modules.has(mdl)) {
modules.add(mdl);
imp_part = imp_part !== '' ? imp_part + ', ' + mdl : mdl;
}
}
if (imp_part !== '') {
fs.appendFileSync(path, res[1] + '{ ' + imp_part + ' }' + res[3] + '\n');
}
});