UNPKG

decaffeinate-parser

Version:

A better AST for CoffeeScript, inspired by CoffeeScriptRedux.

45 lines (44 loc) 1.3 kB
#!/usr/bin/env node -r ts-node/register -r babel-register "use strict"; exports.__esModule = true; var fs_1 = require("fs"); var path_1 = require("path"); var parser_1 = require("../src/parser"); for (var i = 2; i < process.argv.length; i++) { processPath(process.argv[i]); } function processPath(path) { var stat = fs_1.statSync(path); if (stat.isDirectory()) { processDirectory(path); } else if (stat.isFile() && isCoffeeScriptFile(path)) { processFile(path); } } function processFile(path) { var content = fs_1.readFileSync(path, { encoding: 'utf8' }); try { parser_1.parse(content); console.log("OK " + path); } catch (ex) { console.log("NOT OK " + path); console.log(" " + ex.message); console.log(ex.stack .split('\n') .map(function (line) { return " " + line; }) .join('\n')); } } function processDirectory(path) { fs_1.readdirSync(path).forEach(function (child) { if (child[0] === '.' || child === 'node_modules') { return; } processPath(path_1.join(path, child)); }); } function isCoffeeScriptFile(path) { return path_1.extname(path) === '.coffee' && path_1.basename(path, '.coffee').length > 0; }