Comparing version 0.0.9 to 0.1.0
@@ -27,2 +27,3 @@ "use strict"; | ||
if (checkForOverloads(constants, constantFunctions, functions, abiPiece.name)) { | ||
// tslint:disable-next-line | ||
console.log(chalk_1.yellow(`Detected overloaded constant function ${abiPiece.name} skipping...`)); | ||
@@ -29,0 +30,0 @@ return; |
#!/usr/bin/env node | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -9,2 +17,3 @@ const fs_1 = require("fs"); | ||
const glob = require("glob"); | ||
const prettier = require("prettier"); | ||
const generateSource_1 = require("./generateSource"); | ||
@@ -16,19 +25,30 @@ const parseArgs_1 = require("./parseArgs"); | ||
function main() { | ||
const options = parseArgs_1.parseArgs(); | ||
const matches = glob.sync(options.glob, { ignore: "node_modules/**", absolute: true }); | ||
if (matches.length === 0) { | ||
console.log(chalk_1.red(`Found ${matches.length} ABIs.`)); | ||
process.exit(0); | ||
} | ||
console.log(chalk_1.green(`Found ${matches.length} ABIs.`)); | ||
console.log("Generating typings..."); | ||
// copy runtime in directory of first typing (@todo it should be customizable) | ||
const runtimeFilename = "typechain-runtime.ts"; | ||
const runtimePath = path_1.join(path_1.dirname(matches[0]), runtimeFilename); | ||
copyRuntime_1.copyRuntime(runtimePath); | ||
console.log(chalk_1.blue(`${runtimeFilename} => ${runtimePath}`)); | ||
// generate wrappers | ||
matches.forEach(p => processFile(p, options.force, runtimePath)); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const options = parseArgs_1.parseArgs(); | ||
const matches = glob.sync(options.glob, { ignore: "node_modules/**", absolute: true }); | ||
if (matches.length === 0) { | ||
// tslint:disable-next-line | ||
console.log(chalk_1.red(`Found ${matches.length} ABIs.`)); | ||
process.exit(0); | ||
} | ||
// tslint:disable-next-line | ||
console.log(chalk_1.green(`Found ${matches.length} ABIs.`)); | ||
const prettierConfig = yield prettier.resolveConfig(path_1.dirname(matches[0])); | ||
if (prettierConfig) { | ||
// tslint:disable-next-line | ||
console.log("Found prettier config file"); | ||
} | ||
// tslint:disable-next-line | ||
console.log("Generating typings..."); | ||
// copy runtime in directory of first typing (@todo it should be customizable) | ||
const runtimeFilename = "typechain-runtime.ts"; | ||
const runtimePath = path_1.join(path_1.dirname(matches[0]), runtimeFilename); | ||
copyRuntime_1.copyRuntime(runtimePath); | ||
// tslint:disable-next-line | ||
console.log(chalk_1.blue(`${runtimeFilename} => ${runtimePath}`)); | ||
// generate wrappers | ||
matches.forEach(p => processFile(p, options.force, runtimePath, Object.assign({}, (prettierConfig || {}), { parser: "typescript" }))); | ||
}); | ||
} | ||
function processFile(absPath, forceOverwrite, runtimeAbsPath) { | ||
function processFile(absPath, forceOverwrite, runtimeAbsPath, prettierConfig) { | ||
const relativeInputPath = path_1.relative(cwd, absPath); | ||
@@ -40,4 +60,6 @@ const parsedInputPath = path_1.parse(absPath); | ||
const runtimeRelativePath = getRelativeModulePath(parsedInputPath.dir, runtimeAbsPath); | ||
// tslint:disable-next-line | ||
console.log(chalk_1.blue(`${relativeInputPath} => ${relativeOutputPath}`)); | ||
if (fs_extra_1.pathExistsSync(outputPath) && !forceOverwrite) { | ||
// tslint:disable-next-line | ||
console.log(chalk_1.red("File exists, skipping")); | ||
@@ -52,3 +74,3 @@ return; | ||
}); | ||
fs_1.writeFileSync(outputPath, typescriptSourceFile); | ||
fs_1.writeFileSync(outputPath, prettier.format(typescriptSourceFile, prettierConfig)); | ||
} | ||
@@ -62,8 +84,6 @@ function getFilenameWithoutAnyExtensions(filePath) { | ||
} | ||
try { | ||
main(); | ||
} | ||
catch (error) { | ||
console.error(chalk_1.red("Error occured: ", error.message)); | ||
main().catch(e => { | ||
// tslint:disable-next-line | ||
console.error(chalk_1.red("Error occured: ", e.message)); | ||
process.exit(1); | ||
} | ||
}); |
@@ -17,5 +17,5 @@ "use strict"; | ||
import { BigNumber } from "bignumber.js"; | ||
import { TypechainContract, promisify, ITxParams, IPayableTxParams, DeferredTransactionWrapper } from '${context.relativeRuntimePath}' | ||
import { TypeChainContract, promisify, ITxParams, IPayableTxParams, DeferredTransactionWrapper } from '${context.relativeRuntimePath}' | ||
export class ${typeName} extends TypechainContract { | ||
export class ${typeName} extends TypeChainContract { | ||
public readonly rawWeb3Contract: any; | ||
@@ -22,0 +22,0 @@ |
@@ -11,3 +11,2 @@ "use strict"; | ||
const rawOptions = commandLineArgs(optionDefinitions); | ||
console.log(rawOptions); | ||
return { | ||
@@ -14,0 +13,0 @@ force: !!rawOptions.force, |
{ | ||
"name": "typechain", | ||
"version": "0.0.9", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
@@ -18,2 +18,3 @@ "repository": "https://github.com/Neufund/Typechain", | ||
"@types/node": "^8.0.25", | ||
"@types/prettier": "^1.8.1", | ||
"bignumber.js": "^5.0.0", | ||
@@ -25,5 +26,7 @@ "bluebird": "^3.5.1", | ||
"mocha": "^4.0.1", | ||
"prettier": "1.9.1", | ||
"ts-node": "^3.3.0", | ||
"tslint": "^5.8.0", | ||
"tslint-language-service": "^0.9.7", | ||
"typescript": "^2.6.1", | ||
"typestrict": "^0.0.6", | ||
"web3": "0.20.2", | ||
@@ -37,3 +40,4 @@ "web3-typescript-typings": "^0.7.2" | ||
"fs-extra": "^4.0.2", | ||
"glob": "^7.1.2" | ||
"glob": "^7.1.2", | ||
"prettier": "^1.9.1" | ||
}, | ||
@@ -44,14 +48,17 @@ "peerDependencies": { | ||
"scripts": { | ||
"prepublish": "yarn build", | ||
"build": "rm -rf ./dist && tsc -p ./tsconfig.production.json", | ||
"postbuild": "chmod +x ./dist/cli.js", | ||
"lint": "yarn formatting", | ||
"lint:fix": "yarn formatting:fix", | ||
"lint": "yarn formatting && yarn tslint", | ||
"lint:fix": "yarn tslint:fix && yarn formatting:fix", | ||
"tslint": "tslint -c ./tslint.json --project ./tsconfig.json --format stylish --exclude 'test/integration/abis/*.ts'", | ||
"tslint:fix": "tslint -c ./tslint.json --project ./tsconfig.json --format stylish --exclude 'test/integration/abis/*.ts' --fix ", | ||
"formatting": "prettier --list-different **/*.ts", | ||
"formatting:fix": "prettier --write **/*.ts", | ||
"test": "yarn lint && ./scripts/test.sh", | ||
"test:unit": "NODE_ENV=test mocha --require ts-node/register.js 'test/unit/**/*.spec.ts'", | ||
"test:integration": "NODE_ENV=test mocha --require ts-node/register.js 'test/integration/web3.ts' 'test/integration/**/*.spec.ts'", | ||
"test:generateContracts": "NODE_ENV=development ts-node ./lib/cli.ts" | ||
"test:unit": "NODE_ENV=test mocha --require ts-node/register.js --require test/setup-chai.ts 'test/unit/**/*.spec.ts'", | ||
"test:integration": "NODE_ENV=test mocha --require ts-node/register.js --require test/setup-chai.ts 'test/integration/web3.ts' 'test/integration/**/*.spec.ts'", | ||
"test:generateContracts": "NODE_ENV=development ts-node ./lib/cli.ts --force" | ||
}, | ||
"bin": "./dist/cli.js" | ||
} |
@@ -1,2 +0,2 @@ | ||
# Typechain | ||
# TypeChain | ||
@@ -15,3 +15,3 @@ 🔌 Typescript bindings for Ethereum smartcontracts | ||
Note: Typechain requires web3 in version: `0.20.x`. | ||
Note: TypeChain requires web3 in version: `0.20.x`. | ||
@@ -47,5 +47,5 @@ ## Usage | ||
Interacting with blockchain in Javascript is a pain. Web3 interface is sluggish and when you want to | ||
use from Typescript it gets even worse. Often, you can't be sure what given method call will | ||
actually do without looking at ABI file. Typechain is here to solve these problems (as long as you | ||
Interacting with blockchain in Javascript is a pain. Web3 interface is sluggish and when using it | ||
with Typescript it gets even worse. Often, you can't be sure what given method call will | ||
actually do without looking at ABI file. TypeChain is here to solve these problems (as long as you | ||
use Typescript). | ||
@@ -55,3 +55,3 @@ | ||
Typechain is code generator - provide ABI file and you will get Typescript class with flexible | ||
TypeChain is code generator - provide ABI file and you will get Typescript class with flexible | ||
interface for interacting with blockchain. | ||
@@ -80,3 +80,3 @@ | ||
Let's take a look at typings generated for simple | ||
[smartcontract](https://github.com/Neufund/Typechain/blob/master/test/integration/contracts/DumbContract.sol): | ||
[smartcontract](https://github.com/Neufund/TypeChain/blob/master/test/integration/contracts/DumbContract.sol): | ||
@@ -86,3 +86,3 @@ ```typescript | ||
import { | ||
TypechainContract, | ||
TypeChainContract, | ||
promisify, | ||
@@ -94,3 +94,3 @@ ITxParams, | ||
export class DumbContract extends TypechainContract { | ||
export class DumbContract extends TypeChainContract { | ||
public readonly rawWeb3Contract: any; | ||
@@ -154,3 +154,3 @@ | ||
console.log("When calling payable txs, Typechain will make sure that you provide ether value:"); | ||
console.log("When calling payable txs, TypeChain will make sure that you provide ether value:"); | ||
await dumbContract | ||
@@ -170,3 +170,3 @@ .countupForEtherTx() | ||
0x7916df080000000000000000000000000000000000000000000000000000000000000002 | ||
When calling payable txs, Typechain will make sure that you provide ether value: | ||
When calling payable txs, TypeChain will make sure that you provide ether value: | ||
Current counter value is: 12 | ||
@@ -186,3 +186,3 @@ ``` | ||
When you update ABI, just regenerate files with Typechain and Typescript compiler will find any | ||
When you update ABI, just regenerate files with TypeChain and Typescript compiler will find any | ||
breaking changes for you. | ||
@@ -200,3 +200,3 @@ | ||
* improve generated code (auto formatting, more checks, wiring contracts together) | ||
* improve generated code (more checks, wiring contracts together) | ||
* events | ||
@@ -213,1 +213,6 @@ | ||
``` | ||
Original author: | ||
Krzysztof Kaczor | [Github](https://github.com/krzkaczor) | [Twitter](https://twitter.com/krzkaczor) |
@@ -16,3 +16,3 @@ import { BigNumber } from "bignumber.js"; | ||
export class TypechainContract { | ||
export class TypeChainContract { | ||
public readonly rawWeb3Contract: any; | ||
@@ -29,3 +29,3 @@ public readonly address: string; | ||
constructor( | ||
private readonly parentContract: TypechainContract, | ||
private readonly parentContract: TypeChainContract, | ||
private readonly methodName: string, | ||
@@ -32,0 +32,0 @@ private readonly methodArgs: any[], |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118791
28
703
207
7
25
5
+ Addedprettier@^1.9.1
+ Addedprettier@1.19.1(transitive)