Merge pull request #28 from braydonf/refactor/make-dist

Refactor/make dist
This commit is contained in:
Patrick Nagurny 2014-10-22 15:34:10 -04:00
commit 9fdc439d88
8 changed files with 105 additions and 65 deletions

3
.gitignore vendored
View File

@ -1,3 +1,2 @@
node_modules
dist/bitauth.browser.js
dist/bitauth.browser.min.js

View File

@ -185,3 +185,27 @@ BitAuth exposes a connect middleware for use in connect or ExpressJS application
var bitauth = require('bitauth');
app.use( bitauth.middleware );
```
## Development
To build a browser compatible version of BitAuth, run the following command from the project's root directory:
```
npm run make-dist
```
This will output `bitauth.browser.min.js` to the `dist` directory. The script introduces a global variable at `window.bitauth`.
To then run tests for a web browser open `test/index.html` in a browser, such as:
```bash
firefox test/index.html
chromium-browser test/index.html
```
To run tests for Node.js:
```bash
npm run test
```

3
dist/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Ignore everything in this directory
*
!.gitignore

11
dist/README.md vendored
View File

@ -1,11 +0,0 @@
# BitAuth Browser Bundle
To build a browser compatible version of BitAuth, run the following command from
the project's root directory:
```
npm run make-dist
```
This will output `bitauth.browser.js` to this directory. The script introduces a
global variable at `window.bitauth`.

View File

@ -22,12 +22,11 @@
],
"scripts": {
"make-dist": "sh scripts/make-dist.sh",
"test": "mocha test/* --reporter spec",
"test": "mocha test/*.js --reporter spec",
"postinstall": "npm run make-dist"
},
"main": "index.js",
"version": "0.1.1",
"repository": "https://github.com/bitpay/bitauth.git",
"dependencies": {
"bitcore": "0.1.32",
"request": "^2.36.0",
@ -37,9 +36,8 @@
},
"devDependencies": {
"uglify-js": "~2.4.14",
"browserify": "~4.1.11",
"should": "~4.0.4",
"expect.js": "~0.3.1",
"browserify": "=6.1.0",
"chai": "=1.9.1",
"mocha": "~1.20.1"
}
}

View File

@ -1,11 +1,10 @@
cd node_modules/bitcore
echo "Building browser bundle for bitcore..."
node browser/build -s lib/Key,lib/SINKey,lib/SIN,util/util
echo "Building browser bundle for bitauth..."
cd ../../
node_modules/.bin/browserify lib/bitauth.js -s bitauth -x buffertools -i bitcore -o dist/bitauth.browser.js
echo "Compiling bitcore and bitauth..."
node_modules/.bin/uglifyjs node_modules/bitcore/browser/bundle.js dist/bitauth.browser.js -b -o dist/bitauth.browser.js
echo "Minifying bundle..."
node_modules/.bin/uglifyjs dist/bitauth.browser.js -o dist/bitauth.browser.min.js
cp node_modules/bitcore/browser/bundle.js dist/bitcore.bundle.js
echo "Building browser bundle for bitauth..."
node_modules/.bin/browserify lib/bitauth.js -s bitauth -x buffertools -x bitcore -o dist/bitauth.bundle.js
echo "Minifying bitcore and bitauth..."
node_modules/.bin/uglifyjs dist/bitcore.bundle.js dist/bitauth.bundle.js -o dist/bitauth.browser.min.js
echo "Done!"

21
test/index.html Normal file
View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>BitAuth Tests</title>
</head>
<body>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<script type="text/javascript" src="../dist/bitauth.browser.min.js"></script>
<script>
mocha.setup('bdd');
</script>
<script type="text/javascript" src="test.bitauth.js"></script>
<script>
mocha.run();
</script>
</body>
</html>

View File

@ -1,9 +1,17 @@
var should = require('should');
var expect = require('expect.js');
var bitauth = require('../index');
'use strict';
if ( typeof(window) === 'undefined' ) {
var bitauth = require('../index');
} else {
var bitauth = window.bitauth;
}
var chai = chai || require('chai');
describe('bitauth', function() {
var should = chai.should();
var keys = null;
var sin = 'Tf1Jc1xSbqasm5QLwwSQc5umddx2h7mAMHX';
var sinb = 'Tf1Jc1xSbqasm5QLwwSQc5umddx2h7mAMhX';
@ -84,48 +92,47 @@ describe('bitauth', function() {
describe('#validateSinCallback', function() {
var received;
var valid = bitauth.validateSin(sinb, function(err){
if ( err && typeof(err) == 'object' ) {
received = true;
}
});
it('should receive error callback', function() {
expect(received).to.eql(true);
});
});
describe('#encrypt', function() {
it('should encrypt the secret message', function(done) {
enc = bitauth.encrypt(password, secret);
should.exist(enc);
done();
});
});
describe('#decrypt', function() {
it('should decrypt the secret message', function(done) {
var dec = bitauth.decrypt(password, enc);
should.exist(dec);
done();
});
});
describe('#middleware', function() {
it('should expose an express middleware', function(done) {
bitauth.middleware( {} , {} , function() {
it('should receive error callback', function(done) {
var valid = bitauth.validateSin(sinb, function(err){
should.exist(err);
done();
});
});
});
// node specific tests
if ( typeof(window) === 'undefined' ) {
describe('#encrypt', function() {
it('should encrypt the secret message', function(done) {
enc = bitauth.encrypt(password, secret);
should.exist(enc);
done();
});
});
describe('#decrypt', function() {
it('should decrypt the secret message', function(done) {
var dec = bitauth.decrypt(password, enc);
should.exist(dec);
done();
});
});
describe('#middleware', function() {
it('should expose an express middleware', function(done) {
bitauth.middleware( {} , {} , function() {
done();
});
});
});
}
});