Skip to content

Commit 92d6f00

Browse files
committed
chore: enhance build script for precompiles output structure
1 parent 3ca5e17 commit 92d6f00

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

contracts/package.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cosmos-evm-contracts",
33
"packageManager": "pnpm@9.15.0",
4-
"version": "0.0.1",
4+
"version": "0.0.2",
55
"description": "A collection of smart contracts used in the development of the Cosmos EVM blockchain.",
66
"devDependencies": {
77
"@openzeppelin/contracts": "^5.4.0",
@@ -10,14 +10,7 @@
1010
"scripts": {
1111
"build:precompiles": "node scripts/build-precompiles.js",
1212
"compile": "hardhat compile",
13-
"prepublishOnly": "pnpm run build:precompiles"
14-
},
15-
"files": [
16-
"dist",
17-
"README.md"
18-
],
19-
"exports": {
20-
"./*": "./dist/*"
13+
"publish:dist": "pnpm run build:precompiles && cd dist && pnpm publish"
2114
},
2215
"repository": {
2316
"type": "git",

contracts/scripts/build-precompiles.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const ROOT = join(__dirname, "..");
1717
const ARTIFACTS = join(ROOT, "artifacts", "solidity", "precompiles");
1818
const SOLIDITY_SOURCE = join(ROOT, "solidity");
1919
const DIST = join(ROOT, "dist");
20-
const DIST_ABI = join(DIST, "abi");
20+
const OUT_PRECOMPILES = join(DIST, "precompiles");
21+
const OUT_ABI = join(DIST, "abi");
2122

2223
const EXCLUDED_DIRS = ["testdata", "testutil"];
2324

@@ -66,7 +67,8 @@ function buildPrecompiles() {
6667
process.exit(1);
6768
}
6869

69-
ensureDir(DIST_ABI);
70+
ensureDir(OUT_PRECOMPILES);
71+
ensureDir(OUT_ABI);
7072

7173
const copiedSol = new Set();
7274
let count = 0;
@@ -81,8 +83,8 @@ function buildPrecompiles() {
8183

8284
const relFromSolidity = sourceName.replace(/^solidity\//, ""); // precompiles/bank/IBank.sol
8385
const solPath = join(SOLIDITY_SOURCE, relFromSolidity);
84-
const abiOutPath = join(DIST_ABI, relFromSolidity.replace(".sol", ".json"));
85-
const solOutPath = join(DIST, relFromSolidity);
86+
const abiOutPath = join(OUT_ABI, relFromSolidity.replace(".sol", ".json"));
87+
const solOutPath = join(OUT_PRECOMPILES, relFromSolidity.replace(/^precompiles\//, ""));
8688

8789
ensureDir(dirname(abiOutPath));
8890
ensureDir(dirname(solOutPath));
@@ -102,14 +104,30 @@ function buildPrecompiles() {
102104
const relFromSolidity = join("precompiles", rel);
103105
if (copiedSol.has(relFromSolidity)) continue;
104106
const solPath = join(SOLIDITY_SOURCE, relFromSolidity);
105-
const solOutPath = join(DIST, relFromSolidity);
107+
const solOutPath = join(OUT_PRECOMPILES, rel);
106108
ensureDir(dirname(solOutPath));
107109
cpSync(solPath, solOutPath);
108110
count++;
109111
console.log(" ", relFromSolidity, "(no ABI)");
110112
}
111113

112-
console.log("\nDone. Built", count, "precompile file(s) to dist/ (OpenZeppelin style).");
114+
// Copy README and create package.json for publishing from dist/
115+
cpSync(join(ROOT, "README.md"), join(DIST, "README.md"));
116+
const rootPkg = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf8"));
117+
const distPkg = {
118+
name: rootPkg.name,
119+
version: rootPkg.version,
120+
description: rootPkg.description,
121+
repository: rootPkg.repository,
122+
author: rootPkg.author,
123+
license: rootPkg.license,
124+
bugs: rootPkg.bugs,
125+
homepage: rootPkg.homepage,
126+
files: ["precompiles", "abi", "README.md"],
127+
};
128+
writeFileSync(join(DIST, "package.json"), JSON.stringify(distPkg, null, 2), "utf8");
129+
130+
console.log("\nDone. Built", count, "precompile file(s) to dist/ (ready to publish from dist/).");
113131
}
114132

115133
buildPrecompiles();

0 commit comments

Comments
 (0)