Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.

Commit d528e95

Browse files
committed
fix build process, fix dev watchify process
1 parent a7daf4c commit d528e95

File tree

6 files changed

+58
-14
lines changed

6 files changed

+58
-14
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ coverage
55
test/test-bundle.jsnpm-debug.log
66
npm-debug.log
77
test/test-bundle.js
8+
dist

bin/dev-server.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,40 @@
22

33
'use strict';
44

5+
var PouchDB = require('pouchdb');
6+
var COUCH_HOST = process.env.COUCH_HOST || 'http://127.0.0.1:5984';
7+
var HTTP_PORT = 8002;
8+
var CORS_PORT = 2022;
9+
510
var cors_proxy = require("corsproxy");
611
var http_proxy = require("http-proxy");
712
var http_server = require("http-server");
813
var fs = require('fs');
914

10-
var COUCH_HOST = process.env.COUCH_HOST || 'http://127.0.0.1:5984';
15+
var indexfile = "./test/test.js";
16+
var dotfile = "./test/.test-bundle.js";
17+
var outfile = "./test/test-bundle.js";
18+
var watchify = require("watchify");
19+
var w = watchify(indexfile);
1120

12-
var HTTP_PORT = 8000;
13-
var CORS_PORT = 2020;
21+
w.on('update', bundle);
22+
bundle();
23+
24+
function bundle() {
25+
var wb = w.bundle();
26+
wb.on('error', function (err) {
27+
console.error(String(err));
28+
});
29+
wb.on("end", end);
30+
wb.pipe(fs.createWriteStream(dotfile));
31+
32+
function end() {
33+
fs.rename(dotfile, outfile, function (err) {
34+
if (err) { return console.error(err); }
35+
console.log('Updated:', outfile);
36+
});
37+
}
38+
}
1439

1540
function startServers(couchHost) {
1641
http_server.createServer().listen(HTTP_PORT);

index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,10 @@ function AuthError(message) {
144144
} catch (e) {}
145145
}
146146

147-
utils.inherits(AuthError, Error);
147+
utils.inherits(AuthError, Error);
148+
149+
if (typeof window !== 'undefined' && window.PouchDB) {
150+
Object.keys(exports).forEach(function (key) {
151+
window.PouchDB.plugin(key, exports[key]);
152+
});
153+
}

package.json

+15-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"do_tests": "TEST_DB=http://localhost:5984/testdb istanbul test ./node_modules/mocha/bin/_mocha test/test.js",
1212
"jshint": "jshint -c .jshintrc *.js test/test.js",
1313
"test": "npm run jshint && npm run do_tests",
14-
"build": "mkdir -p dist && browserify index.js -s authentication -o dist/pouchdb-authentication.js",
14+
"build-js": "mkdir -p dist && browserify index.js -o dist/pouchdb.authentication.js",
15+
"min": "uglifyjs dist/pouchdb.authentication.js -mc > dist/pouchdb.authentication.min.js",
16+
"build": "npm run build-js && npm run min",
1517
"dev": "browserify test/test.js > test/test-bundle.js && npm run dev-server",
1618
"dev-server": "./bin/dev-server.js"
1719
},
@@ -28,24 +30,29 @@
2830
"url": "https://github.com/pouchdb/authentication/issues"
2931
},
3032
"dependencies": {
31-
"lie": "^2.5.3",
32-
"inherits": "~2.0.1",
33-
"http-proxy": "~0.10.3",
34-
"corsproxy": "~0.2.13",
35-
"http-server": "~0.5.5"
33+
"inherits": "~2.0.1"
3634
},
3735
"devDependencies": {
36+
"lie": "^2.5.3",
3837
"bluebird": "^1.0.7",
39-
"browserify": "~2.36.0",
38+
"browserify": "~3.44.1",
4039
"chai": "~1.8.1",
4140
"chai-as-promised": "~4.1.0",
4241
"istanbul": "~0.1.45",
4342
"jshint": "~2.3.0",
4443
"mocha": "~1.14.0",
4544
"mocha-as-promised": "~2.0.0",
46-
"pouchdb": "^2.0.0"
45+
"pouchdb": "^2.0.0",
46+
"watchify": "~0.7.2",
47+
"http-proxy": "~0.10.4",
48+
"corsproxy": "~0.2.14",
49+
"http-server": "~0.5.5",
50+
"uglify-js": "~2.4.13"
4751
},
4852
"peerDependencies": {
4953
"pouchdb": ">= 2.0.0"
54+
},
55+
"browser": {
56+
"lie" : false
5057
}
5158
}

test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ chai.use(require('chai-as-promised'));
1313
var Promise = require('bluebird');
1414
var all = Promise.all;
1515
if (process.browser) {
16-
process.env.TEST_DB = 'http://localhost:2020/testdb';
16+
process.env.TEST_DB = 'http://localhost:2022/testdb';
1717
}
1818
var dbs = process.env.TEST_DB;
1919
if (!dbs) {

utils.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
'use strict';
22

3-
var Promise = typeof global.Promise === 'function' ? global.Promise : require('lie');
3+
var Promise;
4+
if (typeof window !== 'undefined' && window.PouchDB) {
5+
Promise = window.PouchDB.utils.Promise;
6+
} else {
7+
Promise = typeof global.Promise === 'function' ? global.Promise : require('lie');
8+
}
49

510
function getBaseUrl(db) {
611
return db.getUrl().replace(/\/[^\/]+\/?$/, '');

0 commit comments

Comments
 (0)