summaryrefslogtreecommitdiff
path: root/support/build/compile-modules.js
blob: 73335186e6c2393ee80edac4eae17e9de44bfce8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const async = require('async');
const _ = require('lodash');
const readdirR = require('recursive-readdir');
const joinPath = require('path').join;
const fs = require('fs-extra');
const compileModule = require('./compile-module');

module.exports = function(options, cb) {
    options = _.defaults({}, options, {
        path: 'lib/',
        outpath: 'build',
        es6: false,
        lodashRename: false
    });
    const { path, outpath } = options;

    readdirR(path, [], (err, files) => {
        fs.emptyDirSync(outpath);
        fs.emptyDirSync(joinPath(outpath, 'internal'));
        async.each(files, (file, callback) => {
            const outfile = file.startsWith(path) ?
                file.slice(path.length) :
                file;
            const finalPath = joinPath(outpath, outfile);

            compileModule({
                file,
                output: finalPath,
                lodashRename: options.lodashRename,
                es6: options.es6
            }, callback)

        }, cb);
    });
}