Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
added gulp support closes #29
Browse files Browse the repository at this point in the history
  • Loading branch information
petecoop committed Oct 11, 2014
1 parent a024635 commit 2cd8819
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 29 deletions.
9 changes: 8 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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';
Expand All @@ -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() {
Expand Down
7 changes: 5 additions & 2 deletions app/templates/basic-coffee/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"<% } %>
}
}
7 changes: 5 additions & 2 deletions app/templates/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"<% } %>
}
}
17 changes: 17 additions & 0 deletions app/templates/extras/basic-coffee/gulpfile.js
Original file line number Diff line number Diff line change
@@ -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']);
File renamed without changes.
17 changes: 17 additions & 0 deletions app/templates/extras/basic/gulpfile.js
Original file line number Diff line number Diff line change
@@ -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']);
17 changes: 17 additions & 0 deletions app/templates/extras/mvc-coffee/gulpfile.js
Original file line number Diff line number Diff line change
@@ -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']);
File renamed without changes.
17 changes: 17 additions & 0 deletions app/templates/extras/mvc/gulpfile.js
Original file line number Diff line number Diff line change
@@ -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']);
7 changes: 5 additions & 2 deletions app/templates/mvc-coffee/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
"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",
"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"<% } %>
}
}
7 changes: 5 additions & 2 deletions app/templates/mvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"<% } %>
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
49 changes: 30 additions & 19 deletions test/test-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var path = require('path');
var helpers = require('yeoman-generator').test;

var basicExpected = [
'Gruntfile.js',
'.bowerrc',
'.gitignore',
'bower.json',
Expand All @@ -22,7 +21,6 @@ var basicExpected = [
];

var MVCExpected = [
'Gruntfile.js',
'.bowerrc',
'.gitignore',
'bower.json',
Expand All @@ -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'));
Expand All @@ -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();
Expand Down Expand Up @@ -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);
});
});

Expand All @@ -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);
});
});

Expand All @@ -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);
});
});

Expand All @@ -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) {
Expand All @@ -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);
});
});

Expand All @@ -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);
});
});
});

0 comments on commit 2cd8819

Please sign in to comment.