Skip to content

Commit

Permalink
refactor: updated create readme and license function (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDiscotech authored Oct 20, 2023
1 parent 1863726 commit 24e0149
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 14 deletions.
33 changes: 28 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.

7 changes: 4 additions & 3 deletions src/createPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export const createPackage = (
fse.emptyDirSync(exportDir);
fse.writeJsonSync(`${exportDir}/package.json`, packageJson, { spaces: 4 });

createReadmeAndLicense(packageJson.name, typingType, exportDir);

let interfaceName = '';
// list all of the solidity interfaces
glob(interfacesGlob, (err, interfacePaths) => {
if (err) throw err;
Expand All @@ -41,7 +40,7 @@ export const createPackage = (
fse.outputFileSync(path.join(interfacesDestination, contractPath), relativeInterfaceFile);

// get the interface name
const interfaceName = interfacePath.substring(interfacePath.lastIndexOf('/') + 1, interfacePath.lastIndexOf('.'));
interfaceName = interfacePath.substring(interfacePath.lastIndexOf('/') + 1, interfacePath.lastIndexOf('.'));

// copy interface abi to the export directory
fse.copySync(`${outDir}/${interfaceName}.sol/${interfaceName}.json`, `${abiDestination}/${interfaceName}.json`);
Expand All @@ -66,6 +65,8 @@ export const createPackage = (
});
}

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

// install package dependencies
console.log(`Installing abi dependencies`);
execSync(`cd ${exportDir} && yarn`);
Expand Down
33 changes: 30 additions & 3 deletions src/createReadmeAndLicense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import fse from 'fs-extra';
import { TypingType } from './constants';
import { publicTypeLabels } from './types';

export const createReadmeAndLicense = (packageName: string, typingType: TypingType, exportDir: string) => {
export const createReadmeAndLicense = (
packageName: string,
typingType: TypingType,
exportDir: string,
sampleInterfaceName: string,
) => {
const readmeContent = `
[![npm version](https://img.shields.io/npm/v/${packageName}/latest.svg)](https://www.npmjs.com/package/${packageName}/v/latest)
# ${packageName}
${packageName} offers ${publicTypeLabels[typingType]} for seamless interactions with smart contracts. Integrate these interfaces effortlessly into your projects.
${packageName} offers support for ${publicTypeLabels[typingType]} typing for seamless interactions with smart contracts.
Integrate these interfaces effortlessly into your projects.
## Installation
You can easily install this package using either npm or yarn:
Expand All @@ -22,6 +30,25 @@ export const createReadmeAndLicense = (packageName: string, typingType: TypingTy
npm install ${packageName}
\`\`\`
## Usage
This is an example of how you can import an interface:
\`\`\`typescript
import { ${sampleInterfaceName} } from '${packageName}';
\`\`\`
And then you can interact with it in the way you need.
## Repository
To learn more about this package, please visit the [interface-exporter-action-private](https://github.com/defi-wonderland/interface-exporter-action-private) repo.
## Contributors
Maintained with love by [Wonderland](https://defi.sucks). Made possible by viewers like you.
## License
${packageName} is licensed under the [MIT License](LICENSE).
Expand Down
42 changes: 40 additions & 2 deletions test/unit/createReadmeAndLicense.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,44 @@ describe('createReadmeAndLicense', () => {

it('should create abi README.MD file with correct package name', () => {
const packageName = 'test-package';
createReadmeAndLicense(packageName, TypingType.ABI, exportDir);
const sampleInterface = 'ISampleInterface';
createReadmeAndLicense(packageName, TypingType.ABI, exportDir, sampleInterface);

const readmePath = `${exportDir}/README.MD`;
expect(fse.existsSync(readmePath)).to.be.true;

const readmeContent = fse.readFileSync(readmePath, 'utf8');
expect(readmeContent).to.include(`# ${packageName}`);
});

it('should create ethers v6 README.MD file with correct package name', () => {
const packageName = 'test-package';
const sampleInterface = 'ISampleInterface';
createReadmeAndLicense(packageName, TypingType.ABI, exportDir, sampleInterface);

const readmePath = `${exportDir}/README.MD`;
expect(fse.existsSync(readmePath)).to.be.true;

const readmeContent = fse.readFileSync(readmePath, 'utf8');
expect(readmeContent).to.include(`# ${packageName}`);
});

it('should add the sample interface on the README.MD file', () => {
const packageName = 'test-package';
const sampleInterface = 'ISampleInterface';
createReadmeAndLicense(packageName, TypingType.ABI, exportDir, sampleInterface);

const readmePath = `${exportDir}/README.MD`;
expect(fse.existsSync(readmePath)).to.be.true;

const readmeContent = fse.readFileSync(readmePath, 'utf8');
expect(readmeContent).to.include(`${sampleInterface}`);
});

it('should create web3 README.MD file with correct package name', () => {
const packageName = 'test-package';
const sampleInterface = 'ISampleInterface';
createReadmeAndLicense(packageName, TypingType.CONTRACTS, exportDir, sampleInterface);

const readmePath = `${exportDir}/README.MD`;
expect(fse.existsSync(readmePath)).to.be.true;
Expand All @@ -27,7 +64,8 @@ describe('createReadmeAndLicense', () => {

it('should create LICENSE file if it exists', () => {
const packageName = 'test-package';
createReadmeAndLicense(packageName, TypingType.CONTRACTS, exportDir);
const sampleInterface = 'ISampleInterface';
createReadmeAndLicense(packageName, TypingType.CONTRACTS, exportDir, sampleInterface);

const licenseFilePath = `${exportDir}/LICENSE`;
expect(fse.existsSync(licenseFilePath)).to.be.true;
Expand Down

0 comments on commit 24e0149

Please sign in to comment.