Merge pull request #28 from braydonf/refactor/make-dist
Refactor/make dist
This commit is contained in:
commit
9fdc439d88
|
@ -1,3 +1,2 @@
|
||||||
node_modules
|
node_modules
|
||||||
dist/bitauth.browser.js
|
|
||||||
dist/bitauth.browser.min.js
|
|
||||||
|
|
24
README.md
24
README.md
|
@ -185,3 +185,27 @@ BitAuth exposes a connect middleware for use in connect or ExpressJS application
|
||||||
var bitauth = require('bitauth');
|
var bitauth = require('bitauth');
|
||||||
app.use( bitauth.middleware );
|
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
|
||||||
|
```
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
!.gitignore
|
|
@ -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`.
|
|
|
@ -22,12 +22,11 @@
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"make-dist": "sh scripts/make-dist.sh",
|
"make-dist": "sh scripts/make-dist.sh",
|
||||||
"test": "mocha test/* --reporter spec",
|
"test": "mocha test/*.js --reporter spec",
|
||||||
"postinstall": "npm run make-dist"
|
"postinstall": "npm run make-dist"
|
||||||
},
|
},
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"version": "0.1.1",
|
"version": "0.1.1",
|
||||||
"repository": "https://github.com/bitpay/bitauth.git",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bitcore": "0.1.32",
|
"bitcore": "0.1.32",
|
||||||
"request": "^2.36.0",
|
"request": "^2.36.0",
|
||||||
|
@ -37,9 +36,8 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"uglify-js": "~2.4.14",
|
"uglify-js": "~2.4.14",
|
||||||
"browserify": "~4.1.11",
|
"browserify": "=6.1.0",
|
||||||
"should": "~4.0.4",
|
"chai": "=1.9.1",
|
||||||
"expect.js": "~0.3.1",
|
|
||||||
"mocha": "~1.20.1"
|
"mocha": "~1.20.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
cd node_modules/bitcore
|
cd node_modules/bitcore
|
||||||
echo "Building browser bundle for bitcore..."
|
echo "Building browser bundle for bitcore..."
|
||||||
node browser/build -s lib/Key,lib/SINKey,lib/SIN,util/util
|
node browser/build -s lib/Key,lib/SINKey,lib/SIN,util/util
|
||||||
echo "Building browser bundle for bitauth..."
|
|
||||||
cd ../../
|
cd ../../
|
||||||
node_modules/.bin/browserify lib/bitauth.js -s bitauth -x buffertools -i bitcore -o dist/bitauth.browser.js
|
cp node_modules/bitcore/browser/bundle.js dist/bitcore.bundle.js
|
||||||
echo "Compiling bitcore and bitauth..."
|
echo "Building browser bundle for bitauth..."
|
||||||
node_modules/.bin/uglifyjs node_modules/bitcore/browser/bundle.js dist/bitauth.browser.js -b -o dist/bitauth.browser.js
|
node_modules/.bin/browserify lib/bitauth.js -s bitauth -x buffertools -x bitcore -o dist/bitauth.bundle.js
|
||||||
echo "Minifying bundle..."
|
echo "Minifying bitcore and bitauth..."
|
||||||
node_modules/.bin/uglifyjs dist/bitauth.browser.js -o dist/bitauth.browser.min.js
|
node_modules/.bin/uglifyjs dist/bitcore.bundle.js dist/bitauth.bundle.js -o dist/bitauth.browser.min.js
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
|
|
|
@ -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>
|
|
@ -1,9 +1,17 @@
|
||||||
var should = require('should');
|
'use strict';
|
||||||
var expect = require('expect.js');
|
|
||||||
var bitauth = require('../index');
|
if ( typeof(window) === 'undefined' ) {
|
||||||
|
var bitauth = require('../index');
|
||||||
|
} else {
|
||||||
|
var bitauth = window.bitauth;
|
||||||
|
}
|
||||||
|
|
||||||
|
var chai = chai || require('chai');
|
||||||
|
|
||||||
describe('bitauth', function() {
|
describe('bitauth', function() {
|
||||||
|
|
||||||
|
var should = chai.should();
|
||||||
|
|
||||||
var keys = null;
|
var keys = null;
|
||||||
var sin = 'Tf1Jc1xSbqasm5QLwwSQc5umddx2h7mAMHX';
|
var sin = 'Tf1Jc1xSbqasm5QLwwSQc5umddx2h7mAMHX';
|
||||||
var sinb = 'Tf1Jc1xSbqasm5QLwwSQc5umddx2h7mAMhX';
|
var sinb = 'Tf1Jc1xSbqasm5QLwwSQc5umddx2h7mAMhX';
|
||||||
|
@ -84,48 +92,47 @@ describe('bitauth', function() {
|
||||||
|
|
||||||
describe('#validateSinCallback', function() {
|
describe('#validateSinCallback', function() {
|
||||||
|
|
||||||
var received;
|
it('should receive error callback', function(done) {
|
||||||
|
var valid = bitauth.validateSin(sinb, function(err){
|
||||||
var valid = bitauth.validateSin(sinb, function(err){
|
should.exist(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() {
|
|
||||||
done();
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
Loading…
Reference in New Issue