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

Commit

Permalink
build: browserify ergänzt
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Gabriel committed Sep 10, 2014
1 parent 4855b50 commit 560596e
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .couchappignore
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
// ".*~$" // ".*~$"
// ".*\\.swp$" // ".*\\.swp$"
// ".*\\.bak$" // ".*\\.bak$"
"node_modules$" "node_modules$", "gulp-tasks$", "gulpfile.js"
"gulp-tasks$"
] ]
53 changes: 53 additions & 0 deletions gulp-tasks/browserify.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,53 @@
/* browserify task
---------------
Bundle javascripty things with browserify!
If the watch task is running, this uses watchify instead
of browserify for faster bundling using caching.
*/

var browserify = require('browserify');
var watchify = require('watchify');
var bundleLogger = require('../vendor/couchapp/_attachments/util/bundleLogger');
var gulp = require('gulp');
var handleErrors = require('../vendor/couchapp/_attachments/util/handleErrors');
var source = require('vinyl-source-stream');

gulp.task('browserify', function() {
var bundler = browserify({
// Required watchify args
cache: {}, packageCache: {}, fullPaths: true,
// Specify the entry point of your app
entries: ['./vendor/couchapp/_attachments/evab.js'],
// Add file extentions to make optional in your requires
extensions: ['.js'],
// Enable source maps!
debug: true
});

var bundle = function() {
// Log when bundling starts
bundleLogger.start();

return bundler
.bundle()
// Report compile errors
.on('error', handleErrors)
// Use vinyl-source-stream to make the
// stream gulp compatible. Specifiy the
// desired output filename here.
.pipe(source('app.js'))
// Specify the output destination
.pipe(gulp.dest('./vendor/couchapp/_attachments/'))
// Log when bundling completes!
.on('end', bundleLogger.end);
};

if(global.isWatching) {
bundler = watchify(bundler);
// Rebundle with watchify on changes.
bundler.on('update', bundle);
}

return bundle();
});
4 changes: 3 additions & 1 deletion gulp-tasks/watch.js
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,8 @@
var gulp = require('gulp'); var gulp = require('gulp');


return gulp.task('watch', function() { return gulp.task('watch', function() {
gulp.watch(['_attachments/*', 'vendor/couchapp/_attachments/*', '-vendor/couchapp/_attachments/main.js', '-vendor/couchapp/_attachments/main2.js', '-_attachments/style'], ['dev_src_1', 'dev_src_2']); gulp.watch(['_attachments/*', 'vendor/couchapp/_attachments/*', '-vendor/couchapp/_attachments/main.js', '-vendor/couchapp/_attachments/main2.js', '-vendor/couchapp/_attachments/app.js', '-_attachments/style'], ['dev_src_1', 'dev_src_2']);
gulp.watch(['_attachments/style/*', '-_attachments/style/main.css', '-_attachments/style/evab.min.css'], ['dev_style']); gulp.watch(['_attachments/style/*', '-_attachments/style/main.css', '-_attachments/style/evab.min.css'], ['dev_style']);
// browserify soll wissen, das gewatched wird
global.isWatching = true;
}); });
6 changes: 5 additions & 1 deletion package.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
"gulp-uglify": "~0.3.2", "gulp-uglify": "~0.3.2",
"gulp-notify": "~1.3.1", "gulp-notify": "~1.3.1",
"browserify": "~5.11.1", "browserify": "~5.11.1",
"require-dir": "~0.1.0" "require-dir": "~0.1.0",
"watchify": "~1.0.2",
"vinyl-source-stream": "~1.0.0",
"gulp-util": "~3.0.1",
"pretty-hrtime": "~0.2.1"
} }
} }
21 changes: 21 additions & 0 deletions vendor/couchapp/_attachments/util/bundleLogger.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,21 @@
/* bundleLogger
------------
Provides gulp style logs to the bundle method in browserify.js
*/

var gutil = require('gulp-util');
var prettyHrtime = require('pretty-hrtime');
var startTime;

module.exports = {
start: function() {
startTime = process.hrtime();
gutil.log('Running', gutil.colors.green("'bundle'") + '...');
},

end: function() {
var taskTime = process.hrtime(startTime);
var prettyTime = prettyHrtime(taskTime);
gutil.log('Finished', gutil.colors.green("'bundle'"), 'in', gutil.colors.magenta(prettyTime));
}
};
15 changes: 15 additions & 0 deletions vendor/couchapp/_attachments/util/handleErrors.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,15 @@
var notify = require("gulp-notify");

module.exports = function() {

var args = Array.prototype.slice.call(arguments);

// Send error to notification center with gulp-notify
notify.onError({
title: "Compile Error",
message: "<%= error.message %>"
}).apply(this, args);

// Keep gulp from hanging on this task
this.emit('end');
};

0 comments on commit 560596e

Please sign in to comment.