Last active
August 29, 2015 14:13
-
-
Save vespakoen/fca7b92b98b74057e9da to your computer and use it in GitHub Desktop.
compile ES6 => ES5 for modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| '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