From 60334a8d43c2d53a4e994dad5ba201590982ae91 Mon Sep 17 00:00:00 2001 From: kingcody Date: Wed, 24 Jun 2015 05:41:37 -0400 Subject: [PATCH] feat(server): implement server-side ES6 via babel --- app/templates/Gruntfile.js | 29 +++++++--------------- app/templates/_package.json | 5 ++-- app/templates/mocha.conf.js | 5 +++- app/templates/server/index.js | 7 ++++++ test/test-file-creation.js | 45 ++--------------------------------- 5 files changed, 25 insertions(+), 66 deletions(-) create mode 100644 app/templates/server/index.js diff --git a/app/templates/Gruntfile.js b/app/templates/Gruntfile.js index 028300e68..8d2ef6c96 100644 --- a/app/templates/Gruntfile.js +++ b/app/templates/Gruntfile.js @@ -39,13 +39,13 @@ module.exports = function (grunt) { }, dev: { options: { - script: 'server/app.js', + script: 'server', debug: true } }, prod: { options: { - script: 'dist/server/app.js' + script: 'dist/server' } } }, @@ -61,7 +61,7 @@ module.exports = function (grunt) { '!<%%= yeoman.client %>/{app,components}/**/*.spec.js', '!<%%= yeoman.client %>/{app,components}/**/*.mock.js', '!<%%= yeoman.client %>/app/app.js'], - tasks: ['injector:scripts'] + tasks: [<% if(filters.babel) { %>'newer:babel:client', <% } %>'injector:scripts'] }, injectCss: { files: [ @@ -128,13 +128,6 @@ 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'] @@ -143,11 +136,7 @@ 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}' @@ -261,7 +250,7 @@ module.exports = function (grunt) { // Use nodemon to run server in debug mode with an initial breakpoint nodemon: { debug: { - script: 'server/app.js', + script: 'server', options: { nodeArgs: ['--debug-brk'], env: { @@ -470,7 +459,7 @@ module.exports = function (grunt) { concurrent: { server: [<% if(filters.coffee) { %> 'coffee',<% } %><% if(filters.babel) { %> - 'babel',<% } %><% if(filters.jade) { %> + 'newer:babel:client',<% } %><% if(filters.jade) { %> 'jade',<% } %><% if(filters.stylus) { %> 'stylus',<% } %><% if(filters.sass) { %> 'sass',<% } %><% if(filters.less) { %> @@ -478,7 +467,7 @@ module.exports = function (grunt) { ], test: [<% if(filters.coffee) { %> 'coffee',<% } %><% if(filters.babel) { %> - 'babel',<% } %><% if(filters.jade) { %> + 'newer:babel:client',<% } %><% if(filters.jade) { %> 'jade',<% } %><% if(filters.stylus) { %> 'stylus',<% } %><% if(filters.sass) { %> 'sass',<% } %><% if(filters.less) { %> @@ -495,7 +484,7 @@ module.exports = function (grunt) { }, dist: [<% if(filters.coffee) { %> 'coffee',<% } %><% if(filters.babel) { %> - 'babel',<% } %><% if(filters.jade) { %> + 'newer:babel:client',<% } %><% if(filters.jade) { %> 'jade',<% } %><% if(filters.stylus) { %> 'stylus',<% } %><% if(filters.sass) { %> 'sass',<% } %><% if(filters.less) { %> @@ -639,10 +628,10 @@ module.exports = function (grunt) { options: { sourceMap: true }, - server: { + client: { files: [{ expand: true, - cwd: 'client', + cwd: '<%%= yeoman.client %>', src: [ '{app,components}/**/*.js', '!{app,components}/**/*.spec.js' diff --git a/app/templates/_package.json b/app/templates/_package.json index 346ec2078..1356bab64 100644 --- a/app/templates/_package.json +++ b/app/templates/_package.json @@ -12,7 +12,8 @@ "express-session": "~1.0.2", "errorhandler": "~1.0.0", "compression": "~1.0.1", - "lodash": "~2.4.1",<% if (filters.jade) { %> + "lodash": "~2.4.1",<% if(filters.babel) { %> + "babel-core": "^5.6.4",<% } %><% if (filters.jade) { %> "jade": "~1.2.0",<% } %><% if (filters.html) { %> "ejs": "~0.8.4",<% } %><% if (filters.mongoose) { %> "mongoose": "~3.8.8", @@ -106,7 +107,7 @@ "node": ">=0.10.0" }, "scripts": { - "start": "node server/app.js", + "start": "node server", "test": "grunt test", "update-webdriver": "node node_modules/grunt-protractor-runner/node_modules/protractor/bin/webdriver-manager update" }, diff --git a/app/templates/mocha.conf.js b/app/templates/mocha.conf.js index 54e33bb6f..6b1504e9c 100644 --- a/app/templates/mocha.conf.js +++ b/app/templates/mocha.conf.js @@ -1,4 +1,7 @@ -'use strict'; +'use strict';<% if(filters.babel) { %> + +// Register the Babel require hook +require('babel-core/register');<% } %> var chai = require('chai'); diff --git a/app/templates/server/index.js b/app/templates/server/index.js new file mode 100644 index 000000000..7722a0e6c --- /dev/null +++ b/app/templates/server/index.js @@ -0,0 +1,7 @@ +'use strict';<% if (filters.babel) { %> + +// Register the Babel require hook +require('babel-core/register');<% } %> + +// Export the application +exports = module.exports = require('./app'); diff --git a/test/test-file-creation.js b/test/test-file-creation.js index a863700be..ec794c7ab 100644 --- a/test/test-file-creation.js +++ b/test/test-file-creation.js @@ -11,6 +11,7 @@ var recursiveReadDir = require('recursive-readdir'); describe('angular-fullstack generator', function () { var gen, defaultOptions = { script: 'js', + babel: true, markup: 'html', stylesheet: 'sass', router: 'uirouter', @@ -176,6 +177,7 @@ describe('angular-fullstack generator', function () { 'server/.jshintrc', 'server/.jshintrc-spec', 'server/app.js', + 'server/index.js', 'server/routes.js', 'server/api/thing/index.js', 'server/api/thing/index.spec.js', @@ -476,49 +478,6 @@ 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 SUCCESS'); - 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() { var testOptions = { script: 'coffee',