Skip to content

Commit

Permalink
Kk/monorepo (#175)
Browse files Browse the repository at this point in the history
Kk/monorepo
  • Loading branch information
krzkaczor committed Sep 29, 2019
2 parents 174ab9e + ebd7f4f commit 0283d8f
Show file tree
Hide file tree
Showing 47 changed files with 2,410 additions and 1,037 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ test/integration/targets/truffle/build
test/integration/targets/web3-1.0.0/types/web3-contracts
test/integration/targets/ethers/types/ethers-contracts
test/package-test/types
packages/core/README.md
3 changes: 1 addition & 2 deletions .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"text"
],
"include": [
"lib/**/*.ts",
"runtime/**/*.ts"
"packages/**/*.ts"
],
"exclude": [
"**/*.spec.ts",
Expand Down
3 changes: 1 addition & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"tabWidth": 2,
"semi": true,
"singleQuote": false,
"trailingComma": "all",
"parser": "typescript"
"trailingComma": "all"
}
41 changes: 20 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

## Features ⚡

* static typing - you will never call not existing method again
* IDE support - works with any IDE supporting Typescript
* works with multiple libraries - use `truffle`,`Web3.js 1.0`, `ethers.js`, `Web3.js 0.20.x`
* frictionless - works with simple, JSON ABI files as well as with Truffle style ABIs
- static typing - you will never call not existing method again
- IDE support - works with any IDE supporting Typescript
- works with multiple libraries - use `truffle`,`Web3.js 1.0`, `ethers.js`, `Web3.js 0.20.x`
- frictionless - works with simple, JSON ABI files as well as with Truffle style ABIs

## Installation

Expand All @@ -46,10 +46,9 @@ yarn add --dev typechain
typechain --target=(truffle|web3-1.0.0|legacy) [glob]
```

* `glob` - pattern that will be used to find ABIs, remember about adding quotes: `typechain
"**/*.json"`
* `--target` - `truffle`, `web3-1.0.0`, `ethers` or `legacy`
* `--outDir` - put all generated files to a specific dir
- `glob` - pattern that will be used to find ABIs, remember about adding quotes: `typechain "**/*.json"`
- `--target` - `truffle`, `web3-1.0.0`, `ethers` or `legacy`
- `--outDir` - put all generated files to a specific dir

Typechain always will rewrite existing files. You should not commit them. Read more in FAQ section.

Expand All @@ -61,7 +60,7 @@ typechain --target --outDir app/contracts './node_modules/neufund-contracts/buil

### ts-generator unified config

Typechain is a plugin to [ts-generator](https://github.com/krzkaczor/ts-generator) meaning that you can as well create unified config.
Typechain is a plugin to [ts-generator](https://github.com/krzkaczor/ts-generator) meaning that you can as well create unified config.

`ts-generator.json` file:

Expand Down Expand Up @@ -89,15 +88,15 @@ This can be a great way to run more code generation plugins (css modules types,

### Motivation

Interacting with blockchain in Javascript is a pain. Web3 interface is sluggish and when using it
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).

### How does it work?

TypeChain is code generator - provide ABI file and you will get Typescript class with flexible
interface for interacting with blockchain. Depending on the target parameter it can generate typings for
interface for interacting with blockchain. Depending on the target parameter it can generate typings for
truffle, web3 1.0.0 or web3 0.20.x (legacy target).

### Step by step guide
Expand All @@ -109,15 +108,14 @@ only locally), it will automatically find all `.abi` files in your project and g
classes based on them. You can specify your glob pattern: `typechain --target=your_target "**/*.abi.json"`.
`node_modules` are always ignored. We recommend git ignoring these generated files and making typechain part of your build process.

That's it! Now, just import contract bindings as any other file `import { MyAwesomeContract } from
'./contracts/MyAwesomeContract'` and start interacting with it. We use named exports because of
That's it! Now, just import contract bindings as any other file `import { MyAwesomeContract } from './contracts/MyAwesomeContract'` and start interacting with it. We use named exports because of
[this](https://blog.neufund.org/why-we-have-banned-default-exports-and-you-should-do-the-same-d51fdc2cf2ad).

## Targets 🎯

### Truffle

Truffle target is great when you use truffle contracts already. Check out [truffle-typechain-example](https://github.com/ethereum-ts/truffle-typechain-example) for more details. It require installing [typings](https://www.npmjs.com/package/truffle-typings) for truffle library itself.
Truffle target is great when you use truffle contracts already. Check out [truffle-typechain-example](https://github.com/ethereum-ts/truffle-typechain-example) for more details. It require installing [typings](https://www.npmjs.com/package/truffle-typings) for truffle library itself.

Now you can simply use your contracts as you did before and get full type safety, yay!

Expand All @@ -133,7 +131,6 @@ Use `ethers` target to generate wrappers for [ethers.js](https://github.com/ethe

This was default and only target for typechain 0.2.x. It requires `Web3.js 0.20.x` to be installed in your project and it generates promise based wrappers. It's nice upgrade comparing to raw callbacks but in the near future Typechain will support `Web3js 1.0` target.


## FAQ 🤔

### Q: Should I commit generated files to my repository?
Expand All @@ -156,22 +153,25 @@ Currently we discuss various ideas around extendibility including APIs files (ad
ABIs for covering popular cases like working with dates) or using user-defined templates for
generated code.

### Q: Generated files won't match current codestyle of my project :(
### Q: Generated files won't match current codestyle of my project :(

A: We will automatically format generated classes with `prettier` to match your coding preferences (just make sure to use `.prettierrc` file).
A: We will automatically format generated classes with `prettier` to match your coding preferences (just make sure to use `.prettierrc` file).

Furthermore, we will silent tslint for generated files with `/* tslint:disable */` comments.

### Usage as API

You may want to use `ts-generator` api to kick off whole process by api:
You may want to use `ts-generator` api to kick off whole process by api:

```typescript
import { tsGen } from "ts-generator";
import { Typechain } from "typechain";

async function main() {
await tsGen({ cwd }, new Typechain({ cwd, rawConfig: { files: "your-glob-here", outDir: "optional out dir path" } }));
await tsGen(
{ cwd },
new Typechain({ cwd, rawConfig: { files: "your-glob-here", outDir: "optional out dir path" } }),
);
}
```

Expand All @@ -188,7 +188,6 @@ yarn test # runs tests + linting
DEBUG=typechain typechain
```


# Licence

Krzysztof Kaczor (krzkaczor) MIT | [Github](https://github.com/krzkaczor) | [Twitter](https://twitter.com/krzkaczor)
Krzysztof Kaczor (krzkaczor) MIT | [Github](https://github.com/krzkaczor) | [Twitter](https://twitter.com/krzkaczor)
55 changes: 0 additions & 55 deletions lib/index.ts

This file was deleted.

0 comments on commit 0283d8f

Please sign in to comment.