Publish parity.js to npmjs registry (#2978)

* Skeleton packages

* Publish parity.js package to npm

* [ci skip] js-precompiled 20161029-190427

* Extra step information

* [ci skip] js-precompiled 20161029-192209

* Use autToken for npmjs (cannot run headless in docker)

* [ci skip] js-precompiled 20161029-193414

* Correct package.json structure

* [ci skip] js-precompiled 20161029-194003

* Scope package to public

* [ci skip] js-precompiled 20161029-194529

* Start package version at 0.1.0

* Build proper umd library

* [ci skip] js-precompiled 20161029-231233

* Update build/release stage

* [ci skip] js-precompiled 20161030-071454

* Basic README.md to satisfy npmjs

* [ci skip] js-precompiled 20161030-073150

* CommonJs format

* [ci skip] js-precompiled 20161030-075034

* Update README.md

* update dependencies

* [ci skip] js-precompiled 20161030-075727

* Starting package version

* Build only on master
This commit is contained in:
Jaco Greeff 2016-10-30 09:55:46 +01:00 committed by Gav Wood
parent acaa40e221
commit 70f87ea002
8 changed files with 282 additions and 44 deletions

View File

@ -391,9 +391,6 @@ js-release:
image: ethcore/javascript:latest image: ethcore/javascript:latest
only: only:
- master - master
- beta
- tags
- stable
before_script: before_script:
- ./js/scripts/install-deps.sh - ./js/scripts/install-deps.sh
script: script:

1
js/.gitignore vendored
View File

@ -5,3 +5,4 @@ build
.coverage .coverage
.dist .dist
.happypack .happypack
.npmjs

View File

@ -1,9 +1,9 @@
{ {
"name": "parity.js", "name": "parity.js",
"version": "0.0.1", "version": "0.1.0",
"main": "release/index.js", "main": "release/index.js",
"jsnext:main": "src/index.js", "jsnext:main": "src/index.js",
"author": "Ethcore Team <admin@ethcore.io>", "author": "Parity Team <admin@parity.io>",
"maintainers": [ "maintainers": [
"Jaco Greeff" "Jaco Greeff"
], ],
@ -11,7 +11,7 @@
"license": "GPL-3.0", "license": "GPL-3.0",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/ethcore/parity.js.git" "url": "git+https://github.com/ethcore/parity.git"
}, },
"keywords": [ "keywords": [
"Ethereum", "Ethereum",
@ -27,15 +27,13 @@
"build:app": "webpack --progress", "build:app": "webpack --progress",
"build:lib": "webpack --config webpack.libraries --progress", "build:lib": "webpack --config webpack.libraries --progress",
"build:dll": "webpack --config webpack.vendor --progress", "build:dll": "webpack --config webpack.vendor --progress",
"ci:build": "npm run ci:build:dll && npm run ci:build:app && npm run ci:build:lib", "ci:build": "npm run ci:build:dll && npm run ci:build:app && npm run ci:build:lib",
"ci:build:app": "NODE_ENV=production webpack", "ci:build:app": "NODE_ENV=production webpack",
"ci:build:lib": "NODE_ENV=production webpack --config webpack.libraries", "ci:build:lib": "NODE_ENV=production webpack --config webpack.libraries",
"ci:build:dll": "NODE_ENV=production webpack --config webpack.vendor", "ci:build:dll": "NODE_ENV=production webpack --config webpack.vendor",
"ci:build:npm": "NODE_ENV=production webpack --config webpack.npm",
"start": "npm install && npm run build:dll && npm run start:app", "start": "npm install && npm run build:dll && npm run start:app",
"start:app": "webpack-dev-server -d --history-api-fallback --open --hot --inline --progress --colors --port 3000", "start:app": "webpack-dev-server -d --history-api-fallback --open --hot --inline --progress --colors --port 3000",
"clean": "rm -rf ./build ./coverage", "clean": "rm -rf ./build ./coverage",
"coveralls": "npm run testCoverage && coveralls < coverage/lcov.info", "coveralls": "npm run testCoverage && coveralls < coverage/lcov.info",
"lint": "eslint --ignore-path .gitignore ./src/", "lint": "eslint --ignore-path .gitignore ./src/",
@ -65,7 +63,7 @@
"chai": "^3.5.0", "chai": "^3.5.0",
"chai-enzyme": "0.4.2", "chai-enzyme": "0.4.2",
"cheerio": "0.20.0", "cheerio": "0.20.0",
"copy-webpack-plugin": "^3.0.1", "copy-webpack-plugin": "^4.0.0",
"core-js": "^2.4.1", "core-js": "^2.4.1",
"coveralls": "^2.11.11", "coveralls": "^2.11.11",
"css-loader": "^0.23.1", "css-loader": "^0.23.1",
@ -79,6 +77,7 @@
"eslint-plugin-standard": "^2.0.0", "eslint-plugin-standard": "^2.0.0",
"extract-text-webpack-plugin": "^1.0.1", "extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.8.5", "file-loader": "^0.8.5",
"fs-extra": "^0.30.0",
"happypack": "^2.2.1", "happypack": "^2.2.1",
"history": "^2.0.0", "history": "^2.0.0",
"html-loader": "^0.4.3", "html-loader": "^0.4.3",

81
js/parity.md Normal file
View File

@ -0,0 +1,81 @@
# parity.js
Parity.js is a thin, fast, Promise-based wrapper around the Ethereum APIs.
## installation
Install the package with `npm install --save @parity/parity.js`
## usage
### initialisation
```javascript
// import the actual Api class
import { Api } from '@parity/parity.js';
// do the setup
const transport = new Api.Transport.Http('http://localhost:8545');
const api = new Api(transport);
```
### making calls
perform a call
```javascript
api.eth
.coinbase()
.then((coinbase) => {
console.log(`The coinbase is ${coinbase}`);
});
```
multiple promises
```javascript
Promise
.all([
api.eth.coinbase(),
api.net.listening()
])
.then(([coinbase, listening]) => {
// do stuff here
});
```
chaining promises
```javascript
api.eth
.newFilter({...})
.then((filterId) => api.eth.getFilterChanges(filterId))
.then((changes) => {
console.log(changes);
});
```
### contracts
attach contract
```javascript
const abi = [{ name: 'callMe', inputs: [{ type: 'bool', ...}, { type: 'string', ...}]}, ...abi...];
const address = '0x123456...9abc';
const contract = new api.newContract(abi, address);
```
find & call a function
```javascript
contract.instance
.callMe
.call({ gas: 21000 }, [true, 'someString']) // or estimateGas or postTransaction
.then((result) => {
console.log(`the result was ${result}`);
});
```
## apis
APIs implement the calls as exposed in the [Ethcore JSON Ethereum RPC](https://github.com/ethcore/ethereum-rpc-json/) definitions. Mapping follows the naming conventions of the originals, i.e. `eth_call` becomes `eth.call`, `personal_accounts` becomes `personal.accounts`, etc.

32
js/parity.package.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "@parity/parity.js",
"description": "The Parity Promise-base API & ABI library for interfacing with Ethereum over RPC",
"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": {
"bignumber.js": "^2.3.0",
"js-sha3": "^0.5.2"
}
}

View File

@ -1,11 +1,18 @@
#!/bin/bash #!/bin/bash
set -e set -e
# variables
UTCDATE=`date -u "+%Y%m%d-%H%M%S"`
PACKAGES=( "parity.js" )
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"
# setup the git user defaults for the current repo # setup the git user defaults for the current repo
function setup_git_user { function setup_git_user {
git config push.default simple git config push.default simple
git config merge.ours.driver true git config merge.ours.driver true
git config user.email "jaco+gitlab@ethcore.io" git config user.email "$GITHUB_EMAIL"
git config user.name "GitLab Build Bot" git config user.name "GitLab Build Bot"
} }
@ -15,47 +22,63 @@ GITLOG=./.git/gitcommand.log
pushd $BASEDIR pushd $BASEDIR
cd ../.dist cd ../.dist
# variables # add local files and send it up
UTCDATE=`date -u "+%Y%m%d-%H%M%S"` echo "*** Setting up GitHub config for js-precompiled"
# init git
rm -rf ./.git rm -rf ./.git
git init git init
# add local files and send it up
echo "Setting up GitHub config for js-precompiled"
setup_git_user setup_git_user
echo "Checking out $CI_BUILD_REF_NAME branch" echo "*** Checking out $BRANCH branch"
git remote add origin https://${GITHUB_JS_PRECOMPILED}:@github.com/ethcore/js-precompiled.git git remote add origin $GIT_JS_PRECOMPILED
git fetch origin 2>$GITLOG git fetch origin 2>$GITLOG
git checkout -b $CI_BUILD_REF_NAME git checkout -b $BRANCH
echo "Committing compiled files for $UTCDATE" echo "*** Committing compiled files for $UTCDATE"
git add . git add .
git commit -m "$UTCDATE" git commit -m "$UTCDATE"
echo "Merging remote" echo "*** Merging remote"
git merge origin/$CI_BUILD_REF_NAME -X ours --commit -m "$UTCDATE [release]" git merge origin/$BRANCH -X ours --commit -m "$UTCDATE [release]"
git push origin HEAD:refs/heads/$CI_BUILD_REF_NAME 2>$GITLOG git push origin HEAD:refs/heads/$BRANCH 2>$GITLOG
PRECOMPILED_HASH=`git rev-parse HEAD` PRECOMPILED_HASH=`git rev-parse HEAD`
# back to root # move to root
popd cd ../..
echo "Setting up GitHub config for parity" echo "*** Setting up GitHub config for parity"
setup_git_user setup_git_user
git remote set-url origin https://${GITHUB_JS_PRECOMPILED}:@github.com/ethcore/parity.git git remote set-url origin $GIT_PARITY
git reset --hard origin/$CI_BUILD_REF_NAME 2>$GITLOG git reset --hard origin/$BRANCH 2>$GITLOG
echo "Updating cargo package parity-ui-precompiled#$PRECOMPILED_HASH" echo "*** Bumping package.json patch version"
cd js
npm --no-git-tag-version version
npm version patch
cd ..
echo "*** Updating cargo parity-ui-precompiled#$PRECOMPILED_HASH"
cargo update -p parity-ui-precompiled cargo update -p parity-ui-precompiled
# --precise "$PRECOMPILED_HASH" # --precise "$PRECOMPILED_HASH"
echo "Committing updated files" echo "*** Committing updated files"
git add . git add Cargo.lock js/package.json
git commit -m "[ci skip] js-precompiled $UTCDATE" git commit -m "[ci skip] js-precompiled $UTCDATE"
git push origin HEAD:refs/heads/$CI_BUILD_REF_NAME 2>$GITLOG git push origin HEAD:refs/heads/$BRANCH 2>$GITLOG
echo "*** Building packages for npmjs"
cd js
# 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
cd ..
# back to root
echo "*** Release completed"
popd
# exit with exit code # exit with exit code
exit 0 exit 0

23
js/src/library.js Normal file
View File

@ -0,0 +1,23 @@
// 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 Abi from './abi';
import Api from './api';
export {
Abi,
Api
};

82
js/webpack.npm.js Normal file
View File

@ -0,0 +1,82 @@
// 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 path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const packageJson = require('./package.json');
const ENV = process.env.NODE_ENV || 'development';
const isProd = ENV === 'production';
module.exports = {
context: path.join(__dirname, './src'),
entry: 'library.js',
output: {
path: path.join(__dirname, '.npmjs'),
filename: 'library.js',
libraryTarget: 'commonjs'
},
module: {
loaders: [
{
test: /(\.jsx|\.js)$/,
loader: 'babel',
exclude: /node_modules/
}
]
},
resolve: {
root: path.resolve('./src'),
extensions: ['', '.js']
},
plugins: (function () {
const plugins = [
new CopyWebpackPlugin([
{
from: '../parity.package.json',
to: 'package.json',
transform: function (content, path) {
const json = JSON.parse(content.toString());
json.version = packageJson.version;
return new Buffer(JSON.stringify(json, null, ' '), 'utf-8');
}
},
{
from: '../LICENSE'
},
{
from: '../parity.md',
to: 'README.md'
}
], { copyUnmodified: true })
];
if (isProd) {
plugins.push(new webpack.optimize.UglifyJsPlugin({
screwIe8: true,
compress: {
warnings: false
},
output: {
comments: false
}
}));
}
return plugins;
}())
};