generated from web3/web3.js-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4896948
Showing
12 changed files
with
4,423 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: "@chainsafe", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: ci/cd | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- '**' | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
cache: yarn | ||
node-version: '18' | ||
- name: Install deps | ||
run: yarn install --frozen-lockfile | ||
- name: Build | ||
run: yarn build | ||
- name: Lint | ||
run: yarn run lint | ||
- name: Tests | ||
run: yarn run test | ||
|
||
maybe-release: | ||
name: release | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
steps: | ||
- uses: google-github-actions/release-please-action@v3 | ||
id: release | ||
with: | ||
release-type: node | ||
package-name: release-please-action | ||
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":true}]' | ||
|
||
- uses: actions/checkout@v3 | ||
if: ${{ steps.release.outputs.release_created }} | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
cache: 'yarn' | ||
node-version: 18 | ||
registry-url: 'https://registry.npmjs.org' | ||
if: ${{ steps.release.outputs.release_created }} | ||
|
||
- run: yarn install --frozen-lockfile | ||
if: ${{ steps.release.outputs.release_created }} | ||
|
||
- run: yarn build | ||
if: ${{ steps.release.outputs.release_created }} | ||
|
||
- run: yarn publish --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} | ||
if: ${{ steps.release.outputs.release_created }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: "Semantic PR" | ||
|
||
on: | ||
pull_request_target: | ||
types: | ||
- opened | ||
- edited | ||
- synchronize | ||
|
||
jobs: | ||
main: | ||
name: Validate PR title | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: amannn/action-semantic-pull-request@v4 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
types: | | ||
fix | ||
feat | ||
chore | ||
revert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
web3-plugin-template | ||
=========== | ||
|
||
Contributing | ||
------------ | ||
|
||
Pull requests are welcome. For major changes, please open an issue first | ||
to discuss what you would like to change. | ||
|
||
Please make sure to update tests as appropriate. | ||
|
||
License | ||
------- | ||
|
||
[MIT](https://choosealicense.com/licenses/mit/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "web3-plugin-template", | ||
"version": "1.0.0", | ||
"description": "Template plugin to extend web3.js with additional methods", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"homepage": "https://github.com/web3/web3.js-plugin-template#readme", | ||
"bugs": { | ||
"url": "https://github.com/web3/web3.js-plugin-template/issues" | ||
}, | ||
"scripts": { | ||
"lint": "eslint '{src,test}/**/*.ts'", | ||
"build": "tsc --project tsconfig.build.json", | ||
"test": "jest --config=./test/jest.config.js" | ||
}, | ||
"contributors": [ | ||
"ChainSafe <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:web3/web3.js-plugin-template.git" | ||
}, | ||
"dependencies": { | ||
}, | ||
"devDependencies": { | ||
"@chainsafe/eslint-config": "^2.0.0", | ||
"@types/jest": "^29.5.2", | ||
"@types/node": "^20.2.6", | ||
"eslint": "8", | ||
"jest": "^29.5.0", | ||
"jest-extended": "^4.0.0", | ||
"ts-jest": "^29.1.0", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.1.3", | ||
"web3": "^4.0.3" | ||
}, | ||
"peerDependencies": { | ||
"web3": ">= 4.0.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Web3PluginBase } from "web3"; | ||
|
||
export class TemplatePlugin extends Web3PluginBase { | ||
public pluginNamespace = "template"; | ||
|
||
public test(param: string): void { | ||
console.log(param); | ||
} | ||
} | ||
|
||
// Module Augmentation | ||
declare module "web3" { | ||
interface Web3Context { | ||
template: TemplatePlugin; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Web3, { core } from "web3"; | ||
import { TemplatePlugin } from "../src"; | ||
|
||
describe("TemplatePlugin Tests", () => { | ||
it("should register TokensPlugin plugin on Web3Context instance", () => { | ||
const web3Context = new core.Web3Context("http://127.0.0.1:8545"); | ||
web3Context.registerPlugin(new TemplatePlugin()); | ||
expect(web3Context.template).toBeDefined(); | ||
}); | ||
|
||
describe("TemplatePlugin method tests", () => { | ||
let consoleSpy: jest.SpiedFunction<typeof global.console.log>; | ||
|
||
let web3Context: Web3; | ||
|
||
beforeAll(() => { | ||
web3Context = new Web3("http://127.0.0.1:8545"); | ||
web3Context.registerPlugin(new TemplatePlugin()); | ||
consoleSpy = jest.spyOn(global.console, "log").mockImplementation(); | ||
}); | ||
|
||
afterAll(() => { | ||
consoleSpy.mockRestore(); | ||
}); | ||
|
||
it("should call TempltyPlugin test method with expected param", () => { | ||
web3Context.template.test("test-param"); | ||
expect(consoleSpy).toHaveBeenCalledWith("test-param"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"include": ["src"], | ||
"exclude": ["node_modules", "test"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "./", | ||
"resolveJsonModule": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"target": "es2020", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"moduleResolution": "node", | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"pretty": true, | ||
"removeComments": true, | ||
"sourceMap": true, | ||
"declarationMap": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"outDir": "lib", | ||
"esModuleInterop": true | ||
}, | ||
"include": ["src", "test"], | ||
"exclude": ["node_modules"] | ||
} |
Oops, something went wrong.