Skip to content

Commit

Permalink
fix: improved readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah authored Aug 25, 2023
1 parent d8dc5ca commit 8060b5c
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 87 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@

# Interface Exporter Action

This action generates npm packages based on Solidity contract interfaces. It automates the process of extracting TypeScript interfaces from Solidity contracts and provides compatibility with TypeChain. With support for both web3-v1 and ethers-v6 typings, developers can seamlessly generate typings with only a few lines of yml code.
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.

## Action Inputs

| Input | Description | Default | Options |
| --------------- | ------------------------------------------------ | ------------ | ----------------------- |
| out_dir | The path where contracts are build | **Required** | |
| publish_type | The option to publish | **Required** | abi, ethers-v6, web3-v1 |
| package_name | The name of the package | **Required** | |
| destination_dir | The path to the directory where will be exported | **Required** | |
| 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 | |

## Action Outputs

| Output | Description |
| ------ | ---------------------------------------------- |
| passed | Boolean describing if the script passed or not |
| Output | Description |
| ------ | -------------------------------------------------------- |
| passed | Boolean describing if the action passed correctly or not |

# Usage

## Example

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

```yaml
- name: Use Node.js
Expand All @@ -44,7 +44,7 @@ Publish an NPM package with your interfaces ABIs:
uses: defi-wonderland/interface-exporter-action@v1
with:
out_dir: ./out
publish_type: abi
typing_type: abi
package_name: @my-cool-protocol/core-interfaces-abi
destination_dir: abi-project

Expand All @@ -54,7 +54,7 @@ Publish an NPM package with your interfaces ABIs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
```
Publish an NPM package with a typechain generated files for ethers compatibility from your interfaces.
Interface Exporter Action generates a NPM package with typechain which has compatibility with ethers-v6. Also, the Action provides ABIs interfaces.
```yaml
- name: Use Node.js
Expand All @@ -76,7 +76,7 @@ Publish an NPM package with a typechain generated files for ethers compatibility
uses: defi-wonderland/interface-exporter-action@v1
with:
out_dir: ./out
publish_type: ethers-v6
typing_type: ethers-v6
package_name: @my-cool-protocol/core-interfaces-ethers
destination_dir: ethers-project

Expand All @@ -86,7 +86,7 @@ Publish an NPM package with a typechain generated files for ethers compatibility
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
```
Publish an NPM package with a typechain generated files for web3 compatibility from your interfaces.
Interface Exporter Action generates a NPM package with typechain which has compatibility with web3. Also, the Action provides ABIs interfaces.
```yaml
- name: Use Node.js
Expand All @@ -108,7 +108,7 @@ Publish an NPM package with a typechain generated files for web3 compatibility f
uses: defi-wonderland/interface-exporter-action@v1
with:
out_dir: ./out
publish_type: web3-v1
typing_type: web3-v1
package_name: @my-cool-protocol/core-interfaces-web3
destination_dir: web3-project

Expand All @@ -132,7 +132,7 @@ Build the typescript and package it for distribution
npm run build && npm run package
```

Run the tests :heavy_check_mark:
Run the tests

