@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,131 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.deploymentRecipeFromJson = exports.deploymentRecipeToJson = exports.getNewestMigrationFile = exports.getMigrationFolderPath = exports.getFormattedMigrationDate = exports.readDeploymentRecipeJsonFile = exports.generateDeploymentRecipeJsonFile = void 0;
30
+ const type_1 = require("../util/type");
31
+ const path_1 = __importStar(require("path"));
32
+ const fs_1 = __importDefault(require("fs"));
33
+ const util_1 = require("./util");
34
+ function generateDeploymentRecipeJsonFile(name, deploymentRecipe, network = type_1.Network.devnet) {
35
+ const cellRecipes = deploymentRecipe.cellRecipes;
36
+ const depGroupRecipes = deploymentRecipe.depGroupRecipes;
37
+ const jsonString = JSON.stringify(deploymentRecipeToJson({ cellRecipes, depGroupRecipes }), null, 2);
38
+ const outputFilePath = `${(0, util_1.getContractsPath)(network)}/${name}/migrations/${getFormattedMigrationDate()}.json`;
39
+ if (outputFilePath) {
40
+ if (!fs_1.default.existsSync((0, path_1.dirname)(outputFilePath))) {
41
+ fs_1.default.mkdirSync((0, path_1.dirname)(outputFilePath), { recursive: true });
42
+ }
43
+ fs_1.default.writeFileSync(outputFilePath, jsonString);
44
+ console.log(`${name} migration json file ${outputFilePath} generated successfully.`);
45
+ }
46
+ }
47
+ exports.generateDeploymentRecipeJsonFile = generateDeploymentRecipeJsonFile;
48
+ function readDeploymentRecipeJsonFile(filePath) {
49
+ const jsonString = fs_1.default.readFileSync(filePath, 'utf-8');
50
+ const data = JSON.parse(jsonString);
51
+ return deploymentRecipeFromJson(data);
52
+ }
53
+ exports.readDeploymentRecipeJsonFile = readDeploymentRecipeJsonFile;
54
+ function getFormattedMigrationDate() {
55
+ const now = new Date();
56
+ const year = now.getFullYear();
57
+ const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are zero-based
58
+ const day = String(now.getDate()).padStart(2, '0');
59
+ const hours = String(now.getHours()).padStart(2, '0');
60
+ const minutes = String(now.getMinutes()).padStart(2, '0');
61
+ const seconds = String(now.getSeconds()).padStart(2, '0');
62
+ return `${year}-${month}-${day}-${hours}${minutes}${seconds}`;
63
+ }
64
+ exports.getFormattedMigrationDate = getFormattedMigrationDate;
65
+ function getMigrationFolderPath(scriptName, network) {
66
+ const contractsPath = (0, util_1.getContractsPath)(network);
67
+ return path_1.default.resolve(contractsPath, `${scriptName}/migrations`);
68
+ }
69
+ exports.getMigrationFolderPath = getMigrationFolderPath;
70
+ function getNewestMigrationFile(folderPath) {
71
+ const files = fs_1.default
72
+ .readdirSync(folderPath)
73
+ .filter((file) => file.endsWith('.json')) // Ensure only JSON files are considered
74
+ .sort((a, b) => {
75
+ // Extract the timestamp part of the filename and compare them
76
+ const timestampA = a.split('.json')[0];
77
+ const timestampB = b.split('.json')[0];
78
+ return timestampA.localeCompare(timestampB);
79
+ });
80
+ // Return the full path of the newest file (last in sorted array) or undefined if no files
81
+ return files.length > 0 ? path_1.default.join(folderPath, files[files.length - 1]) : undefined;
82
+ }
83
+ exports.getNewestMigrationFile = getNewestMigrationFile;
84
+ function deploymentRecipeToJson(recipe) {
85
+ return {
86
+ cell_recipes: recipe.cellRecipes.map((val) => {
87
+ return {
88
+ name: val.name,
89
+ tx_hash: val.txHash,
90
+ index: val.index,
91
+ occupied_capacity: val.occupiedCapacity,
92
+ data_hash: val.dataHash,
93
+ type_id: val.typeId,
94
+ };
95
+ }),
96
+ dep_group_recipes: recipe.depGroupRecipes.map((val) => {
97
+ return {
98
+ name: val.name,
99
+ tx_hash: val.txHash,
100
+ index: val.index,
101
+ data_hash: val.dataHash,
102
+ occupied_capacity: val.occupiedCapacity,
103
+ };
104
+ }),
105
+ };
106
+ }
107
+ exports.deploymentRecipeToJson = deploymentRecipeToJson;
108
+ function deploymentRecipeFromJson(json) {
109
+ return {
110
+ cellRecipes: json.cell_recipes.map((val) => {
111
+ return {
112
+ name: val.name,
113
+ txHash: val.tx_hash,
114
+ index: val.index,
115
+ occupiedCapacity: val.occupied_capacity,
116
+ dataHash: val.data_hash,
117
+ typeId: val.type_id,
118
+ };
119
+ }),
120
+ depGroupRecipes: json.dep_group_recipes.map((val) => {
121
+ return {
122
+ name: val.name,
123
+ txHash: val.tx_hash,
124
+ index: val.index,
125
+ dataHash: val.data_hash,
126
+ occupiedCapacity: val.occupied_capacity,
127
+ };
128
+ }),
129
+ };
130
+ }
131
+ exports.deploymentRecipeFromJson = deploymentRecipeFromJson;
@@ -0,0 +1,38 @@
1
+ import { Script } from '@ckb-lumos/lumos';
2
+ import { Network } from '../util/type';
3
+ import { HashType } from '@ckb-ccc/core';
4
+ export interface DeploymentOptions {
5
+ name: string;
6
+ binFilePath: string;
7
+ enableTypeId: boolean;
8
+ lockScript: Script;
9
+ }
10
+ export interface DeploymentToml {
11
+ cells: {
12
+ name: string;
13
+ enable_type_id: 'true' | 'false';
14
+ location: {
15
+ file: string;
16
+ };
17
+ }[];
18
+ lock: {
19
+ code_hash: string;
20
+ args: string;
21
+ hash_type: HashType;
22
+ };
23
+ }
24
+ export declare function generateDeploymentToml(options: DeploymentOptions, network: Network): void;
25
+ export declare function readDeploymentToml(scriptName: string, network: Network): {
26
+ cells: {
27
+ name: string;
28
+ enableTypeId: boolean;
29
+ location: {
30
+ file: string;
31
+ };
32
+ }[];
33
+ lock: {
34
+ codeHash: string;
35
+ args: string;
36
+ hashType: string;
37
+ };
38
+ };
@@ -0,0 +1,60 @@
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.readDeploymentToml = exports.generateDeploymentToml = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const toml_1 = __importDefault(require("@iarna/toml"));
9
+ const path_1 = require("path");
10
+ const util_1 = require("./util");
11
+ function generateDeploymentToml(options, network) {
12
+ const data = {
13
+ cells: [
14
+ {
15
+ name: options.name,
16
+ enable_type_id: options.enableTypeId ? 'true' : 'false',
17
+ location: {
18
+ file: options.binFilePath,
19
+ },
20
+ },
21
+ ],
22
+ lock: {
23
+ code_hash: options.lockScript.codeHash,
24
+ args: options.lockScript.args,
25
+ hash_type: options.lockScript.hashType,
26
+ },
27
+ };
28
+ const tomlString = toml_1.default.stringify(data);
29
+ const outputFilePath = `${(0, util_1.getContractsPath)(network)}/${options.name}/deployment.toml`;
30
+ if (outputFilePath) {
31
+ if (!fs_1.default.existsSync((0, path_1.dirname)(outputFilePath))) {
32
+ fs_1.default.mkdirSync((0, path_1.dirname)(outputFilePath), { recursive: true });
33
+ }
34
+ fs_1.default.writeFileSync(outputFilePath, tomlString);
35
+ console.log(`${options.name} deployment.toml file ${outputFilePath} generated successfully.`);
36
+ }
37
+ }
38
+ exports.generateDeploymentToml = generateDeploymentToml;
39
+ function readDeploymentToml(scriptName, network) {
40
+ const filePath = `${(0, util_1.getContractsPath)(network)}/${scriptName}/deployment.toml`;
41
+ const file = fs_1.default.readFileSync(filePath, 'utf-8');
42
+ const data = toml_1.default.parse(file);
43
+ return {
44
+ cells: [
45
+ {
46
+ name: data.cells[0].name,
47
+ enableTypeId: data.cells[0].enable_type_id === 'true' ? true : false,
48
+ location: {
49
+ file: data.cells[0].location.file,
50
+ },
51
+ },
52
+ ],
53
+ lock: {
54
+ codeHash: data.lock.code_hash,
55
+ args: data.lock.args,
56
+ hashType: data.lock.hash_type,
57
+ },
58
+ };
59
+ }
60
+ exports.readDeploymentToml = readDeploymentToml;
@@ -0,0 +1,2 @@
1
+ import { Network } from '../util/type';
2
+ export declare function getContractsPath(network: Network): string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getContractsPath = void 0;
4
+ const setting_1 = require("../cfg/setting");
5
+ const type_1 = require("../util/type");
6
+ function getContractsPath(network) {
7
+ const settings = (0, setting_1.readSettings)();
8
+ if (network === type_1.Network.devnet) {
9
+ return settings.devnet.contractsPath;
10
+ }
11
+ if (network === type_1.Network.testnet) {
12
+ return settings.testnet.contractsPath;
13
+ }
14
+ if (network === type_1.Network.mainnet) {
15
+ return settings.mainnet.contractsPath;
16
+ }
17
+ throw new Error(`invalid network ${network}`);
18
+ }
19
+ exports.getContractsPath = getContractsPath;
@@ -0,0 +1,41 @@
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.initChainIfNeeded = void 0;
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const path_1 = __importDefault(require("path"));
18
+ const fs_2 = require("../util/fs");
19
+ const setting_1 = require("../cfg/setting");
20
+ function initChainIfNeeded() {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const settings = (0, setting_1.readSettings)();
23
+ const devnetSourcePath = path_1.default.resolve(setting_1.packageRootPath, './ckb/devnet');
24
+ const devnetConfigPath = settings.devnet.configPath;
25
+ if (!(0, fs_2.isFolderExists)(devnetConfigPath)) {
26
+ const devnetConfigPath = settings.devnet.configPath;
27
+ yield (0, fs_2.copyFilesWithExclusion)(devnetSourcePath, devnetConfigPath, ['data']);
28
+ console.debug(`init devnet config folder: ${devnetConfigPath}`);
29
+ // copy and edit ckb-miner.toml
30
+ const minerToml = path_1.default.join(devnetSourcePath, 'ckb-miner.toml');
31
+ const newMinerToml = path_1.default.join(devnetConfigPath, 'ckb-miner.toml');
32
+ // Read the content of the ckb-miner.toml file
33
+ const data = fs_1.default.readFileSync(minerToml, 'utf8');
34
+ // Replace the URL
35
+ const modifiedData = data.replace('http://ckb:8114/', settings.devnet.rpcUrl);
36
+ // Write the modified content back to the file
37
+ fs_1.default.writeFileSync(newMinerToml, modifiedData, 'utf8');
38
+ }
39
+ });
40
+ }
41
+ exports.initChainIfNeeded = initChainIfNeeded;
@@ -1,10 +1,9 @@
1
- export declare function installDependency(): Promise<void>;
2
- export declare function downloadBinaryAndUnzip(): Promise<void>;
3
- export declare function downloadAndSaveCKBBinary(tempFilePath: string): Promise<void>;
1
+ export declare function installCKBBinary(version: string): Promise<void>;
2
+ export declare function downloadCKBBinaryAndUnzip(version: string): Promise<void>;
3
+ export declare function downloadAndSaveCKBBinary(version: string, tempFilePath: string): Promise<void>;
4
4
  export declare function unZipFile(filePath: string, extractDir: string, useTar?: boolean): Promise<void>;
