Skip to content
This repository was archived by the owner on Mar 26, 2018. It is now read-only.

Commit 9ad4d74

Browse files
Pentiadohermansje
authored andcommitted
feat(gen): add Gulp support
add an option to use Gulp instead of Grunt Closes #672 (+1 squashed commits) Squashed commits: [87a7e7c] feat(gen): add support for Gulp Add an option to use Gulp instead of Grunt
1 parent e579df9 commit 9ad4d74

File tree

3 files changed

+293
-11
lines changed

3 files changed

+293
-11
lines changed

app/index.js

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,43 @@ Generator.prototype.welcome = function welcome() {
150150
}
151151
};
152152

153-
Generator.prototype.askForCompass = function askForCompass() {
153+
Generator.prototype.askForGulp = function askForGulp() {
154154
var cb = this.async();
155155

156156
this.prompt([{
157+
type: 'confirm',
158+
name: 'gulp',
159+
message: 'Would you like to use Gulp (experimental) instead of Grunt?',
160+
default: false
161+
}], function (props) {
162+
this.gulp = props.gulp;
163+
164+
cb();
165+
}.bind(this));
166+
};
167+
168+
Generator.prototype.askForStyles = function askForStyles() {
169+
var gulp = this.gulp;
170+
var cb = this.async();
171+
172+
this.prompt([{
173+
type: 'confirm',
174+
name: 'sass',
175+
message: 'Would you like to use Sass?',
176+
default: true,
177+
when: function () {
178+
return gulp;
179+
}
180+
}, {
157181
type: 'confirm',
158182
name: 'compass',
159183
message: 'Would you like to use Sass (with Compass)?',
160-
default: true
184+
default: true,
185+
when: function () {
186+
return !gulp;
187+
}
161188
}], function (props) {
189+
this.sass = props.sass;
162190
this.compass = props.compass;
163191

164192
cb();
@@ -167,6 +195,7 @@ Generator.prototype.askForCompass = function askForCompass() {
167195

168196
Generator.prototype.askForBootstrap = function askForBootstrap() {
169197
var compass = this.compass;
198+
var gulp = this.gulp;
170199
var cb = this.async();
171200

172201
this.prompt([{
@@ -180,7 +209,7 @@ Generator.prototype.askForBootstrap = function askForBootstrap() {
180209
message: 'Would you like to use the Sass version of Bootstrap?',
181210
default: true,
182211
when: function (props) {
183-
return props.bootstrap && compass;
212+
return !gulp && (props.bootstrap && compass);
184213
}
185214
}], function (props) {
186215
this.bootstrap = props.bootstrap;
@@ -294,8 +323,9 @@ Generator.prototype.readIndex = function readIndex() {
294323
};
295324

296325
Generator.prototype.bootstrapFiles = function bootstrapFiles() {
297-
var cssFile = 'styles/main.' + (this.compass ? 's' : '') + 'css';
298-
this.copy(
326+
var sass = this.compass || this.sass;
327+
var cssFile = 'styles/main.' + (sass ? 's' : '') + 'css';
328+
this.copy(
299329
path.join('app', cssFile),
300330
path.join(this.appPath, cssFile)
301331
);
@@ -322,22 +352,28 @@ Generator.prototype.packageFiles = function packageFiles() {
322352
this.template('root/_bower.json', 'bower.json');
323353
this.template('root/_bowerrc', '.bowerrc');
324354
this.template('root/_package.json', 'package.json');
325-
this.template('root/_Gruntfile.js', 'Gruntfile.js');
355+
if (this.gulp) {
356+
this.template('root/_Gulpfile.js', 'Gulpfile.js');
357+
} else {
358+
this.template('root/_Gruntfile.js', 'Gruntfile.js');
359+
}
326360
if (this.typescript) {
327361
this.template('root/_tsd.json', 'tsd.json');
328362
}
329363
this.template('root/README.md', 'README.md');
364+
330365
};
331366

332367
Generator.prototype._injectDependencies = function _injectDependencies() {
368+
var taskRunner = this.gulp ? 'gulp' : 'grunt';
333369
if (this.options['skip-install']) {
334370
this.log(
335371
'After running `npm install & bower install`, inject your front end dependencies' +
336372
'\ninto your source code by running:' +
337373
'\n' +
338-
'\n' + chalk.yellow.bold('grunt wiredep')
374+
'\n' + chalk.yellow.bold(taskRunner + ' wiredep')
339375
);
340376
} else {
341-
this.spawnCommand('grunt', ['wiredep']);
377+
this.spawnCommand(taskRunner, ['wiredep']);
342378
}
343379
};

templates/common/root/_Gulpfile.js

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
// Generated on <%= (new Date).toISOString().split('T')[0] %> using <%= pkg.name %> <%= pkg.version %>
2+
'use strict';
3+
4+
var gulp = require('gulp');
5+
var $ = require('gulp-load-plugins')();
6+
var openURL = require('open');
7+
var lazypipe = require('lazypipe');
8+
var rimraf = require('rimraf');
9+
var wiredep = require('wiredep').stream;
10+
var runSequence = require('run-sequence');
11+
12+
var yeoman = {
13+
app: require('./bower.json').appPath || 'app',
14+
dist: 'dist'
15+
};
16+
17+
var paths = {
18+
scripts: [yeoman.app + '/scripts/**/*.<% if (coffee) { %>coffee<% } else { %>js<% } %>'],
19+
styles: [yeoman.app + '/styles/**/*.<% if (sass) { %>scss<% } else { %>css<% } %>'],
20+
test: ['test/spec/**/*.<% if (coffee) { %>coffee<% } else { %>js<% } %>'],
21+
testRequire: [
22+
yeoman.app + '/bower_components/angular/angular.js',
23+
yeoman.app + '/bower_components/angular-mocks/angular-mocks.js',
24+
yeoman.app + '/bower_components/angular-resource/angular-resource.js',
25+
yeoman.app + '/bower_components/angular-cookies/angular-cookies.js',
26+
yeoman.app + '/bower_components/angular-sanitize/angular-sanitize.js',
27+
yeoman.app + '/bower_components/angular-route/angular-route.js',<% if (coffee) { %>
28+
'test/mock/**/*.coffee',
29+
'test/spec/**/*.coffee'<% } else { %>
30+
'test/mock/**/*.js',
31+
'test/spec/**/*.js'<% } %>
32+
],
33+
karma: 'karma.conf.js',
34+
views: {
35+
main: yeoman.app + '/index.html',
36+
files: [yeoman.app + '/views/**/*.html']
37+
}
38+
};
39+
40+
////////////////////////
41+
// Reusable pipelines //
42+
////////////////////////
43+
44+
var lintScripts = lazypipe()<% if (coffee) { %>
45+
.pipe($.coffeelint)
46+
.pipe($.coffeelint.reporter);<% } else { %>
47+
.pipe($.jshint, '.jshintrc')
48+
.pipe($.jshint.reporter, 'jshint-stylish');<% } %>
49+
50+
var styles = lazypipe()<% if (sass) { %>
51+
.pipe($.rubySass, {
52+
style: 'expanded',
53+
precision: 10
54+
})<% } %>
55+
.pipe($.autoprefixer, 'last 1 version')
56+
.pipe(gulp.dest, '.tmp/styles');
57+
58+
///////////
59+
// Tasks //
60+
///////////
61+
62+
gulp.task('styles', function () {
63+
return gulp.src(paths.styles)
64+
.pipe(styles());
65+
});<% if (coffee) { %>
66+
67+
gulp.task('coffee', function() {
68+
return gulp.src(paths.scripts)
69+
.pipe(lintScripts())
70+
.pipe($.coffee({bare: true}).on('error', $.util.log))
71+
.pipe(gulp.dest('.tmp/scripts'));
72+
});<% } %>
73+
74+
gulp.task('lint:scripts', function () {
75+
return gulp.src(paths.scripts)
76+
.pipe(lintScripts());
77+
});
78+
79+
gulp.task('clean:tmp', function (cb) {
80+
rimraf('./.tmp', cb);
81+
});
82+
83+
gulp.task('start:client', ['start:server', <% if (coffee) { %>'coffee', <% } %>'styles'], function () {
84+
openURL('http://localhost:9000');
85+
});
86+
87+
gulp.task('start:server', function() {
88+
$.connect.server({
89+
root: [yeoman.app, '.tmp'],
90+
livereload: true,
91+
// Change this to '0.0.0.0' to access the server from outside.
92+
port: 9000
93+
});
94+
});
95+
96+
gulp.task('start:server:test', function() {
97+
$.connect.server({
98+
root: ['test', yeoman.app, '.tmp'],
99+
livereload: true,
100+
port: 9001
101+
});
102+
});
103+
104+
gulp.task('watch', function () {
105+
106+
$.watch({glob: paths.styles})
107+
.pipe($.plumber())
108+
.pipe(styles())
109+
.pipe($.connect.reload());
110+
111+
$.watch({glob: paths.views.files})
112+
.pipe($.plumber())
113+
.pipe($.connect.reload());
114+
115+
$.watch({glob: paths.scripts})
116+
.pipe($.plumber())
117+
.pipe(lintScripts())<% if (coffee) { %>
118+
.pipe($.coffee({bare: true}).on('error', $.util.log))
119+
.pipe(gulp.dest('.tmp/scripts'))<% } %>
120+
.pipe($.connect.reload());
121+
122+
$.watch({glob: paths.test})
123+
.pipe($.plumber())
124+
.pipe(lintScripts());
125+
126+
gulp.watch('bower.json', ['bower']);
127+
});
128+
129+
gulp.task('serve', function (callback) {
130+
runSequence('clean:tmp',
131+
['lint:scripts'],
132+
['start:client'],
133+
'watch', callback);
134+
});
135+
136+
gulp.task('serve:prod', function() {
137+
$.connect.server({
138+
root: [yeoman.dist],
139+
livereload: true,
140+
port: 9000
141+
});
142+
});
143+
144+
gulp.task('test', ['start:server:test'], function () {
145+
var testToFiles = paths.testRequire.concat(paths.scripts, paths.test);
146+
return gulp.src(testToFiles)
147+
.pipe($.karma({
148+
configFile: paths.karma,
149+
action: 'watch'
150+
}));
151+
});
152+
153+
// inject bower components
154+
gulp.task('bower', function () {
155+
return gulp.src(paths.views.main)
156+
.pipe(wiredep({
157+
directory: yeoman.app + '/bower_components',
158+
ignorePath: '..'
159+
}))
160+
.pipe(gulp.dest(yeoman.app + '/views'));
161+
});
162+
163+
///////////
164+
// Build //
165+
///////////
166+
167+
gulp.task('build', function (callback) {
168+
runSequence('clean:dist',
169+
['images', 'copy:extras', 'copy:fonts', 'client:build'],
170+
callback);
171+
});
172+
173+
gulp.task('clean:dist', function () {
174+
rimraf('./dist', cb);
175+
});
176+
177+
gulp.task('client:build', ['html', 'styles'], function () {
178+
var jsFilter = $.filter('**/*.js');
179+
var cssFilter = $.filter('**/*.css');
180+
181+
return gulp.src(paths.views.main)
182+
.pipe($.useref.assets({searchPath: [yeoman.app, '.tmp']}))
183+
.pipe(jsFilter)
184+
.pipe($.ngAnnotate())
185+
.pipe($.uglify())
186+
.pipe(jsFilter.restore())
187+
.pipe(cssFilter)
188+
.pipe($.minifyCss({cache: true}))
189+
.pipe(cssFilter.restore())
190+
.pipe($.rev())
191+
.pipe($.useref.restore())
192+
.pipe($.revReplace())
193+
.pipe($.useref())
194+
.pipe(gulp.dest(yeoman.dist));
195+
});
196+
197+
gulp.task('html', function () {
198+
return gulp.src(yeoman.app + '/views/**/*')
199+
.pipe(gulp.dest(yeoman.dist + '/views'));
200+
});
201+
202+
gulp.task('images', function () {
203+
return gulp.src(yeoman.app + '/images/**/*')
204+
.pipe($.cache($.imagemin({
205+
optimizationLevel: 5,
206+
progressive: true,
207+
interlaced: true
208+
})))
209+
.pipe(gulp.dest(yeoman.dist + '/images'));
210+
});
211+
212+
gulp.task('copy:extras', function () {
213+
return gulp.src(yeoman.app + '/*/.*', { dot: true })
214+
.pipe(gulp.dest(yeoman.dist));
215+
});
216+
217+
gulp.task('copy:fonts', function () {
218+
return gulp.src(yeoman.app + '/fonts/**/*')
219+
.pipe(gulp.dest(yeoman.dist + '/fonts'));
220+
});

templates/common/root/_package.json

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
11
{
22
"name": "<%= _.slugify(appname) %>",
33
"private": true,
4-
"devDependencies": {
4+
"devDependencies": {<% if (gulp) { %>
5+
"gulp": "^3.9.0",
6+
"gulp-connect": "^2.2.0",
7+
"gulp-autoprefixer": "2.3.1",
8+
"gulp-cache": "^0.2.10",
9+
"rimraf": "^2.4.0",
10+
"gulp-filter": "^2.0.2",
11+
"gulp-imagemin": "^2.3.0",
12+
"gulp-jshint": "^1.11.1",
13+
"gulp-karma": "0.0.4",
14+
"gulp-load-plugins": "^0.10.0",
15+
"gulp-plumber": "^1.0.1",
16+
"gulp-minify-css": "^1.2.0",
17+
"gulp-rev": "^5.0.1",
18+
"gulp-rev-replace": "^0.4.2",
19+
"gulp-uglify": "^1.2.0",
20+
"gulp-useref": "^1.2.0",
21+
"gulp-util": "^3.0.6",
22+
"gulp-watch": "^4.2.4",
23+
"run-sequence": "^1.1.1",
24+
"wiredep": "^2.2.2",
25+
"lazypipe": "^0.2.4",
26+
"gulp-ng-annotate": "^1.0.0",
27+
"open": "0.0.5"<% if (sass) { %>,
28+
"gulp-ruby-sass": "^0.4.3"<% } %><% if (coffee) { %>,
29+
"gulp-coffeelint": "^0.5.0",
30+
"gulp-coffee": "^2.3.1",<% } %><% } else { %>
531
"autoprefixer-core": "^5.2.1",
632
"grunt": "^0.4.5",
733
"grunt-angular-templates": "^0.5.7",
@@ -30,8 +56,8 @@
3056
"grunt-usemin": "^3.0.0",
3157
"grunt-wiredep": "^2.0.0",
3258
"jit-grunt": "^0.9.1",
33-
"jshint-stylish": "^1.0.0",
34-
"time-grunt": "^1.0.0"
59+
"time-grunt": "^1.0.0",<% } %>
60+
"jshint-stylish": "^1.0.0"
3561
},
3662
"engines": {
3763
"node": ">=0.10.0"

0 commit comments

Comments
 (0)