<commit_before>var fs = require('fs'),
    path = require('path'),
    chalk = require('chalk'),
    glob = require('glob'),
    compiler = require('ember-template-compiler'),
    argv = require('yargs')
        .usage('Usage: $0 -i [dir] -o [file]')
        .demand(['i', 'o'])
        .options('i', {
            describe: 'input directory',
            alias: 'input'
        })
        .options('o', {
            describe: 'output file',
            alias: 'output'
        })
        .argv;
            
            

function buildTemplate(name, content) {
    return "define('" + name +"', ['exports'], function(__exports__){ __exports__['default'] = " + content + "; });"
}

glob(path.join(argv.input, "**/*.hbs"), function(er, files) {
    var output  = [];

    files.forEach(function(f){
        var body = fs.readFileSync(f, 'utf8'),
            name = f.replace(/\.hbs/, ''),
            template;

        template = compiler.precompile(body).toString();

        output.push(buildTemplate(name, template));
        console.log(chalk.green('compiling: ' + f));
    });

    fs.writeFile(argv.output, output.join('\n'), function(err){
        if (err) {
            console.log(chalk.red(err));
        }
        else {
            console.log(chalk.green('finished'));
        }
    }); 
});
<commit_msg>The input argument now accepts either a file or directory.<commit_after>var fs = require('fs'),
    path = require('path'),
    chalk = require('chalk'),
    glob = require('glob'),
    compiler = require('ember-template-compiler'),
    argv = require('yargs')
        .usage('Usage: $0 -i [dir] -o [file]')
        .demand(['i', 'o'])
        .options('i', {
            describe: 'input directory',
            alias: 'input'
        })
        .options('o', {
            describe: 'output file',
            alias: 'output'
        })
        .argv;
            
            

function buildTemplate(name, content) {
    return "define('" + name +"', ['exports'], function(__exports__){ __exports__['default'] = " + content + "; });"
}

function processFile(f) {
    var body = fs.readFileSync(f, 'utf8'),
    name = f.replace(/\.hbs/, ''),
    template;

    template = compiler.precompile(body).toString();

    console.log(chalk.green('compiling: ' + f));
    return buildTemplate(name, template);
}

function writeFile(contents) {
    fs.writeFile(argv.output, contents, function(err){
        if (err) {
            console.log(chalk.red(err));
        }
        else {
            console.log(chalk.green('finished'));
        }
    }); 
}

if (fs.statSync(argv.input).isDirectory()) {
    glob(path.join(argv.input, "**/*.hbs"), function(er, files) {
        var output  = [];
        files.forEach(function(f) {
            output.push(processFile(f));
        });
        writeFile(output.join('\n'));
    });
} else {
    writeFile(processFile(argv.input));    
}

{'fraction_non_alphanumeric': 0.18432861580945806, 'fraction_numerical': 0.001380738695201933, 'mean_word_length': 2.1465798045602607, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6857468', 'n_tokens_mistral': 887, 'n_tokens_neox': 880, 'n_words': 164}