Skip to content

Commit

Permalink
Merge pull request #28 from braydonf/refactor/make-dist
Browse files Browse the repository at this point in the history
Refactor/make dist
  • Loading branch information
pnagurny committed Oct 22, 2014
2 parents 9e54ccd + c18ee6f commit 9fdc439
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 55 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules
dist/bitauth.browser.js
dist/bitauth.browser.min.js

24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 3 additions & 0 deletions dist/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore everything in this directory
*
!.gitignore
11 changes: 0 additions & 11 deletions dist/README.md

This file was deleted.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
11 changes: 5 additions & 6 deletions scripts/make-dist.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 21 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -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>
69 changes: 38 additions & 31 deletions test/bitauth.js → test/test.bitauth.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
it('should receive error callback', function(done) {
var valid = bitauth.validateSin(sinb, function(err){
should.exist(err);
done();
});
});

});

describe('#encrypt', function() {
// node specific tests
if ( typeof(window) === 'undefined' ) {

it('should encrypt the secret message', function(done) {
enc = bitauth.encrypt(password, secret);
should.exist(enc);
done();
describe('#encrypt', function() {

it('should encrypt the secret message', function(done) {
enc = bitauth.encrypt(password, secret);
should.exist(enc);
done();
});
});

});
describe('#decrypt', function() {

describe('#decrypt', function() {
it('should decrypt the secret message', function(done) {
var dec = bitauth.decrypt(password, enc);
should.exist(dec);
done();
});

it('should decrypt the secret message', function(done) {
var dec = bitauth.decrypt(password, enc);
should.exist(dec);
done();
});

});

describe('#middleware', function() {
describe('#middleware', function() {

it('should expose an express middleware', function(done) {
bitauth.middleware( {} , {} , function() {
done();
it('should expose an express middleware', function(done) {
bitauth.middleware( {} , {} , function() {
done();
});
});

});

});
}

});

0 comments on commit 9fdc439

Please sign in to comment.