@offckb/cli 0.2.6 → 0.3.0-canary-cfe9b48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/README.md +59 -17
  2. package/ckb/devnet/specs/dev.toml +7 -7
  3. package/dist/cfg/env-path.d.ts +9 -0
  4. package/dist/cfg/env-path.js +63 -0
  5. package/dist/cfg/setting.d.ts +45 -0
  6. package/dist/cfg/setting.js +124 -0
  7. package/dist/cli.js +54 -30
  8. package/dist/cmd/clean.js +7 -5
  9. package/dist/cmd/config.d.ts +11 -0
  10. package/dist/cmd/config.js +102 -0
  11. package/dist/cmd/create.d.ts +1 -1
  12. package/dist/cmd/create.js +19 -8
  13. package/dist/cmd/debug.d.ts +13 -0
  14. package/dist/cmd/debug.js +100 -0
  15. package/dist/cmd/deploy.js +45 -25
  16. package/dist/cmd/deposit.js +11 -7
  17. package/dist/cmd/inject-config.d.ts +0 -3
  18. package/dist/cmd/inject-config.js +20 -80
  19. package/dist/cmd/list-hashes.d.ts +25 -1
  20. package/dist/cmd/list-hashes.js +24 -16
  21. package/dist/cmd/{deployed-scripts.d.ts → my-scripts.d.ts} +1 -1
  22. package/dist/cmd/my-scripts.js +25 -0
  23. package/dist/cmd/node.d.ts +5 -1
  24. package/dist/cmd/node.js +22 -8
  25. package/dist/cmd/proxy-rpc.d.ts +7 -0
  26. package/dist/cmd/proxy-rpc.js +23 -0
  27. package/dist/cmd/sync-config.js +16 -11
  28. package/dist/cmd/system-scripts.d.ts +42 -0
  29. package/dist/cmd/system-scripts.js +265 -0
  30. package/dist/deploy/migration.d.ts +45 -0
  31. package/dist/deploy/migration.js +131 -0
  32. package/dist/deploy/toml.d.ts +38 -0
  33. package/dist/deploy/toml.js +60 -0
  34. package/dist/deploy/util.d.ts +2 -0
  35. package/dist/deploy/util.js +19 -0
  36. package/dist/node/init-chain.js +41 -0
  37. package/dist/{cmd/develop → node}/install.d.ts +4 -5
  38. package/dist/{cmd/develop → node}/install.js +32 -32
  39. package/dist/scripts/gen.d.ts +5 -0
  40. package/dist/scripts/gen.js +69 -0
  41. package/dist/scripts/public.d.ts +8 -0
  42. package/dist/scripts/public.js +396 -0
  43. package/dist/scripts/type.d.ts +46 -0
  44. package/dist/scripts/type.js +19 -0
  45. package/dist/scripts/util.d.ts +3 -0
  46. package/dist/scripts/util.js +84 -0
  47. package/dist/template/config.d.ts +4 -0
  48. package/dist/template/config.js +60 -0
  49. package/dist/template/offckb.config.d.ts +69 -0
  50. package/dist/template/offckb.config.js +81 -0
  51. package/dist/{util/template.d.ts → template/option.d.ts} +1 -1
  52. package/dist/template/option.js +11 -0
  53. package/dist/template/option.json +16 -0
  54. package/dist/tools/ckb-debugger.d.ts +12 -0
  55. package/dist/tools/ckb-debugger.js +31 -0
  56. package/dist/tools/ckb-tx-dumper.d.ts +6 -0
  57. package/dist/tools/ckb-tx-dumper.js +21 -0
  58. package/dist/tools/rpc-proxy.d.ts +9 -0
  59. package/dist/tools/rpc-proxy.js +84 -0
  60. package/dist/util/ckb.d.ts +64 -0
  61. package/dist/util/ckb.js +16 -3
  62. package/dist/util/encoding.d.ts +1 -0
  63. package/dist/util/encoding.js +7 -1
  64. package/dist/util/fs.d.ts +1 -2
  65. package/dist/util/fs.js +8 -32
  66. package/dist/util/git.js +19 -7
  67. package/dist/util/request.d.ts +8 -0
  68. package/dist/util/request.js +57 -0
  69. package/dist/util/type.d.ts +1 -0
  70. package/dist/util/validator.d.ts +1 -0
  71. package/dist/util/validator.js +13 -4
  72. package/package.json +9 -4
  73. package/templates/offckb.config.ts +3 -3
  74. package/templates/template.json +16 -0
  75. package/dist/cfg/const.d.ts +0 -21
  76. package/dist/cfg/const.js +0 -51
  77. package/dist/cmd/deployed-scripts.js +0 -14
  78. package/dist/cmd/develop/build-account.d.ts +0 -1
  79. package/dist/cmd/develop/build-account.js +0 -9
  80. package/dist/cmd/develop/genkey.d.ts +0 -14
  81. package/dist/cmd/develop/genkey.js +0 -143
  82. package/dist/cmd/develop/init-chain.js +0 -76
  83. package/dist/cmd/develop/lumos-config.d.ts +0 -4
  84. package/dist/cmd/develop/lumos-config.js +0 -153
  85. package/dist/util/config.d.ts +0 -9
  86. package/dist/util/config.js +0 -136
  87. package/dist/util/template.js +0 -30
  88. package/templates/config.json +0 -98
  89. /package/ckb/devnet/specs/{omni_lock → omnilock} +0 -0
  90. /package/ckb/devnet/specs/{spore-scripts → spore}/spore +0 -0
  91. /package/ckb/devnet/specs/{spore-scripts/cluster → spore/spore_cluster} +0 -0
  92. /package/ckb/devnet/specs/{spore-scripts/cluster_agent → spore/spore_cluster_agent} +0 -0
  93. /package/ckb/devnet/specs/{spore-scripts/cluster_proxy → spore/spore_cluster_proxy} +0 -0
  94. /package/ckb/devnet/specs/{spore-scripts → spore}/spore_extension_lua +0 -0
  95. /package/ckb/devnet/specs/{xudt_rce → xudt} +0 -0
  96. /package/dist/{cmd/develop → node}/init-chain.d.ts +0 -0
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ // this file is generated by offckb-cli
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.readEnvNetwork = exports.SystemScriptName = void 0;
8
+ const path_1 = __importDefault(require("path"));
9
+ var SystemScriptName;
10
+ (function (SystemScriptName) {
11
+ SystemScriptName["secp256k1_blake160_sighash_all"] = "secp256k1_blake160_sighash_all";
12
+ SystemScriptName["secp256k1_blake160_multisig_all"] = "secp256k1_blake160_multisig_all";
13
+ SystemScriptName["dao"] = "dao";
14
+ SystemScriptName["sudt"] = "sudt";
15
+ SystemScriptName["xudt"] = "xudt";
16
+ SystemScriptName["omnilock"] = "omnilock";
17
+ SystemScriptName["anyone_can_pay"] = "anyone_can_pay";
18
+ SystemScriptName["always_success"] = "always_success";
19
+ SystemScriptName["spore"] = "spore";
20
+ SystemScriptName["spore_cluster"] = "spore_cluster";
21
+ SystemScriptName["spore_cluster_agent"] = "spore_cluster_agent";
22
+ SystemScriptName["spore_cluster_proxy"] = "spore_cluster_proxy";
23
+ SystemScriptName["spore_extension_lua"] = "spore_extension_lua";
24
+ })(SystemScriptName || (exports.SystemScriptName = SystemScriptName = {}));
25
+ function readEnvNetwork() {
26
+ // you may need to update the env method
27
+ // according to your frontend framework
28
+ const network = process.env.NETWORK;
29
+ const defaultNetwork = 'devnet';
30
+ if (!network)
31
+ return defaultNetwork;
32
+ if (!['devnet', 'testnet', 'mainnet'].includes(network)) {
33
+ return defaultNetwork;
34
+ }
35
+ return network;
36
+ }
37
+ exports.readEnvNetwork = readEnvNetwork;
38
+ const offCKBConfig = {
39
+ version: '@offckb-update-version',
40
+ contractBinFolder: '../build/release',
41
+ contractInfoFolder: './offckb', // this folder record the script deployment information
42
+ networks: {
43
+ devnet: {
44
+ rpc_url: 'http://127.0.0.1:8114',
45
+ addressPrefix: 'ckt',
46
+ },
47
+ testnet: {
48
+ rpc_url: 'https://testnet.ckb.dev/rpc',
49
+ addressPrefix: 'ckt',
50
+ },
51
+ mainnet: {
52
+ rpc_url: 'https://mainnet.ckb.dev/rpc',
53
+ addressPrefix: 'ckb',
54
+ },
55
+ },
56
+ get currentNetwork() {
57
+ const network = readEnvNetwork();
58
+ return network;
59
+ },
60
+ get addressPrefix() {
61
+ const network = readEnvNetwork();
62
+ return this.networks[network].addressPrefix;
63
+ },
64
+ get rpcUrl() {
65
+ const network = readEnvNetwork();
66
+ return this.networks[network].rpc_url;
67
+ },
68
+ get systemScripts() {
69
+ const network = readEnvNetwork();
70
+ const networkSystemScripts = require(path_1.default.resolve(this.contractInfoFolder, 'system-scripts.json'));
71
+ const systemScripts = networkSystemScripts[network];
72
+ return systemScripts;
73
+ },
74
+ get myScripts() {
75
+ const network = readEnvNetwork();
76
+ const networkMyScripts = require(path_1.default.resolve(this.contractInfoFolder, 'my-scripts.json'));
77
+ const myScripts = networkMyScripts[network];
78
+ return myScripts;
79
+ },
80
+ };
81
+ exports.default = offCKBConfig;
@@ -5,4 +5,4 @@ export interface BareTemplateOption {
5
5
  tag: string[];
6
6
  author: string;
7
7
  }
