Skip to content

feat(app): Add Babel option #998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down
52 changes: 45 additions & 7 deletions app/templates/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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}'
Expand Down Expand Up @@ -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) { %>
Expand All @@ -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) { %>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) { %>
Expand Down
4 changes: 3 additions & 1 deletion app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"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) { %>
"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",
Expand Down
4 changes: 4 additions & 0 deletions app/templates/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@
<script src="socket.io-client/socket.io.js"></script><% } %>
<!-- endbuild -->

<% if(filters.babel) { %>
<!-- build:js(.tmp) app/app.js -->
<% } else { %>
<!-- build:js({.tmp,client}) app/app.js -->
<% } %>
<script src="app/app.js"></script>
<!-- injector:js -->
<!-- endinjector -->
Expand Down
17 changes: 16 additions & 1 deletion app/templates/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},

Expand All @@ -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: [],

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.*",
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
43 changes: 43 additions & 0 deletions test/test-file-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down