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

Commit 28064ce

Browse files
committed
fix(gen): gulpfile.js generation fixes
Fixes for a bunch of issues with gulpfile.js with @bumprat code #1299
1 parent cb9d420 commit 28064ce

File tree

1 file changed

+66
-36
lines changed

1 file changed

+66
-36
lines changed

templates/common/root/_gulpfile.js

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,32 @@ var runSequence = require('run-sequence');
1111

1212
var yeoman = {
1313
app: require('./bower.json').appPath || 'app',
14-
dist: 'dist'
14+
dist: 'dist',
15+
temp: '.tmp',
16+
test: 'test'
1517
};
1618

19+
var jsx = '<% if (coffee) { %>coffee<% } else { %>js<% } %>';
20+
var cssx = '<% if (sass) { %>scss<% } else { %>css<% } %>';
21+
1722
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<% } %>'],
23+
scripts: [yeoman.app + '/scripts/**/*.' + jsx],
24+
styles: [yeoman.app + '/styles/**/*.' + cssx],
25+
test: ['test/spec/**/*.' + jsx],
2126
testRequire: [
2227
yeoman.app + '/bower_components/angular/angular.js',
2328
yeoman.app + '/bower_components/angular-mocks/angular-mocks.js',
2429
yeoman.app + '/bower_components/angular-resource/angular-resource.js',
2530
yeoman.app + '/bower_components/angular-cookies/angular-cookies.js',
2631
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+
yeoman.app + '/bower_components/angular-route/angular-route.js',
33+
'test/mock/**/*.' + jsx,
34+
'test/spec/**/*.' + jsx
3235
],
3336
karma: 'karma.conf.js',
3437
views: {
3538
main: yeoman.app + '/index.html',
39+
bowermain: yeoman.temp + '/index.html',
3640
files: [yeoman.app + '/views/**/*.html']
3741
}
3842
};
@@ -44,21 +48,29 @@ var paths = {
4448
var lintScripts = lazypipe()<% if (coffee) { %>
4549
.pipe($.coffeelint)
4650
.pipe($.coffeelint.reporter);<% } else { %>
47-
.pipe($.jshint, '.jshintrc')
51+
.pipe($.jshint/*, '.jshintrc'*/)
4852
.pipe($.jshint.reporter, 'jshint-stylish');<% } %>
4953

5054
var styles = lazypipe()<% if (sass) { %>
5155
.pipe($.sass, {
5256
outputStyle: 'expanded',
5357
precision: 10
5458
})<% } %>
55-
.pipe($.autoprefixer, 'last 1 version')
56-
.pipe(gulp.dest, '.tmp/styles');
59+
.pipe($.autoprefixer, {browsers: ['last 2 version']})
60+
.pipe(gulp.dest, yeoman.temp + '/styles');
5761

5862
///////////
5963
// Tasks //
6064
///////////
6165

66+
// get arguments
67+
var argv = {};
68+
process.argv.forEach(function(arg, index, all){
69+
if (arg[0] == '-' && (index + 1 < all.length)) {
70+
argv[arg.substr(1)] = all[index+1];
71+
}
72+
});
73+
6274
gulp.task('styles', function () {
6375
return gulp.src(paths.styles)
6476
.pipe(styles());
@@ -68,7 +80,7 @@ gulp.task('coffee', function() {
6880
return gulp.src(paths.scripts)
6981
.pipe(lintScripts())
7082
.pipe($.coffee({bare: true}).on('error', $.util.log))
71-
.pipe(gulp.dest('.tmp/scripts'));
83+
.pipe(gulp.dest(yeoman.temp + '/scripts'));
7284
});<% } %>
7385

7486
gulp.task('lint:scripts', function () {
@@ -77,27 +89,29 @@ gulp.task('lint:scripts', function () {
7789
});
7890

7991
gulp.task('clean:tmp', function (cb) {
80-
rimraf('./.tmp', cb);
92+
rimraf(yeoman.temp, cb);
8193
});
8294

83-
gulp.task('start:client', ['start:server', <% if (coffee) { %>'coffee', <% } %>'styles'], function () {
95+
gulp.task('start:client', ['start:server', <% if (coffee) { %>'coffee', <% } else {%> 'lint:scripts', <%} %>'styles'], function () {
8496
openURL('http://localhost:9000');
8597
});
8698

8799
gulp.task('start:server', function() {
88100
$.connect.server({
89-
root: [yeoman.app, '.tmp'],
101+
root: [yeoman.app, yeoman.temp],
90102
livereload: true,
91103
// Change this to '0.0.0.0' to access the server from outside.
92-
port: 9000
104+
port: 9000,
105+
middleware: serveStaticBower
93106
});
94107
});
95108

96109
gulp.task('start:server:test', function() {
97110
$.connect.server({
98-
root: ['test', yeoman.app, '.tmp'],
111+
root: [yeoman.test, yeoman.app, yeoman.temp],
99112
livereload: true,
100-
port: 9001
113+
port: 9001,
114+
middleware: serveStaticBower
101115
});
102116
});
103117

@@ -113,30 +127,34 @@ gulp.task('watch', function () {
113127

114128
$.watch(paths.scripts)
115129
.pipe($.plumber())
116-
.pipe(lintScripts())<% if (coffee) { %>
130+
.pipe(lintScripts())
131+
<% if (coffee) { %>
117132
.pipe($.coffee({bare: true}).on('error', $.util.log))
118-
.pipe(gulp.dest('.tmp/scripts'))<% } %>
133+
.pipe(gulp.dest(yeoman.temp + '/scripts'))
134+
<% } %>
119135
.pipe($.connect.reload());
120136

121137
$.watch(paths.test)
122-
.pipe($.plumber())
123-
.pipe(lintScripts());
138+
.pipe($.plumber());
124139

125140
gulp.watch('bower.json', ['bower']);
126141
});
127142

128143
gulp.task('serve', function (cb) {
129144
runSequence('clean:tmp',
145+
['bower'],
130146
['lint:scripts'],
131147
['start:client'],
132148
'watch', cb);
133149
});
134150

151+
// gulp serve:prod -port 8080
135152
gulp.task('serve:prod', function() {
136153
$.connect.server({
137154
root: [yeoman.dist],
138-
livereload: true,
139-
port: 9000
155+
livereload: true
156+
port: argv.port || 80,
157+
middleware: serveStaticBower
140158
});
141159
});
142160

@@ -153,35 +171,36 @@ gulp.task('test', ['start:server:test'], function () {
153171
gulp.task('bower', function () {
154172
return gulp.src(paths.views.main)
155173
.pipe(wiredep({
156-
directory: yeoman.app + '/bower_components',
174+
directory: /*yeoman.app + */'/bower_components',
157175
ignorePath: '..'
158176
}))
159-
.pipe(gulp.dest(yeoman.app + '/views'));
177+
// .pipe(gulp.dest(yeoman.app + '/views'));
178+
.pipe(gulp.dest(yeoman.temp));
160179
});
161180

162181
///////////
163182
// Build //
164183
///////////
165184

166185
gulp.task('clean:dist', function (cb) {
167-
rimraf('./dist', cb);
186+
rimraf(yeoman.dist, cb);
168187
});
169188

170-
gulp.task('client:build', ['html', 'styles'], function () {
189+
gulp.task('client:build', ['bower', 'html', 'styles'], function () {
171190
var jsFilter = $.filter('**/*.js');
172191
var cssFilter = $.filter('**/*.css');
173192

174-
return gulp.src(paths.views.main)
175-
.pipe($.useref({searchPath: [yeoman.app, '.tmp']}))
193+
return gulp.src(paths.views.bowermain)
194+
.pipe($.useref({searchPath: [yeoman.app, yeoman.temp]}))
176195
.pipe(jsFilter)
177196
.pipe($.ngAnnotate())
178197
.pipe($.uglify())
179198
.pipe(jsFilter.restore())
180199
.pipe(cssFilter)
181200
.pipe($.minifyCss({cache: true}))
182201
.pipe(cssFilter.restore())
183-
.pipe($.rev())
184-
.pipe($.revReplace())
202+
// .pipe($.rev())
203+
// .pipe($.revReplace())
185204
.pipe(gulp.dest(yeoman.dist));
186205
});
187206

@@ -205,13 +224,24 @@ gulp.task('copy:extras', function () {
205224
.pipe(gulp.dest(yeoman.dist));
206225
});
207226

227+
gulp.task('copy:favicon', function () {
228+
return gulp.src(yeoman.app + '/favicon.ico')
229+
.pipe(gulp.dest(yeoman.dist));
230+
});
231+
208232
gulp.task('copy:fonts', function () {
209-
return gulp.src(yeoman.app + '/fonts/**/*')
233+
return gulp.src('./bower_components/bootstrap/dist/fonts/**/*')
210234
.pipe(gulp.dest(yeoman.dist + '/fonts'));
211235
});
212236

213-
gulp.task('build', ['clean:dist'], function () {
214-
runSequence(['images', 'copy:extras', 'copy:fonts', 'client:build']);
237+
gulp.task('build', ['clean:dist', 'bower'], function () {
238+
runSequence(['images', 'copy:extras', 'copy:fonts', 'copy:favicon', 'client:build']);
215239
});
216240

241+
gulp.task('wiredep', ['bower']);
217242
gulp.task('default', ['build']);
243+
244+
245+
function serveStaticBower(connect, opt){
246+
return [['/bower_components', connect.static('./bower_components')]
247+
]}

0 commit comments

Comments
 (0)