8
- export declare function loadBareTemplateOpts(): Promise<Array<BareTemplateOption>>;
8
+ export declare function loadBareTemplateOpts(): Array<BareTemplateOption>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadBareTemplateOpts = void 0;
7
+ const option_json_1 = __importDefault(require("./option.json"));
8
+ function loadBareTemplateOpts() {
9
+ return option_json_1.default;
10
+ }
11
+ exports.loadBareTemplateOpts = loadBareTemplateOpts;
@@ -0,0 +1,16 @@
1
+ [
2
+ {
3
+ "name": "Remix-Vite Bare Templates",
4
+ "value": "remix-vite-template",
5
+ "description": "A full-stack template with Remix-vite and ckb-script-templates",
6
+ "tag": ["remix", "vite", "tailwindcss", "ckb-script-templates", "typescript", "rust"],
7
+ "author": "retric@cryptape.com"
8
+ },
9
+ {
10
+ "name": "Next.js Bare Templates",
11
+ "value": "next-js-template",
12
+ "description": "A full-stack template with Next.js framework and ckb-script-templates",
13
+ "tag": ["next.js", "tailwindcss", "ckb-script-templates", "typescript", "rust"],
14
+ "author": "retric@cryptape.com"
15
+ }
16
+ ]
@@ -0,0 +1,12 @@
1
+ export interface DebugOption {
2
+ fullTxJsonFilePath: string;
3
+ cellIndex: number;
4
+ cellType: 'output' | 'input';
5
+ scriptGroupType: 'lock' | 'type';
6
+ }
7
+ export declare class CKBDebugger {
8
+ static runRaw(options: string): void;
9
+ static runTxCellScript({ fullTxJsonFilePath, cellIndex, cellType, scriptGroupType }: DebugOption): void;
10
+ static isBinaryInstalled(): boolean;
11
+ static installCKBDebugger(): void;
12
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CKBDebugger = void 0;
4
+ const child_process_1 = require("child_process");
5
+ class CKBDebugger {
6
+ static runRaw(options) {
7
+ const command = `ckb-debugger ${options}`;
8
+ (0, child_process_1.execSync)(command, { stdio: 'inherit' });
9
+ }
10
+ static runTxCellScript({ fullTxJsonFilePath, cellIndex, cellType, scriptGroupType }) {
11
+ const command = `ckb-debugger --tx-file ${fullTxJsonFilePath} --cell-index ${cellIndex} --cell-type ${cellType} --script-group-type ${scriptGroupType}`;
12
+ (0, child_process_1.execSync)(command, { stdio: 'inherit' });
13
+ }
14
+ static isBinaryInstalled() {
15
+ const result = (0, child_process_1.spawnSync)('ckb-debugger', ['--version'], { stdio: 'ignore' });
16
+ return result.status === 0;
17
+ }
18
+ static installCKBDebugger() {
19
+ const command = `cargo install --git https://github.com/nervosnetwork/ckb-standalone-debugger ckb-debugger`;
20
+ try {
21
+ console.log('Installing ckb-debugger...');
22
+ (0, child_process_1.execSync)(command);
23
+ console.log('ckb-debugger installed successfully.');
24
+ }
25
+ catch (error) {
26
+ console.error('Failed to install ckb-debugger:', error);
27
+ process.exit(1);
28
+ }
29
+ }
30
+ }
31
+ exports.CKBDebugger = CKBDebugger;
@@ -0,0 +1,6 @@
1
+ export interface DumpOption {
2
+ rpc: string;
3
+ txJsonFilePath: string;
4
+ outputFilePath: string;
5
+ }
6
+ export declare function dumpTransaction({ rpc, txJsonFilePath, outputFilePath }: DumpOption): void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.dumpTransaction = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const child_process_1 = require("child_process");
9
+ const setting_1 = require("../cfg/setting");
10
+ function dumpTransaction({ rpc, txJsonFilePath, outputFilePath }) {
11
+ const ckbTransactionDumperPath = path_1.default.resolve(setting_1.packageRootPath, 'node_modules/.bin/ckb-transaction-dumper');
12
+ const command = `${ckbTransactionDumperPath} --rpc ${rpc} --tx "${txJsonFilePath}" --output "${outputFilePath}"`;
13
+ try {
14
+ (0, child_process_1.execSync)(command, { stdio: 'inherit' });
15
+ console.debug('Dump transaction successfully');
16
+ }
17
+ catch (error) {
18
+ console.error('Command failed:', error.message);
19
+ }
20
+ }
21
+ exports.dumpTransaction = dumpTransaction;
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ import http from 'http';
3
+ import { Network } from '../util/type';
4
+ export declare function createRPCProxy(network: Network, targetRpcUrl: string, port: number): {
5
+ server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
6
+ network: Network;
7
+ start: () => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
8
+ stop: () => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
9
+ };
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createRPCProxy = void 0;
7
+ const http_proxy_1 = __importDefault(require("http-proxy"));
8
+ const http_1 = __importDefault(require("http"));
9
+ const type_1 = require("../util/type");
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const setting_1 = require("../cfg/setting");
12
+ const path_1 = __importDefault(require("path"));
13
+ // todo: if we use import this throws error in tsc building
14
+ const { cccA } = require('@ckb-ccc/core/advanced');
15
+ function createRPCProxy(network, targetRpcUrl, port) {
16
+ const proxy = http_proxy_1.default.createProxyServer({
17
+ target: targetRpcUrl, // Target RPC server
18
+ });
19
+ const server = http_1.default.createServer((req, res) => {
20
+ proxy.web(req, res, {}, (err) => {
21
+ if (err) {
22
+ console.error('Proxy error:', err);
23
+ res.writeHead(500, { 'Content-Type': 'text/plain' });
24
+ res.end('Proxy error');
25
+ }
26
+ });
27
+ proxy.on('proxyReq', (_, req) => {
28
+ let reqData = '';
29
+ req.on('data', (chunk) => {
30
+ reqData += chunk;
31
+ });
32
+ req.on('end', () => {
33
+ try {
34
+ const jsonRpcContent = JSON.parse(reqData);
35
+ console.debug('Incoming Request: ', jsonRpcContent);
36
+ const method = jsonRpcContent.method;
37
+ const params = jsonRpcContent.params;
38
+ if (method === 'send_transaction') {
39
+ const tx = params[0];
40
+ // todo: record tx
41
+ if (network === type_1.Network.devnet) {
42
+ const cccTx = cccA.JsonRpcTransformers.transactionTo(tx);
43
+ const txHash = cccTx.hash();
44
+ const settings = (0, setting_1.readSettings)();
45
+ console.log('txHash: ', txHash, settings, settings.devnet.transactionsPath);
46
+ if (!fs_1.default.existsSync(settings.devnet.transactionsPath)) {
47
+ fs_1.default.mkdirSync(settings.devnet.transactionsPath);
48
+ }
49
+ const txFile = path_1.default.resolve(settings.devnet.transactionsPath, `${txHash}.json`);
50
+ fs_1.default.writeFileSync(txFile, JSON.stringify(tx, null, 2));
51
+ }
52
+ }
53
+ }
54
+ catch (err) {
55
+ console.error('Error parsing JSON-RPC content:', err);
56
+ }
57
+ });
58
+ });
59
+ // Capture the content from the response (or request)
60
+ proxy.on('proxyRes', (proxyRes) => {
61
+ let data = '';
62
+ proxyRes.on('data', (chunk) => {
63
+ data += chunk;
64
+ });
65
+ proxyRes.on('end', () => {
66
+ console.log('Captured content:', data);
67
+ // Do something with the captured content
68
+ });
69
+ });
70
+ });
71
+ return {
72
+ server,
73
+ network,
74
+ start: () => {
75
+ return server.listen(port, () => {
76
+ console.debug(`CKB ${network} RPC Proxy server running on http://localhost:${port}`);
77
+ });
78
+ },
79
+ stop: () => {
80
+ return server.close();
81
+ },
82
+ };
83
+ }
84
+ exports.createRPCProxy = createRPCProxy;
@@ -67,6 +67,69 @@ export declare class CKB {
67
67
  INDEX: string;
68
68
  DEP_TYPE: "code";
69
69
  };
70
+ XUDT: {
71
+ CODE_HASH: string;
72
+ HASH_TYPE: "type";
73
+ TX_HASH: string;
74
+ INDEX: string;
75
+ DEP_TYPE: "code";
76
+ };
77
+ };
78
+ } | {
79
+ PREFIX: string;
80
+ SCRIPTS: {
81
+ SECP256K1_BLAKE160: {
82
+ CODE_HASH: string;
83
+ HASH_TYPE: "type";
84
+ TX_HASH: string;
85
+ INDEX: string;
86
+ DEP_TYPE: "depGroup";
87
+ SHORT_ID: number;
88
+ };
89
+ SECP256K1_BLAKE160_MULTISIG: {
90
+ CODE_HASH: string;
91
+ HASH_TYPE: "type";
92
+ TX_HASH: string;
93
+ INDEX: string;
94
+ DEP_TYPE: "depGroup";
95
+ SHORT_ID: number;
96
+ };
97
+ DAO: {
98
+ CODE_HASH: string;
99
+ HASH_TYPE: "type";
100
+ TX_HASH: string;
101
+ INDEX: string;
102
+ DEP_TYPE: "code";
103
+ };
104
+ SUDT: {
105
+ CODE_HASH: string;
106
+ HASH_TYPE: "type";
107
+ TX_HASH: string;
108
+ INDEX: string;
109
+ DEP_TYPE: "code";
110
+ };
111
+ ANYONE_CAN_PAY: {
112
+ CODE_HASH: string;
113
+ HASH_TYPE: "type";
114
+ TX_HASH: string;
115
+ INDEX: string;
116
+ DEP_TYPE: "depGroup";
117
+ SHORT_ID: number;
118
+ };
119
+ OMNILOCK: {
120
+ CODE_HASH: string;
121
+ HASH_TYPE: "type";
122
+ TX_HASH: string;
123
+ INDEX: string;
124
+ DEP_TYPE: "code";
125
+ };
126
+ XUDT: {
127
+ CODE_HASH: string;
128
+ HASH_TYPE: "data1";
129
+ TX_HASH: string;
130
+ INDEX: string;
131
+ DEP_TYPE: "code";
132
+ };
70
133
  };
71
134
  };
