2014-09-01 17:16:39 +02:00
|
|
|
'use strict';
|
|
|
|
|
2014-05-28 22:29:34 -04:00
|
|
|
var gulp = require('gulp');
|
|
|
|
var bump = require('gulp-bump');
|
|
|
|
var shell = require('gulp-shell');
|
2014-05-05 21:53:09 -04:00
|
|
|
var browserify = require('browserify');
|
2014-05-28 22:29:34 -04:00
|
|
|
var argv = require('minimist')(process.argv.slice(2));
|
|
|
|
var Promise = require('bluebird');
|
|
|
|
var fs = Promise.promisifyAll(require('fs'));
|
2014-09-01 17:16:39 +02:00
|
|
|
var jshint = require('gulp-jshint');
|
2014-05-05 21:53:09 -04:00
|
|
|
|
|
|
|
var excluded = {
|
2014-08-14 18:00:48 -04:00
|
|
|
oracle: ['oracle'],
|
2014-06-04 04:10:27 -04:00
|
|
|
mariasql: ['mariasql'],
|
|
|
|
sqlite3: ['sqlite3'],
|
|
|
|
mysql: ['mysql'],
|
2014-06-09 16:27:03 -04:00
|
|
|
mysql2: ['mysql2'],
|
2014-06-04 04:10:27 -04:00
|
|
|
pg: ['pg', 'pg.js', 'pg-query-stream'],
|
|
|
|
websql: ['sqlite3']
|
2014-05-05 22:22:51 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
var bases = {
|
2014-08-14 18:00:48 -04:00
|
|
|
oracle: './lib/dialects/oracle',
|
2014-06-04 04:10:27 -04:00
|
|
|
mariasql: './lib/dialects/maria',
|
|
|
|
mysql: './lib/dialects/mysql',
|
2014-06-09 16:27:03 -04:00
|
|
|
mysql2: './lib/dialects/mysql2',
|
2014-06-04 04:10:27 -04:00
|
|
|
pg: './lib/dialects/postgres',
|
|
|
|
sqlite3: './lib/dialects/sqlite3',
|
|
|
|
websql: './lib/dialects/websql'
|
2014-05-05 21:53:09 -04:00
|
|
|
};
|
|
|
|
|
2014-07-21 09:42:56 -04:00
|
|
|
var alwaysExcluded = ['./lib/migrate/index.js', './lib/seed/index.js'];
|
2014-05-05 21:53:09 -04:00
|
|
|
|
2014-05-28 22:29:34 -04:00
|
|
|
function ensureOutputDirectory() {
|
|
|
|
return fs.mkdirAsync('./browser').catch(function(){});
|
|
|
|
}
|
|
|
|
|
2014-07-10 22:41:24 -04:00
|
|
|
function build(targets) {
|
2014-08-14 18:00:48 -04:00
|
|
|
var b = browserify(['./knex.js'], {standalone: 'Knex'});
|
2014-05-05 22:22:51 -04:00
|
|
|
for (var key in bases) {
|
|
|
|
if (targets.indexOf(key) === -1) {
|
|
|
|
b.exclude(bases[key]);
|
|
|
|
}
|
|
|
|
}
|
2014-05-05 21:53:09 -04:00
|
|
|
targets.forEach(function(target) {
|
|
|
|
excluded[target].forEach(function(file) {
|
|
|
|
b.exclude(file);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
alwaysExcluded.forEach(function(file) {
|
|
|
|
b.exclude(file);
|
|
|
|
});
|
2014-07-10 22:41:24 -04:00
|
|
|
return b;
|
|
|
|
}
|
2014-05-05 21:53:09 -04:00
|
|
|
|
2014-07-10 22:41:24 -04:00
|
|
|
function buildKnex() {
|
2014-08-14 18:00:48 -04:00
|
|
|
var b = build(['mysql', 'mysql2', 'mariasql', 'pg', 'sqlite3', 'websql', 'oracle']);
|
2014-07-10 22:41:24 -04:00
|
|
|
var outStream = fs.createWriteStream('./browser/knex.js');
|
2014-08-14 18:00:48 -04:00
|
|
|
b.bundle().pipe(outStream);
|
2014-07-10 22:41:24 -04:00
|
|
|
return outStream;
|
2014-05-28 22:29:34 -04:00
|
|
|
}
|
2014-05-05 21:53:09 -04:00
|
|
|
|
2014-06-03 01:37:19 -04:00
|
|
|
function buildWebSQL() {
|
2014-07-10 22:41:24 -04:00
|
|
|
var b = build(['websql']);
|
|
|
|
var outStream = fs.createWriteStream('./browser/websql.js');
|
2014-08-14 18:00:48 -04:00
|
|
|
b.bundle().pipe(outStream);
|
2014-07-10 22:41:24 -04:00
|
|
|
return outStream;
|
2014-06-03 01:37:19 -04:00
|
|
|
}
|
|
|
|
|
2014-07-10 22:41:24 -04:00
|
|
|
gulp.task('build', function() {
|
|
|
|
|
2014-09-01 17:16:39 +02:00
|
|
|
// Need to temporarily rename, otherwise browserify seems to read the
|
2014-07-10 22:41:24 -04:00
|
|
|
// local package.json, sees the browser path and doesn't build properly.
|
|
|
|
return ensureOutputDirectory().then(function() {
|
|
|
|
return fs.renameAsync('./package.json', './.package.json');
|
|
|
|
}).then(function() {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
function finish() {
|
|
|
|
fs.renameAsync('./.package.json', './package.json').then(resolve).catch(reject);
|
|
|
|
}
|
|
|
|
buildKnex().on('finish', function() {
|
|
|
|
buildWebSQL().on('finish', finish);
|
|
|
|
});
|
|
|
|
});
|
2014-05-28 22:29:34 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-05-29 01:57:59 -04:00
|
|
|
// Run the test... TODO: split these out to individual components.
|
2014-09-01 17:16:39 +02:00
|
|
|
gulp.task('jshint', function () {
|
2014-09-10 12:15:58 -04:00
|
|
|
gulp.src([
|
|
|
|
'*.js', 'lib/**/*.js', 'test/**/*.js',
|
|
|
|
'!test/coverage/**/*.js', '!test/integration/migrate/migrations/*.js'
|
|
|
|
])
|
2014-09-01 17:16:39 +02:00
|
|
|
.pipe(jshint())
|
|
|
|
.pipe(jshint.reporter('default'))
|
|
|
|
.pipe(jshint.reporter('fail'));
|
|
|
|
});
|
2014-05-29 01:57:59 -04:00
|
|
|
gulp.task('test', ['jshint'], shell.task(['npm run test']));
|
|
|
|
|
2014-06-06 17:38:52 -04:00
|
|
|
gulp.task('bump', function() {
|
2014-05-28 22:29:34 -04:00
|
|
|
var type = argv.type || 'patch';
|
|
|
|
return gulp.src('./package.json')
|
|
|
|
.pipe(bump({type: type}))
|
|
|
|
.pipe(gulp.dest('./'));
|
|
|
|
});
|
2014-06-06 17:38:52 -04:00
|
|
|
gulp.task('release', function() {
|
2014-05-28 22:29:34 -04:00
|
|
|
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 + '"',
|
2014-06-06 17:38:52 -04:00
|
|
|
'git tag ' + json.version,
|
|
|
|
'npm publish',
|
|
|
|
'git push',
|
|
|
|
'git push --tags',
|
|
|
|
'git checkout gh-pages',
|
|
|
|
'git merge master',
|
|
|
|
'git push',
|
|
|
|
'git checkout master'
|
2014-05-28 22:29:34 -04:00
|
|
|
])();
|
|
|
|
});
|
2014-09-01 17:16:39 +02:00
|
|
|
});
|