Skip to content

Commit

Permalink
Feat/ts (#7)
Browse files Browse the repository at this point in the history
implement bundler in ts
  • Loading branch information
killroy192 authored Dec 18, 2023
1 parent 115beb5 commit c7fee0f
Show file tree
Hide file tree
Showing 52 changed files with 5,190 additions and 14,504 deletions.
64 changes: 45 additions & 19 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,53 @@
module.exports = {
env: {
commonjs: true,
browser: false,
es2021: true,
"jest/globals": true,
mocha: true,
node: true,
jest: true,
},
globals: {
hre: "readonly",
},
plugins: ["jest"],
extends: ["standard", "prettier"],
overrides: [
{
env: {
node: true,
},
files: [".eslintrc.{js,cjs}"],
parserOptions: {
sourceType: "script",
},
},

root: true,

plugins: ["@typescript-eslint", "json", "promise", "import", "prettier"],

extends: [
"eslint:recommended",
"plugin:node/recommended",
"plugin:json/recommended",
"plugin:promise/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"prettier",
],

parser: "@typescript-eslint/parser",

parserOptions: {
ecmaVersion: "latest",
ecmaVersion: 12,
},

rules: {
"node/no-missing-import": "off",
"node/no-unpublished-import": "off",
"prettier/prettier": "warn",
"import/order": [
"warn",
{
alphabetize: {
order: "asc",
caseInsensitive: true,
},
},
],
"sort-vars": ["warn", { ignoreCase: true }],
"node/no-unsupported-features/es-syntax": [
"error",
{ ignores: ["modules"] },
],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
},
rules: {},

ignorePatterns: ["dist", "**/*.d.ts"],
};
2 changes: 2 additions & 0 deletions .github/workflows/quality-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
- uses: actions/checkout@v3
- name: Install modules
run: npm i
- name: Typeccheck
run: npm run typecheck;
- name: Run linitng
run: npm run lint
- name: Run unit tests
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: npm ci
- run: npm run build:pkg
- run: npm publish
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
cache
artifacts
.vscode
.vscode
dist
1 change: 1 addition & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
. "$(dirname -- "$0")/_/husky.sh"

npm run lint;
npm run typecheck;
npm run test:unit;
npm run test:integration;
4 changes: 2 additions & 2 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"src/**/*.js": [
"src/**/*.ts": [
"eslint --fix",
"prettier --write"
],
"integration/**/*.js": [
"integration/**/*.ts": [
"eslint --fix",
"prettier --write"
]
Expand Down
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
# sol-bundler
Build, update and redeploy smartcontracts with hardhat with one config
sol-bundler tracks contract changes and redeploys only those where any changes were made
Build, update and redeploy smart contracts with hardhat with one config.
`sol-bundler` tracks contract changes and redeploys only those where any changes were made.

## Installation
run `npm install @dgma/sol-bundler`
run `npm install --save-dev @dgma/sol-bundler`
## Usage
1. Create deployment config in hardhat
```js
module.exports = {
```ts
import { type HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-ethers";
import { dynamicAddress } from "./src";

const config: HardhatUserConfig = {
solidity: "0.8.17",
paths: {
sources: "./testData",
tests: "./integration",
},
networks: {
hardhat: {
deployment: {
// omit lockFile if you want to have a fresh deploy each time
lockFile: "deployment-lock.json",
config: {
TestLibrary: {},
TestContract: {
args: ["hello"],
options: {
libs: {
TestLibrary: (_, ctx) => ctx.TestLibrary.address,
TestLibrary: dynamicAddress("TestLibrary"),
},
},
},
Expand All @@ -28,9 +36,12 @@ module.exports = {
},
},
};

export default config;
```
3. Write deployment script/task
```js
2. Write deployment script or task
```ts
import hre from "hardhat";
const { solBundler } = require('@dgma/sol-bundler');

const deploy = () => solBundler(hre)
Expand Down
14 changes: 7 additions & 7 deletions hardhat.config.js → hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
require("@nomicfoundation/hardhat-ethers");
require("@nomicfoundation/hardhat-chai-matchers");
import { type HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-ethers";
import { dynamicAddress } from "./src";

const getAddr = (contractName) => (_, ctx) => ctx[contractName].address;

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
const config: HardhatUserConfig = {
solidity: "0.8.17",
paths: {
sources: "./testData",
Expand All @@ -19,7 +17,7 @@ module.exports = {
args: ["hello"],
options: {
libs: {
TestLibrary: getAddr("TestLibrary"),
TestLibrary: dynamicAddress("TestLibrary"),
},
},
},
Expand All @@ -28,3 +26,5 @@ module.exports = {
},
},
};

export default config;
7 changes: 0 additions & 7 deletions index.js

This file was deleted.

7 changes: 4 additions & 3 deletions integration/main.test.js → integration/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const { expect } = require("chai");
const { solBundler } = require("../index");
import { expect } from "chai";
import hre from "hardhat";
import { type IGlobalState, solBundler } from "../src";

describe("main", () => {
it("should deploy contracts based on config file", async () => {
const { ctx, deployedContracts } = await solBundler(hre);
const { ctx, deployedContracts } = (await solBundler(hre)) as IGlobalState;
expect(deployedContracts).to.eql(["TestLibrary", "TestContract"]);
expect(ctx).to.have.property("TestContract");
expect(ctx).to.have.property("TestLibrary");
Expand Down
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testPathIgnorePatterns: ["integration"],
};
Loading

0 comments on commit c7fee0f

Please sign in to comment.