Created
October 22, 2019 18:21
-
-
Save nchanged/22f38c803492da41e41961ddd6ab67ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as path from 'path'; | |
import * as buntis from 'buntis'; | |
import * as fs from 'fs'; | |
var walkSync = function(dir, filelist) { | |
var fs = fs || require('fs'), | |
files = fs.readdirSync(dir); | |
filelist = filelist || []; | |
files.forEach(function(file) { | |
if (!/node_modules/.test(file)) { | |
if (fs.statSync(path.join(dir, file)).isDirectory()) { | |
filelist = walkSync(path.join(dir, file), filelist); | |
} else { | |
if (/.tsx?$/.test(file)) { | |
filelist.push(path.join(dir, file)); | |
} | |
} | |
} | |
}); | |
return filelist; | |
}; | |
const filelist = []; | |
walkSync(__dirname, filelist); | |
function parse(filePath) { | |
const contents = fs.readFileSync(filePath).toString(); | |
const extension = path.extname(filePath); | |
try { | |
buntis.parseTSModule(contents, { | |
directives: true, | |
jsx: extension === '.tsx', | |
next: true, | |
}); | |
} catch (e) { | |
console.log('----------'); | |
console.log(filePath); | |
console.error(e); | |
} | |
} | |
for (const f of filelist) { | |
parse(f); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment