Skip to content

Commit bc03aba

Browse files
Carson BruceAwk34
Carson Bruce
authored andcommitted
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
1 parent f6f912f commit bc03aba

File tree

5 files changed

+105
-8
lines changed

5 files changed

+105
-8
lines changed

Diff for: app/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({
7878

7979
return filterMap[val];
8080
}
81+
}, {
82+
type: "confirm",
83+
name: "babel",
84+
message: "Would you like to use Javascript ES6 in your client by preprocessing it with Babel?",
85+
when: function (answers) {
86+
return answers.script === 'js';
87+
}
8188
}, {
8289
type: "list",
8390
name: "markup",
@@ -110,6 +117,9 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({
110117
return answers.bootstrap;
111118
}
112119
}], function (answers) {
120+
121+
this.filters.babel = !!answers.babel;
122+
if(this.filters.babel){ this.filters.js = true; }
113123
this.filters[answers.script] = true;
114124
this.filters[answers.markup] = true;
115125
this.filters[answers.stylesheet] = true;
@@ -211,6 +221,7 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({
211221

212222
if(this.filters.ngroute) filters.push('ngroute');
213223
if(this.filters.uirouter) filters.push('uirouter');
224+
if(this.filters.babel) extensions.push('babel');
214225
if(this.filters.coffee) extensions.push('coffee');
215226
if(this.filters.js) extensions.push('js');
216227
if(this.filters.html) extensions.push('html');

Diff for: app/templates/Gruntfile.js

+45-7
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ module.exports = function (grunt) {
127127
'<%%= yeoman.client %>/{app,components}/**/*.spec.{coffee,litcoffee,coffee.md}'
128128
],
129129
tasks: ['karma']
130+
},<% } %><% if(filters.babel) { %>
131+
babel: {
132+
files: [
133+
'<%%= yeoman.client %>/{app,components}/**/*.js',
134+
'!<%%= yeoman.client %>/{app,components}/**/*.spec.js'
135+
],
136+
tasks: ['babel']
130137
},<% } %>
131138
gruntfile: {
132139
files: ['Gruntfile.js']
@@ -135,7 +142,11 @@ module.exports = function (grunt) {
135142
files: [
136143
'{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.css',
137144
'{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.html',
145+
<% if(filters.babel) { %>
146+
'.tmp/{app,components}/**/*.js',
147+
<% } else { %>
138148
'{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.js',
149+
<% } %>
139150
'!{.tmp,<%%= yeoman.client %>}{app,components}/**/*.spec.js',
140151
'!{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.mock.js',
141152
'<%%= yeoman.client %>/assets/images/{,*//*}*.{png,jpg,jpeg,gif,webp,svg}'
@@ -442,14 +453,16 @@ module.exports = function (grunt) {
442453
// Run some tasks in parallel to speed up the build process
443454
concurrent: {
444455
server: [<% if(filters.coffee) { %>
445-
'coffee',<% } %><% if(filters.jade) { %>
456+
'coffee',<% } %><% if(filters.babel) { %>
457+
'babel',<% } %><% if(filters.jade) { %>
446458
'jade',<% } %><% if(filters.stylus) { %>
447459
'stylus',<% } %><% if(filters.sass) { %>
448460
'sass',<% } %><% if(filters.less) { %>
449461
'less',<% } %>
450462
],
451463
test: [<% if(filters.coffee) { %>
452-
'coffee',<% } %><% if(filters.jade) { %>
464+
'coffee',<% } %><% if(filters.babel) { %>
465+
'babel',<% } %><% if(filters.jade) { %>
453466
'jade',<% } %><% if(filters.stylus) { %>
454467
'stylus',<% } %><% if(filters.sass) { %>
455468
'sass',<% } %><% if(filters.less) { %>
@@ -465,7 +478,8 @@ module.exports = function (grunt) {
465478
}
466479
},
467480
dist: [<% if(filters.coffee) { %>
468-
'coffee',<% } %><% if(filters.jade) { %>
481+
'coffee',<% } %><% if(filters.babel) { %>
482+
'babel',<% } %><% if(filters.jade) { %>
469483
'jade',<% } %><% if(filters.stylus) { %>
470484
'stylus',<% } %><% if(filters.sass) { %>
471485
'sass',<% } %><% if(filters.less) { %>
@@ -551,6 +565,24 @@ module.exports = function (grunt) {
551565
ext: '.js'
552566
}]
553567
}
568+
},<% } %><% if(filters.babel) { %>
569+
570+
// Compiles ES6 to JavaScript using Babel
571+
babel: {
572+
options: {
573+
sourceMap: true
574+
},
575+
server: {
576+
files: [{
577+
expand: true,
578+
cwd: 'client',
579+
src: [
580+
'{app,components}/**/*.js',
581+
'!{app,components}/**/*.spec.js'
582+
],
583+
dest: '.tmp'
584+
}]
585+
}
554586
},<% } %><% if(filters.stylus) { %>
555587

556588
// Compiles Stylus to CSS
@@ -620,10 +652,16 @@ module.exports = function (grunt) {
620652
},
621653
files: {
622654
'<%%= yeoman.client %>/index.html': [
623-
['{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.js',
624-
'!{.tmp,<%%= yeoman.client %>}/app/app.js',
625-
'!{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.spec.js',
626-
'!{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.mock.js']
655+
[
656+
<% if(filters.babel) { %>
657+
'.tmp/{app,components}/**/*.js',
658+
<% } else { %>
659+
'{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.js',
660+
<% } %>
661+
'!{.tmp,<%%= yeoman.client %>}/app/app.js',
662+
'!{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.spec.js',
663+
'!{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.mock.js'
664+
]
627665
]
628666
}
629667
},<% if(filters.stylus) { %>

Diff for: app/templates/_package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"grunt-contrib-watch": "~0.6.1",<% if(filters.coffee) { %>
4646
"grunt-contrib-coffee": "^0.10.1",<% } %><% if(filters.jade) { %>
4747
"grunt-contrib-jade": "^0.11.0",<% } %><% if(filters.less) { %>
48-
"grunt-contrib-less": "^0.11.0",<% } %>
48+
"grunt-contrib-less": "^0.11.0",<% } %><% if(filters.babel) { %>
49+
"grunt-babel": "~5.0.0",<% } %>
4950
"grunt-google-cdn": "~0.4.0",
5051
"grunt-newer": "~0.7.0",
5152
"grunt-ng-annotate": "^0.2.3",

Diff for: app/templates/client/index.html

+4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
<script src="socket.io-client/socket.io.js"></script><% } %>
5151
<!-- endbuild -->
5252

53+
<% if(filters.babel) { %>
54+
<!-- build:js(.tmp) app/app.js -->
55+
<% } else { %>
5356
<!-- build:js({.tmp,client}) app/app.js -->
57+
<% } %>
5458
<script src="app/app.js"></script>
5559
<!-- injector:js -->
5660
<!-- endinjector -->

Diff for: test/test-file-creation.js

+43
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,49 @@ describe('angular-fullstack generator', function () {
145145
// });
146146
});
147147

148+
describe('with Babel ES6 preprocessor', function() {
149+
beforeEach(function() {
150+
helpers.mockPrompt(gen, {
151+
script: 'js',
152+
babel: true,
153+
markup: 'jade',
154+
stylesheet: 'less',
155+
router: 'uirouter'
156+
});
157+
});
158+
159+
it('should run client tests successfully', function(done) {
160+
this.timeout(60000);
161+
gen.run({}, function () {
162+
exec('grunt test:client', function (error, stdout, stderr) {
163+
expect(stdout, 'Client tests failed \n' + stdout ).to.contain('Executed 1 of 1\u001b[32m SUCCESS\u001b');
164+
done();
165+
});
166+
});
167+
});
168+
169+
it('should pass jshint', function(done) {
170+
this.timeout(60000);
171+
gen.run({}, function () {
172+
exec('grunt jshint', function (error, stdout, stderr) {
173+
expect(stdout).to.contain('Done, without errors.');
174+
done();
175+
});
176+
});
177+
});
178+
179+
it('should run server tests successfully', function(done) {
180+
this.timeout(60000);
181+
gen.run({}, function () {
182+
exec('grunt test:server', function (error, stdout, stderr) {
183+
expect(stdout, 'Server tests failed (do you have mongoDB running?) \n' + stdout).to.contain('Done, without errors.');
184+
done();
185+
});
186+
});
187+
});
188+
});
189+
190+
148191
describe('with other preprocessors and oauth', function() {
149192
beforeEach(function() {
150193
helpers.mockPrompt(gen, {

0 commit comments

Comments
 (0)