"use strict";

var fs = require('fs');
var esprima = require('./node_modules/esprima-harmony');

var args = process.argv.splice(2);

if (args.length === 0) {
    console.log('Error: no input file.');
    process.exit(1);
}

function parseFile(f) {
        var content;
        // just in case a file somehow doesn't exist because it got
        // deleted very quickly before the filescan picked it up
        try {
            content = fs.readFileSync(f, 'utf-8');
        } catch(e) {
            return null;
        }
        return {
            path: f,
            ast: esprima.parse(content)
        };
}

try {
    var files = args.map(parseFile);
    console.log(JSON.stringify({files: files}));
} catch (e) {
    console.log('Error: ' + e.message);
    process.exit(1);
}