5
5
  export declare function decompressTarGzAsync(tarballPath: string, destinationDir: string): Promise<void>;
6
- export declare function getInstalledVersion(): string | null;
7
- export declare function isVersionOutdated(installedVersion: string): boolean;
6
+ export declare function getVersionFromBinary(binPath: string): string | null;
8
7
  export declare function getOS(): string;
9
8
  export declare function getArch(): string;
10
9
  export declare function getExtension(): 'tar.gz' | 'zip';
@@ -35,8 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.buildDownloadUrl = exports.getExtension = exports.getArch = exports.getOS = exports.isVersionOutdated = exports.getInstalledVersion = exports.decompressTarGzAsync = exports.unZipFile = exports.downloadAndSaveCKBBinary = exports.downloadBinaryAndUnzip = exports.installDependency = void 0;
39
- const axios_1 = __importDefault(require("axios"));
38
+ exports.buildDownloadUrl = exports.getExtension = exports.getArch = exports.getOS = exports.getVersionFromBinary = exports.decompressTarGzAsync = exports.unZipFile = exports.downloadAndSaveCKBBinary = exports.downloadCKBBinaryAndUnzip = exports.installCKBBinary = void 0;
40
39
  const child_process_1 = require("child_process");
41
40
  const fs = __importStar(require("fs"));
