Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow installing package from git, keep bytecode in hex. #8

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local = true
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
"directories": {
"test": "test"
},
"files": [
"contracts",
"resources",
"scripts"
],
"scripts": {
"package-npm": "node scripts/package-npm.js",
"compile": "node_modules/.bin/truffle compile",
"deploy": "node_modules/.bin/truffle migrate",
"test": "rm -rf build && node_modules/.bin/truffle test"
"compile": "truffle compile",
"deploy": "truffle migrate",
"test": "rm -rf build && truffle test",
"postinstall": "scripts/postinstall"
},
"repository": {
"type": "git",
Expand All @@ -23,11 +29,11 @@
},
"homepage": "https://github.com/singnet/token-contracts#readme",
"dependencies": {
"truffle": "4.0.1",
"zeppelin-solidity": "1.4.0"
"zeppelin-solidity": "1.4.0",
"fs-extra": "^5.0.0"
},
"devDependencies": {
"fs-extra": "^5.0.0",
"truffle": "4.0.1",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"chai-bignumber": "^2.0.2"
Expand Down
11 changes: 9 additions & 2 deletions scripts/package-npm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use-strict";

const fs = require("fs");
const fse = require("fs-extra");
const path = require("path");
const npmModulePath = "build/npm-module";
Expand All @@ -16,7 +17,7 @@ const mapFiles = {
"resources/SingularityNetToken.json": {
"abi": "abi/SingularityNetToken.json",
"networks": "networks/SingularityNetToken.json",
"bytecode": "bytecode/SingularityNetToken.json"
"bytecode": "bytecode/SingularityNetToken.hex"
},
"resources/npm-README.md": "README.md",
"LICENSE": "LICENSE"
Expand Down Expand Up @@ -54,7 +55,13 @@ for (let sourceFile in mapFiles) {
let destFile = path.join(npmModulePath, mapFiles[sourceFile][key]);
let destParent = path.resolve(destFile, "../");
fse.mkdirsSync(destParent);
fse.writeJsonSync(destFile, fse.readJsonSync(sourceFile)[key]);
if (key === "bytecode") {
// write bytecode as pure hex number string to be compatible
// with abigen
fs.writeFileSync(destFile, fse.readJsonSync(sourceFile)[key]);
} else {
fse.writeJsonSync(destFile, fse.readJsonSync(sourceFile)[key]);
}
}
} else {
let destFile = path.join(npmModulePath, mapFiles[sourceFile]);
Expand Down
8 changes: 8 additions & 0 deletions scripts/postinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

if [[ "$npm_config_local" == "true" ]]; then
exit 0
fi

npm run package-npm
cp -R ./build/npm-module/* .