@offckb/cli 0.3.0-canary-119a74a.0 → 0.3.0-canary-4e24414.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.
- package/dist/node/install.js +36 -8
- package/package.json +3 -1
package/dist/node/install.js
CHANGED
|
@@ -46,6 +46,7 @@ const tar = __importStar(require("tar"));
|
|
|
46
46
|
const request_1 = require("../util/request");
|
|
47
47
|
const setting_1 = require("../cfg/setting");
|
|
48
48
|
const encoding_1 = require("../util/encoding");
|
|
49
|
+
const cpu_features_1 = __importDefault(require("cpu-features"));
|
|
49
50
|
function installCKBBinary(version) {
|
|
50
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
52
|
const ckbBinPath = (0, setting_1.getCKBBinaryPath)(version);
|
|
@@ -67,18 +68,16 @@ function installCKBBinary(version) {
|
|
|
67
68
|
exports.installCKBBinary = installCKBBinary;
|
|
68
69
|
function downloadCKBBinaryAndUnzip(version) {
|
|
69
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
const
|
|
71
|
-
const osname = getOS();
|
|
72
|
-
const ext = getExtension();
|
|
73
|
-
const ckbVersionOSName = `ckb_v${version}_${arch}-${osname}`;
|
|
71
|
+
const ckbPackageName = buildCKBGithubReleasePackageName(version);
|
|
74
72
|
try {
|
|
75
|
-
const
|
|
73
|
+
const ext = getExtension();
|
|
74
|
+
const tempFilePath = path.join(os_1.default.tmpdir(), `${ckbPackageName}.${ext}`);
|
|
76
75
|
yield downloadAndSaveCKBBinary(version, tempFilePath);
|
|
77
76
|
// Unzip the file
|
|
78
77
|
const extractDir = path.join((0, setting_1.readSettings)().bins.downloadPath, `ckb_v${version}`);
|
|
79
78
|
yield unZipFile(tempFilePath, extractDir, ext === 'tar.gz');
|
|
80
79
|
// Install the extracted files
|
|
81
|
-
const sourcePath = path.join(extractDir,
|
|
80
|
+
const sourcePath = path.join(extractDir, ckbPackageName);
|
|
82
81
|
const targetPath = (0, setting_1.getCKBBinaryInstallPath)(version);
|
|
83
82
|
if (fs.existsSync(targetPath)) {
|
|
84
83
|
fs.rmdirSync(targetPath, { recursive: true });
|
|
@@ -97,6 +96,7 @@ exports.downloadCKBBinaryAndUnzip = downloadCKBBinaryAndUnzip;
|
|
|
97
96
|
function downloadAndSaveCKBBinary(version, tempFilePath) {
|
|
98
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
98
|
const downloadURL = buildDownloadUrl(version);
|
|
99
|
+
console.log(`downloading ${downloadURL} ..`);
|
|
100
100
|
const response = yield request_1.Request.send(downloadURL);
|
|
101
101
|
const arrayBuffer = yield response.arrayBuffer();
|
|
102
102
|
fs.writeFileSync(tempFilePath, Buffer.from(arrayBuffer));
|
|
@@ -189,10 +189,38 @@ function getExtension() {
|
|
|
189
189
|
}
|
|
190
190
|
return 'zip';
|
|
191
191
|
}
|
|
192
|
-
function
|
|
192
|
+
function isPortable() {
|
|
193
|
+
const features = (0, cpu_features_1.default)();
|
|
194
|
+
if (features.arch === 'x86') {
|
|
195
|
+
const flags = features.flags;
|
|
196
|
+
// if lacks any of the following instruction, use portable binary
|
|
197
|
+
return !(flags.avx2 && flags.sse4_2 && flags.bmi2 && flags.pclmulqdq);
|
|
198
|
+
}
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
function buildCKBGithubReleasePackageName(version, opt = {}) {
|
|
202
|
+
const os = opt.os || getOS();
|
|
203
|
+
const arch = opt.arch || getArch();
|
|
204
|
+
if (isPortable()) {
|
|
205
|
+
return `ckb_v${version}_${arch}-${os}-portable`;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
return `ckb_v${version}_${arch}-${os}`;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function buildCKBGithubReleasePackageNameWithExtension(version, opt = {}) {
|
|
193
212
|
const os = opt.os || getOS();
|
|
194
213
|
const arch = opt.arch || getArch();
|
|
195
214
|
const extension = opt.ext || getExtension();
|
|
196
|
-
|
|
215
|
+
if (isPortable()) {
|
|
216
|
+
return `ckb_v${version}_${arch}-${os}-portable.${extension}`;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
return `ckb_v${version}_${arch}-${os}.${extension}`;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function buildDownloadUrl(version, opt = {}) {
|
|
223
|
+
const fullPackageName = buildCKBGithubReleasePackageNameWithExtension(version, opt);
|
|
224
|
+
return `https://github.com/nervosnetwork/ckb/releases/download/v${version}/${fullPackageName}`;
|
|
197
225
|
}
|
|
198
226
|
exports.buildDownloadUrl = buildDownloadUrl;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@offckb/cli",
|
|
3
|
-
"version": "0.3.0-canary-
|
|
3
|
+
"version": "0.3.0-canary-4e24414.0",
|
|
4
4
|
"description": "ckb development network for your first try",
|
|
5
5
|
"author": "CKB EcoFund",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/adm-zip": "^0.5.5",
|
|
49
|
+
"@types/cpu-features": "^0.0.3",
|
|
49
50
|
"@types/node": "^20.11.19",
|
|
50
51
|
"@types/node-fetch": "^2.6.11",
|
|
51
52
|
"@types/semver": "^7.5.7",
|
|
@@ -68,6 +69,7 @@
|
|
|
68
69
|
"child_process": "^1.0.2",
|
|
69
70
|
"ckb-transaction-dumper": "^0.4.0",
|
|
70
71
|
"commander": "^12.0.0",
|
|
72
|
+
"cpu-features": "^0.0.10",
|
|
71
73
|
"http-proxy": "^1.18.1",
|
|
72
74
|
"https-proxy-agent": "^7.0.5",
|
|
73
75
|
"node-fetch": "2",
|