Skip to content
This repository has been archived by the owner on May 25, 2019. It is now read-only.

Commit

Permalink
Merge pull request #543 from thejameskyle/tjk/babel
Browse files Browse the repository at this point in the history
Add support for Babel
  • Loading branch information
silvenon committed Jun 13, 2015
2 parents 8845120 + 785b143 commit 34453b8
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 59 deletions.
16 changes: 6 additions & 10 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ module.exports = yeoman.generators.Base.extend({
});
this.testFramework = this.options['test-framework'];

this.option('coffee', {
desc: 'Use CoffeeScript',
this.option('babel', {
desc: 'Use Babel',
type: Boolean,
defaults: false
defaults: true
});
this.coffee = this.options.coffee;
this.babel = this.options.babel;

this.pkg = require('../package.json');
},
Expand Down Expand Up @@ -167,11 +167,7 @@ module.exports = yeoman.generators.Base.extend({
this.mkdir('app/images');
this.write('app/index.html', this.indexFile);

if (this.coffee) {
this.copy('main.coffee', 'app/scripts/main.coffee');
} else {
this.copy('main.js', 'app/scripts/main.js');
}
this.copy('main.js', 'app/scripts/main.js');
},

install: function () {
Expand All @@ -180,7 +176,7 @@ module.exports = yeoman.generators.Base.extend({
options: {
'skip-message': this.options['skip-install-message'],
'skip-install': this.options['skip-install'],
'coffee': this.options.coffee
'babel': this.options.babel
}
});

Expand Down
36 changes: 18 additions & 18 deletions app/templates/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ module.exports = function (grunt) {
bower: {
files: ['bower.json'],
tasks: ['wiredep']
},<% if (coffee) { %>
coffee: {
files: ['<%%= config.app %>/scripts/{,*/}*.{coffee,litcoffee,coffee.md}'],
tasks: ['coffee:dist']
},<% if (babel) { %>
babel: {
files: ['<%%= config.app %>/scripts/{,*/}*.js'],
tasks: ['babel:dist']
},
coffeeTest: {
files: ['test/spec/{,*/}*.{coffee,litcoffee,coffee.md}'],
tasks: ['coffee:test', 'test:watch']
babelTest: {
files: ['test/spec/{,*/}*.js'],
tasks: ['babel:test', 'test:watch']
},<% } else { %>
js: {
files: ['<%%= config.app %>/scripts/{,*/}*.js'],
Expand Down Expand Up @@ -155,15 +155,15 @@ module.exports = function (grunt) {
specs: 'test/spec/{,*/}*.js'
}
}
},<% } %><% if (coffee) { %>
},<% } %><% if (babel) { %>

// Compiles CoffeeScript to JavaScript
coffee: {
// Compiles ES6 with Babel
babel: {
dist: {
files: [{
expand: true,
cwd: '<%%= config.app %>/scripts',
src: '{,*/}*.{coffee,litcoffee,coffee.md}',
src: '{,*/}*.js',
dest: '.tmp/scripts',
ext: '.js'
}]
Expand All @@ -172,7 +172,7 @@ module.exports = function (grunt) {
files: [{
expand: true,
cwd: 'test/spec',
src: '{,*/}*.{coffee,litcoffee,coffee.md}',
src: '{,*/}*.js',
dest: '.tmp/spec',
ext: '.js'
}]
Expand Down Expand Up @@ -405,17 +405,17 @@ module.exports = function (grunt) {

// Run some tasks in parallel to speed up build process
concurrent: {
server: [<% if (coffee) { %>
'coffee:dist',<% } %><% if (includeSass) { %>
server: [<% if (babel) { %>
'babel:dist',<% } %><% if (includeSass) { %>
'sass:server'<% } else { %>
'copy:styles'<% } %>
],
test: [<% if (coffee) { %>
'coffee'<% } %><% if (coffee && !includeSass) { %>,<% } %><% if (!includeSass) { %>
test: [<% if (babel) { %>
'babel'<% } %><% if (babel && !includeSass) { %>,<% } %><% if (!includeSass) { %>
'copy:styles'<% } %>
],
dist: [<% if (coffee) { %>
'coffee',<% } %><% if (includeSass) { %>
dist: [<% if (babel) { %>
'babel',<% } %><% if (includeSass) { %>
'sass',<% } else { %>
'copy:styles',<% } %>
'imagemin',
Expand Down
4 changes: 2 additions & 2 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"grunt-autoprefixer": "^2.2.0",
"grunt-browser-sync": "^2.1.2",
"grunt-concurrent": "^1.0.0",
"grunt-contrib-clean": "^0.6.0",<% if (coffee) { %>
"grunt-contrib-coffee": "^0.13.0",<% } %>
"grunt-contrib-clean": "^0.6.0",<% if (babel) { %>
"grunt-babel": "^5.0.0",<% } %>
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-copy": "^0.8.0",
"grunt-contrib-cssmin": "^0.12.2",
Expand Down
2 changes: 0 additions & 2 deletions app/templates/main.coffee

This file was deleted.

7 changes: 3 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

* CSS Autoprefixing
* Built-in preview server with LiveReload
* Automagically compile CoffeeScript & Sass
* Automagically compile ES6 (with Babel) & Sass
* Automagically lint your scripts
* Automagically wire up your Bower components with [grunt-wiredep](#third-party-dependencies).
* Awesome Image Optimization (via OptiPNG, pngquant, jpegtran and gifsicle)
Expand Down Expand Up @@ -66,10 +66,9 @@ We have [recipes](docs/recipes) for integrating other popular technologies like

Defaults to `mocha`. Can be switched for another supported testing framework like `jasmine`.

* `--coffee`

Add support for [CoffeeScript](http://coffeescript.org/).
* `--babel`

Add support for [Babel](http://babeljs.io/).

## Contribute

Expand Down
37 changes: 14 additions & 23 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ describe('Webapp generator', function () {
'app/scripts/main.js'
));
assert.noFile([
'app/styles/main.scss',
'app/scripts/main.coffee'
'app/styles/main.scss'
]);

assert.fileContent(expectedContent);
assert.noFileContent([
['Gruntfile.js', /coffee/],
['Gruntfile.js', /modernizr/],
['app/index.html', /modernizr/],
['bower.json', /modernizr/],
Expand All @@ -80,26 +78,6 @@ describe('Webapp generator', function () {
});
});

it('creates expected CoffeeScript files', function (done) {
runGen.withOptions(
_.extend(options, {coffee: true})
).on('end', function () {

assert.file([].concat(
expected,
'app/scripts/main.coffee'
));
assert.noFile('app/scripts/main.js');

assert.fileContent([].concat(
expectedContent,
[['Gruntfile.js', /coffee/]]
));

done();
});
});

it('creates expected modernizr components', function (done) {
runGen.withOptions(options).withPrompt({features: ['includeModernizr']})
.on('end', function () {
Expand Down Expand Up @@ -160,5 +138,18 @@ describe('Webapp generator', function () {
done();
});
});

it('creates the expected Babel config', function (done) {
runGen.withOptions(
_.extend(options, { babel: true })
).on('end', function () {
assert.fileContent([
['Gruntfile.js', /babel/],
['package.json', /babel/]
]);

done();
});
});
});
});

0 comments on commit 34453b8

Please sign in to comment.