Skip to content

Commit

Permalink
Merge pull request #10 from pawanpaudel93/feat/minify
Browse files Browse the repository at this point in the history
feat: add contract code minification/modification
  • Loading branch information
pawanpaudel93 authored Dec 1, 2024
2 parents 5f16dc7 + 8acc9c1 commit 7d6a550
Show file tree
Hide file tree
Showing 12 changed files with 1,623 additions and 1,288 deletions.
44 changes: 38 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ A package for deploying AO contracts.
- Support for deployment configuration.
- Flexible concurrency and retry options for reliable deployments.
- CLI and API interfaces for versatile usage.
- Minify or modify the contract before deployment.

## Installation

### Basic Installation

### Using npm

```sh
Expand All @@ -42,6 +45,17 @@ yarn add ao-deploy --dev
bun add ao-deploy --dev
```

### Optional Dependencies

If you plan to use the `--minify` option, you'll need to install [lua-format](https://github.com/Herrtt/luamin.js):

```sh
npm install lua-format --save-dev # npm
pnpm add lua-format --save-dev # pnpm
yarn add lua-format --dev # yarn
bun add lua-format --dev # bun
```

## Usage

### CLI
Expand Down Expand Up @@ -75,6 +89,7 @@ Options:
--sqlite Use sqlite aos module when spawning new process.
--retry-count [count] Number of retries for deploying contract. (default: 10)
--retry-delay [delay] Delay between retries in milliseconds. (default: 3000)
--minify Reduce the size of the contract before deployment. (default: false)
-h, --help display help for command
```

Expand All @@ -84,6 +99,15 @@ Options:
ao-deploy process.lua -n tictactoe -w wallet.json --tags name1:value1 name2:value2
```

### Example: Deploy contract with minify

> [!Note]
> Make sure to install `lua-format` as mentioned in [Optional Dependencies](#optional-dependencies) section.
```sh
ao-deploy process.lua -n tictactoe -w wallet.json --tags name1:value1 name2:value2 --minify
```

#### Example: Deploy contracts with configuration

Here is an example using a deployment configuration:
Expand All @@ -100,13 +124,19 @@ const config = defineConfig({
luaPath,
name: `contract-1`,
contractPath: "contract-1.lua",
wallet
wallet,
minify: true // Minify the contract before deployment
},
contract_2: {
luaPath,
name: `contract-2`,
contractPath: "contract-2.lua",
wallet
wallet,
// Custom source transformer function
contractTransformer: (source) => {
// Example: Remove all comments from the source code
return source.replace(/\s*--.*\n/g, "");
}
},
contract_3: {
luaPath,
Expand Down Expand Up @@ -226,8 +256,8 @@ async function main() {
delay: 3000
}
});
const processUrl = `https://ao_marton.g8way.io/#/process/${processId}`;
const messageUrl = `${processUrl}/${messageId}`;
const processUrl = `https://www.ao.link/#/entity/${processId}`;
const messageUrl = `https://www.ao.link/#/message/${messageId}`;
console.log(
`\nDeployed Process: ${processUrl} \nDeployment Message: ${messageUrl}`
);
Expand Down Expand Up @@ -255,6 +285,8 @@ The `deployContract` function accepts the following parameters within the Deploy
- `retry` (optional): Retry options with `count` and `delay` properties. By default, it will retry up to `10` times with a `3000` milliseconds delay between attempts.
- `luaPath` (optional): The path to the Lua modules seperated by semicolon.
- `processId` (optional): The process id of existing process.
- `minify` (optional): Reduce the size of the contract before deployment.
- `contractTransformer` (optional): Custom function to transform source code before deployment.

#### Example: deployContracts

Expand Down Expand Up @@ -293,8 +325,8 @@ async function main() {
results.forEach((result, idx) => {
if (result.status === "fulfilled") {
const { processId, messageId } = result.value;
const processUrl = `https://ao_marton.g8way.io/#/process/${processId}`;
const messageUrl = `${processUrl}/${messageId}`;
const processUrl = `https://www.ao.link/#/entity/${processId}`;
const messageUrl = `https://www.ao.link/#/message/${messageId}`;
console.log(
`\nDeployed Process: ${processUrl} \nDeployment Message: ${messageUrl}`
);
Expand Down
43 changes: 24 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ao-deploy",
"type": "module",
"version": "0.5.0",
"version": "0.6.0",
"packageManager": "[email protected]",
"description": "A package for deploying AO contracts",
"author": "Pawan Paudel <[email protected]>",
Expand Down Expand Up @@ -46,6 +46,7 @@
"lint": "eslint .",
"prepublishOnly": "nr build",
"release": "bumpp && npm publish",
"release:beta": "bumpp --tag beta && npm publish --tag beta",
"start": "esno src/index.ts",
"test": "vitest",
"typecheck": "tsc --noEmit",
Expand All @@ -55,39 +56,43 @@
"fmt:check": "prettier --check ."
},
"dependencies": {
"@permaweb/aoconnect": "^0.0.58",
"arweave": "^1.15.1",
"@permaweb/aoconnect": "^0.0.62",
"arweave": "^1.15.5",
"chalk": "^5.3.0",
"commander": "^12.0.0",
"jiti": "^1.21.0",
"commander": "^12.1.0",
"jiti": "^1.21.6",
"p-limit": "^4.0.0",
"pretty-file-tree": "^1.0.1"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
"@types/node": "^20.12.8",
"bumpp": "^9.4.1",
"eslint": "^8.57.0",
"@eslint/js": "^9.16.0",
"@types/node": "^20.17.9",
"bumpp": "^9.8.1",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"esno": "^4.7.0",
"globals": "^15.9.0",
"lint-staged": "^15.2.2",
"pnpm": "^8.15.8",
"prettier": "^3.3.3",
"rimraf": "^5.0.5",
"esno": "^4.8.0",
"globals": "^15.12.0",
"lint-staged": "^15.2.10",
"lua-format": "^1.5.2",
"pnpm": "^8.15.9",
"prettier": "^3.4.1",
"rimraf": "^5.0.10",
"simple-git-hooks": "^2.11.1",
"tsx": "^4.16.5",
"typescript": "^5.4.5",
"typescript-eslint": "^8.1.0",
"tsx": "^4.19.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.16.0",
"unbuild": "^2.0.0",
"vite": "^5.2.11",
"vite": "^5.4.11",
"vitest": "^1.6.0"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": "eslint . --fix"
},
"peerDependencies": {
"lua-format": "^1.5.2"
}
}
Loading

0 comments on commit 7d6a550

Please sign in to comment.