Extended publishing of libraries to npm (#3786)

* Extended publishing of libraries to npm

* Update source links

* Add some tests before publishing NPM library

* Fix Shapeshift tests
This commit is contained in:
Jaco Greeff 2016-12-11 10:13:34 +01:00 committed by GitHub
parent bfb684a641
commit 36b8e4b6a8
23 changed files with 394 additions and 38 deletions

View File

@ -0,0 +1,34 @@
# @parity/Etherscan
A thin, lightweight promise wrapper for the api.etherscan.io/apis service, exposing a common endpoint for use in JavaScript applications.
[https://github.com/ethcore/parity/tree/master/js/src/3rdparty/etherscan](https://github.com/ethcore/parity/tree/master/js/src/3rdparty/etherscan)
## usage
installation -
```
npm install --save @parity/Etherscan
```
Usage -
```
const etherscan = require('@parity/Etherscan');
// api calls goes here
```
## api
account (exposed on etherscan.account) -
- `balance(address)`
- `balances(addresses)` (array or addresses)
- `transactions(address, page)` (page offset starts at 0, returns 25)
stats (exposed on etherscan.stats) -
- `price()`
- `supply()`

View File

@ -0,0 +1,33 @@
{
"name": "@parity/Etherscan",
"description": "The Parity Promise-based library for interfacing with Etherscan over HTTP",
"version": "0.0.0",
"main": "library.js",
"author": "Parity Team <admin@parity.io>",
"maintainers": [
"Jaco Greeff"
],
"contributors": [],
"license": "GPL-3.0",
"repository": {
"type": "git",
"url": "git+https://github.com/ethcore/parity.git"
},
"keywords": [
"Ethereum",
"ABI",
"API",
"RPC",
"Parity",
"Promise"
],
"scripts": {
},
"devDependencies": {
"chai": "3.5.0",
"mocha": "3.2.0"
},
"dependencies": {
"node-fetch": "~1.6.3"
}
}

View File

@ -1,7 +1,9 @@
# parity.js
# @parity/parity.js
Parity.js is a thin, fast, Promise-based wrapper around the Ethereum APIs.
[https://github.com/ethcore/parity/tree/master/js/src/api](https://github.com/ethcore/parity/tree/master/js/src/api)
## installation
Install the package with `npm install --save @parity/parity.js`

View File

@ -1,6 +1,6 @@
{
"name": "@parity/parity.js",
"description": "The Parity Promise-base API & ABI library for interfacing with Ethereum over RPC",
"description": "The Parity Promise-based API & ABI library for interfacing with Ethereum over RPC",
"version": "0.0.0",
"main": "library.js",
"author": "Parity Team <admin@parity.io>",
@ -26,8 +26,8 @@
"devDependencies": {
},
"dependencies": {
"bignumber.js": "^2.3.0",
"js-sha3": "^0.5.2",
"node-fetch": "^1.6.3"
"bignumber.js": "~2.3.0",
"js-sha3": "~0.5.2",
"node-fetch": "~1.6.3"
}
}

View File

@ -0,0 +1,26 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
const parity = require('../');
describe('load the Parity library', function () {
it('should no throw any error', () => {
expect(parity).to.be.ok;
expect(parity.Api).to.be.ok;
expect(parity.Abi).to.be.ok;
});
});

View File

@ -0,0 +1,34 @@
# @parity/ShapeShift
A thin ES6 promise wrapper around the shapeshift.io APIs as documented at https://shapeshift.io/api
[https://github.com/ethcore/parity/tree/master/js/src/3rdparty/shapeshift](https://github.com/ethcore/parity/tree/master/js/src/3rdparty/shapeshift)
## usage
installation -
```
npm install --save @parity/ShapeShift
```
Usage -
```
const APIKEY = 'private affiliate key or undefined';
const shapeshift = require('@parity/ShapeShift')(APIKEY);
// api calls goes here
```
## api
queries -
- `getCoins()` [https://shapeshift.io/api#api-104](https://shapeshift.io/api#api-104)
- `getMarketInfo(pair)` [https://shapeshift.io/api#api-103](https://shapeshift.io/api#api-103)
- `getStatus(depositAddress)` [https://shapeshift.io/api#api-5](https://shapeshift.io/api#api-5)
transactions -
- `shift(toAddress, returnAddress, pair)` [https://shapeshift.io/api#api-7](https://shapeshift.io/api#api-7)

View File

@ -0,0 +1,31 @@
{
"name": "@parity/ShapeShift",
"description": "The Parity Promise-based library for interfacing with ShapeShift over HTTP",
"version": "0.0.0",
"main": "library.js",
"author": "Parity Team <admin@parity.io>",
"maintainers": [
"Jaco Greeff"
],
"contributors": [],
"license": "GPL-3.0",
"repository": {
"type": "git",
"url": "git+https://github.com/ethcore/parity.git"
},
"keywords": [
"Ethereum",
"ABI",
"API",
"RPC",
"Parity",
"Promise"
],
"scripts": {
},
"devDependencies": {
},
"dependencies": {
"node-fetch": "~1.6.3"
}
}

View File

@ -0,0 +1,29 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
const chai = require('chai');
// const chaiAsPromised from 'chai-as-promised';
// const chaiEnzyme from 'chai-enzyme';
// const sinonChai from 'sinon-chai';
// chai.use(chaiAsPromised);
// chai.use(chaiEnzyme());
// chai.use(sinonChai);
// expose expect to global so we won't have to manually import & define it in every test
global.expect = chai.expect;
module.exports = {};

1
js/npm/test/mocha.opts Normal file
View File

@ -0,0 +1 @@
-r ./test/mocha.config

View File

@ -43,7 +43,7 @@
"test": "NODE_ENV=test mocha 'src/**/*.spec.js'",
"test:coverage": "NODE_ENV=test istanbul cover _mocha -- 'src/**/*.spec.js'",
"test:e2e": "NODE_ENV=test mocha 'src/**/*.e2e.js'",
"test:npm": "(cd .npmjs && npm i) && node test/npmLibrary && (rm -rf .npmjs/node_modules)",
"test:npm": "(cd .npmjs && npm i) && node test/npmParity && (rm -rf .npmjs/node_modules)",
"prepush": "npm run lint:cached"
},
"devDependencies": {

33
js/scripts/dryrun-npm.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
set -e
# variables
PACKAGES=( "Parity" "Etherscan" "ShapeShift" )
# change into the build directory
BASEDIR=`dirname $0`
cd $BASEDIR/..
# build all packages
echo "*** Building packages for npmjs"
echo "$NPM_TOKEN" >> ~/.npmrc
for PACKAGE in ${PACKAGES[@]}
do
echo "*** Building $PACKAGE"
LIBRARY=$PACKAGE npm run ci:build:npm
DIRECTORY=.npmjs/$(echo $PACKAGE | tr '[:upper:]' '[:lower:]')
cd $DIRECTORY
echo "*** Executing $PACKAGE tests from $DIRECTORY"
npm test
echo "*** Publishing $PACKAGE from $DIRECTORY"
echo "npm publish --access public || true"
cd ../..
done
cd ..
# exit with exit code
exit 0

View File

@ -3,7 +3,7 @@ set -e
# variables
UTCDATE=`date -u "+%Y%m%d-%H%M%S"`
PACKAGES=( "parity.js" )
PACKAGES=( "Parity" "Etherscan" "ShapeShift" )
BRANCH=$CI_BUILD_REF_NAME
GIT_JS_PRECOMPILED="https://${GITHUB_JS_PRECOMPILED}:@github.com/ethcore/js-precompiled.git"
GIT_PARITY="https://${GITHUB_JS_PRECOMPILED}:@github.com/ethcore/parity.git"
@ -59,19 +59,27 @@ git reset --hard origin/$BRANCH 2>$GITLOG
if [ "$BRANCH" == "master" ]; then
cd js
echo "*** Bumping package.json patch version"
npm --no-git-tag-version version
npm version patch
echo "*** Building packages for npmjs"
# echo -e "$NPM_USERNAME\n$NPM_PASSWORD\n$NPM_EMAIL" | npm login
echo "$NPM_TOKEN" >> ~/.npmrc
npm run ci:build:npm
echo "*** Publishing $PACKAGE to npmjs"
cd .npmjs
npm publish --access public || true
cd ../..
for PACKAGE in ${PACKAGES[@]}
do
echo "*** Building $PACKAGE"
LIBRARY=$PACKAGE npm run ci:build:npm
DIRECTORY=.npmjs/$(echo $PACKAGE | tr '[:upper:]' '[:lower:]')
echo "*** Publishing $PACKAGE from $DIRECTORY"
cd $DIRECTORY
npm publish --access public || true
cd ../..
done
cd ..
fi
echo "*** Updating cargo parity-ui-precompiled#$PRECOMPILED_HASH"

View File

@ -14,11 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import etherscan from './';
const etherscan = require('./');
const TESTADDR = '0xbf885e2b55c6bcc84556a3c5f07d3040833c8d00';
describe.skip('etherscan/account', () => {
describe.skip('etherscan/account', function () {
this.timeout(60 * 1000);
const checkBalance = function (balance, addr) {
expect(balance).to.be.ok;
expect(balance.account).to.equal(addr);

View File

@ -14,9 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import etherscan from './';
const etherscan = require('./');
describe.skip('etherscan/stats', function () {
this.timeout(60 * 1000);
describe.skip('etherscan/stats', () => {
it('retrieves the latest price', () => {
return etherscan.stats
.price()

View File

@ -14,22 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import chai from 'chai';
import nock from 'nock';
const nock = require('nock');
global.expect = chai.expect; // eslint-disable-line no-undef
import 'isomorphic-fetch';
import es6Promise from 'es6-promise';
es6Promise.polyfill();
import initShapeshift from './';
import initRpc from './rpc';
const ShapeShift = require('./');
const initShapeshift = (ShapeShift.default || ShapeShift);
const APIKEY = '0x123454321';
const shapeshift = initShapeshift(APIKEY);
const rpc = initRpc(APIKEY);
const rpc = shapeshift.getRpc();
function mockget (requests) {
let scope = nock(rpc.ENDPOINT);
@ -62,7 +55,7 @@ function mockpost (requests) {
return scope;
}
export {
module.exports = {
APIKEY,
mockget,
mockpost,

View File

@ -14,7 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import { APIKEY, mockget, mockpost, rpc } from './helpers.spec.js';
const helpers = require('./helpers.spec.js');
const APIKEY = helpers.APIKEY;
const mockget = helpers.mockget;
const mockpost = helpers.mockpost;
const rpc = helpers.rpc;
describe('shapeshift/rpc', () => {
describe('GET', () => {

View File

@ -26,6 +26,10 @@ export default function (rpc) {
return rpc.get(`marketinfo/${pair}`);
}
function getRpc () {
return rpc;
}
function getStatus (depositAddress) {
return rpc.get(`txStat/${depositAddress}`);
}
@ -103,6 +107,7 @@ export default function (rpc) {
return {
getCoins,
getMarketInfo,
getRpc,
getStatus,
shift,
subscribe,

View File

@ -14,7 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import { mockget, mockpost, shapeshift } from './helpers.spec.js';
const helpers = require('./helpers.spec.js');
const mockget = helpers.mockget;
const mockpost = helpers.mockpost;
const shapeshift = helpers.shapeshift;
describe('shapeshift/calls', () => {
describe('getCoins', () => {

View File

@ -0,0 +1,34 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import 'babel-polyfill/dist/polyfill.js';
import es6Promise from 'es6-promise';
es6Promise.polyfill();
const isNode = typeof global !== 'undefined' && typeof global !== 'undefined';
const isBrowser = typeof self !== 'undefined' && typeof self.window !== 'undefined';
if (isBrowser) {
require('whatwg-fetch');
}
if (isNode) {
global.fetch = require('node-fetch');
}
import Etherscan from './3rdparty/etherscan';
module.exports = Etherscan;

View File

@ -0,0 +1,34 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import 'babel-polyfill/dist/polyfill.js';
import es6Promise from 'es6-promise';
es6Promise.polyfill();
const isNode = typeof global !== 'undefined' && typeof global !== 'undefined';
const isBrowser = typeof self !== 'undefined' && typeof self.window !== 'undefined';
if (isBrowser) {
require('whatwg-fetch');
}
if (isNode) {
global.fetch = require('node-fetch');
}
import ShapeShift from './3rdparty/shapeshift';
module.exports = ShapeShift;

View File

@ -15,8 +15,8 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
try {
var Api = require('../.npmjs/library.js').Api;
var Abi = require('../.npmjs/library.js').Abi;
var Api = require('../.npmjs/parity/library.js').Api;
var Abi = require('../.npmjs/parity/library.js').Abi;
if (typeof Api !== 'function') {
throw new Error('No Api');

View File

@ -23,14 +23,27 @@ const Shared = require('./shared');
const ENV = process.env.NODE_ENV || 'development';
const isProd = ENV === 'production';
const LIBRARY = process.env.LIBRARY;
if (!LIBRARY) {
process.exit(-1);
}
const SRC = LIBRARY.toLowerCase();
const OUTPUT_PATH = path.join(__dirname, '../.npmjs', SRC);
const TEST_CONTEXT = SRC === 'parity'
? '../npm/parity/test/'
: `../src/3rdparty/${SRC}/`;
console.log(`Building ${LIBRARY} from library.${SRC}.js to .npmjs/${SRC}`);
module.exports = {
context: path.join(__dirname, '../src'),
target: 'node',
entry: 'library.js',
entry: `library.${SRC}.js`,
output: {
path: path.join(__dirname, '../.npmjs'),
path: OUTPUT_PATH,
filename: 'library.js',
library: 'Parity',
library: LIBRARY,
libraryTarget: 'umd',
umdNamedDefine: true
},
@ -66,19 +79,52 @@ module.exports = {
plugins: Shared.getPlugins().concat([
new CopyWebpackPlugin([
{
from: '../parity.package.json',
from: `../npm/${SRC}/package.json`,
to: 'package.json',
transform: function (content, path) {
const json = JSON.parse(content.toString());
json.version = packageJson.version;
// Add tests dependencies to Dev Deps
json.devDependencies.chai = packageJson.devDependencies.chai;
json.devDependencies.mocha = packageJson.devDependencies.mocha;
json.devDependencies.nock = packageJson.devDependencies.nock;
// Add test script
json.scripts.test = 'mocha \'test/*.spec.js\'';
return new Buffer(JSON.stringify(json, null, ' '), 'utf-8');
}
},
{
from: '../LICENSE'
},
// Copy the base test config
{
from: '../parity.md',
from: '../npm/test',
to: 'test'
},
// Copy the actual tests
{
context: TEST_CONTEXT,
from: '**/*.spec.js',
to: 'test',
transform: function (content, path) {
let output = content.toString();
// Don't skip tests
output = output.replace(/describe\.skip/, 'describe');
// Require parent library
output = output.replace('require(\'./\')', 'require(\'../\')');
return new Buffer(output, 'utf-8');
}
},
{
from: `../npm/${SRC}/README.md`,
to: 'README.md'
}
], { copyUnmodified: true })