```bash
npm test
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
out_dir:
description: 'path to the `out` folder containing the compiled contracts'
required: true
publish_type:
typing_type:
description: 'interface compatibility: abi, ethers-v6, web3-v1'
required: true
package_name:
Expand Down
50 changes: 25 additions & 25 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.

2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const web3Dependencies = {
'web3-core': '1.9.0',
};

export enum PublishType {
export enum TypingType {
ABI = 'abi',
ETHERS_V6 = 'ethers-v6',
WEB3_V1 = 'web3-v1',
Expand Down
21 changes: 7 additions & 14 deletions src/createPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ import { execSync } from 'child_process';
import { PackageJson } from './types';
import { createReadmeAndLicense } from './createReadmeAndLicense';
import { transformRemappings } from './transformRemappings';
import { PublishType } from './constants';

export const createPackage = (
exportDir: string,
outDir: string,
packageJson: PackageJson,
publishType: PublishType,
) => {
import { TypingType } from './constants';

export const createPackage = (exportDir: string, outDir: string, packageJson: PackageJson, typingType: TypingType) => {
const abiDir = `${exportDir}/abi`;
const contractsDir = `${exportDir}/contracts`;
const interfacesDir = './solidity/interfaces';
Expand All @@ -22,7 +17,7 @@ export const createPackage = (
fse.emptyDirSync(exportDir);
fse.writeJsonSync(`${exportDir}/package.json`, packageJson, { spaces: 4 });

createReadmeAndLicense(packageJson.name, publishType, exportDir);
createReadmeAndLicense(packageJson.name, typingType, exportDir);

// list all of the solidity interfaces
glob(interfacesGlob, (err, interfacePaths) => {
Expand All @@ -49,11 +44,9 @@ export const createPackage = (
execSync(`cd ${exportDir} && yarn`);

// use typechain if needed
if (publishType === PublishType.ETHERS_V6 || publishType === PublishType.WEB3_V1) {
console.log(`Generating types for ${publishType}`);
execSync(
`yarn typechain --target ${publishType} --out-dir ${exportDir}/${publishType} '${exportDir}/abi/*.json'`,
);
if (typingType === TypingType.ETHERS_V6 || typingType === TypingType.WEB3_V1) {
console.log(`Generating types for ${typingType}`);
execSync(`yarn typechain --target ${typingType} --out-dir ${exportDir}/${typingType} '${exportDir}/abi/*.json'`);
}
});
};
15 changes: 5 additions & 10 deletions src/createPackages.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import fse from 'fs-extra';
import { createPackage } from './createPackage';
import { PublishType, ethersDependencies, web3Dependencies } from './constants';
import { TypingType, ethersDependencies, web3Dependencies } from './constants';
import { execSync } from 'child_process';

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

Expand All @@ -23,8 +18,8 @@ export const createPackages = (

// Add additional dependencies if needed
let additionalDependencies: Record<string, string> = {};
if (publishType === PublishType.ETHERS_V6) additionalDependencies = ethersDependencies;
if (publishType === PublishType.WEB3_V1) additionalDependencies = web3Dependencies;
if (typingType === TypingType.ETHERS_V6) additionalDependencies = ethersDependencies;
if (typingType === TypingType.WEB3_V1) additionalDependencies = web3Dependencies;

const packageJson = {
name: packageName,
Expand All @@ -36,5 +31,5 @@ export const createPackages = (
};

// Create package
createPackage(destinationDir, outDir, packageJson, publishType);
createPackage(destinationDir, outDir, packageJson, typingType);
};
6 changes: 3 additions & 3 deletions src/createReadmeAndLicense.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import fse from 'fs-extra';
import { PublishType } from './constants';
import { TypingType } from './constants';
import { publicTypeLabels } from './types';

export const createReadmeAndLicense = (packageName: string, publishType: PublishType, exportDir: string) => {
export const createReadmeAndLicense = (packageName: string, typingType: TypingType, exportDir: string) => {
const readmeContent = `
# ${packageName}
${packageName} offers ${publicTypeLabels[publishType]} interfaces for designed for seamless interaction with smart contracts. Integrate these interfaces effortlessly into your projects.
${packageName} offers ${publicTypeLabels[typingType]} interfaces for designed for seamless interaction with smart contracts. Integrate these interfaces effortlessly into your projects.
## Installation
Expand Down
10 changes: 5 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import * as core from '@actions/core';
import { createPackages } from './createPackages';
import { PublishType } from './constants';
import { TypingType } from './constants';

// eslint-disable-next-line @typescript-eslint/require-await
async function run(): Promise<void> {
try {
core.debug(`Parsing inputs`);
const outDir = core.getInput('out_dir');
const publishType = core.getInput('publish_type') as PublishType;
const typingType = core.getInput('typing_type') as TypingType;
const packageName = core.getInput('package_name');
const destinationDir = core.getInput('destination_dir');

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

createPackages(outDir, publishType, packageName, destinationDir);
createPackages(outDir, typingType, packageName, destinationDir);
core.setOutput('passed', true);
} catch (e) {
const error = e as Error;
Expand Down
10 changes: 5 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { PublishType } from './constants';
import { TypingType } from './constants';

export interface PackageJson {
name: string;
version: string;
dependencies: Record<string, string>;
}

export const publicTypeLabels: Record<PublishType, string> = {
[PublishType.ABI]: 'ABI',
[PublishType.ETHERS_V6]: 'Ethers.js',
[PublishType.WEB3_V1]: 'Web3',
export const publicTypeLabels: Record<TypingType, string> = {
[TypingType.ABI]: 'ABI',
[TypingType.ETHERS_V6]: 'Ethers.js',
[TypingType.WEB3_V1]: 'Web3',
};
Loading

0 comments on commit 8060b5c

Please sign in to comment.