-
Notifications
You must be signed in to change notification settings - Fork 19
/
checkDefinitionFiles.js
58 lines (46 loc) · 1.51 KB
/
checkDefinitionFiles.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
51
52
53
54
55
56
57
58
const fs = require('fs');
const path = require('path');
let dtsFileDirectory = {};
function getAllJsFilesAndBuildDefinitionFileDirectory(dirPath, arrayOfFiles) {
files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach(function (file) {
if (fs.statSync(dirPath + '/' + file).isDirectory()) {
arrayOfFiles = getAllJsFilesAndBuildDefinitionFileDirectory(
dirPath + '/' + file,
arrayOfFiles
);
} else if (file.endsWith('.d.ts')) {
dtsFileDirectory[path.join(__dirname, dirPath, '/', file)] = true;
} else {
arrayOfFiles.push(path.join(__dirname, dirPath, '/', file));
}
});
return arrayOfFiles;
}
function checkForDefinitionFiles() {
const libFiles = getAllJsFilesAndBuildDefinitionFileDirectory('lib');
checkAllJsDefinitionFiles(libFiles);
dtsFileDirectory = {};
const esFiles = getAllJsFilesAndBuildDefinitionFileDirectory('es');
checkAllJsDefinitionFiles(esFiles);
console.log('All definition files are sucessfully generated');
}
function checkAllJsDefinitionFiles(files) {
const missingDefinitionFiles = [];
for (const file of files) {
if (!dtsFileDirectory[file.replace('.js', '.d.ts')]) {
missingDefinitionFiles.push(file);
}
}
if (missingDefinitionFiles.length > 0) {
console.error(
'Missing definition files: ',
missingDefinitionFiles.join(',')
);
throw new Error(
'Some files are missing definition files, please check stack trace above'
);
}
}
checkForDefinitionFiles();