Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1dcfcb
commit d2bb71c
Showing
29 changed files
with
449 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ tmp | |
node_modules | ||
docs/_site | ||
docs/static/css | ||
docs/static/js/custom | ||
npm-debug.log | ||
*~ | ||
coverage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ tests/cordova/www | |
.idea | ||
phantomjsdriver.log | ||
bower_components | ||
./docs/ | ||
./docs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
var TARGET_DIR = __dirname + '/../docs/static/js/custom'; | ||
var NUM_CONCURRENT_PROMISES = require('os').cpus().length; | ||
|
||
var combinations = require('combinations'); | ||
var browserify = require('browserify'); | ||
var bluebird = require('bluebird'); | ||
var fs = bluebird.promisifyAll(require('fs')); | ||
var rimraf = require('rimraf'); | ||
var rimrafAsync = bluebird.promisify(rimraf); | ||
var mkdirp = require('mkdirp'); | ||
var streamToPromise = require('stream-to-promise'); | ||
var uglify = require('uglify-js'); | ||
var zlib = bluebird.promisifyAll(require('zlib')); | ||
var options = require('../lib/custom/options'); | ||
var generateName = require('../lib/custom/generateName'); | ||
var generateCode = require('../lib/custom/generateCode'); | ||
|
||
rimraf.sync(TARGET_DIR); | ||
mkdirp.sync(TARGET_DIR); | ||
|
||
function build(comboName, code) { | ||
var sourceFile = TARGET_DIR + '/pouchdb-custom-source-' + comboName + '.js'; | ||
var targetFile = TARGET_DIR + '/pouchdb-custom-' + comboName + '.js'; | ||
var targetMinFile = TARGET_DIR + '/pouchdb-custom-' + comboName + '.min.js'; | ||
|
||
var relativeCode = code.replace(/require\('pouchdb/g, | ||
'require(\'../../../..'); | ||
|
||
return fs.writeFileAsync(sourceFile, relativeCode, 'utf8').then(function () { | ||
var b = browserify(sourceFile, { | ||
standalone: 'PouchDB' | ||
}).plugin('bundle-collapser/plugin'); | ||
var stream = b.bundle().pipe(fs.createWriteStream(targetFile)); | ||
return streamToPromise(stream); | ||
}).then(function () { | ||
var uglified = uglify.minify(targetFile, { | ||
mangle: true, | ||
compress: {} | ||
}); | ||
return fs.writeFileAsync(targetMinFile, uglified.code, 'utf8'); | ||
}).then(function () { | ||
return rimrafAsync(sourceFile); | ||
}).then(function () { | ||
return bluebird.all([ | ||
fs.statAsync(targetFile), | ||
fs.statAsync(targetMinFile), | ||
bluebird.resolve().then(function () { | ||
var stream = fs.createReadStream(targetMinFile) | ||
.pipe(zlib.createGzip()); | ||
return streamToPromise(stream); | ||
}) | ||
]).then(function (arr) { | ||
var size = arr[0].size; | ||
var sizeMin = arr[1].size; | ||
var gzipped = arr[2]; | ||
return { | ||
size: size, | ||
sizeMin: sizeMin, | ||
sizeGzipped: gzipped.length | ||
}; | ||
}); | ||
}); | ||
} | ||
|
||
// don't overload the user's CPU, but also don't try to do absolutely | ||
// everything at once. it's a better UX to see a little bit of progress | ||
function createPromiseChains() { | ||
var promises = []; | ||
for (var i = 0; i < NUM_CONCURRENT_PROMISES; i++) { | ||
promises.push(bluebird.resolve()); | ||
} | ||
return promises; | ||
} | ||
|
||
var combos = combinations(options); | ||
combos.unshift([]); // add an empty one as well, at the beginning | ||
var builtInfo = {}; | ||
var promises = createPromiseChains(); | ||
var numDone = 0; | ||
var promiseIndex = 0; | ||
|
||
function buildPromise(combo, comboName, code) { | ||
var debuggableComboName = combo.map(function (x) { | ||
return x.name; | ||
}); | ||
return function () { | ||
return build(comboName, code).then(function (info) { | ||
console.log('Built custom build', | ||
JSON.stringify(debuggableComboName), | ||
'with ID', | ||
comboName, | ||
'(' + (++numDone) + '/' + combos.length +')...'); | ||
builtInfo[comboName] = info; | ||
}); | ||
}; | ||
} | ||
|
||
console.log('Building with', promises.length, 'concurrent promises...'); | ||
|
||
combos.forEach(function (combo) { | ||
var comboName = generateName(combo); | ||
var code = generateCode(combo); | ||
promises[promiseIndex] = promises[promiseIndex].then( | ||
buildPromise(combo, comboName, code)); | ||
if (++promiseIndex === promises.length) { | ||
promiseIndex = 0; | ||
} | ||
}); | ||
|
||
bluebird.all(promises).then(function () { | ||
return fs.writeFileAsync(TARGET_DIR + '/info.js', | ||
'window.customBuildsInfo = ' + | ||
JSON.stringify(builtInfo) + | ||
';', 'utf8'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
var PouchDB = require('./pouchdb'); | ||
|
||
// Some tests explicitly override this; also it's useful to have | ||
// it attached to utils for the custom builds, although it's a little awkward. | ||
PouchDB.ajax = PouchDB.utils.ajax = require('../lib/deps/ajax/prequest'); | ||
|
||
var httpAdapter = require('../lib/adapters/http'); | ||
PouchDB.adapter('http', httpAdapter); | ||
PouchDB.adapter('https', httpAdapter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
var PouchDB = require('./pouchdb'); | ||
|
||
var idb = require('../lib/adapters/idb'); | ||
PouchDB.adapter('idb', idb, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
var PouchDB = require('./pouchdb'); | ||
|
||
var level = require('../lib/adapters/leveldb'); | ||
PouchDB.adapter('leveldb', level, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
var PouchDB = require('./pouchdb'); | ||
|
||
PouchDB.plugin(require('../lib/mapreduce')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
var PouchDB = require('../lib/setup'); | ||
|
||
PouchDB.utils = require('../lib/utils'); | ||
PouchDB.Errors = require('../lib/deps/errors'); | ||
PouchDB.version = require('../lib/version'); | ||
|
||
module.exports = PouchDB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
var PouchDB = require('./pouchdb'); | ||
|
||
PouchDB.replicate = require('../lib/replicate').replicate; | ||
PouchDB.sync = require('../lib/sync'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
var PouchDB = require('./pouchdb'); | ||
|
||
var websql = require('../lib/adapters/websql'); | ||
PouchDB.adapter('websql', websql, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<div id="custom-builder"> | ||
<div> | ||
<div id="custom-options"> | ||
</div> | ||
</div> | ||
<div> | ||
<pre><code id="custom-code"></code></pre> | ||
<div id="custom-buttons"> | ||
<div> | ||
<a id="download-custom" class="btn btn-primary" href="#"> | ||
Download | ||
</a> | ||
</div> | ||
<div> | ||
<a id="download-custom-min" class="btn btn-primary" href="#"> | ||
Download min | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script src="static/js/custom/builder.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
layout: 2ColLeft | ||
title: Custom Builds | ||
sidebar: nav.html | ||
--- | ||
|
||
PouchDB supports custom builds! You can use exclude the parts of | ||
PouchDB you're not using, and then either download it from this page, or | ||
include it in your project as a | ||
[Browserifiable](http://browserify.com/)/[Webpackable](http://webpack.github.io/) | ||
script. | ||
|
||
{% include custom_builds.html %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#custom-builder { | ||
display: flex; | ||
width: 100%; | ||
margin-top: 30px; | ||
} | ||
|
||
#custom-builder > div:first-child { | ||
margin-right:5px; | ||
flex: 1; | ||
} | ||
|
||
#custom-builder > div:last-child { | ||
flex: 2; | ||
} | ||
|
||
#custom-options label { | ||
margin-left: 20px; | ||
font-size: 16px; | ||
} | ||
|
||
#custom-buttons { | ||
display: flex; | ||
width: 100%; | ||
} | ||
|
||
#custom-buttons > div:first-child { | ||
margin-right:5px; | ||
} | ||
|
||
#custom-buttons > div { | ||
flex-grow: 1; | ||
flex-shrink: 1; | ||
} | ||
|
||
#custom-buttons a { | ||
width: 100%; | ||
} | ||
|
||
.custom-option-info { | ||
color: #333; | ||
font-style: italic; | ||
margin: 5px 20px 5px; | ||
font-size: 12px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.