Skip to content

Commit 93393b9

Browse files
committed
hacking build
1 parent 7703fc7 commit 93393b9

23 files changed

Lines changed: 160 additions & 156 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ out/*
3636

3737
# Generated content
3838
public/*
39-
styles/sprites/*
4039

4140
# Bower stuff.
4241
bower_components/

gulpfile.js

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ gulp.on('task_start', function(msg) {
3131

3232
gulp.on('task_stop', function(msg) {
3333
gulp.executing.splice(gulp.executing.indexOf(msg.task), 1);
34-
gulp.hasOnce = gulp.executing.filter(function(name) {
35-
return name.match(/-once$/);
36-
}).length > 0;
37-
console.log(gulp.executing, gulp.hasOnce);
34+
console.log(gulp.executing.join(','));
3835
});
3936

4037

@@ -47,29 +44,18 @@ function lazyRequireTask(path) {
4744

4845
return function(callback) {
4946
var task = require(path).apply(this, args);
50-
5147
return task(callback);
5248
};
5349
}
5450

5551
function wrapWatch(watch, task) {
5652
return function(callback) {
5753
if (process.env.WATCH) {
58-
gulp.watch(watch, function(cb) {
59-
if (gulp.hasOnce) {
60-
var wait = function() {
61-
if (gulp.hasOnce) return;
62-
gulp.removeListener('task_stop', wait);
63-
gulp.start(task);
64-
};
65-
gulp.on('task_stop', wait);
66-
} else {
67-
gulp.start(task);
68-
}
69-
});
54+
setTimeout(function() {
55+
gulp.watch(watch, [task]);
56+
}, 1000); // don't start watching too fast (node.js bug, see https://github.com/joyent/node/issues/8326)
7057
} else {
7158
callback(); // @see usage examples, wrapWatch only triggers watch, should depend on ['task']
72-
// gulp.start(task, callback);
7359
}
7460
};
7561
}
@@ -78,7 +64,7 @@ gulp.task('lint-once', lazyRequireTask('./tasks/lint', { src: jsSources }));
7864

7965
gulp.task('lint-or-die', lazyRequireTask('./tasks/lint', { src: jsSources, dieOnError: true }));
8066

81-
gulp.task('lint', ['lint-once'], wrapWatch(jsSources, 'lint'));
67+
gulp.task('lint', wrapWatch(jsSources, 'lint-once'));
8268

8369
// usage: gulp loaddb --db fixture/db
8470
gulp.task('loaddb', lazyRequireTask('./tasks/loadDb'));
@@ -89,21 +75,25 @@ gulp.task("nodemon", lazyRequireTask('./tasks/nodemon', {
8975
watch: ["hmvc", "modules"]
9076
}));
9177

92-
gulp.task("client:livereload", lazyRequireTask("./tasks/livereload", { watch: "public/{i,img,js,styles}/*.*" }));
78+
gulp.task("client:livereload", lazyRequireTask("./tasks/livereload", { watch: "public/{i,img,js,styles}/**/*.*" }));
9379

9480
gulp.task('link-modules', lazyRequireTask('./tasks/linkModules', { src: ['client', 'modules/*', 'hmvc/*'] }));
9581

