Skip to content

Commit 955912c

Browse files
PentiadoAwk34
authored andcommitted
feat(app): Add experimental Gulp option
This is from an old PR and needs to be updated + tested
1 parent f30566a commit 955912c

3 files changed

Lines changed: 313 additions & 3 deletions

File tree

app/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({
6666
this.log('# Client\n');
6767

6868
this.prompt([{
69+
type: 'confirm',
70+
name: 'gulp',
71+
message: 'Would you like to use Gulp (experimental) instead of Grunt?',
72+
default: false
73+
}, {
6974
type: "list",
7075
name: "script",
7176
message: "What would you like to write scripts with?",
@@ -117,7 +122,7 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({
117122
return answers.bootstrap;
118123
}
119124
}], function (answers) {
120-
125+
this.filters.gulp = !!answers.gulp;
121126
this.filters.babel = !!answers.babel;
122127
if(this.filters.babel){ this.filters.js = true; }
123128
this.filters[answers.script] = true;

app/templates/Gulpfile.js

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
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 http = require('http');
7+
var openURL = require('open');
8+
var lazypipe = require('lazypipe');
9+
var wiredep = require('wiredep').stream;
10+
var nodemon = require('nodemon');
11+
var runSequence = require('run-sequence');
12+
var path = require('path');<% if (stylus) { %>
13+
var nib = require('nib');<% } %>
14+
var config;
15+
16+
var yeoman = {
17+
app: require('./bower.json').appPath || 'app',
18+
dist: 'dist'
19+
};
20+
21+
var paths = {
22+
client: {
23+
scripts: [yeoman.app + '/scripts/**/*.<% if (coffee) { %>coffee<% } else { %>js<% } %>'],
24+
styles: [yeoman.app + '/styles/**/*.<% if (stylus) { %>styl<% } else if (sass) { %>scss<% } else { %>css<% } %>'],
25+
test: ['test/client/**/*.<% if (coffee) { %>coffee<% } else { %>js<% } %>'],
26+
testRequire: [
27+
yeoman.app + '/bower_components/angular/angular.js',
28+
yeoman.app + '/bower_components/angular-mocks/angular-mocks.js',
29+
yeoman.app + '/bower_components/angular-resource/angular-resource.js',
30+
yeoman.app + '/bower_components/angular-cookies/angular-cookies.js',
31+
yeoman.app + '/bower_components/angular-sanitize/angular-sanitize.js',
32+
yeoman.app + '/bower_components/angular-route/angular-route.js',<% if (coffee) { %>
33+
'test/mock/**/*.coffee',
34+
'test/spec/**/*.coffee'<% } else { %>
35+
'test/mock/**/*.js',
36+
'test/spec/**/*.js'<% } %>
37+
]
38+
},
39+
server: {<% if (coffee) { %>
40+
scripts: ['lib/**/*.coffee'],
41+
test: ['test/server/**/*.coffee'],<% } else { %>
42+
scripts: ['lib/**/*.js'],
43+
test: ['test/server/**/*.js'],<% } %>
44+
45+
},
46+
views: {<% if (jade) { %>
47+
main: yeoman.app + '/views/index.jade',
48+
files: [yeoman.app + '/views/**/*.jade']<% } else {%>
49+
main: yeoman.app + '/views/index.html',
50+
files: [yeoman.app + '/views/**/*.html']<% } %>
51+
},
52+
karma: 'karma.conf.js'
53+
};
54+
55+
//////////////////////
56+
// Helper functions //
57+
//////////////////////
58+
59+
function onServerLog(log) {
60+
console.log($.util.colors.white('[') + $.util.colors.yellow('nodemon') + $.util.colors.white('] ') + log.message);
61+
}
62+
63+
function checkAppReady(cb) {
64+
var options = {
65+
host: 'localhost',
66+
port: config.port,
67+
};
68+
http.get(options, function() {
69+
cb(true);
70+
}).on('error', function() {
71+
cb(false);
72+
});
73+
}
74+
75+
// Call page until first success
76+
function whenServerReady (cb) {
77+
var serverReady = false;
78+
var appReadyInterval = setInterval(function () {
79+
checkAppReady(function(ready){
80+
if (!ready || serverReady) { return; }
81+
clearInterval(appReadyInterval);
82+
serverReady = true;
83+
cb();
84+
});
85+
}, 100);
86+
}
87+
88+
////////////////////////
89+
// Reusable pipelines //
90+
////////////////////////
91+
92+
var lintScripts = lazypipe()<% if (coffee) { %>
93+
.pipe($.coffeelint)
94+
.pipe($.coffeelint.reporter);<% } else { %>
95+
.pipe($.jshint, '.jshintrc')
96+
.pipe($.jshint.reporter, 'jshint-stylish');<% } %>
97+
98+
var styles = lazypipe()<% if (stylus) { %>
99+
.pipe($.stylus, {
100+
use: [nib()],
101+
errors: true
102+
})<% } %><% if (sass) { %>
103+
.pipe($.rubySass, {
104+
style: 'expanded',
105+
precision: 10
106+
})<% } %>
107+
.pipe($.autoprefixer, 'last 1 version')
108+
.pipe(gulp.dest, '.tmp/styles');
109+
110+
///////////
111+
// Tasks //
112+
///////////
113+
114+
gulp.task('styles', function () {
115+
return gulp.src(paths.client.styles)
116+
.pipe(styles());
117+
});<% if (coffee) { %>
118+
119+
gulp.task('coffee', function() {
120+
return gulp.src(paths.client.scripts)
121+
.pipe(lintScripts())
122+
.pipe($.coffee({bare: true}).on('error', $.util.log))
123+
.pipe(gulp.dest('.tmp/scripts'));
124+
});<% } %>
125+
126+
gulp.task('lint:scripts', function () {
127+
var scripts = paths.client.scripts.concat(paths.server.scripts);
128+
return gulp.src(scripts).pipe(lintScripts());
129+
});
130+
131+
gulp.task('clean:tmp', function () {
132+
return gulp.src('.tmp', {read: false}).pipe($.clean());
133+
});
134+
135+
gulp.task('start:client', [<% if (coffee) { %>'coffee', <% } %>'styles'], function (callback) {
136+
whenServerReady(function () {
137+
openURL('http://localhost:' + config.port);
138+
callback();
139+
});
140+
});
141+
142+
gulp.task('start:server', function () {
143+
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
144+
config = require('./lib/config/config');
145+
nodemon('-w lib server.js')
146+
.on('log', onServerLog);
147+
});
148+
149+
gulp.task('watch', function () {
150+
var testFiles = paths.client.test.concat(paths.server.test);
151+
152+
$.watch({glob: paths.client.styles})
153+
.pipe($.plumber())
154+
.pipe(styles())
155+
.pipe($.livereload());
156+
157+
$.watch({glob: paths.views.files})
158+
.pipe($.plumber())
159+
.pipe($.livereload());
160+
161+
$.watch({glob: paths.client.scripts})
162+
.pipe($.plumber())
163+
.pipe(lintScripts())<% if (coffee) { %>
164+
.pipe($.coffee({bare: true}).on('error', $.util.log))
165+
.pipe(gulp.dest('.tmp/scripts'))<% } %>
166+
.pipe($.livereload());
167+
168+
$.watch({glob: paths.server.scripts.concat(testFiles)})
169+
.pipe($.plumber())
170+
.pipe(lintScripts());
171+
172+
gulp.watch('bower.json', ['bower']);
173+
});
174+
175+
gulp.task('serve', function (callback) {
176+
runSequence('clean:tmp',
177+
['lint:scripts'],
178+
['start:server', 'start:client'],
179+
'watch', callback);
180+
});
181+
182+
gulp.task('test:server', function () {
183+
process.env.NODE_ENV = 'test';
184+
return gulp.src(paths.server.test)
185+
.pipe($.mocha({reporter: 'spec'}));
186+
});
187+
188+
gulp.task('test:client', function () {
189+
var testFiles = paths.client.testRequire.concat(paths.client.test)
190+
gulp.src(testFiles)
191+
.pipe($.karma({
192+
configFile: paths.karma,
193+
action: 'watch'
194+
}));
195+
});
196+
197+
// inject bower components
198+
gulp.task('bower', function () {
199+
return gulp.src(paths.views.main)
200+
.pipe(wiredep({
201+
directory: yeoman.app + '/bower_components',
202+
ignorePath: '..'
203+
}))
204+
.pipe(gulp.dest(yeoman.app + '/views/'));
205+
});
206+
207+
///////////
208+
// Build //
209+
///////////
210+
211+
gulp.task('build', function (callback) {
212+
runSequence('clean:dist',
213+
['images', 'copy:extras', 'copy:fonts', 'copy:server', 'client:build'],
214+
callback);
215+
});
216+
217+
gulp.task('clean:dist', function () {
218+
return gulp.src('dist', {read: false}).pipe($.clean());
219+
});
220+
221+
gulp.task('client:build', ['html'], function () {
222+
var jsFilter = $.filter('**/*.js');
223+
var cssFilter = $.filter('**/*.css');<% if (jade) { %>
224+
var assets = $.filter('**/*.{js,css}');<% } %>
225+
226+
return gulp.src(paths.views.main)<% if (jade) { %>
227+
.pipe($.jade({pretty: true}))<% } %>
228+
.pipe($.useref.assets({searchPath: [yeoman.app, '.tmp']}))
229+
.pipe(jsFilter)
230+
.pipe($.ngmin())
231+
.pipe($.uglify())
232+
.pipe(jsFilter.restore())
233+
.pipe(cssFilter)
234+
.pipe($.minifyCss({cache: true}))
235+
.pipe(cssFilter.restore())
236+
.pipe($.rev())
237+
.pipe($.useref.restore())
238+
.pipe($.revReplace())
239+
.pipe($.useref())<% if (jade) { %>
240+
.pipe(assets)<% } %>
241+
.pipe(gulp.dest(yeoman.dist + '/public'));
242+
});
243+
244+
gulp.task('html', function () {
245+
return gulp.src(yeoman.app + '/views/**/*')
246+
.pipe(gulp.dest(yeoman.dist + '/public/views'));
247+
});
248+
249+
gulp.task('images', function () {
250+
return gulp.src(yeoman.app + '/images/**/*')
251+
.pipe($.cache($.imagemin({
252+
optimizationLevel: 5,
253+
progressive: true,
254+
interlaced: true
255+
})))
256+
.pipe(gulp.dest(yeoman.dist + '/public/images'));
257+
});
258+
259+
gulp.task('copy:extras', function () {
260+
return gulp.src(yeoman.app + '/*.*', { dot: true })
261+
.pipe(gulp.dest(yeoman.dist + '/public'));
262+
});
263+
264+
gulp.task('copy:fonts', function () {
265+
return gulp.src(yeoman.app + '/fonts/**/*')
266+
.pipe(gulp.dest(yeoman.dist + '/fonts'));
267+
});
268+
269+
gulp.task('copy:server', function(){
270+
return gulp.src([
271+
'package.json',
272+
'server.js',
273+
'lib/**/*'
274+
], {cwdbase: true}).pipe(gulp.dest(yeoman.dist));
275+
});

app/templates/_package.json

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,37 @@
2929
"socket.io-client": "^1.0.6",
3030
"socketio-jwt": "^3.0.0"<% } %>
3131
},
32-
"devDependencies": {
32+
"devDependencies": {<% if (gulp) { %>
33+
"gulp": "^3.6.2",
34+
"gulp-autoprefixer": "0.0.7",
35+
"gulp-cache": "^0.1.3",
36+
"gulp-clean": "^0.2.4",
37+
"gulp-filter": "^0.4.1",
38+
"gulp-imagemin": "^0.5.0",
39+
"gulp-jshint": "^1.5.5",
40+
"gulp-karma": "0.0.4",
41+
"gulp-livereload": "^1.3.1",
42+
"gulp-load-plugins": "^0.5.0",
43+
"gulp-plumber": "^0.6.1",
44+
"gulp-rev": "^0.3.2",
45+
"gulp-rev-replace": "^0.1.0",
46+
"gulp-uglify": "^0.2.1",
47+
"gulp-useref": "^0.4.2",
48+
"gulp-minify-css": "^0.3.4",
49+
"gulp-util": "^2.2.14",
50+
"gulp-watch": "^0.6.2",
51+
"gulp-ngmin": "^0.2.0",
52+
"utile": "~0.2.1",
53+
"nodemon": "^1.0.17",
54+
"run-sequence": "^0.3.6",
55+
"wiredep": "^1.4.4",<% if (jade) { %>
56+
"gulp-jade": "^0.5.0",<% } %>
57+
"lazypipe": "^0.2.1",<% if (stylus) { %>
58+
"gulp-stylus": "^1.0.0",
59+
"nib": "^1.0.2",<% } %><% if (sass) { %>
60+
"gulp-ruby-sass": "^0.4.3",<% } %><% if (coffee) { %>
61+
"gulp-coffeelint": "^0.3.2",
62+
"gulp-coffee": "^1.4.2",<% } %><% } else { %>
3363
"grunt": "~0.4.4",
3464
"grunt-autoprefixer": "~0.7.2",
3565
"grunt-wiredep": "~1.8.0",
@@ -65,7 +95,7 @@
6595
"grunt-build-control": "~0.4.0",
6696
"grunt-mocha-test": "~0.10.2",<% if(filters.sass) { %>
6797
"grunt-contrib-sass": "^0.7.3",<% } %><% if(filters.stylus) { %>
68-
"grunt-contrib-stylus": "latest",<% } %>
98+
"grunt-contrib-stylus": "latest",<% } %><% } %>
6999
"jit-grunt": "^0.5.0",
70100
"time-grunt": "~0.3.1",
71101
"grunt-express-server": "~0.4.17",

0 commit comments

Comments
 (0)