Skip to content

Commit

Permalink
Add babel compile
Browse files Browse the repository at this point in the history
  • Loading branch information
jung-kim committed Jan 14, 2016
1 parent 1cb62c9 commit d543586
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -36,3 +36,5 @@ report/
/components/**/*.bundle.js

coverage

/src
46 changes: 40 additions & 6 deletions Gruntfile.js
Expand Up @@ -7,11 +7,17 @@ var semver = require('semver');
var async = require('async');
var browserify = require('browserify');
var electronPackager = require('electron-packager');
var babelPlugins = require('babel-features').options().plugins;

module.exports = function(grunt) {

var packageJson = grunt.file.readJSON('package.json');

if (grunt.cli.tasks.indexOf('package') > -1 || grunt.cli.tasks.indexOf('babel:electron') > -1) {
grunt.log.debug('Babel presets: ', ['es2015', 'stage-0']);
} else {
grunt.log.debug('Babel plugins: ', babelPlugins);
}

grunt.initConfig({
pkg: packageJson,
less: {
Expand All @@ -34,7 +40,7 @@ module.exports = function(grunt) {
watch: {
scripts: {
files: ['public/source/**/*.js', 'source/**/*.js', 'components/**/*.js'],
tasks: ['browserify-common', 'browserify-components'],
tasks: ['browserify-common', 'browserify-components', 'babel:prod'],
options: {
spawn: false,
},
Expand Down Expand Up @@ -188,7 +194,7 @@ module.exports = function(grunt) {
electron: {
files: [
{ expand: true, src: ['public/**'], dest: 'build/resource/' },
{ expand: true, src: ['source/**'], dest: 'build/resource/' },
{ expand: true, src: ['src/**'], dest: 'build/resource/' },
{ expand: true, src: ['components/**'], dest: 'build/resource/' },
{ expand: true, src: ['assets/**'], dest: 'build/resource/' },
{ expand: true, src: ['node_modules/**'], dest: 'build/resource/' },
Expand All @@ -199,7 +205,8 @@ module.exports = function(grunt) {
clean: {
electron: ['./build'],
coverage: ['./coverage'],
'coverage-unit': ['./coverage/coverage-unit']
'coverage-unit': ['./coverage/coverage-unit'],
babel: ['./src']
},
electron: {
package: {
Expand Down Expand Up @@ -232,6 +239,32 @@ module.exports = function(grunt) {
mask: 'spec.*.js'
}
}
},
babel: {
prod: {
options: {
plugins: babelPlugins
},
files: [{
expand: true,
cwd: 'source',
src: ['**/*.js'],
dest: 'src',
ext: '.js'
}]
},
electron: {
options: {
presets: ['es2015', 'stage-0']
},
files: [{
expand: true,
cwd: 'source',
src: ['**/*.js'],
dest: 'src',
ext: '.js'
}]
}
}
});

Expand Down Expand Up @@ -393,9 +426,10 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-mocha-istanbul');
grunt.loadNpmTasks('grunt-babel');

// Default task, builds everything needed
grunt.registerTask('default', ['less:production', 'jshint', 'browserify-common', 'browserify-components', 'lineending:production', 'imageEmbed:default', 'copy:main', 'imagemin:default']);
grunt.registerTask('default', ['clean:babel', 'less:production', 'jshint', 'babel:prod', 'browserify-common', 'browserify-components', 'lineending:production', 'imageEmbed:default', 'copy:main', 'imagemin:default']);

// Run tests
grunt.registerTask('unittest', ['mochaTest']);
Expand All @@ -408,7 +442,7 @@ module.exports = function(grunt) {
grunt.registerTask('publishminor', ['default', 'test', 'release:minor']);

// Create electron package
grunt.registerTask('package', ['clean:electron', 'copy:electron', 'electron']);
grunt.registerTask('package', ['clean:electron', 'clean:babel', 'babel:electron', 'copy:electron', 'electron']);

// run unit test coverage, assumes project is compiled
grunt.registerTask('coverage-unit', ['clean:coverage-unit', 'mocha_istanbul:unit']);
Expand Down
6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -58,8 +58,10 @@
},
"devDependencies": {
"ansi-color": "~0.2.1",
"babel-core": "^5.8.34",
"babel-features": "*",
"babel-core": "~6.4.0",
"babel-features": "~2.0.0-beta",
"babel-preset-es2015": "~6.3.13",
"babel-preset-stage-0": "~6.3.13",
"browserify": "~11.2.0",
"electron-packager": "~5.1.0",
"expect.js": "~0.3.1",
Expand Down

0 comments on commit d543586

Please sign in to comment.