Skip to content

Commit

Permalink
refactor: updated action args (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDiscotech authored Oct 24, 2023
1 parent d0d8302 commit e3847c4
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 248 deletions.
40 changes: 21 additions & 19 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
name: 'Interface exporter action'
description: 'An action to generate npm packages based on Solidity contract interfaces'
description: 'An action to generate npm packages based on Solidity interfaces and contracts'
author: 'Wonderland'

inputs:
out_dir:
description: 'path to the `out` folder containing the compiled contracts'
required: true
interfaces_dir:
description: 'path to the `interfaces` folder containing the contract interfaces'
default: 'src/interfaces'
required: false
typing_type:
description: 'interface compatibility: abi, contracts'
required: true
package_name:
description: 'name of the package to be publish'
required: true
destination_dir:
description: 'path to the directory where your package will be exported'
description: 'name of the package to be published'
required: true
contracts_dir:
description: 'path to the directory where the contracts are located'
out:
description: 'path to the `out` folder containing the compiled contracts'
required: false
default: 'out'
interfaces:
description: 'path to the interfaces directory'
required: false
default: 'solidity/interfaces'
contracts:
description: 'path to the contracts directory'
required: false
default: 'solidity/contracts'
export_type:
description: '`interface` for exporting only the interfaces and their ABIs, `contracts` for exporting the contracts, interfaces and their ABIs as well'
required: false
default: 'interfaces'

outputs:
passed:
description: 'boolean describing if the test passed or not'
exported:
description: 'boolean describing package was exported successfully or not'
runs:
using: 'node16'
main: 'dist/index.js'
150 changes: 68 additions & 82 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.

4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum TypingType {
ABI = 'abi',
export enum ExportType {
INTERFACES = 'interfaces',
CONTRACTS = 'contracts',
}
32 changes: 32 additions & 0 deletions src/copySolidityFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import glob from 'glob';
import path from 'path';
import fse from 'fs-extra';
import { transformRemappings } from './transformRemappings';

export const copySolidityFiles = (baseDir: string, filesDir: string, destinationDir: string) => {
const filesDestination = `${destinationDir}/${filesDir}`;
const abiDestination = `${destinationDir}/abi`;

// List all of the solidity files on the input directory
const filesGlob = `${filesDir}/**/*.sol`;
glob(filesGlob, (err, filesPaths) => {
if (err) throw err;

for (const filePath of filesPaths) {
const file = fse.readFileSync(filePath, 'utf8');
const relativeFile = transformRemappings(file);

// Copy the file to the destination directory
const relativeFilePath = filePath.substring(filesDir.length + 1);
fse.outputFileSync(path.join(filesDestination, relativeFilePath), relativeFile);
console.log(`Copied ${relativeFilePath} to ${filesDestination}`);

// Copy the abi to the export directory using the same file name
const fileName = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.lastIndexOf('.'));
fse.copySync(`${baseDir}/${fileName}.sol/${fileName}.json`, `${abiDestination}/${fileName}.json`);
console.log(`Copied ${fileName}.json to ${abiDestination}`);
}

console.log(`Copied ${filesPaths.length} interfaces and ABIs`);
});
};
Loading

0 comments on commit e3847c4

Please sign in to comment.