Skip to content

Commit f7074a2

Browse files
authored
Merge pull request #264 from ckb-devrel/impl-feedback
Impl feedback
2 parents 3135451 + 2e8bbd3 commit f7074a2

11 files changed

Lines changed: 388 additions & 29 deletions

src/templates/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const BASE_TEMPLATE_METADATA: TemplateMetadata = {
5252
requiredFiles: [
5353
'package.json.template',
5454
'jest.config.cjs.template',
55-
'.gitignore',
55+
'gitignore.template',
5656
'README.md.template',
5757
'deployment/scripts.json.template',
5858
'deployment/README.md.template',

src/templates/processor.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ export class TemplateProcessor {
6464
const relativePath = path.relative(this.templateDir, filePath);
6565
const fileName = path.basename(filePath);
6666

67+
// Exclude template metadata files
68+
if (fileName === '_template.config.json') {
69+
return false;
70+
}
71+
6772
// Always include required files
6873
if (BASE_TEMPLATE_METADATA.requiredFiles.some((reqFile) => relativePath.includes(reqFile))) {
6974
return true;
@@ -111,15 +116,16 @@ export class TemplateProcessor {
111116
const basePackageJson = {
112117
name: context.projectName,
113118
version: '0.1.0',
114-
description: 'CKB JavaScript VM project',
119+
description: 'CKB JavaScript Smart Contract project',
115120
private: true,
116121
type: 'module',
117122
scripts: {
118123
build: 'node scripts/build-all.js',
119124
'build:contract': 'node scripts/build-contract.js',
120-
test: 'jest',
125+
test: 'node scripts/build-all.js && jest',
121126
'add-contract': 'node scripts/add-contract.js',
122-
clean: 'rimraf contracts/*/dist',
127+
deploy: 'node scripts/build-all.js && node scripts/deploy.js',
128+
clean: 'rimraf dist',
123129
format: 'prettier --write .',
124130
},
125131
dependencies: TEMPLATE_CONFIG.dependencies,
@@ -159,6 +165,12 @@ export class TemplateProcessor {
159165
finalTargetPath = path.join(dir, '.env');
160166
}
161167

168+
// Handle gitignore.template -> .gitignore
169+
if (fileName === 'gitignore') {
170+
const dir = path.dirname(finalTargetPath);
171+
finalTargetPath = path.join(dir, '.gitignore');
172+
}
173+
162174
// Ensure target directory exists
163175
const targetDir = path.dirname(finalTargetPath);
164176
fs.mkdirSync(targetDir, { recursive: true });

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

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# {{PROJECT_NAME}}
22

3-
A CKB JavaScript VM project for developing smart contracts on the CKB blockchain.
3+
A JavaScript project for developing smart contracts on the CKB blockchain.
44

55
## Overview
66

@@ -12,15 +12,17 @@ This project uses the CKB JavaScript VM (ckb-js-vm) to write smart contracts in
1212
{{PROJECT_NAME}}/
1313
├── contracts/ # Smart contract source code
1414
│ └── hello-world/
15-
│ ├── src/
16-
│ │ └── index.{{LANGUAGE}} # Contract implementation
17-
│ └── dist/ # Compiled output (generated)
15+
│ └── src/
16+
│ └── index.{{LANGUAGE}} # Contract implementation
1817
├── tests/ # Contract tests
1918
│ └── hello-world.test.{{LANGUAGE}}
2019
├── scripts/ # Build and utility scripts
2120
│ ├── build-all.js
2221
│ ├── build-contract.js
2322
│ └── add-contract.js
23+
├── dist/ # Compiled output (generated)
24+
│ ├── hello-world.js # Bundled JavaScript
25+
│ └── hello-world.bc # Compiled bytecode
2426
├── package.json
2527
{{#if_typescript}}├── tsconfig.json # TypeScript configuration
2628
├── tsconfig.base.json # Base TypeScript settings
@@ -88,9 +90,9 @@ This will:
8890

8991
### Build Output
9092

91-
Each contract generates two files in its `dist/` directory:
92-
- `{contract-name}.js` - Bundled JavaScript code
93-
- `{contract-name}.bc` - Compiled bytecode for CKB execution
93+
All contracts are built to the global `dist/` directory:
94+
- `dist/{contract-name}.js` - Bundled JavaScript code
95+
- `dist/{contract-name}.bc` - Compiled bytecode for CKB execution
9496

9597
### Testing
9698

@@ -106,9 +108,53 @@ Tests use the `ckb-testtool` framework to simulate CKB blockchain execution. Eac
106108
- `build:contract <name>` - Build a specific contract
107109
- `test` - Run all tests
108110
- `add-contract <name>` - Add a new contract
111+
- `deploy` - Deploy contracts to CKB network
109112
- `clean` - Remove all build outputs
110113
- `format` - Format code with Prettier
111114

115+
## Deployment
116+
117+
Deploy your contracts to CKB networks using the built-in deploy script:
118+
119+
### Basic Usage
120+
121+
```bash
122+
# Deploy to devnet (default)
123+
{{PACKAGE_MANAGER}} run deploy
124+
125+
# Deploy to testnet
126+
{{PACKAGE_MANAGER}} run deploy -- --network testnet
127+
128+
# Deploy to mainnet
129+
{{PACKAGE_MANAGER}} run deploy -- --network mainnet
130+
```
131+
132+
### Advanced Options
133+
134+
```bash
135+
# Deploy with upgradable type ID
136+
{{PACKAGE_MANAGER}} run deploy -- --network testnet --type-id
137+
138+
# Deploy with custom private key
139+
{{PACKAGE_MANAGER}} run deploy -- --network testnet --privkey 0x...
140+
141+
# Combine multiple options
142+
{{PACKAGE_MANAGER}} run deploy -- --network testnet --type-id --privkey 0x...
143+
```
144+
145+
### Available Options
146+
147+
- `--network <network>` - Target network: `devnet`, `testnet`, or `mainnet` (default: `devnet`)
148+
- `--privkey <privkey>` - Private key for deployment (default: uses offckb's deployer account)
149+
- `--type-id` - Enable upgradable type ID for contract updates
150+
151+
### Deployment Artifacts
152+
153+
After successful deployment, artifacts are saved to the `deployment/` directory:
154+
- `deployment/scripts.json` - Contract script information
155+
- `deployment/<network>/<contract>/deployment.toml` - Deployment configuration
156+
- `deployment/<network>/<contract>/migrations/` - Migration history
157+
112158
## Dependencies
113159

114160
### Core Dependencies

templates/v4/base-template/.gitignore renamed to templates/v4/base-template/gitignore.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ node_modules/
33
.pnpm-store/
44

55
# Build outputs
6-
contracts/*/dist/
76
dist/
87
build/
98

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/** @type {import('jest').Config} */
22
module.exports = {
33
testEnvironment: "node",
4-
testPathIgnorePatterns: ["/node_modules/", "/dist/", "/contracts/*/dist/"],
4+
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
55
moduleFileExtensions: ["js", "json"],
66
testMatch: ["**/tests/**/*.test.js"],
77
transformIgnorePatterns: [
88
"node_modules/(?!(@ckb-ccc|ckb-testtool)/)"
99
],
1010
collectCoverageFrom: [
1111
"contracts/*/src/**/*.js",
12-
"!contracts/*/dist/**"
12+
"!dist/**"
1313
]
1414
};

templates/v4/base-template/jest.config.cjs.ts.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
module.exports = {
33
preset: "ts-jest",
44
testEnvironment: "node",
5-
testPathIgnorePatterns: ["/node_modules/", "/dist/", "/contracts/*/dist/"],
5+
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
66
collectCoverageFrom: [
77
"contracts/*/src/**/*.ts",
8-
"!contracts/*/dist/**"
8+
"!dist/**"
99
]
1010
};

0 commit comments

Comments
 (0)