Skip to content

Commit

Permalink
feat: added interfaces path as parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah authored Aug 25, 2023
1 parent 8060b5c commit f61c653
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 23 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

# Interface Exporter Action

Interface Exporter Action automates the process of extracting TypeScript interfaces from Solidity contracts and provides compatibility with TypeChain. The action allows users generating a NPM package compatible with web3-v1 or ethers-v6 typings. Developers can seamlessly generate typings with only a few lines of yaml code.
Interface Exporter Action automates the process of extracting TypeScript interfaces from Solidity contracts and provides compatibility with TypeChain. The action allows users to generate an NPM package compatible with web3-v1 or ethers-v6 typings. Developers can seamlessly generate typings with only a few lines of yaml code.

## Action Inputs

| Input | Description | Options |
| --------------- | -------------------------------------------------------------------- | ----------------------- |
| out_dir | The path to the directory where contracts are built | |
| typing_type | Typing option which NPM package will be compatible | abi, ethers-v6, web3-v1 |
| package_name | Choosen name for the exported NPM package | |
| destination_dir | The path to the destination directory where the NPM will be exported | |
| Input | Description | Default | Options |
| --------------- | -------------------------------------------------------------------- | -------------- | ----------------------- |
| out_dir | The path to the directory where contracts are built | **Required** | |
| interfaces_dir | The path to the directory where the interfaces are located | src/interfaces | |
| typing_type | Typing option which NPM package will be compatible | **Required** | abi, ethers-v6, web3-v1 |
| package_name | Choosen name for the exported NPM package | **Required** | |
| destination_dir | The path to the destination directory where the NPM will be exported | **Required** | |

## Action Outputs

Expand All @@ -25,7 +26,7 @@ Interface Exporter Action automates the process of extracting TypeScript interfa

## Example

Interface Exporter Action generates a NPM package with your interfaces ABIs:
Interface Exporter Action generates an NPM package with your interfaces ABIs:

```yaml
- name: Use Node.js
Expand All @@ -44,6 +45,7 @@ Interface Exporter Action generates a NPM package with your interfaces ABIs:
uses: defi-wonderland/interface-exporter-action@v1
with:
out_dir: ./out
interfaces_dir: src/interfaces
typing_type: abi
package_name: @my-cool-protocol/core-interfaces-abi
destination_dir: abi-project
Expand All @@ -54,7 +56,7 @@ Interface Exporter Action generates a NPM package with your interfaces ABIs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
```
Interface Exporter Action generates a NPM package with typechain which has compatibility with ethers-v6. Also, the Action provides ABIs interfaces.
Interface Exporter Action generates an NPM package with typechain which has compatibility with ethers-v6. Also, the Action provides ABIs interfaces.
```yaml
- name: Use Node.js
Expand All @@ -75,7 +77,8 @@ Interface Exporter Action generates a NPM package with typechain which has compa
- name: Export interfaces for ethers compatibility
uses: defi-wonderland/interface-exporter-action@v1
with:
out_dir: ./out
out_dir: out
interfaces_dir: src/interfaces
typing_type: ethers-v6
package_name: @my-cool-protocol/core-interfaces-ethers
destination_dir: ethers-project
Expand All @@ -86,7 +89,7 @@ Interface Exporter Action generates a NPM package with typechain which has compa
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
```
Interface Exporter Action generates a NPM package with typechain which has compatibility with web3. Also, the Action provides ABIs interfaces.
Interface Exporter Action generates an NPM package with typechain which has compatibility with web3. Also, the Action provides ABIs interfaces.
```yaml
- name: Use Node.js
Expand All @@ -108,6 +111,7 @@ Interface Exporter Action generates a NPM package with typechain which has compa
uses: defi-wonderland/interface-exporter-action@v1
with:
out_dir: ./out
interfaces_dir: src/interfaces
typing_type: web3-v1
package_name: @my-cool-protocol/core-interfaces-web3
destination_dir: web3-project
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ inputs:
out_dir:
description: 'path to the `out` folder containing the compiled contracts'
required: true
typing_type:
interfaces_dir:
description: 'path to the `interfaces` folder containing the contract interfaces'
default: 'src/interfaces'
required: false
publish_type:
description: 'interface compatibility: abi, ethers-v6, web3-v1'
required: true
package_name:
Expand Down
10 changes: 5 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions src/createPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import { createReadmeAndLicense } from './createReadmeAndLicense';
import { transformRemappings } from './transformRemappings';
import { TypingType } from './constants';

export const createPackage = (exportDir: string, outDir: string, packageJson: PackageJson, typingType: TypingType) => {
export const createPackage = (
exportDir: string,
outDir: string,
interfacesDir: string,
packageJson: PackageJson,
typingType: TypingType,
) => {
const abiDir = `${exportDir}/abi`;
const contractsDir = `${exportDir}/contracts`;
const interfacesDir = './solidity/interfaces';
const interfacesGlob = `${interfacesDir}/**/*.sol`;

// empty export directory
Expand Down
10 changes: 8 additions & 2 deletions src/createPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { createPackage } from './createPackage';
import { TypingType, ethersDependencies, web3Dependencies } from './constants';
import { execSync } from 'child_process';

export const createPackages = (outDir: string, typingType: TypingType, packageName: string, destinationDir: string) => {
export const createPackages = (
outDir: string,
typingType: TypingType,
packageName: string,
destinationDir: string,
interfacesDir: string,
) => {
// Empty export directory
fse.emptyDirSync(destinationDir);

Expand Down Expand Up @@ -31,5 +37,5 @@ export const createPackages = (outDir: string, typingType: TypingType, packageNa
};

// Create package
createPackage(destinationDir, outDir, packageJson, typingType);
createPackage(destinationDir, outDir, interfacesDir, packageJson, typingType);
};
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ async function run(): Promise<void> {
const typingType = core.getInput('typing_type') as TypingType;
const packageName = core.getInput('package_name');
const destinationDir = core.getInput('destination_dir');
const interfacesDir = core.getInput('interfaces_dir');

if (!Object.values(TypingType).includes(typingType)) {
throw new Error(`Invalid input for typing_type. Valid inputs are : ${Object.values(TypingType).join(', ')}`);
}

createPackages(outDir, typingType, packageName, destinationDir);
createPackages(outDir, typingType, packageName, destinationDir, interfacesDir);
core.setOutput('passed', true);
} catch (e) {
const error = e as Error;
Expand Down

0 comments on commit f61c653

Please sign in to comment.