42
41
  const path = __importStar(require("path"));
@@ -44,56 +43,61 @@ const semver_1 = __importDefault(require("semver"));
44
43
  const os_1 = __importDefault(require("os"));
45
44
  const adm_zip_1 = __importDefault(require("adm-zip"));
46
45
  const tar = __importStar(require("tar"));
47
- const const_1 = require("../../cfg/const");
48
- const BINARY = const_1.ckbBinPath;
49
- const MINIMAL_VERSION = const_1.minimalRequiredCKBVersion;
50
- // Function to download and install the dependency binary
51
- function installDependency() {
46
+ const request_1 = require("../util/request");
47
+ const setting_1 = require("../cfg/setting");
48
+ const encoding_1 = require("../util/encoding");
49
+ function installCKBBinary(version) {
52
50
  return __awaiter(this, void 0, void 0, function* () {
53
- const version = getInstalledVersion();
54
- if (version) {
55
- if (isVersionOutdated(version)) {
56
- console.log(`${BINARY} version ${version} is outdated, download and install the new version ${MINIMAL_VERSION}..`);
51
+ const ckbBinPath = (0, setting_1.getCKBBinaryPath)(version);
52
+ const outputVersion = getVersionFromBinary(ckbBinPath);
53
+ if (outputVersion) {
54
+ if (!semver_1.default.eq(version, outputVersion)) {
55
+ console.log(`CKB version ${outputVersion} is not equal to the ${version}, download and install the new version ${version}..`);
57
56
  }
58
57
  else {
59
58
  return;
60
59
  }
61
60
  }
62
61
  else {
63
- console.log(`${BINARY} not found, download and install the new version ${MINIMAL_VERSION}..`);
62
+ console.log(`CKB Binary not found, download and install the new version ${version}..`);
64
63
  }
65
- yield downloadBinaryAndUnzip();
64
+ yield downloadCKBBinaryAndUnzip(version);
66
65
  });
67
66
  }
68
- exports.installDependency = installDependency;
69
- function downloadBinaryAndUnzip() {
67
+ exports.installCKBBinary = installCKBBinary;
68
+ function downloadCKBBinaryAndUnzip(version) {
70
69
  return __awaiter(this, void 0, void 0, function* () {
71
70
  const arch = getArch();
72
71
  const osname = getOS();
73
72
  const ext = getExtension();
74
- const ckbVersionOSName = `ckb_v${MINIMAL_VERSION}_${arch}-${osname}`;
73
+ const ckbVersionOSName = `ckb_v${version}_${arch}-${osname}`;
75
74
  try {
76
75
  const tempFilePath = path.join(os_1.default.tmpdir(), `${ckbVersionOSName}.${ext}`);
77
- yield downloadAndSaveCKBBinary(tempFilePath);
76
+ yield downloadAndSaveCKBBinary(version, tempFilePath);
78
77
  // Unzip the file
79
- const extractDir = path.join(const_1.targetEnvironmentPath, `ckb_v${MINIMAL_VERSION}`);
78
+ const extractDir = path.join((0, setting_1.readSettings)().bins.downloadPath, `ckb_v${version}`);
80
79
  yield unZipFile(tempFilePath, extractDir, ext === 'tar.gz');
81
80
  // Install the extracted files
82
81
  const sourcePath = path.join(extractDir, ckbVersionOSName);
83
- fs.renameSync(sourcePath, const_1.ckbFolderPath); // Move binary to desired location
84
- fs.chmodSync(const_1.ckbBinPath, '755'); // Make the binary executable
85
- console.log('CKB installed successfully.');
82
+ const targetPath = (0, setting_1.getCKBBinaryInstallPath)(version);
83
+ if (fs.existsSync(targetPath)) {
84
+ fs.rmdirSync(targetPath, { recursive: true });
85
+ }
86
+ fs.mkdirSync(targetPath, { recursive: true });
87
+ fs.renameSync(sourcePath, targetPath); // Move binary to desired location
88
+ fs.chmodSync((0, setting_1.getCKBBinaryPath)(version), '755'); // Make the binary executable
89
+ console.log(`CKB ${version} installed successfully.`);
86
90
  }
87
91
  catch (error) {
88
92
  console.error('Error installing dependency binary:', error);
89
93
  }
90
94
  });
91
95
  }
92
- exports.downloadBinaryAndUnzip = downloadBinaryAndUnzip;
93
- function downloadAndSaveCKBBinary(tempFilePath) {
96
+ exports.downloadCKBBinaryAndUnzip = downloadCKBBinaryAndUnzip;
97
+ function downloadAndSaveCKBBinary(version, tempFilePath) {
94
98
  return __awaiter(this, void 0, void 0, function* () {
95
- const downloadURL = buildDownloadUrl(MINIMAL_VERSION);
96
- const response = yield axios_1.default.get(downloadURL, {
99
+ const downloadURL = buildDownloadUrl(version);
100
+ const response = yield request_1.Request.get(downloadURL, {
97
101
  responseType: 'arraybuffer',
98
102
  });
99
103
  fs.writeFileSync(tempFilePath, response.data);
@@ -136,9 +140,9 @@ function decompressTarGzAsync(tarballPath, destinationDir) {
136
140
  });
137
141
  }
138
142
  exports.decompressTarGzAsync = decompressTarGzAsync;
139
- function getInstalledVersion() {
143
+ function getVersionFromBinary(binPath) {
140
144
  try {
141
- const versionOutput = (0, child_process_1.execSync)(`${BINARY} --version`, {
145
+ const versionOutput = (0, child_process_1.execSync)(`${(0, encoding_1.encodeBinPathForTerminal)(binPath)} --version`, {
142
146
  encoding: 'utf-8',
143
147
  });
144
148
  const versionMatch = versionOutput.match(/(\d+\.\d+\.\d+)/);
@@ -151,11 +155,7 @@ function getInstalledVersion() {
151
155
  return null;
152
156
  }
153
157
  }
154
- exports.getInstalledVersion = getInstalledVersion;
155
- function isVersionOutdated(installedVersion) {
156
- return semver_1.default.lt(installedVersion, MINIMAL_VERSION);
157
- }
158
- exports.isVersionOutdated = isVersionOutdated;
158
+ exports.getVersionFromBinary = getVersionFromBinary;
159
159
  function getOS() {
160
160
  const platform = os_1.default.platform();
161
161
  if (platform === 'darwin') {
@@ -0,0 +1,5 @@
1
+ import { NetworkMyScripts, NetworkSystemScripts } from './type';
2
+ export declare function genSystemScripts(): NetworkSystemScripts | null;
3
+ export declare function genSystemScriptsJsonFile(filePath: string): void;
4
+ export declare function genMyScripts(): NetworkMyScripts;
5
+ export declare function genMyScriptsJsonFile(filePath: string): void;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.genMyScriptsJsonFile = exports.genMyScripts = exports.genSystemScriptsJsonFile = exports.genSystemScripts = void 0;
30
+ const fs = __importStar(require("fs"));
31
+ const public_1 = __importDefault(require("./public"));
32
+ const system_scripts_1 = require("../cmd/system-scripts");
33
+ const path_1 = __importDefault(require("path"));
34
+ const type_1 = require("../util/type");
35
+ const util_1 = require("./util");
36
+ function genSystemScripts() {
37
+ const devnetScripts = (0, system_scripts_1.getSystemScriptsFromListHashes)();
38
+ if (devnetScripts != null) {
39
+ const networkScripts = {
40
+ devnet: devnetScripts,
41
+ testnet: public_1.default.testnet,
42
+ mainnet: public_1.default.mainnet,
43
+ };
44
+ return networkScripts;
45
+ }
46
+ return null;
47
+ }
48
+ exports.genSystemScripts = genSystemScripts;
49
+ function genSystemScriptsJsonFile(filePath) {
50
+ const scripts = genSystemScripts();
51
+ fs.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
52
+ fs.writeFileSync(filePath, JSON.stringify(scripts, null, 2));
53
+ }
54
+ exports.genSystemScriptsJsonFile = genSystemScriptsJsonFile;
55
+ function genMyScripts() {
56
+ const networkMyScripts = {
57
+ devnet: (0, util_1.readUserDeployedScriptsInfo)(type_1.Network.devnet),
58
+ testnet: (0, util_1.readUserDeployedScriptsInfo)(type_1.Network.testnet),
59
+ mainnet: (0, util_1.readUserDeployedScriptsInfo)(type_1.Network.mainnet),
60
+ };
61
+ return networkMyScripts;
62
+ }
63
+ exports.genMyScripts = genMyScripts;
64
+ function genMyScriptsJsonFile(filePath) {
65
+ const scripts = genMyScripts();
66
+ fs.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
67
+ fs.writeFileSync(filePath, JSON.stringify(scripts, null, 2));
68
+ }
69
+ exports.genMyScriptsJsonFile = genMyScriptsJsonFile;
@@ -0,0 +1,8 @@
1
+ import { SystemScriptsRecord } from './type';
2
+ export declare const TESTNET_SYSTEM_SCRIPTS: SystemScriptsRecord;
3
+ export declare const MAINNET_SYSTEM_SCRIPTS: SystemScriptsRecord;
4
+ declare const _default: {
5
+ testnet: SystemScriptsRecord;
6
+ mainnet: SystemScriptsRecord;
7
+ };
8
+ export default _default;