Skip to content

Instantly share code, notes, and snippets.

@nchanged
Created October 22, 2019 18:21
Show Gist options
  • Save nchanged/22f38c803492da41e41961ddd6ab67ab to your computer and use it in GitHub Desktop.
Save nchanged/22f38c803492da41e41961ddd6ab67ab to your computer and use it in GitHub Desktop.
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