forked from dubzzz/fast-check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildTypes.js
50 lines (44 loc) · 1.25 KB
/
buildTypes.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// @ts-check
const fs = require('fs');
const path = require('path');
const glob = require('glob');
/**
* @param {string} fileDir
* @returns {void}
*/
const mkdirRec = fileDir => {
if (fs.existsSync(fileDir)) return;
const parentDir = path.dirname(fileDir);
if (parentDir.length === 0) return;
mkdirRec(parentDir);
fs.mkdirSync(fileDir);
};
/**
* @param {string} toLabel
* @param {((ctn: string) => string)[]} transformations
* @returns {void}
*/
const rewriteTypesTo = (toLabel, transformations) => {
glob('lib/types/**/*.d.ts', {}, function(err, files) {
for (const f of files) {
const newFileName = f.replace('/types/', '/' + toLabel + '/');
const directoryPath = path.dirname(newFileName);
mkdirRec(directoryPath);
const originalContent = fs.readFileSync(f).toString();
let content = originalContent;
for (const t of transformations) {
content = t(content);
}
fs.writeFileSync(newFileName, content);
}
});
};
/**
* @param {string} content
* @returns {string}
*/
const bigintToAny = content => {
return content.replace(/([^\w\d]|^)bigint([^\w\d]|$)/g, '$1any$2');
};
rewriteTypesTo('ts3.2', []);
rewriteTypesTo('types', [bigintToAny]);