mirror of
https://github.com/knex/knex.git
synced 2025-12-26 14:38:38 +00:00
browserify -> webpack
This commit is contained in:
parent
0a2367fb07
commit
7dfad30ff0
59656
browser/knex.js
59656
browser/knex.js
File diff suppressed because it is too large
Load Diff
20118
browser/websql.js
20118
browser/websql.js
File diff suppressed because it is too large
Load Diff
80
gulpfile.js
80
gulpfile.js
@ -3,91 +3,11 @@
|
||||
var gulp = require('gulp');
|
||||
var bump = require('gulp-bump');
|
||||
var shell = require('gulp-shell');
|
||||
var browserify = require('browserify');
|
||||
var argv = require('minimist')(process.argv.slice(2));
|
||||
var Promise = require('bluebird');
|
||||
var fs = Promise.promisifyAll(require('fs'));
|
||||
var jshint = require('gulp-jshint');
|
||||
|
||||
var excluded = {
|
||||
oracle: ['oracle'],
|
||||
"strong-oracle": ['strong-oracle'],
|
||||
mariasql: ['mariasql'],
|
||||
sqlite3: ['sqlite3'],
|
||||
mysql: ['mysql'],
|
||||
mysql2: ['mysql2'],
|
||||
pg: ['pg', 'pg.js', 'pg-query-stream'],
|
||||
websql: ['sqlite3']
|
||||
};
|
||||
|
||||
var bases = {
|
||||
oracle: './lib/dialects/oracle',
|
||||
"strong-oracle": './lib/dialects/strong-oracle',
|
||||
mariasql: './lib/dialects/maria',
|
||||
mysql: './lib/dialects/mysql',
|
||||
mysql2: './lib/dialects/mysql2',
|
||||
pg: './lib/dialects/postgres',
|
||||
sqlite3: './lib/dialects/sqlite3',
|
||||
websql: './lib/dialects/websql'
|
||||
};
|
||||
|
||||
var alwaysExcluded = ['./lib/migrate/index.js', './lib/seed/index.js'];
|
||||
|
||||
function ensureOutputDirectory() {
|
||||
return fs.mkdirAsync('./browser').catch(function(){});
|
||||
}
|
||||
|
||||
function build(targets) {
|
||||
var b = browserify(['./knex.js'], {standalone: 'Knex'});
|
||||
for (var key in bases) {
|
||||
if (targets.indexOf(key) === -1) {
|
||||
b.exclude(bases[key]);
|
||||
}
|
||||
}
|
||||
targets.forEach(function(target) {
|
||||
excluded[target].forEach(function(file) {
|
||||
b.exclude(file);
|
||||
});
|
||||
});
|
||||
alwaysExcluded.forEach(function(file) {
|
||||
b.exclude(file);
|
||||
});
|
||||
return b;
|
||||
}
|
||||
|
||||
function buildKnex() {
|
||||
var b = build(['mysql', 'mysql2', 'mariasql', 'pg', 'sqlite3', 'websql', 'oracle']);
|
||||
var outStream = fs.createWriteStream('./browser/knex.js');
|
||||
b.bundle().pipe(outStream);
|
||||
return outStream;
|
||||
}
|
||||
|
||||
function buildWebSQL() {
|
||||
var b = build(['websql']);
|
||||
var outStream = fs.createWriteStream('./browser/websql.js');
|
||||
b.bundle().pipe(outStream);
|
||||
return outStream;
|
||||
}
|
||||
|
||||
gulp.task('build', function() {
|
||||
|
||||
// Need to temporarily rename, otherwise browserify seems to read the
|
||||
// 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// Run the test... TODO: split these out to individual components.
|
||||
gulp.task('jshint', function () {
|
||||
gulp.src([
|
||||
|
||||
10
index.html
10
index.html
@ -653,8 +653,8 @@ knex('users').whereNot('votes', '>', 100)
|
||||
WhereNot is not suitable for "in" and "between" type subqueries. You should use "not in" and "not between" instead.
|
||||
</p>
|
||||
|
||||
<pre class="display">
|
||||
var subquery = knex('users').whereNot('votes', '>', 100).andWhere('status', 'active').orWhere('name', 'John').select('id');
|
||||
<pre class="js">
|
||||
var subquery = knex('users').whereNot('votes', '>', 100).andWhere('status', 'active').orWhere('name', 'John').select('id');
|
||||
|
||||
<span style='text-decoration:line-through'>knex('accounts').whereNot('id', 'in', subquery)</span>
|
||||
knex('accounts').where('id', 'not in', subquery)
|
||||
@ -3059,9 +3059,11 @@ $ npm test
|
||||
<script src="docs/assets/jquery.min.js"></script>
|
||||
<script src="docs/assets/jquery.cookie.js"></script>
|
||||
<script src="docs/assets/highlight.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/2.9.24/bluebird.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.7.0/lodash.js"></script>
|
||||
<script src="browser/knex.js"></script>
|
||||
<script>
|
||||
var trx = {}, dialects = {};
|
||||
var trx, dialects = {};
|
||||
|
||||
// Feel free to play with these in the console.
|
||||
var knex = Knex({client: 'websql'});
|
||||
@ -3080,6 +3082,8 @@ $ npm test
|
||||
var code = $(this).data('code') || $(this).data('code', $(this).text()).data('code');
|
||||
try {
|
||||
var blocks = code.split('\n\n')
|
||||
dialects[dialect].client.transacting = true
|
||||
trx = dialects[dialect]
|
||||
blocks[blocks.length - 1] = 'return (' + blocks[blocks.length - 1] + ').toString()';
|
||||
$(this).html('<code class="js">' + code + '</code><br /><br />Outputs:<br /><code class="sql">' + new Function('knex', 'trx', blocks.join('\n\n'))(dialects[dialect], trx)) + '</code>';
|
||||
} catch (e) {
|
||||
|
||||
@ -16,9 +16,9 @@ inherits(Client_MariaSQL, Client_MySQL)
|
||||
|
||||
assign(Client_MariaSQL.prototype, {
|
||||
|
||||
dialect: 'mariasql'
|
||||
dialect: 'mariasql',
|
||||
|
||||
driverName: 'mariasql'
|
||||
driverName: 'mariasql',
|
||||
|
||||
// Get a raw connection, called by the `pool` whenever a new
|
||||
// connection needs to be added to the pool.
|
||||
@ -34,7 +34,7 @@ assign(Client_MariaSQL.prototype, {
|
||||
})
|
||||
.on('error', rejecter);
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// Return the database for the MariaSQL client.
|
||||
database: function() {
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var crypto = require('crypto');
|
||||
var _ = require('lodash');
|
||||
var helpers = require('../../helpers');
|
||||
|
||||
function generateCombinedName(postfix, name, subNames) {
|
||||
var limit = 30;
|
||||
var crypto = require('crypto');
|
||||
var limit = 30;
|
||||
if (!Array.isArray(subNames)) subNames = subNames ? [subNames] : [];
|
||||
var table = name.replace(/\.|-/g, '_');
|
||||
var subNamesPart = subNames.join('_');
|
||||
|
||||
@ -7,6 +7,7 @@ var _ = require('lodash');
|
||||
|
||||
var Client_SQLite3 = require('../sqlite3');
|
||||
var Promise = require('../../promise');
|
||||
var assign = require('lodash/object/assign');
|
||||
|
||||
function Client_WebSQL(config) {
|
||||
Client_SQLite3.call(this, config);
|
||||
|
||||
@ -24,7 +24,7 @@ function Knex(config) {
|
||||
Dialect = makeClient(Client)
|
||||
} else {
|
||||
var clientName = config.client || config.dialect
|
||||
Dialect = makeClient(require('./dialects/' + (aliases[clientName] || clientName)))
|
||||
Dialect = makeClient(require('./dialects/' + (aliases[clientName] || clientName) + '/index.js'))
|
||||
}
|
||||
return makeKnex(new Dialect(config))
|
||||
}
|
||||
|
||||
29
package.json
29
package.json
@ -6,16 +6,6 @@
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"browser": {
|
||||
"./lib/dialects/oracle": false,
|
||||
"./lib/dialects/strong-oracle": false,
|
||||
"./lib/dialects/maria": false,
|
||||
"./lib/dialects/mysql": false,
|
||||
"./lib/dialects/mysql2": false,
|
||||
"./lib/dialects/postgres": false,
|
||||
"./lib/dialects/sqlite3": false,
|
||||
"sqlite3": false
|
||||
},
|
||||
"dependencies": {
|
||||
"bluebird": "^2.9.24",
|
||||
"chalk": "^1.0.0",
|
||||
@ -23,6 +13,7 @@
|
||||
"debug": "^2.1.3",
|
||||
"inherits": "~2.0.1",
|
||||
"interpret": "^0.5.2",
|
||||
"jshint": "^2.7.0",
|
||||
"liftoff": "~2.0.0",
|
||||
"lodash": "^3.7.0",
|
||||
"minimist": "~1.1.0",
|
||||
@ -33,18 +24,20 @@
|
||||
"v8flags": "^2.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"through": "^2.3.4",
|
||||
"browserify": "~5.12.1",
|
||||
"chai": "^1.9.1",
|
||||
"chai-as-promised": "^4.1.0",
|
||||
"coveralls": "~2.11.1",
|
||||
"gulp": "^3.8.11",
|
||||
"gulp-bump": "^0.1.8",
|
||||
"gulp-git": "~0.5.0",
|
||||
"gulp-shell": "^0.2.5",
|
||||
"gulp-jshint": "^1.8.4",
|
||||
"chai": "^1.9.1",
|
||||
"chai-as-promised": "^4.1.0",
|
||||
"gulp-shell": "^0.2.5",
|
||||
"istanbul": "~0.3.0",
|
||||
"jshint": "~2.5.1",
|
||||
"mariasql": "~0.1.21",
|
||||
"mocha": "^1.20.0",
|
||||
"mysql": "^2.6.2",
|
||||
"mysql2": "^0.15.5",
|
||||
"node-uuid": "~1.4.0",
|
||||
"pg": "^4.3.0",
|
||||
"pg-query-stream": "^0.7.0",
|
||||
@ -52,10 +45,8 @@
|
||||
"sinon": "^1.10.0",
|
||||
"sinon-chai": "^2.5.0",
|
||||
"sqlite3": "~3.0.2",
|
||||
"mariasql": "~0.1.21",
|
||||
"mysql2": "^0.15.5",
|
||||
"istanbul": "~0.3.0",
|
||||
"coveralls": "~2.11.1"
|
||||
"through": "^2.3.4",
|
||||
"webpack": "^1.8.9"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gulp build",
|
||||
|
||||
44
webpack.config.js
Normal file
44
webpack.config.js
Normal file
@ -0,0 +1,44 @@
|
||||
var webpack = require('webpack');
|
||||
|
||||
var plugins = [
|
||||
new webpack.NormalModuleReplacementPlugin(/\.\.\/(migrate|seed)/, 'lodash/utility/noop'),
|
||||
new webpack.IgnorePlugin(/(migrate|seed|bin)/, /lib/),
|
||||
new webpack.IgnorePlugin(/(sqlite3|pg|pg-query-stream|mysql|mysql2|oracle)/, /node_modules/)
|
||||
];
|
||||
|
||||
if (process.env.COMPRESS) {
|
||||
plugins.push(
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compressor: {
|
||||
warnings: false
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
output: {
|
||||
library: 'Knex',
|
||||
libraryTarget: 'umd'
|
||||
},
|
||||
|
||||
externals: [{
|
||||
"bluebird": {
|
||||
root: "Bluebird",
|
||||
commonjs2: "bluebird",
|
||||
commonjs: "bluebird",
|
||||
amd: "bluebird"
|
||||
},
|
||||
"lodash": {
|
||||
root: "_",
|
||||
commonjs2: "lodash",
|
||||
commonjs: "lodash",
|
||||
amd: "lodash"
|
||||
},
|
||||
"crypto": "crypto"
|
||||
}],
|
||||
|
||||
plugins: plugins
|
||||
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user