├── .jshintrc ├── .travis.yml ├── test ├── fixtures │ ├── numeric_literal.js │ ├── array.js │ ├── destructuring.js │ ├── args.js │ ├── for_of.js │ ├── template_literal.js │ ├── module.js │ ├── object_initializer.js │ ├── arrow.js │ ├── generator.js │ └── class.js └── traceur_test.js ├── .gitignore ├── lib ├── server.js └── compiler.js ├── LICENSE-MIT ├── Gruntfile.js ├── package.json ├── README.md └── tasks └── traceur.js /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "strict": true 4 | } 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | -------------------------------------------------------------------------------- /test/fixtures/numeric_literal.js: -------------------------------------------------------------------------------- 1 | export var nums = [0b11, 0o17]; 2 | -------------------------------------------------------------------------------- /test/fixtures/array.js: -------------------------------------------------------------------------------- 1 | export function squared(arr) { 2 | return [for (x of arr) x * x]; 3 | }; 4 | -------------------------------------------------------------------------------- /test/fixtures/destructuring.js: -------------------------------------------------------------------------------- 1 | var {a, b} = { 2 | a: 'This is A', 3 | b: 'This is B' 4 | }; 5 | export {a, b}; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | test/tmp 4 | .DS_Store 5 | *.sublime-* 6 | **/dist/* 7 | .idea 8 | .jshintrc 9 | -------------------------------------------------------------------------------- /test/fixtures/args.js: -------------------------------------------------------------------------------- 1 | export function test(a = 100, ...rest){ 2 | return { 3 | a: a, 4 | rest: rest 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/for_of.js: -------------------------------------------------------------------------------- 1 | export function sum(arr) { 2 | var sum = 0; 3 | for (var item of arr) { 4 | sum += item; 5 | } 6 | return sum; 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/template_literal.js: -------------------------------------------------------------------------------- 1 | var person = {firstName: 'John', lastName: 'Smith'}; 2 | export var literal = `My name is ${person.firstName} ${person.lastName}.`; 3 | -------------------------------------------------------------------------------- /test/fixtures/module.js: -------------------------------------------------------------------------------- 1 | import {a as moduleA, b} from './destructuring'; 2 | import * as m from './destructuring'; 3 | export var text = [moduleA, b, m.a, m.b].join(', '); 4 | -------------------------------------------------------------------------------- /test/fixtures/object_initializer.js: -------------------------------------------------------------------------------- 1 | var x = 10; 2 | var y = 5; 3 | 4 | export var obj = { 5 | x, 6 | y, 7 | add() { 8 | return this.x + this.y; 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /test/fixtures/arrow.js: -------------------------------------------------------------------------------- 1 | export var pi = () => 3.1415; 2 | export var square = a => a * a; 3 | export var greater = (a, b) => { 4 | if (a > b) { 5 | return true; 6 | } 7 | return false; 8 | }; 9 | -------------------------------------------------------------------------------- /lib/server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var compile = require('./compiler').compile; 3 | 4 | process.on('message', function(msg) { 5 | try { 6 | var compiled = compile(msg.content, msg.options); 7 | process.send({id: msg.id, result: compiled}); 8 | } catch (e) { 9 | process.send({id: msg.id, error: e.message }); 10 | } 11 | }); 12 | 13 | -------------------------------------------------------------------------------- /test/fixtures/generator.js: -------------------------------------------------------------------------------- 1 | function* range(start, end, step) { 2 | while (start < end) { 3 | yield start; 4 | start += step; 5 | } 6 | } 7 | 8 | function squareSum(arr) { 9 | var comp = (for (x of arr) x * x); 10 | var sum = 0; 11 | for (var x2 of comp) { 12 | sum += x2; 13 | } 14 | return sum; 15 | } 16 | 17 | export var generator = { 18 | range: range, 19 | squareSum: squareSum 20 | }; 21 | -------------------------------------------------------------------------------- /test/fixtures/class.js: -------------------------------------------------------------------------------- 1 | class Person { 2 | 3 | constructor (name) { 4 | this.name = name; 5 | } 6 | 7 | hi () { 8 | return this.name; 9 | } 10 | 11 | // Computed property 12 | get firstInitial() { 13 | return this.name.slice(0, 1); 14 | } 15 | 16 | } 17 | 18 | export class Man extends Person { 19 | 20 | constructor (name) { 21 | super(name); 22 | } 23 | 24 | hi () { 25 | return 'I am a man and my name is ' + super.hi(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Aaron Frost 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /* 2 | * grunt-traceur 3 | * https://github.com/aaron/grunt 4 | * 5 | * Copyright (c) 2013 Aaron Frost 6 | * Licensed under the MIT license. 7 | */ 8 | 9 | 'use strict'; 10 | 11 | module.exports = function(grunt) { 12 | 13 | // Project configuration. 14 | grunt.initConfig({ 15 | 16 | // Configuration to be run (and then tested). 17 | traceur: { 18 | options: { 19 | experimental: true, 20 | modules: 'commonjs', 21 | sourceMaps: true, 22 | arrayComprehension: true, 23 | generatorComprehension: true, 24 | moduleNaming: { 25 | addPrefix: "test/fixtures", 26 | stripPrefix: "test/tmp" 27 | }, 28 | copyRuntime: "test/tmp" 29 | // traceur options here 30 | }, 31 | test: { 32 | files: [{ 33 | expand: true, 34 | cwd: 'test/fixtures', 35 | src: ['*.js'], 36 | dest: 'test/tmp' 37 | }] 38 | } 39 | }, 40 | nodeunit: { 41 | tests: ['test/*_test.js'] 42 | }, 43 | clean: { 44 | build: ["test/tmp"] 45 | } 46 | 47 | }); 48 | 49 | // Actually load this plugin's task(s). 50 | grunt.loadTasks('tasks'); 51 | 52 | grunt.loadNpmTasks('grunt-contrib-nodeunit'); 53 | grunt.loadNpmTasks('grunt-contrib-clean'); 54 | 55 | grunt.registerTask('default', ['clean:build', 'traceur', 'nodeunit', 'clean:build']); 56 | 57 | //Same as default, but doesn't clean at the end, so that you can see the output. 58 | grunt.registerTask('test', ['clean:build', 'traceur', 'nodeunit']); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "grunt-traceur", 3 | "description": "A grunt plugin for Google's Traceur-Compile, a lib to compile ES6 JavaScript into ES5 JavaScript.", 4 | "version": "0.5.5", 5 | "homepage": "https://github.com/aaronfrost/grunt-traceur", 6 | "author": { 7 | "name": "Aaron Frost", 8 | "email": "aaronfrost@gmail.com", 9 | "url": "40win.com" 10 | }, 11 | "contributors": [ 12 | { 13 | "name": "Manuel Braun", 14 | "email": "mb@w69b.com" 15 | }, 16 | { 17 | "name": "Jeff McRiffey", 18 | "email": "jeff.mcriffey@ambition.com" 19 | }, 20 | { 21 | "name": "Martin Jurča", 22 | "email": "mjurca@centrum.cz" 23 | } 24 | ], 25 | "scripts": { 26 | "test": "grunt" 27 | }, 28 | "repository": { 29 | "type": "git", 30 | "url": "git://github.com/aaronfrost/grunt-traceur.git" 31 | }, 32 | "bugs": { 33 | "url": "https://github.com/aaronfrost/grunt-traceur/issues" 34 | }, 35 | "licenses": [ 36 | { 37 | "type": "MIT", 38 | "url": "https://github.com/aaronfrost/grunt-traceur/blob/master/LICENSE-MIT" 39 | } 40 | ], 41 | "main": "Gruntfile.js", 42 | "engines": { 43 | "node": ">=0.8.0" 44 | }, 45 | "dependencies": { 46 | "es6-promise": "^1.0.0", 47 | "lodash": "^4.17.13" 48 | }, 49 | "peerDependencies": { 50 | "grunt": ">=0.4.0", 51 | "traceur": ">=0.0.88" 52 | }, 53 | "devDependencies": { 54 | "grunt": "^0.4.5", 55 | "grunt-cli": "^0.1.13", 56 | "grunt-contrib-clean": "^0.6.0", 57 | "grunt-contrib-nodeunit": "^0.4.1" 58 | }, 59 | "keywords": [ 60 | "gruntplugin" 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /lib/compiler.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var fork = require('child_process').fork; 3 | var os = require('os'); 4 | 5 | var gruntOnlyOptions = ['includeRuntime', 'moduleNames']; 6 | 7 | function getTraceurOptions(options) { 8 | var traceurOptions = {}; 9 | var keys = Object.keys(options).filter(function(key) { 10 | return gruntOnlyOptions.indexOf(key) === -1; 11 | }); 12 | 13 | keys.forEach(function(key) { 14 | traceurOptions[key] = options[key]; 15 | }); 16 | 17 | return traceurOptions; 18 | } 19 | 20 | /** 21 | * @param {string} content js source. 22 | * @param {Object} options traceur config. 23 | * @return {string} compiled js source. 24 | */ 25 | exports.compile = function(content, options) { 26 | // import lazzily as traceur pollutes the global namespace. 27 | var traceur = require('traceur'); 28 | var sourceMap = ''; 29 | var compiler, result; 30 | 31 | compiler = new traceur.NodeCompiler(getTraceurOptions(options)); 32 | 33 | try { 34 | result = compiler.compile(content, options.sourceName, options.outputName); 35 | 36 | if (options.sourceMaps) { 37 | sourceMap = compiler.getSourceMap(); 38 | } 39 | } catch (e) { 40 | throw new Error(e); 41 | } 42 | 43 | return [result, sourceMap]; 44 | }; 45 | 46 | /** 47 | */ 48 | exports.server = function() { 49 | 50 | var server; 51 | var msgId = 0; 52 | var listeners = {}; 53 | 54 | function spawnServer() { 55 | server = fork(__dirname + '/server.js'); 56 | server.on('message', onMessage); 57 | server.on('error', function(err) { 58 | console.error('server error: ' + err); 59 | }); 60 | } 61 | 62 | function onMessage(msg) { 63 | var listener = listeners[msg.id]; 64 | if (listener) { 65 | delete listeners[msg.id]; 66 | listener(msg); 67 | } 68 | } 69 | 70 | var api = {}; 71 | 72 | /** 73 | * @param {string} content js source. 74 | * @param {Object} options traceur config. 75 | * @param {function(string, string)} callback that is called with an error 76 | * message (if any) and the compiled source. 77 | */ 78 | api.compile = function(content, options, callback) { 79 | var id = msgId++; 80 | listeners[id] = function(msg) { 81 | if (msg.error) { 82 | callback(msg.error); 83 | } else { 84 | callback(null, msg.result); 85 | } 86 | }; 87 | server.send({content: content, 88 | options: options, 89 | id: id}); 90 | }; 91 | 92 | /** 93 | * stop the server 94 | */ 95 | api.stop = function() { 96 | server.disconnect(); 97 | }; 98 | 99 | spawnServer(); 100 | return api; 101 | }; 102 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | _published the 0.5.0 release to npmjs.org_ 2 | # grunt-traceur 3 | 4 | [![Build Status](https://travis-ci.org/aaronfrost/grunt-traceur.svg?branch=master)](https://travis-ci.org/aaronfrost/grunt-traceur) 5 | 6 | > A grunt plugin for Google's Traceur-Compile, a lib to compile ES6 JavaScript into ES5 JavaScript. 7 | 8 | ## Getting Started 9 | This plugin requires Grunt `~0.4.0` 10 | 11 | If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: 12 | 13 | ```shell 14 | npm install grunt-traceur --save-dev 15 | ``` 16 | 17 | One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: 18 | 19 | ```js 20 | grunt.loadNpmTasks('grunt-traceur'); 21 | ``` 22 | 23 | ## The "traceur" task 24 | 25 | ### Overview 26 | In your project's Gruntfile, add a section named `traceur` to the data object passed into `grunt.initConfig()`. 27 | 28 | ```js 29 | grunt.initConfig({ 30 | traceur: { 31 | options: { 32 | // traceur options here 33 | experimental: true, 34 | // module naming options, 35 | moduleNaming: { 36 | stripPrefix: "src/es6", 37 | addPrefix: "com/mycompany/project" 38 | }, 39 | copyRuntime: 'src/es5' 40 | }, 41 | custom: { 42 | files: [{ 43 | expand: true, 44 | cwd: 'src/es6', 45 | src: ['*.js'], 46 | dest: 'src/es5' 47 | }] 48 | }, 49 | }, 50 | }) 51 | ``` 52 | Once the files have been transpiled into ES5, you can minify or concat them. 53 | 54 | ### Options 55 | 56 | Any specified option will be passed through directly to traceur, thus you can specify any option that traceur supports. 57 | 58 | Some common options: 59 | 60 | * `experimental` - Turn on all experimental features 61 | * `blockBinding` - Turn on support for `let` and `const` 62 | * `copyRuntime` - Copies the traceur_runtime.js to the location which you specify here 63 | * `moduleNames` - Generate named module (default: true) 64 | * `moduleNaming.stripPrefix` - Strip the specified prefix from generated module names 65 | * `moduleNaming.addPrefix` - Add the specified prefix to the generated module names (applied AFTER the `moduleNaming.stripPrefix` option) 66 | 67 | ## Contributing 68 | In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). 69 | 70 | ## Release History 71 | _(Nothing yet)_ 72 | -------------------------------------------------------------------------------- /test/traceur_test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* 4 | ======== A Handy Little Nodeunit Reference ======== 5 | https://github.com/caolan/nodeunit 6 | 7 | Test methods: 8 | test.expect(numAssertions) 9 | test.done() 10 | Test assertions: 11 | test.ok(value, [message]) 12 | test.equal(actual, expected, [message]) 13 | test.notEqual(actual, expected, [message]) 14 | test.deepEqual(actual, expected, [message]) 15 | test.notDeepEqual(actual, expected, [message]) 16 | test.strictEqual(actual, expected, [message]) 17 | test.notStrictEqual(actual, expected, [message]) 18 | test.throws(block, [error], [message]) 19 | test.doesNotThrow(block, [error], [message]) 20 | test.ifError(value) 21 | */ 22 | 23 | var fs = require('fs'); 24 | var path = require('path'); 25 | 26 | function getType (obj) { 27 | return Object.prototype.toString.call(obj) 28 | } 29 | 30 | exports.traceur = { 31 | 32 | args: function (test) { 33 | var func = require('./tmp/args').test; 34 | var result = func(undefined, 1, 2, 3); 35 | test.equal(result.a, 100, 'default argument should work'); 36 | var restType = getType(result.rest); 37 | test.equal(restType, '[object Array]', 'rest arguments should be converted to an array'); 38 | test.done(); 39 | }, 40 | 41 | destructuring: function (test) { 42 | var vals = require('./tmp/destructuring'); 43 | test.equal(vals.a, 'This is A', 'destructuring assignment should work'); 44 | test.equal(vals.b, 'This is B', 'destructuring assignment should work'); 45 | test.done(); 46 | }, 47 | 48 | module: function (test) { 49 | var module = require('./tmp/module'); 50 | test.equal(module.text, 'This is A, This is B, This is A, This is B', 51 | 'module, import and export should work'); 52 | test.done(); 53 | }, 54 | 55 | class: function (test) { 56 | var Man = require('./tmp/class').Man; 57 | var name = 'john'; 58 | var man = new Man(name); 59 | var msg = man.hi(); 60 | test.equal(msg, 'I am a man and my name is ' + name, 'class and inheritance should work'); 61 | test.equal(man.firstInitial, 'j', 'computed properties should work'); 62 | test.done(); 63 | }, 64 | 65 | arrow: function(test) { 66 | var arrow = require('./tmp/arrow'); 67 | test.equal(arrow.pi(), 3.1415); 68 | test.equal(arrow.square(5), 25); 69 | test.equal(arrow.greater(4, 1), true); 70 | test.equal(arrow.greater(1, 4), false); 71 | test.done(); 72 | }, 73 | 74 | forOf: function(test) { 75 | var sum = require('./tmp/for_of').sum; 76 | test.equal(sum([1, 2, 3, 4]), 10); 77 | test.done(); 78 | }, 79 | 80 | generator: function(test) { 81 | var range = require('./tmp/generator').generator.range; 82 | var gen = range(0, 10, 2); 83 | var item = gen.next(); 84 | for (var i = 0; !item.done; i += 2) { 85 | test.equal(item.value, i); 86 | item = gen.next(); 87 | } 88 | test.done(); 89 | }, 90 | 91 | generatorComprehension: function(test) { 92 | var squareSum = require('./tmp/generator').generator.squareSum; 93 | test.equal(squareSum([1, 2, 3, 4]), 30); 94 | test.done(); 95 | }, 96 | 97 | arrayComprehension: function(test) { 98 | var squared = require('./tmp/array').squared; 99 | test.deepEqual(squared([1, 2, 3, 4]), [1, 4, 9, 16]); 100 | test.done(); 101 | }, 102 | 103 | numericLiteral: function(test) { 104 | var nums = require('./tmp/numeric_literal').nums; 105 | test.deepEqual(nums, [3, 15]); 106 | test.done(); 107 | }, 108 | 109 | templateLiteral: function(test) { 110 | var literal = require('./tmp/template_literal').literal; 111 | test.equal(literal, 'My name is John Smith.'); 112 | test.done(); 113 | }, 114 | 115 | objectInitializer: function(test) { 116 | var obj = require('./tmp/object_initializer').obj; 117 | test.equal(obj.x, 10); 118 | test.equal(obj.y, 5); 119 | test.equal(obj.add(), 15); 120 | test.done(); 121 | }, 122 | 123 | sourceMaps: function (test) { 124 | var regex = /\.map$/i; 125 | var files = fs.readdirSync(path.join(__dirname, 'tmp')).filter(function (filename) { 126 | return regex.test(filename); 127 | }); 128 | 129 | files.forEach(function(file) { //make sure the files have contents 130 | test.ok( 131 | fs.readFileSync(path.join(__dirname, 'tmp', file), 'utf-8') 132 | ); 133 | }); 134 | test.equal(files.length, 11); 135 | test.done(); 136 | } 137 | }; 138 | -------------------------------------------------------------------------------- /tasks/traceur.js: -------------------------------------------------------------------------------- 1 | /* 2 | * grunt-traceur 3 | * https://github.com/aaron/grunt 4 | * 5 | * Copyright (c) 2013 Aaron Frost 6 | * Licensed under the MIT license. 7 | */ 8 | 9 | 'use strict'; 10 | var _ = require('lodash'); 11 | var fs = require('fs'); 12 | var path = require('path'); 13 | var compiler = require('../lib/compiler'); 14 | var Promise = require('es6-promise').Promise; 15 | var RUNTIME_PATH = (function () { 16 | return require('traceur').RUNTIME_PATH; 17 | })(); 18 | 19 | function asyncCompile(content, options, callback) { 20 | var result; 21 | try { 22 | result = compiler.compile(content, options); 23 | } catch (e) { 24 | callback(e.message, null); 25 | return; 26 | } 27 | callback(null, result); 28 | } 29 | 30 | /* 31 | * Compiles one file 32 | */ 33 | function compileOne (grunt, compile, src, dest, options) { 34 | return new Promise(function (resolve, reject) { 35 | if (src.length > 1) { 36 | var error = new Error('source MUST be a single file OR multiple files using ' + 37 | 'expand:true. Check out the README.'); 38 | reject(error.message); 39 | } 40 | src = src[0]; 41 | var content = grunt.file.read(src).toString('utf8'); 42 | options.filename = dest; 43 | options.sourceName = dest; 44 | options.outputName = dest; 45 | if (options.moduleNaming) { 46 | var addPrefix = options.moduleNaming.addPrefix; 47 | var stripPrefix = options.moduleNaming.stripPrefix; 48 | if (stripPrefix) { 49 | var namePrefixMatched = (stripPrefix + '/') === 50 | options.sourceName.substring(0, stripPrefix.length + path.sep.length); 51 | if (namePrefixMatched) { 52 | options.sourceName = 53 | options.sourceName.substring(stripPrefix.length + path.sep.length); 54 | } 55 | } 56 | if (addPrefix) { 57 | options.sourceName = addPrefix + path.sep + options.sourceName; 58 | } 59 | } 60 | compile(content, options, function (err, result) { 61 | var sourceMapName, sourceMapPath; 62 | if (err) { 63 | grunt.log.error(src + ' -> ' + dest); 64 | reject(err); 65 | } else { 66 | if (options.sourceMaps) { 67 | sourceMapName = path.basename(src, path.extname(src)) + '.map'; 68 | sourceMapPath = path.join(dest, '..', sourceMapName); 69 | grunt.file.write(sourceMapPath, result[1]); 70 | grunt.log.debug('SourceMap written to "' + sourceMapName + '"'); 71 | } 72 | grunt.file.write(dest, result[0], { 73 | encoding: 'utf8' 74 | }); 75 | grunt.log.debug('Compiled successfully to "' + dest + '"'); 76 | grunt.log.ok(src + ' -> ' + dest); 77 | resolve(); 78 | } 79 | }); 80 | }); 81 | } 82 | 83 | module.exports = function(grunt) { 84 | grunt.registerMultiTask('traceur', 85 | 'Compile ES6 JavaScript to ES5 JavaScript', function() { 86 | var options = this.options({ 87 | moduleNames: true, 88 | moduleNaming: { 89 | stripPrefix: "", 90 | addPrefix: "" 91 | } 92 | }); 93 | grunt.log.debug('using options: ' + JSON.stringify(options)); 94 | var done = this.async(); 95 | // we use a flag so that every errors are printed out 96 | // instead of quitting at the first one 97 | var success = true; 98 | var server, compile; 99 | 100 | if (options.spawn) { 101 | server = compiler.server(); 102 | compile = server.compile; 103 | } else { 104 | compile = asyncCompile; 105 | } 106 | delete options.spawn; 107 | if (!this.files.length) { 108 | grunt.log.error('none of the listed sources are valid'); 109 | success = false; 110 | } 111 | 112 | //Warn about deprecation of 'includeRuntime' 113 | if(!_.isUndefined(options.includeRuntime)){ 114 | grunt.log.error('The use of \'includeRuntime\' has been deprecated in favor of \'copyRuntime\' as of grunt-traceur@0.5.1. The traceur_runtime.js was not included. Please update your options and retry.'); 115 | } 116 | Promise 117 | .all(this.files.map(function (group) { 118 | return compileOne(grunt, compile, group.src, group.dest, options) 119 | .catch(function (err) { 120 | grunt.log.error('ERRORS:'); 121 | grunt.log.error(err); 122 | success = false; 123 | }); 124 | })) 125 | .then(function () { 126 | var runtime, runtimeFilename; 127 | if (server) { 128 | server.stop(); 129 | } 130 | if(!_.isUndefined(options.copyRuntime)){ 131 | if(_.isEmpty(options.copyRuntime)){ 132 | grunt.log.error('Unable to perform \'copyRuntime\' because the value is not specified.'); 133 | return; 134 | } 135 | runtime = fs.readFileSync(RUNTIME_PATH); 136 | runtimeFilename = path.join(options.copyRuntime, 'traceur_runtime.js') 137 | grunt.file.write(runtimeFilename, runtime, { 138 | encoding: 'utf8' 139 | }); 140 | grunt.log.ok('TRACEUR_RUNTIME.JS -> ' + runtimeFilename); 141 | } 142 | done(success); 143 | }); 144 | }); 145 | }; 146 | --------------------------------------------------------------------------------