diff --git a/app/index.js b/app/index.js index b37b8b1..ad0532b 100644 --- a/app/index.js +++ b/app/index.js @@ -86,6 +86,11 @@ ExpressGenerator.prototype.promptDatabase = function () { }; ExpressGenerator.prototype.promptBuildTool = function () { + + if (this.options.buildTool) { + return true; + } + var done = this.async(); var prompt = [{ type: 'list', @@ -106,7 +111,7 @@ ExpressGenerator.prototype.promptBuildTool = function () { ExpressGenerator.prototype.buildEnv = function buildEnv() { this.sourceRoot(path.join(__dirname, 'templates', 'common')); this.expandFiles('**', { cwd: this.sourceRoot() }).map(function (file) { - this.template(file, file.replace(/^_/, '')); + this.template(file, file.replace(/^_/, '')); }, this); var name = this.options.mvc ? 'mvc' : 'basic'; @@ -128,6 +133,8 @@ ExpressGenerator.prototype.buildEnv = function buildEnv() { if (this.options.database === 'mysql' || this.options.database === 'postgresql') { this.copy(path.join(__dirname, 'templates', 'extras', name, 'model-index.' + filetype), 'app/models/index.' + filetype); } + var buildFile = this.options.buildTool === 'grunt' ? 'Gruntfile.js' : 'gulpfile.js'; + this.copy(path.join(__dirname, 'templates', 'extras', name, buildFile), buildFile); }; ExpressGenerator.prototype.assetsDirs = function assetsDirs() { diff --git a/app/templates/basic-coffee/package.json b/app/templates/basic-coffee/package.json index 4ccf3d9..1ee6b1d 100644 --- a/app/templates/basic-coffee/package.json +++ b/app/templates/basic-coffee/package.json @@ -16,13 +16,16 @@ "jade": "~1.3.1"<% } %><% if(options.viewEngine == 'ejs'){ %>, "ejs": "~1.0.0"<% } %> }, - "devDependencies": { + "devDependencies": {<% if(options.buildTool == 'grunt'){ %> "grunt": "~0.4.5", "grunt-develop": "~0.4.0", "grunt-contrib-watch": "~0.6.1", "request": "~2.36.0", "time-grunt": "~0.3.2", "load-grunt-tasks": "~0.6.0", - "coffee-script": "^1.7.1" + "coffee-script": "^1.7.1"<% } %><% if(options.buildTool == 'gulp'){ %> + "gulp": "~3.8.8", + "gulp-nodemon": "~1.0.4", + "gulp-livereload": "~2.1.1"<% } %> } } diff --git a/app/templates/basic/package.json b/app/templates/basic/package.json index 5a551c7..3b9a7fa 100644 --- a/app/templates/basic/package.json +++ b/app/templates/basic/package.json @@ -15,12 +15,15 @@ "jade": "~1.3.1"<% } %><% if(options.viewEngine == 'ejs'){ %>, "ejs": "~1.0.0"<% } %> }, - "devDependencies": { + "devDependencies": {<% if(options.buildTool == 'grunt'){ %> "grunt": "~0.4.5", "grunt-develop": "~0.4.0", "grunt-contrib-watch": "~0.6.1", "request": "~2.36.0", "time-grunt": "~0.3.2", - "load-grunt-tasks": "~0.6.0" + "load-grunt-tasks": "~0.6.0"<% } %><% if(options.buildTool == 'gulp'){ %> + "gulp": "~3.8.8", + "gulp-nodemon": "~1.0.4", + "gulp-livereload": "~2.1.1"<% } %> } } diff --git a/app/templates/basic-coffee/Gruntfile.js b/app/templates/extras/basic-coffee/Gruntfile.js similarity index 100% rename from app/templates/basic-coffee/Gruntfile.js rename to app/templates/extras/basic-coffee/Gruntfile.js diff --git a/app/templates/extras/basic-coffee/gulpfile.js b/app/templates/extras/basic-coffee/gulpfile.js new file mode 100644 index 0000000..f589038 --- /dev/null +++ b/app/templates/extras/basic-coffee/gulpfile.js @@ -0,0 +1,17 @@ +var gulp = require('gulp'), + nodemon = require('gulp-nodemon'), + livereload = require('gulp-livereload'); + +gulp.task('develop', function () { + livereload.listen(); + nodemon({ + script: 'bin/www', + ext: 'js coffee <%= options.viewEngine %>', + }).on('restart', function () { + setTimeout(function () { + livereload.changed(); + }, 500); + }); +}); + +gulp.task('default', ['develop']); \ No newline at end of file diff --git a/app/templates/basic/Gruntfile.js b/app/templates/extras/basic/Gruntfile.js similarity index 100% rename from app/templates/basic/Gruntfile.js rename to app/templates/extras/basic/Gruntfile.js diff --git a/app/templates/extras/basic/gulpfile.js b/app/templates/extras/basic/gulpfile.js new file mode 100644 index 0000000..e112bcd --- /dev/null +++ b/app/templates/extras/basic/gulpfile.js @@ -0,0 +1,17 @@ +var gulp = require('gulp'), + nodemon = require('gulp-nodemon'), + livereload = require('gulp-livereload'); + +gulp.task('develop', function () { + livereload.listen(); + nodemon({ + script: 'bin/www', + ext: 'js <%= options.viewEngine %>', + }).on('restart', function () { + setTimeout(function () { + livereload.changed(); + }, 500); + }); +}); + +gulp.task('default', ['develop']); \ No newline at end of file diff --git a/app/templates/mvc-coffee/Gruntfile.js b/app/templates/extras/mvc-coffee/Gruntfile.js similarity index 100% rename from app/templates/mvc-coffee/Gruntfile.js rename to app/templates/extras/mvc-coffee/Gruntfile.js diff --git a/app/templates/extras/mvc-coffee/gulpfile.js b/app/templates/extras/mvc-coffee/gulpfile.js new file mode 100644 index 0000000..387ffe1 --- /dev/null +++ b/app/templates/extras/mvc-coffee/gulpfile.js @@ -0,0 +1,17 @@ +var gulp = require('gulp'), + nodemon = require('gulp-nodemon'), + livereload = require('gulp-livereload'); + +gulp.task('develop', function () { + livereload.listen(); + nodemon({ + script: 'app.js', + ext: 'js coffee <%= options.viewEngine %>', + }).on('restart', function () { + setTimeout(function () { + livereload.changed(); + }, 500); + }); +}); + +gulp.task('default', ['develop']); \ No newline at end of file diff --git a/app/templates/mvc/Gruntfile.js b/app/templates/extras/mvc/Gruntfile.js similarity index 100% rename from app/templates/mvc/Gruntfile.js rename to app/templates/extras/mvc/Gruntfile.js diff --git a/app/templates/extras/mvc/gulpfile.js b/app/templates/extras/mvc/gulpfile.js new file mode 100644 index 0000000..9869440 --- /dev/null +++ b/app/templates/extras/mvc/gulpfile.js @@ -0,0 +1,17 @@ +var gulp = require('gulp'), + nodemon = require('gulp-nodemon'), + livereload = require('gulp-livereload'); + +gulp.task('develop', function () { + livereload.listen(); + nodemon({ + script: 'app.js', + ext: 'js <%= options.viewEngine %>', + }).on('restart', function () { + setTimeout(function () { + livereload.changed(); + }, 500); + }); +}); + +gulp.task('default', ['develop']); \ No newline at end of file diff --git a/app/templates/mvc-coffee/package.json b/app/templates/mvc-coffee/package.json index 46e1778..5664a30 100644 --- a/app/templates/mvc-coffee/package.json +++ b/app/templates/mvc-coffee/package.json @@ -24,7 +24,7 @@ "jade": "~1.3.0"<% } %><% if(options.viewEngine == 'ejs'){ %>, "ejs": "~1.0.0"<% } %> }, - "devDependencies": { + "devDependencies": {<% if(options.buildTool == 'grunt'){ %> "grunt": "~0.4.5", "grunt-develop": "~0.4.0", "grunt-contrib-watch": "~0.6.1", @@ -32,6 +32,9 @@ "request": "~2.36.0", "time-grunt": "~0.3.2", "load-grunt-tasks": "~0.6.0", - "coffee-script": "^1.7.1" + "coffee-script": "^1.7.1"<% } %><% if(options.buildTool == 'gulp'){ %> + "gulp": "~3.8.8", + "gulp-nodemon": "~1.0.4", + "gulp-livereload": "~2.1.1"<% } %> } } diff --git a/app/templates/mvc/package.json b/app/templates/mvc/package.json index d066678..2aab5ce 100644 --- a/app/templates/mvc/package.json +++ b/app/templates/mvc/package.json @@ -25,13 +25,16 @@ "jade": "~1.3.0"<% } %><% if(options.viewEngine == 'ejs'){ %>, "ejs": "~1.0.0"<% } %> }, - "devDependencies": { + "devDependencies": {<% if(options.buildTool == 'grunt'){ %> "grunt": "~0.4.5", "grunt-develop": "~0.4.0", "grunt-contrib-watch": "~0.6.1", "grunt-contrib-compass": "~0.9.0", "request": "~2.36.0", "time-grunt": "~0.3.2", - "load-grunt-tasks": "~0.6.0" + "load-grunt-tasks": "~0.6.0"<% } %><% if(options.buildTool == 'gulp'){ %> + "gulp": "~3.8.8", + "gulp-nodemon": "~1.0.4", + "gulp-livereload": "~2.1.1"<% } %> } } diff --git a/package.json b/package.json index 21a16fb..a65cf40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "generator-express", - "version": "2.1.3", + "version": "2.2.0", "description": "A nodejs express generator for Yeoman", "keywords": [ "yeoman-generator", diff --git a/test/test-creation.js b/test/test-creation.js index c7f814e..5f5a337 100644 --- a/test/test-creation.js +++ b/test/test-creation.js @@ -6,7 +6,6 @@ var path = require('path'); var helpers = require('yeoman-generator').test; var basicExpected = [ - 'Gruntfile.js', '.bowerrc', '.gitignore', 'bower.json', @@ -22,7 +21,6 @@ var basicExpected = [ ]; var MVCExpected = [ - 'Gruntfile.js', '.bowerrc', '.gitignore', 'bower.json', @@ -48,7 +46,7 @@ var appFiles = { var toCoffeeFileArray = function (fileArray) { var newArray = []; for (var i in fileArray) { - if (fileArray[i] === 'app.js' || fileArray[i] === 'Gruntfile.js') { + if (fileArray[i] === 'app.js') { newArray.push(fileArray[i]); } else { newArray.push(fileArray[i].replace(/(.*?)\.js$/, '$1.coffee')); @@ -58,17 +56,19 @@ var toCoffeeFileArray = function (fileArray) { return newArray; }; -var runGenerationTest = function (extraFiles, type, engine, coffee, database, callback) { +var runGenerationTest = function (extraFiles, type, engine, coffee, database, buildTool, callback) { var expectedFiles; this.app.options[type] = true; this.app.options['skip-install'] = true; this.app.options.database = database; this.app.options.viewEngine = engine; this.app.options.coffee = coffee; + this.app.options.buildTool = buildTool; expectedFiles = extraFiles.concat(appFiles[type]); if (this.app.options.coffee) { expectedFiles = toCoffeeFileArray(expectedFiles); } + expectedFiles.push(buildTool === 'grunt' ? 'Gruntfile.js' : 'gulpfile.js'); this.app.run({}, function () { assert.file(expectedFiles); callback(); @@ -97,11 +97,19 @@ describe('Express generator', function () { ]; it('creates expected files', function (done) { - runGenerationTest.call(this, expected, 'basic', 'jade', false, 'none', done); + runGenerationTest.call(this, expected, 'basic', 'jade', false, 'none', 'grunt', done); }); it('works with coffee', function (done) { - runGenerationTest.call(this, expected, 'basic', 'jade', true, 'none', done); + runGenerationTest.call(this, expected, 'basic', 'jade', true, 'none', 'grunt', done); + }); + + it('works with gulp', function (done) { + runGenerationTest.call(this, expected, 'basic', 'jade', false, 'none', 'gulp', done); + }); + + it('works with coffee and gulp', function (done) { + runGenerationTest.call(this, expected, 'basic', 'jade', true, 'none', 'gulp', done); }); }); @@ -114,11 +122,11 @@ describe('Express generator', function () { ]; it('creates expected files', function (done) { - runGenerationTest.call(this, expected, 'basic', 'ejs', false, 'none', done); + runGenerationTest.call(this, expected, 'basic', 'ejs', false, 'none', 'grunt', done); }); it('works with coffee', function (done) { - runGenerationTest.call(this, expected, 'basic', 'ejs', true, 'none', done); + runGenerationTest.call(this, expected, 'basic', 'ejs', true, 'none', 'grunt', done); }); }); @@ -130,16 +138,19 @@ describe('Express generator', function () { 'app/views/index.jade' ]; it('creates expected files', function (done) { - runGenerationTest.call(this, expected, 'mvc', 'jade', false, 'none', done); + runGenerationTest.call(this, expected, 'mvc', 'jade', false, 'none', 'grunt', done); }); it('works with coffee', function (done) { - var expected = [ - 'app/views/layout.jade', - 'app/views/error.jade', - 'app/views/index.jade' - ]; - runGenerationTest.call(this, expected, 'mvc', 'jade', true, 'none', done); + runGenerationTest.call(this, expected, 'mvc', 'jade', true, 'none', 'grunt', done); + }); + + it('works with gulp', function (done) { + runGenerationTest.call(this, expected, 'mvc', 'jade', false, 'none', 'gulp', done); + }); + + it('works with coffee and gulp', function (done) { + runGenerationTest.call(this, expected, 'mvc', 'jade', true, 'none', 'gulp', done); }); }); @@ -151,7 +162,7 @@ describe('Express generator', function () { 'app/views/error.ejs', 'app/views/index.ejs' ]; - runGenerationTest.call(this, expected, 'mvc', 'ejs', false, 'none', done); + runGenerationTest.call(this, expected, 'mvc', 'ejs', false, 'none', 'grunt', done); }); it('works with coffee', function (done) { @@ -161,7 +172,7 @@ describe('Express generator', function () { 'app/views/error.ejs', 'app/views/index.ejs' ]; - runGenerationTest.call(this, expected, 'mvc', 'ejs', true, 'none', done); + runGenerationTest.call(this, expected, 'mvc', 'ejs', true, 'none', 'grunt', done); }); }); @@ -170,14 +181,14 @@ describe('Express generator', function () { var expected = [ 'app/models/index.js' ]; - runGenerationTest.call(this, expected, 'mvc', 'jade', false, 'mysql', done); + runGenerationTest.call(this, expected, 'mvc', 'jade', false, 'mysql', 'grunt', done); }); it('works with coffee', function (done) { var expected = [ 'app/models/index.js' ]; - runGenerationTest.call(this, expected, 'mvc', 'jade', true, 'mysql', done); + runGenerationTest.call(this, expected, 'mvc', 'jade', true, 'mysql', 'grunt', done); }); }); });