forked from bookshelf/bookshelf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
93 lines (83 loc) · 2.72 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var gulp = require('gulp');
var bump = require('gulp-bump');
var shell = require('gulp-shell');
var browserify = require('browserify');
var through = require('through');
var argv = require('minimist')(process.argv.slice(2));
var Promise = require('bluebird');
var path = require('path');
var fs = Promise.promisifyAll(require('fs'));
var externals = ['events', 'buffer', 'lodash', 'bluebird', 'knex', 'backbone', 'trigger-then',
'create-error', 'inflection', 'inherits', 'simple-extend', 'semver'];
var alwaysExcluded = [];
function ensureOutputDirectory() {
return fs.mkdirAsync('./browser').catch(function(){});
}
function buildBookshelf() {
var outfile = argv.o || 'bookshelf.js';
var standalone = argv.s || 'Bookshelf';
var b = browserify(['./bookshelf.js']);
b.transform(function() {
var data = '';
function write (buf) { data += buf; }
function end () {
this.queue(data.replace("require('bluebird/js/main/promise')()", "require('bluebird')"));
this.queue(null);
}
return through(write, end);
});
alwaysExcluded.forEach(function(file) {
b.exclude(file);
});
externals.forEach(function(file) {
b.external(file);
});
ensureOutputDirectory().then(function() {
var outStream = fs.createWriteStream('./browser/' + outfile);
b.bundle({standalone: standalone}).pipe(outStream);
});
}
function buildDependencies() {
var b = browserify();
externals.forEach(function(ext) {
ext === 'knex' ? b.require(path.join(__dirname, '/node_modules/knex/browser/knex.js'), {expose: 'knex'}) : b.require(ext);
});
ensureOutputDirectory().then(function() {
var depStream = fs.createWriteStream('./browser/deps.js');
b.bundle().pipe(depStream);
});
}
gulp.task('build', function() {
buildBookshelf();
buildDependencies();
});
gulp.task('build:bookshelf', buildBookshelf);
gulp.task('build:deps', buildDependencies);
// Run the test... TODO: split these out to individual components.
gulp.task('jshint', shell.task(['npm run jshint']));
gulp.task('test', ['jshint'], shell.task(['npm run test']));
gulp.task('bump', function() {
var type = argv.type || 'patch';
return gulp.src('./package.json')
.pipe(bump({type: type}))
.pipe(gulp.dest('./'));
});
gulp.task('release', function() {
return fs.readFileAsync('./package.json')
.bind(JSON)
.then(JSON.parse)
.then(function(json) {
return shell.task([
'git add -u',
'git commit -m "release ' + json.version + '"',
'git tag ' + json.version,
'npm publish',
'git push',
'git push --tags',
'git checkout gh-pages',
'git merge master',
'git push',
'git checkout master'
])();
});
});