From bc03aba9ee82812f29f4ec9f86daf3b8d1c531b8 Mon Sep 17 00:00:00 2001 From: Carson Bruce Date: Wed, 22 Apr 2015 15:57:24 +1200 Subject: [PATCH 1/5] feat(app): additional app generator option for ES6 preprocessing using babel Added a follow up question to the first language selection question to enable ES6 client support with Babel. Related issue: Any plans for es6 and traceur support? #684 --- app/index.js | 11 +++++++ app/templates/Gruntfile.js | 52 ++++++++++++++++++++++++++++----- app/templates/_package.json | 3 +- app/templates/client/index.html | 4 +++ test/test-file-creation.js | 43 +++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 8 deletions(-) diff --git a/app/index.js b/app/index.js index 6e4724801..194b337a6 100644 --- a/app/index.js +++ b/app/index.js @@ -78,6 +78,13 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({ return filterMap[val]; } + }, { + type: "confirm", + name: "babel", + message: "Would you like to use Javascript ES6 in your client by preprocessing it with Babel?", + when: function (answers) { + return answers.script === 'js'; + } }, { type: "list", name: "markup", @@ -110,6 +117,9 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({ return answers.bootstrap; } }], function (answers) { + + this.filters.babel = !!answers.babel; + if(this.filters.babel){ this.filters.js = true; } this.filters[answers.script] = true; this.filters[answers.markup] = true; this.filters[answers.stylesheet] = true; @@ -211,6 +221,7 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({ if(this.filters.ngroute) filters.push('ngroute'); if(this.filters.uirouter) filters.push('uirouter'); + if(this.filters.babel) extensions.push('babel'); if(this.filters.coffee) extensions.push('coffee'); if(this.filters.js) extensions.push('js'); if(this.filters.html) extensions.push('html'); diff --git a/app/templates/Gruntfile.js b/app/templates/Gruntfile.js index a0267aaa4..96a662066 100644 --- a/app/templates/Gruntfile.js +++ b/app/templates/Gruntfile.js @@ -127,6 +127,13 @@ module.exports = function (grunt) { '<%%= yeoman.client %>/{app,components}/**/*.spec.{coffee,litcoffee,coffee.md}' ], tasks: ['karma'] + },<% } %><% if(filters.babel) { %> + babel: { + files: [ + '<%%= yeoman.client %>/{app,components}/**/*.js', + '!<%%= yeoman.client %>/{app,components}/**/*.spec.js' + ], + tasks: ['babel'] },<% } %> gruntfile: { files: ['Gruntfile.js'] @@ -135,7 +142,11 @@ module.exports = function (grunt) { files: [ '{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.css', '{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.html', + <% if(filters.babel) { %> + '.tmp/{app,components}/**/*.js', + <% } else { %> '{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.js', + <% } %> '!{.tmp,<%%= yeoman.client %>}{app,components}/**/*.spec.js', '!{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.mock.js', '<%%= yeoman.client %>/assets/images/{,*//*}*.{png,jpg,jpeg,gif,webp,svg}' @@ -442,14 +453,16 @@ module.exports = function (grunt) { // Run some tasks in parallel to speed up the build process concurrent: { server: [<% if(filters.coffee) { %> - 'coffee',<% } %><% if(filters.jade) { %> + 'coffee',<% } %><% if(filters.babel) { %> + 'babel',<% } %><% if(filters.jade) { %> 'jade',<% } %><% if(filters.stylus) { %> 'stylus',<% } %><% if(filters.sass) { %> 'sass',<% } %><% if(filters.less) { %> 'less',<% } %> ], test: [<% if(filters.coffee) { %> - 'coffee',<% } %><% if(filters.jade) { %> + 'coffee',<% } %><% if(filters.babel) { %> + 'babel',<% } %><% if(filters.jade) { %> 'jade',<% } %><% if(filters.stylus) { %> 'stylus',<% } %><% if(filters.sass) { %> 'sass',<% } %><% if(filters.less) { %> @@ -465,7 +478,8 @@ module.exports = function (grunt) { } }, dist: [<% if(filters.coffee) { %> - 'coffee',<% } %><% if(filters.jade) { %> + 'coffee',<% } %><% if(filters.babel) { %> + 'babel',<% } %><% if(filters.jade) { %> 'jade',<% } %><% if(filters.stylus) { %> 'stylus',<% } %><% if(filters.sass) { %> 'sass',<% } %><% if(filters.less) { %> @@ -551,6 +565,24 @@ module.exports = function (grunt) { ext: '.js' }] } + },<% } %><% if(filters.babel) { %> + + // Compiles ES6 to JavaScript using Babel + babel: { + options: { + sourceMap: true + }, + server: { + files: [{ + expand: true, + cwd: 'client', + src: [ + '{app,components}/**/*.js', + '!{app,components}/**/*.spec.js' + ], + dest: '.tmp' + }] + } },<% } %><% if(filters.stylus) { %> // Compiles Stylus to CSS @@ -620,10 +652,16 @@ module.exports = function (grunt) { }, files: { '<%%= yeoman.client %>/index.html': [ - ['{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.js', - '!{.tmp,<%%= yeoman.client %>}/app/app.js', - '!{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.spec.js', - '!{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.mock.js'] + [ + <% if(filters.babel) { %> + '.tmp/{app,components}/**/*.js', + <% } else { %> + '{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.js', + <% } %> + '!{.tmp,<%%= yeoman.client %>}/app/app.js', + '!{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.spec.js', + '!{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.mock.js' + ] ] } },<% if(filters.stylus) { %> diff --git a/app/templates/_package.json b/app/templates/_package.json index e8c64559b..5d0592941 100644 --- a/app/templates/_package.json +++ b/app/templates/_package.json @@ -45,7 +45,8 @@ "grunt-contrib-watch": "~0.6.1",<% if(filters.coffee) { %> "grunt-contrib-coffee": "^0.10.1",<% } %><% if(filters.jade) { %> "grunt-contrib-jade": "^0.11.0",<% } %><% if(filters.less) { %> - "grunt-contrib-less": "^0.11.0",<% } %> + "grunt-contrib-less": "^0.11.0",<% } %><% if(filters.babel) { %> + "grunt-babel": "~5.0.0",<% } %> "grunt-google-cdn": "~0.4.0", "grunt-newer": "~0.7.0", "grunt-ng-annotate": "^0.2.3", diff --git a/app/templates/client/index.html b/app/templates/client/index.html index e823e372d..e9dcd5729 100644 --- a/app/templates/client/index.html +++ b/app/templates/client/index.html @@ -50,7 +50,11 @@ <% } %> + <% if(filters.babel) { %> + + <% } else { %> + <% } %> diff --git a/test/test-file-creation.js b/test/test-file-creation.js index 774a6f658..beb8b14b8 100644 --- a/test/test-file-creation.js +++ b/test/test-file-creation.js @@ -145,6 +145,49 @@ describe('angular-fullstack generator', function () { // }); }); + describe('with Babel ES6 preprocessor', function() { + beforeEach(function() { + helpers.mockPrompt(gen, { + script: 'js', + babel: true, + markup: 'jade', + stylesheet: 'less', + router: 'uirouter' + }); + }); + + it('should run client tests successfully', function(done) { + this.timeout(60000); + gen.run({}, function () { + exec('grunt test:client', function (error, stdout, stderr) { + expect(stdout, 'Client tests failed \n' + stdout ).to.contain('Executed 1 of 1\u001b[32m SUCCESS\u001b'); + done(); + }); + }); + }); + + it('should pass jshint', function(done) { + this.timeout(60000); + gen.run({}, function () { + exec('grunt jshint', function (error, stdout, stderr) { + expect(stdout).to.contain('Done, without errors.'); + done(); + }); + }); + }); + + it('should run server tests successfully', function(done) { + this.timeout(60000); + gen.run({}, function () { + exec('grunt test:server', function (error, stdout, stderr) { + expect(stdout, 'Server tests failed (do you have mongoDB running?) \n' + stdout).to.contain('Done, without errors.'); + done(); + }); + }); + }); + }); + + describe('with other preprocessors and oauth', function() { beforeEach(function() { helpers.mockPrompt(gen, { From 7a3b6d4b0d5c30803f1716568f02b9111cb9ace4 Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Tue, 16 Jun 2015 16:32:38 -0400 Subject: [PATCH 2/5] docs(readme): Add Babel to list of available scripting languages --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index cca4ac419..5d11f17aa 100644 --- a/readme.md +++ b/readme.md @@ -35,7 +35,7 @@ Run `grunt` for building, `grunt serve` for preview, and `grunt serve:dist` for **Client** -* Scripts: `JavaScript`, `CoffeeScript` +* Scripts: `JavaScript`, `CoffeeScript`, `Babel` * Markup: `HTML`, `Jade` * Stylesheets: `CSS`, `Stylus`, `Sass`, `Less`, * Angular Routers: `ngRoute`, `ui-router` From cbb06a48e28c594a53f61e49857cbb711bd74ce9 Mon Sep 17 00:00:00 2001 From: Carson Bruce Date: Wed, 17 Jun 2015 09:58:45 +1200 Subject: [PATCH 3/5] feat(app): additional app generator option for ES6 preprocessing using babel Building on from the ES6 client preprocessor have added karma config and related karma-babel-preprocessor module for ES6 client tests for complete ES6 client support Related issue: Any plans for es6 and traceur support? #684 --- app/templates/_package.json | 1 + app/templates/karma.conf.js | 17 ++++++++++++++++- test/fixtures/bower.json | 1 - test/fixtures/package.json | 4 +++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/templates/_package.json b/app/templates/_package.json index 5d0592941..fc374be27 100644 --- a/app/templates/_package.json +++ b/app/templates/_package.json @@ -46,6 +46,7 @@ "grunt-contrib-coffee": "^0.10.1",<% } %><% if(filters.jade) { %> "grunt-contrib-jade": "^0.11.0",<% } %><% if(filters.less) { %> "grunt-contrib-less": "^0.11.0",<% } %><% if(filters.babel) { %> + "karma-babel-preprocessor": "^5.2.1", "grunt-babel": "~5.0.0",<% } %> "grunt-google-cdn": "~0.4.0", "grunt-newer": "~0.7.0", diff --git a/app/templates/karma.conf.js b/app/templates/karma.conf.js index 57b3fa6f2..e7307a90a 100644 --- a/app/templates/karma.conf.js +++ b/app/templates/karma.conf.js @@ -36,7 +36,8 @@ module.exports = function(config) { preprocessors: { '**/*.jade': 'ng-jade2js', - '**/*.html': 'html2js', + '**/*.html': 'html2js',<% if(filters.babel) { %> + 'client/app/**/*.js': 'babel',<% } %> '**/*.coffee': 'coffee', }, @@ -48,6 +49,20 @@ module.exports = function(config) { stripPrefix: 'client/' }, + <% if(filters.babel) { %> + babelPreprocessor: { + options: { + sourceMap: 'inline' + }, + filename: function (file) { + return file.originalPath.replace(/\.js$/, '.es5.js'); + }, + sourceFileName: function (file) { + return file.originalPath; + } + }, + <% } %> + // list of files / patterns to exclude exclude: [], diff --git a/test/fixtures/bower.json b/test/fixtures/bower.json index 7d9aae354..10dff6513 100644 --- a/test/fixtures/bower.json +++ b/test/fixtures/bower.json @@ -5,7 +5,6 @@ "angular": ">=1.2.*", "json3": "~3.3.1", "es5-shim": "~3.0.1", - "jquery": "~1.11.0", "bootstrap-sass-official": "~3.1.1", "bootstrap": "~3.1.1", "angular-resource": ">=1.2.*", diff --git a/test/fixtures/package.json b/test/fixtures/package.json index 856e4fcc2..c110f7838 100644 --- a/test/fixtures/package.json +++ b/test/fixtures/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "main": "server/app.js", "dependencies": { - "express": "~4.0.0", + "express": "~4.9.0", "morgan": "~1.0.0", "body-parser": "~1.5.0", "method-override": "~1.0.0", @@ -46,6 +46,8 @@ "grunt-contrib-coffee": "^0.10.1", "grunt-contrib-jade": "^0.11.0", "grunt-contrib-less": "^0.11.0", + "karma-babel-preprocessor": "^5.2.1", + "grunt-babel": "~5.0.0", "grunt-google-cdn": "~0.4.0", "grunt-newer": "~0.7.0", "grunt-ng-annotate": "^0.2.3", From acecde9d0e02b579d4b0a2a33d7c0f24067258ec Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Wed, 17 Jun 2015 00:45:10 -0400 Subject: [PATCH 4/5] fix(travis): Add nodejs 12 to travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 85fbe4a6b..5434c4542 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: node_js node_js: - '0.10' - '0.11' + - '0.12' before_install: - gem update --system - gem install sass --version "=3.3.7" From 498d7516b3d171c36e001330acbe2b2b9de6fd38 Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Wed, 17 Jun 2015 00:54:06 -0400 Subject: [PATCH 5/5] Revert "fix(travis): Add nodejs 12 to travis.yml" This reverts commit acecde9d0e02b579d4b0a2a33d7c0f24067258ec. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5434c4542..85fbe4a6b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: node_js node_js: - '0.10' - '0.11' - - '0.12' before_install: - gem update --system - gem install sass --version "=3.3.7"