Skip to content

Instantly share code, notes, and snippets.

@vespakoen
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save vespakoen/fca7b92b98b74057e9da to your computer and use it in GitHub Desktop.

Select an option

Save vespakoen/fca7b92b98b74057e9da to your computer and use it in GitHub Desktop.
compile ES6 => ES5 for modules
'use strict';
var fs = require('fs');
var path = require('path');
var _ = require('underscore');
var exec = require('child-process-promise').exec;
var Compiler = require('traceur').NodeCompiler;
var traceurOptions = {
sourceMaps : 'inline',
modules : 'commonjs'
};
var compiler = new Compiler(traceurOptions);
exec('find lib')
.then(function (result) {
var files = result.stdout.split("\n");
var jsFiles = _.filter(files, function (file) {
var extension = file.substring(file.indexOf('.') + 1);
return extension === 'js';
});
_.each(jsFiles, function (jsFile) {
fs.readFile(jsFile, function (err, contents) {
var buildFile = jsFile.replace('lib/', 'build/');
var compiled = compiler.compile(contents.toString(), buildFile, buildFile);
exec('mkdir -p ' + path.dirname(buildFile))
.then(function () {
fs.writeFile(buildFile, compiled);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment