Skip to content

Commit

Permalink
feat: add ckb-js-std package
Browse files Browse the repository at this point in the history
  • Loading branch information
XuJiandong committed Jan 20, 2025
1 parent 9921ac9 commit e2d1b66
Show file tree
Hide file tree
Showing 15 changed files with 1,143 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ dkms.conf
.vscode

build
node_modules/
dist/
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"private": true,
"workspaces": [
"packages/*"
],
"scripts": {
"build:prepare": "pnpm -r install",
"build": "pnpm -r run build",
"docs": "typedoc"
},
"devDependencies": {
"esbuild": "0.24.2",
"eslint": "9.18.0",
"prettier": "3.4.2",
"typescript": "^5.7.3"
},
"pnpm": {}
}
3 changes: 3 additions & 0 deletions packages/bindings/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

export function loadScript(offset?: number, length?: number): ArrayBuffer;
export function currentCycles(): number;
17 changes: 17 additions & 0 deletions packages/bindings/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@ckb-js-std/bindings",
"version": "0.1.0",
"description": "bindings for ckb-js-vm",
"author": "CKB-VM Team",
"license": "MIT",
"private": false,
"homepage": "https://github.com/nervosnetwork/ckb-js-vm",
"repository": {
"type": "git",
"url": "https://github.com/nervosnetwork/ckb-js-vm.git"
},
"scripts": {
},
"sideEffects": false,
"types": "index"
}
8 changes: 8 additions & 0 deletions packages/bindings/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es2020",
"module": "ESNext",
"moduleResolution": "Bundler",
"types": [ "./index.d.ts" ]
}
}
30 changes: 30 additions & 0 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@ckb-js-std/examples",
"version": "0.1.0",
"description": "Write scripts in JavaScript on CKB-VM",
"author": "CKB-VM Team",
"license": "MIT",
"private": false,
"homepage": "https://github.com/nervosnetwork/ckb-js-vm",
"repository": {
"type": "git",
"url": "https://github.com/nervosnetwork/ckb-js-vm.git"
},
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.js",
"scripts": {
"start": "ckb-debugger --read-file dist/index.js --bin ../../build/ckb-js-vm -- -r",
"build": "tsc --noEmit && esbuild src/index.ts --bundle --outfile=dist/index.js --external:ckb --target=es2022",
"clean": "rm -f dist/*"
},
"devDependencies": {
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@ckb-js-std/bindings": "workspace:*",
"@ckb-js-std/examples": "link:"
}
}
10 changes: 10 additions & 0 deletions packages/examples/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as ckb from "ckb";

function main() {
let script = ckb.loadScript();
console.log(`script length is ${script.byteLength}`);
let cycles = ckb.currentCycles();
console.log(`current cycles is ${cycles}`);
}

main();
24 changes: 24 additions & 0 deletions packages/examples/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "es2022",
"incremental": true,
"allowJs": true,
"importHelpers": false,
"declaration": true,
"declarationMap": true,
"experimentalDecorators": true,
"useDefineForClassFields": false,
"esModuleInterop": true,
"strict": true,
"noImplicitAny": true,
"strictBindCallApply": true,
"strictNullChecks": true,
"alwaysStrict": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true
},
"include": [
"src/**/*"
]
}
12 changes: 12 additions & 0 deletions packages/examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler",
"outDir": "./dist",
"baseUrl": ".",
"paths": {
"ckb": ["node_modules/@ckb-js-std/bindings"]
}
}
}
Loading

0 comments on commit e2d1b66

Please sign in to comment.