72
135
  initializedLumosConfig(): void;
@@ -74,4 +137,5 @@ export declare class CKB {
74
137
  transfer(options: Options, lumosConfig: config.Config): Promise<string>;
75
138
  transferAll(privateKey: string, toAddress: string, lumosConfig: config.Config): Promise<string>;
76
139
  }
140
+ export declare function readPredefinedDevnetLumosConfig(): config.Config;
77
141
  export {};
package/dist/util/ckb.js CHANGED
@@ -16,13 +16,13 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
16
16
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.CKB = void 0;
19
+ exports.readPredefinedDevnetLumosConfig = exports.CKB = void 0;
20
20
  const lumos_1 = require("@ckb-lumos/lumos");
21
21
  const base_1 = require("@ckb-lumos/base");
22
22
  const codec_1 = require("@ckb-lumos/codec");
23
- const config_1 = require("./config");
24
23
  const validator_1 = require("./validator");
25
24
  const type_1 = require("./type");
25
+ const system_scripts_1 = require("../cmd/system-scripts");
26
26
  const { ScriptValue } = base_1.values;
27
27
  const networks = {
28
28
  devnet: {
@@ -70,7 +70,7 @@ class CKB {
70
70
  }
71
71
  getLumosConfig() {
72
72
  if (this.network === type_1.Network.devnet) {
73
- return (0, config_1.readPredefinedDevnetLumosConfig)();
73
+ return readPredefinedDevnetLumosConfig();
74
74
  }
75
75
  if (this.network === type_1.Network.testnet) {
76
76
  return lumos_1.config.predefined.AGGRON4;
@@ -297,3 +297,16 @@ class CKB {
297
297
  }
298
298
  }
299
299
  exports.CKB = CKB;
300
+ function readPredefinedDevnetLumosConfig() {
301
+ try {
302
+ const systemScripts = (0, system_scripts_1.getSystemScriptsFromListHashes)();
303
+ if (systemScripts) {
304
+ return (0, system_scripts_1.toLumosConfig)(systemScripts);
305
+ }
306
+ throw new Error('systemScripts not found!');
307
+ }
308
+ catch (error) {
309
+ throw new Error('getSystemScriptsFromListHashes error' + error.message);
310
+ }
311
+ }
312
+ exports.readPredefinedDevnetLumosConfig = readPredefinedDevnetLumosConfig;
@@ -1 +1,2 @@
1
1
  export declare function setUTF8EncodingForWindows(): void;
2
+ export declare function encodeBinPathForTerminal(path: string): string;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.setUTF8EncodingForWindows = void 0;
6
+ exports.encodeBinPathForTerminal = exports.setUTF8EncodingForWindows = void 0;
7
7
  const child_process_1 = require("child_process");
8
8
  const os_1 = __importDefault(require("os"));
9
9
  function setUTF8EncodingForWindows() {
@@ -17,3 +17,9 @@ function setUTF8EncodingForWindows() {
17
17
  }
18
18
  }
19
19
  exports.setUTF8EncodingForWindows = setUTF8EncodingForWindows;
20
+ function encodeBinPathForTerminal(path) {
21
+ // some path contains space in the string
22
+ // this fix the space in the terminal
23
+ return `"${path}"`;
24
+ }
25
+ exports.encodeBinPathForTerminal = encodeBinPathForTerminal;
package/dist/util/fs.d.ts CHANGED
@@ -3,10 +3,9 @@ export declare function copyFolderSync(source: string, destination: string): voi
3
3
  export declare function copyFileSync(source: string, target: string): void;
4
4
  export declare function copyFilesWithExclusion(sourceDir: string, destinationDir: string, excludedFolders: string[]): Promise<void>;
5
5
  export declare function copyRecursive(source: string, destination: string, excludedFolders: string[]): Promise<void>;
6
- export declare function updateVersionInTSFile(newVersion: string, filePath: string): void;
7
6
  export declare function readFileToUint8Array(filePath: string): Promise<Uint8Array>;
8
- export declare function convertFilenameToUppercase(filePath: string): string;
9
7
  export declare function listBinaryFilesInFolder(folderPath: string): string[];
10
8
  export declare function isBinaryFile(filePath: string): boolean;
11
9
  export declare function isAbsolutePath(filePath: string): boolean;
12
10
  export declare function findFileInFolder(folderPath: string, fileName: string): string | null;
11
+ export declare function getSubfolders(folderPath: string): string[];
package/dist/util/fs.js CHANGED
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.findFileInFolder = exports.isAbsolutePath = exports.isBinaryFile = exports.listBinaryFilesInFolder = exports.convertFilenameToUppercase = exports.readFileToUint8Array = exports.updateVersionInTSFile = exports.copyRecursive = exports.copyFilesWithExclusion = exports.copyFileSync = exports.copyFolderSync = exports.isFolderExists = void 0;
35
+ exports.getSubfolders = exports.findFileInFolder = exports.isAbsolutePath = exports.isBinaryFile = exports.listBinaryFilesInFolder = exports.readFileToUint8Array = exports.copyRecursive = exports.copyFilesWithExclusion = exports.copyFileSync = exports.copyFolderSync = exports.isFolderExists = void 0;
36
36
  const fs = __importStar(require("fs"));
37
37
  const path = __importStar(require("path"));
38
38
  function isFolderExists(folderPath) {
@@ -121,29 +121,6 @@ function copyRecursive(source, destination, excludedFolders) {
121
121
  });
122
122
  }
123
123
  exports.copyRecursive = copyRecursive;
124
- function updateVersionInTSFile(newVersion, filePath) {
125
- try {
126
- // Read the contents of the TS file
127
- const fileContents = fs.readFileSync(filePath, 'utf8');
128
- // Use a regular expression to find the version value
129
- const regex = /const\s+offCKBConfig:\s+OffCKBConfig\s*=\s*\{\s*version:\s*'([^']+)'/;
130
- const match = fileContents.match(regex);
131
- if (match) {
132
- // Replace the version value with the new value
133
- const updatedContents = fileContents.replace(regex, `const offCKBConfig: OffCKBConfig = {\n version: '${newVersion}'`);
134
- // Write the updated contents back to the file
135
- fs.writeFileSync(filePath, updatedContents, 'utf8');
136
- console.log(`Version updated to '${newVersion}' in ${filePath}`);
137
- }
138
- else {
139
- console.error(`Could not find version value in ${filePath}`);
140
- }
141
- }
142
- catch (error) {
143
- console.error(`Error updating version in ${filePath}: ${error}`);
144
- }
145
- }
146
- exports.updateVersionInTSFile = updateVersionInTSFile;
147
124
  function readFileToUint8Array(filePath) {
148
125
  return __awaiter(this, void 0, void 0, function* () {
149
126
  return new Promise((resolve, reject) => {
@@ -158,14 +135,6 @@ function readFileToUint8Array(filePath) {
158
135
  });
159
136
  }
160
137
  exports.readFileToUint8Array = readFileToUint8Array;
161
- function convertFilenameToUppercase(filePath) {
162
- // Extract the filename from the file path
163
- const filename = path.basename(filePath);
164
- // Convert the filename to uppercase
165
- const uppercaseFilename = filename.toUpperCase();
166
- return uppercaseFilename;
167
- }
168
- exports.convertFilenameToUppercase = convertFilenameToUppercase;
169
138
  function listBinaryFilesInFolder(folderPath) {
170
139
  // Check if the provided path is a directory
171
140
  if (!fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) {
@@ -216,3 +185,10 @@ function findFileInFolder(folderPath, fileName) {
216
185
  return null;
217
186
  }
218
187
  exports.findFileInFolder = findFileInFolder;
188
+ function getSubfolders(folderPath) {
189
+ return fs.readdirSync(folderPath).filter((file) => {
190
+ const fullPath = path.join(folderPath, file);
191
+ return fs.statSync(fullPath).isDirectory();
192
+ });
193
+ }
194
+ exports.getSubfolders = getSubfolders;
package/dist/util/git.js CHANGED
@@ -27,8 +27,8 @@ exports.gitCloneAndDownloadFolderSync = exports.isGitInstalled = void 0;
27
27
  const child_process_1 = require("child_process");
28
28
  const fs = __importStar(require("fs"));
29
29
  const path = __importStar(require("path"));
30
- const const_1 = require("../cfg/const");
31
30
  const fs_1 = require("./fs");
31
+ const setting_1 = require("../cfg/setting");
32
32
  function isGitInstalled() {
33
33
  try {
34
34
  (0, child_process_1.execSync)('git --version');
@@ -41,7 +41,8 @@ function isGitInstalled() {
41
41
  exports.isGitInstalled = isGitInstalled;
42
42
  function gitCloneAndDownloadFolderSync(repoUrl, branch, subFolderName, targetPath) {
43
43
  console.log('start cloning the dapp template..');
44
- const tempFolder = path.resolve(const_1.dappTemplatePath, 'temp-clone-folder');
44
+ const settings = (0, setting_1.readSettings)();
45
+ const tempFolder = path.resolve(settings.dappTemplate.downloadPath, 'temp-clone-folder');
45
46
  if (!isGitInstalled()) {
46
47
  console.log('Git is not installed, please check https://git-scm.com/');
47
48
  return process.exit(1);
@@ -54,17 +55,21 @@ function gitCloneAndDownloadFolderSync(repoUrl, branch, subFolderName, targetPat
54
55
  fs.mkdirSync(tempFolder, { recursive: true });
55
56
  // Clone the repository
56
57
  try {
57
- const cloneCommand = `git clone -n --depth=1 --single-branch --branch ${branch} --filter=tree:0 ${repoUrl} ${tempFolder}`;
58
+ const cloneCommand = `git clone -n --depth=1 --filter=tree:0 --single-branch --branch ${branch} ${repoUrl} ${tempFolder}`;
59
+ console.log(cloneCommand);
58
60
  (0, child_process_1.execSync)(cloneCommand);
59
61
  }
60
62
  catch (error) {
61
63
  console.error('Error:', error);
62
64
  process.exit(1);
63
65
  }
64
- // checkout the examples sub folder
66
+ // Set up sparse-checkout for the subfolder
65
67
  try {
66
- (0, child_process_1.execSync)(`git sparse-checkout set ${subFolderName}`, { cwd: tempFolder });
67
- (0, child_process_1.execSync)(`git checkout`, { cwd: tempFolder });
68
+ console.log(subFolderName, tempFolder);
69
+ (0, child_process_1.execSync)('git sparse-checkout init --cone', { cwd: tempFolder });
70
+ // Use the full path for sparse-checkout
71
+ (0, child_process_1.execSync)(`git sparse-checkout set "${subFolderName}"`, { cwd: tempFolder });
72
+ (0, child_process_1.execSync)('git checkout', { cwd: tempFolder });
68
73
  }
69
74
  catch (error) {
70
75
  console.error('Error:', error);
@@ -74,8 +79,15 @@ function gitCloneAndDownloadFolderSync(repoUrl, branch, subFolderName, targetPat
74
79
  if (!fs.existsSync(targetPath) || !fs.statSync(targetPath).isDirectory()) {
75
80
  fs.mkdirSync(targetPath, { recursive: true });
76
81
  }
82
+ // Copy the specific subfolder
77
83
  const source = path.resolve(tempFolder, subFolderName);
78
- (0, fs_1.copyFolderSync)(source, targetPath);
84
+ if (fs.existsSync(source)) {
85
+ (0, fs_1.copyFolderSync)(source, targetPath);
86
+ }
87
+ else {
88
+ console.error(`Subfolder ${subFolderName} not found in the cloned repository ${source}.`);
89
+ process.exit(1);
90
+ }
79
91
  // Empty the temp folder if it exists
80
92
  if (fs.existsSync(tempFolder)) {
81
93
  fs.rmSync(tempFolder, { recursive: true });
@@ -0,0 +1,8 @@
1
+ import { AxiosProxyConfig, AxiosRequestConfig } from 'axios';
2
+ export declare class Request {
3
+ static proxy: AxiosProxyConfig | undefined;
4
+ static send(_config: AxiosRequestConfig): Promise<import("axios").AxiosResponse<any, any>>;
5
+ static get(url: string, _config?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<any, any>>;
6
+ static parseProxyUrl(url: string): AxiosProxyConfig;
7
+ static proxyConfigToUrl(proxy: AxiosProxyConfig): string;
8
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Request = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const setting_1 = require("../cfg/setting");
18
+ class Request {
19
+ static send(_config) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const config = this.proxy ? Object.assign({ proxy: this.proxy }, _config) : _config;
22
+ return yield (0, axios_1.default)(config);
23
+ });
24
+ }
25
+ static get(url, _config) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const config = this.proxy ? Object.assign({ proxy: this.proxy }, _config) : _config;
28
+ console.log(config);
29
+ return yield axios_1.default.get(url, config);
30
+ });
31
+ }
32
+ static parseProxyUrl(url) {
33
+ const parsedUrl = new URL(url);
34
+ const proxyConfig = {
35
+ host: parsedUrl.hostname,
36
+ port: parseInt(parsedUrl.port, 10),
37
+ };
38
+ if (parsedUrl.username || parsedUrl.password) {
39
+ proxyConfig.auth = {
40
+ username: parsedUrl.username,
41
+ password: parsedUrl.password,
42
+ };
43
+ }
44
+ if (parsedUrl.protocol) {
45
+ proxyConfig.protocol = parsedUrl.protocol.slice(0, -1); // Remove the trailing ':'
46
+ }
47
+ return proxyConfig;
48
+ }
49
+ static proxyConfigToUrl(proxy) {
50
+ const protocol = proxy.protocol ? `${proxy.protocol}://` : '';
51
+ const auth = proxy.auth ? `${proxy.auth.username}:${proxy.auth.password}@` : '';
52
+ const port = proxy.port ? `:${proxy.port}` : '';
53
+ return `${protocol}${auth}${proxy.host}${port}`;
54
+ }
55
+ }
56
+ exports.Request = Request;
57
+ Request.proxy = (0, setting_1.readSettings)().proxy;
@@ -6,3 +6,4 @@ export declare enum Network {
6
6
  export interface NetworkOption {
7
7
  network: Network;
8
8
  }
9
+ export type H256 = string;
@@ -2,3 +2,4 @@ export declare function validateTypescriptWorkspace(): void;
2
2
  export declare function validateExecDappEnvironment(): void;
3
3
  export declare function isValidNetworkString(network: string): boolean;
4
4
  export declare function validateNetworkOpt(network: string): void;
5
+ export declare function isValidVersion(version: unknown): boolean;