96-
gulp.task("client:sync-resources", lazyRequireTask('./tasks/syncResources', {
82+
gulp.task("client:sync-resources-once", lazyRequireTask('./tasks/syncResources', {
9783
'assets/fonts': 'public/fonts',
9884
'assets/img': 'public/img'
9985
}));
10086

87+
gulp.task("client:sync-resources",
88+
wrapWatch('assets/{fonts,img}/**', 'client:sync-resources-once')
89+
);
90+
10191
gulp.task("client:sync-css-images-once", lazyRequireTask('./tasks/syncCssImages', {
10292
src: 'styles/**/*.{png,svg,gif,jpg}',
10393
dst: 'public/i'
10494
}));
10595

106-
gulp.task('client:sync-css-images', ['client:sync-css-images-once'],
96+
gulp.task('client:sync-css-images',
10797
wrapWatch('styles/**/*.{png,svg,gif,jpg}', 'client:sync-css-images-once')
10898
);
10999

@@ -127,29 +117,31 @@ gulp.task('client:minify', lazyRequireTask('./tasks/minify', {
127117
root: './public'
128118
}));
129119

130-
131-
gulp.task('client:compile-css', ['client:compile-css-once'], wrapWatch(["styles/**/*.styl"], "client:compile-css-once"));
120+
gulp.task('client:compile-css', wrapWatch(["styles/**/*.styl"], "client:compile-css-once"));
132121

133122

134123
gulp.task("client:browserify:clean", lazyRequireTask('./tasks/browserifyClean', { dst: './public/js'}));
135124

136-
gulp.task("client:browserify-once", ['link-modules', 'client:browserify:clean'], lazyRequireTask('./tasks/browserify'));
137-
gulp.task("client:browserify", ['client:browserify-once'], wrapWatch(['client/**', 'hmvc/**/client/**'], "client:browserify-once"));
125+
gulp.task("client:browserify-once", ['client:browserify:clean'], lazyRequireTask('./tasks/browserify'));
126+
gulp.task("client:browserify", wrapWatch(['client/**', 'hmvc/**/client/**'], "client:browserify-once"));
138127

139128
// we depend on compile-css, because if build-md5-list-once works in parallel with client:compile-css,
140129
// then compile-css recreates files and build-md5-list-once misses them or errors when they are suddenly removed
141130
gulp.task("client:build-md5-list-once",
142131
lazyRequireTask('./tasks/buildMd5List', { cwd: 'public', src: './{fonts,js,styles}/**/*.*', dst: './public.md5.json' }));
143132

144-
gulp.task("client:build-md5-list", ['client:build-md5-list-once'],
145-
wrapWatch(['public/**'], 'client:build-md5-list-once')); // watch dirs only, not just files (to see new files)
133+
gulp.task("client:build-md5-list",
134+
wrapWatch(['public/{fonts,js,styles}/**'], 'client:build-md5-list-once')); // watch dirs only, not just files (to see new files)
146135

147136

148137
gulp.task('build', function(callback) {
149-
runSequence('link-modules', "client:sync-resources", 'client:compile-css', 'client:browserify', 'client:sync-css-images', 'client:build-md5-list', callback);
138+
runSequence('link-modules', "client:sync-resources-once", 'client:compile-css-once', 'client:browserify-once', 'client:sync-css-images-once', 'client:build-md5-list-once', callback);
150139
});
151140

152-
gulp.task('dev', ['nodemon', 'client:livereload', 'build']);
141+
gulp.task('dev', function(callback) {
142+
runSequence('build', ["client:sync-resources", 'client:compile-css', 'client:browserify', 'client:sync-css-images', 'client:build-md5-list', 'nodemon', 'client:livereload'], callback);
143+
// runSequence('build', ['nodemon', 'client:livereload', 'client:build-md5-list'], callback);
144+
});
153145

154146
gulp.task('tutorial:import', ['link-modules'], lazyRequireTask('tutorial/tasks/import', {
155147
root: 'javascript-tutorial',

hmvc/profile/templates/account.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ block content
1616

1717

1818

19-
script(src=addFileMd5("/js/profile.js"))
19+
script(src=addAssetVersion("/js/profile.js"))
2020
script require('profile/client').init();
2121

2222

hmvc/tutorial/templates/article.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ block sidebar
66
block content
77
!= body
88

9-
script(src=addFileMd5("/js/tutorial.js"))
9+
script(src=addAssetVersion("/js/tutorial.js"))
1010
script require('tutorial/client').init();

modules/config/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ if (process.env.NODE_ENV == 'development' && process.env.DEV_TRACE) {
1212

1313
require('lib/debug');
1414

15-
1615
var path = require('path');
1716
var fs = require('fs');
1817

modules/lib/debug.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ if (process.env.NODE_ENV == 'development') {
2323
* When a code dies with a strange event error w/o trace
2424
* Here I try to see what actually died
2525
*/
26-
if (process.env.DUMP_EVENT_ERRORS) {
26+
if (process.env.DEBUG_ERROR) {
2727
var proto = require('events').EventEmitter.prototype;
2828
var emit = proto.emit;
29-
proto.emit = function(type) {
30-
if (type == 'error') console.log(this, arguments);
31-
emit.apply(this, arguments);
29+
proto.emit = function(type, err) {
30+
if (type == 'error') {
31+
console.log(this.test, this.constructor.name, err.message, err.stack);
32+
process.exit(1);
33+
}
34+
else emit.apply(this, arguments);
3235
};
3336

3437
}

modules/setup/render.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ function addStandardHelpers(locals, ctx) {
7272

7373
locals.bem = require('bem-jade')();
7474

75-
locals.addFileMd5 = function(publicPath) {
75+
locals.addAssetVersion = function(publicPath) {
7676
if (publicPath[0] != '/') {
77-
throw new Error("addFileMd5 needs an /absolute/path");
77+
throw new Error("addAssetVersion needs an /absolute/path");
7878
}
7979
var md5 = getPublicMd5(publicPath);
8080
if (!md5) {
8181
throw new Error("No md5 for " + publicPath);
8282
}
83-
return publicPath + '?r=' + md5;
83+
return publicPath.replace('.', '.v' + md5 + '.');
8484
};
8585

8686
// locals.debug = true;

modules/setup/static.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,38 @@ function* staticMiddleware(next) {
8787
this.throw(404);
8888
}
8989

90-
var ext = path.extname(filepath).slice(1);
90+
// strip version
91+
filepath = stripVersion(filepath);
9192

92-
if (~['jpg', 'png', 'gif'].indexOf(ext) && this.cookies.get('hires')) {
93-
var try2x = filepath.slice(0, -ext.length-1) + '@2x.' + ext;
94-
if (yield fs.exists(try2x)) {
95-
filepath = try2x;
96-
}
93+
if (this.cookies.get('hires')) {
94+
filepath = yield try2xImage(filepath);
9795
}
9896

99-
10097
// use mime-types module instead of send built-in mime
10198
// (which doesn't show encoding on application/javascript)
102-
function onHeaders(res, filePath, stat) {
103-
res.setHeader('Content-Type', mime.contentType(path.basename(filePath)));
99+
function onHeaders(res, filepath, stat) {
100+
res.setHeader('Content-Type', mime.contentType(path.basename(filepath)));
104101
}
105102

106103
send(this.req, filepath, opts)
107104
.on('headers', onHeaders)
108105
.pipe(this.res);
109106

110107
}
108+
109+
function stripVersion(filepath) {
110+
return filepath.replace(/\.v.*?\./, '.');
111+
}
112+
113+
function* try2xImage(filepath) {
114+
var ext = path.extname(filepath).slice(1);
115+
116+
if (~['jpg', 'png', 'gif'].indexOf(ext)) {
117+
var try2x = filepath.slice(0, -ext.length-1) + '@2x.' + ext;
118+
if (yield fs.exists(try2x)) {
119+
filepath = try2x;
120+
}
121+
}
122+
123+
return filepath;
124+
}

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"event-stream": "*",
2626
"fs-extra": "*",
2727
"glob": "*",
28+
"glob-stream": "^3.1.15",
2829
"gm": "*",
2930
"gulp-cache": "*",
3031
"gulp-concat": "*",
@@ -42,7 +43,6 @@
4243
"gulp-rimraf": "*",
4344
"gulp-stylus": "*",
4445
"gulp-util": "*",
45-
"gulp.spritesmith": "*",
4646
"humane-js": "*",
4747
"humanize-number": "0.0.2",
4848
"image-size": "*",
@@ -103,10 +103,11 @@
103103
"stylus": "*",
104104
"svgutils": "*",
105105
"through": "^2.3.4",
106-
"through2": "*",
106+
"through2": "^0.6.1",
107107
"thunkify": "*",
108108
"uglify-js": "^2.4.15",
109109
"uglifyify": "^2.5.0",
110+
"vinyl": "^0.4.3",
110111
"vinyl-fs": "*",
111112
"vinyl-source-stream": "*",
112113
"yargs": "*"
@@ -127,13 +128,13 @@
127128
"gulp-mocha": "*",
128129
"gulp-sourcemaps": "*",
129130
"gulp-streamify": "0.0.5",
130-
"gulp-stylus-sprite": "*",
131131
"gulp-uglify": "^0.3.1",
132132
"lazypipe": "*",
133133
"mocha": "*",
134134
"node-notifier": "*",
135135
"nodemailer-stub-transport": "*",
136136
"requireify": "^0.2.1",
137+
"run-sequence": "^0.3.6",
137138
"should": "*",
138139
"sinon": "*",
139140
"superagent": "*",

styles/base.styl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ ie = false unless ie is defined
1919
@import 'nib/text'
2020
@import 'nib/size'
2121

22-
@require "sprites/*"
2322
@require "blocks/variables/variables"
2423
@require "blocks/reset/reset"
2524
@require "blocks/placeholders/*"
@@ -63,7 +62,7 @@ ie = false unless ie is defined
6362
@require "blocks/submit-button/submit-button"
6463
// @require "blocks/secondary-button/secondary-button"
6564
@require "blocks/page-footer/page-footer"
66-
@require "blocks/soc-icon/soc-icon"
65+
/*@require "blocks/soc-icon/soc-icon"*/
6766
@require "blocks/social/social"
6867
// @require "blocks/user/user"
6968
// @require "blocks/user-menu/user-menu"
@@ -90,7 +89,7 @@ ie = false unless ie is defined
9089
// @require "blocks/select2/select2"
9190
// @require "blocks/full-phone/full-phone"
9291
// @require "blocks/confirm/confirm"
93-
@require "blocks/social-link/social-link"
92+
/*@require "blocks/social-link/social-link"*/
9493
// @require "blocks/text-compact-label/text-compact-label"
9594
// @require "blocks/course-search/course-search"
9695
// @require "blocks/header-note/header-note"

0 commit comments

Comments
 (0)