Skip to content

Commit cae9dcf

Browse files
committed
fix(template): name the build file to real contract name
1 parent 2cee7f3 commit cae9dcf

8 files changed

Lines changed: 9 additions & 25 deletions

templates/v4/base-template/README.md.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ This will:
8989
### Build Output
9090

9191
Each contract generates two files in its `dist/` directory:
92-
- `index.js` - Bundled JavaScript code
93-
- `index.bc` - Compiled bytecode for CKB execution
92+
- `{contract-name}.js` - Bundled JavaScript code
93+
- `{contract-name}.bc` - Compiled bytecode for CKB execution
9494

9595
### Testing
9696

templates/v4/base-template/scripts/add-contract.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
import fs from 'fs';
44
import path from 'path';
55
import readline from 'readline';
6-
import { fileURLToPath } from 'url';
7-
8-
const __filename = fileURLToPath(import.meta.url);
9-
const __dirname = path.dirname(__filename);
106

117
function askQuestion(question) {
128
const rl = readline.createInterface({
@@ -28,10 +24,6 @@ function validateContractName(name) {
2824
return validNamePattern.test(name) && name.length > 0;
2925
}
3026

31-
function processTemplate(content, contractName, language) {
32-
return content.replace(/\{\{CONTRACT_NAME\}\}/g, contractName).replace(/\{\{LANGUAGE\}\}/g, language);
33-
}
34-
3527
async function addContract() {
3628
let contractName = process.argv[2];
3729

@@ -123,7 +115,7 @@ describe('${contractName} contract', () => {
123115
124116
const mainScript = resource.deployCell(hexFrom(readFileSync(DEFAULT_SCRIPT_CKB_JS_VM)), tx, false);
125117
const alwaysSuccessScript = resource.deployCell(hexFrom(readFileSync(DEFAULT_SCRIPT_ALWAYS_SUCCESS)), tx, false);
126-
const contractScript = resource.deployCell(hexFrom(readFileSync('contracts/${contractName}/dist/index.bc')), tx, false);
118+
const contractScript = resource.deployCell(hexFrom(readFileSync('contracts/${contractName}/dist/${contractName}.bc')), tx, false);
127119
128120
mainScript.args = hexFrom(
129121
'0x0000' +

templates/v4/base-template/scripts/build-all.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
import fs from 'fs';
44
import path from 'path';
55
import { execSync } from 'child_process';
6-
import { fileURLToPath } from 'url';
7-
8-
const __filename = fileURLToPath(import.meta.url);
9-
const __dirname = path.dirname(__filename);
106

117
function buildAllContracts() {
128
const contractsDir = path.join(process.cwd(), 'contracts');

templates/v4/base-template/scripts/build-contract.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
import { execSync } from 'child_process';
44
import path from 'path';
55
import fs from 'fs';
6-
import { fileURLToPath } from 'url';
7-
8-
const __filename = fileURLToPath(import.meta.url);
9-
const __dirname = path.dirname(__filename);
106

117
function buildContract(contractName) {
128
if (!contractName) {
@@ -41,8 +37,8 @@ function buildContract(contractName) {
4137
// Ensure dist directory exists
4238
fs.mkdirSync(distDir, { recursive: true });
4339

44-
const outputJsFile = path.join(distDir, 'index.js');
45-
const outputBcFile = path.join(distDir, 'index.bc');
40+
const outputJsFile = path.join(distDir, `${contractName}.js`);
41+
const outputBcFile = path.join(distDir, `${contractName}.bc`);
4642

4743
console.log(`Building ${contractName} from ${srcFile}...`);
4844

templates/v4/base-template/tests/{{CONTRACT_NAME}}.devnet.test.js.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe("{{CONTRACT_NAME}} contract", () => {
1515

1616
test("should execute successfully", async () => {
1717
const ckbJsVmScript = systemScripts.devnet["ckb-js-vm"];
18-
const contractScript = scripts.devnet["index.bc"];
18+
const contractScript = scripts.devnet["{{CONTRACT_NAME}}.bc"];
1919

2020
const mainScript = {
2121
codeHash: ckbJsVmScript.script.codeHash,

templates/v4/base-template/tests/{{CONTRACT_NAME}}.devnet.test.ts.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe("{{CONTRACT_NAME}} contract", () => {
1515

1616
test("should execute successfully", async () => {
1717
const ckbJsVmScript = systemScripts.devnet["ckb-js-vm"];
18-
const contractScript = scripts.devnet["index.bc"];
18+
const contractScript = scripts.devnet["{{CONTRACT_NAME}}.bc"];
1919

2020
const mainScript = {
2121
codeHash: ckbJsVmScript.script.codeHash,

templates/v4/base-template/tests/{{CONTRACT_NAME}}.mock.test.js.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('{{CONTRACT_NAME}} contract', () => {
99

1010
const mainScript = resource.deployCell(hexFrom(readFileSync(DEFAULT_SCRIPT_CKB_JS_VM)), tx, false);
1111
const alwaysSuccessScript = resource.deployCell(hexFrom(readFileSync(DEFAULT_SCRIPT_ALWAYS_SUCCESS)), tx, false);
12-
const contractScript = resource.deployCell(hexFrom(readFileSync('contracts/{{CONTRACT_NAME}}/dist/index.bc')), tx, false);
12+
const contractScript = resource.deployCell(hexFrom(readFileSync('contracts/{{CONTRACT_NAME}}/dist/{{CONTRACT_NAME}}.bc')), tx, false);
1313

1414
mainScript.args = hexFrom(
1515
'0x0000' +

templates/v4/base-template/tests/{{CONTRACT_NAME}}.mock.test.ts.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('{{CONTRACT_NAME}} contract', () => {
99

1010
const mainScript = resource.deployCell(hexFrom(readFileSync(DEFAULT_SCRIPT_CKB_JS_VM)), tx, false);
1111
const alwaysSuccessScript = resource.deployCell(hexFrom(readFileSync(DEFAULT_SCRIPT_ALWAYS_SUCCESS)), tx, false);
12-
const contractScript = resource.deployCell(hexFrom(readFileSync('contracts/{{CONTRACT_NAME}}/dist/index.bc')), tx, false);
12+
const contractScript = resource.deployCell(hexFrom(readFileSync('contracts/{{CONTRACT_NAME}}/dist/{{CONTRACT_NAME}}.bc')), tx, false);
1313

1414
mainScript.args = hexFrom(
1515
'0x0000' +

0 commit comments

Comments
 (0)