Skip to content

Commit cf8fdb6

Browse files
committed
updated Mind Cli (v1.0.3)
1 parent 157474d commit cf8fdb6

File tree

7 files changed

+723
-1466
lines changed

7 files changed

+723
-1466
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ dt
66
data
77
mind-cli
88
mind-cli.js
9-
mind-cli.exe
9+
mind-cli.exe
10+
11+
bin

bin/mind-cli

-8 Bytes
Binary file not shown.

package-lock.json

Lines changed: 94 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mindc",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "A ts cli to interact with Mind-Smart-Chain",
55
"main": "./dist/src/cli.js",
66
"bin": {

src/node/commands/get-genesis.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ export function generateGenesisJson() {
109109
}
110110
},
111111
"blockGasTarget": 0,
112-
"burnContract": {
113-
"6342215": "0xF7C81F2aA9670223998D630D8185BA17Ef67f825"
114-
},
115-
"burnContractDestinationAddress": "0x0000000000000000000000000000000000000000"
116112
},
117113
"bootnodes": [
118114
"/ip4/37.60.239.84/tcp/10001/p2p/16Uiu2HAmUkuKgbDRaZzjE8SzNp3ptZcJCD8pFV2XwkZ9Tc2jpxaZ",

src/node/commands/install-node.ts

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import { Octokit } from '@octokit/rest';
88

99
const octokit = new Octokit();
1010

11-
async function downloadAndInstallBinary(url: string, targetPath: string): Promise<void> {
11+
async function downloadAndInstallBinary(targetPath: string): Promise<void> {
1212
try {
13-
const response = await octokit.repos.getReleaseByTag({
13+
// Fetch the latest release instead of a specific version
14+
const response = await octokit.repos.getLatestRelease({
1415
owner: 'Mind-chain',
1516
repo: 'Msc-node',
16-
tag: 'v1.0.10'
1717
});
1818

1919
const asset = response.data.assets.find(asset => asset.name === 'mind');
@@ -28,8 +28,6 @@ async function downloadAndInstallBinary(url: string, targetPath: string): Promis
2828
format: 'Downloading [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} bytes',
2929
}, Presets.shades_classic);
3030

31-
progressBar.start(totalLength, 0);
32-
3331
const writer = fs.createWriteStream(targetPath);
3432

3533
const responseStream = await axios({
@@ -38,34 +36,41 @@ async function downloadAndInstallBinary(url: string, targetPath: string): Promis
3836
responseType: 'stream',
3937
});
4038

39+
// Start the progress bar when the download begins
40+
progressBar.start(totalLength, 0);
41+
4142
responseStream.data.on('data', (chunk: Buffer) => {
4243
progressBar.increment(chunk.length);
4344
writer.write(chunk);
4445
});
4546

46-
responseStream.data.on('end', () => {
47-
writer.end();
48-
progressBar.stop();
49-
console.log('Binary downloaded successfully.');
50-
// Set execute permission
51-
fs.chmodSync(targetPath, '755');
52-
console.log('Mind installed successfully.');
53-
54-
// Add a delay before executing the binary
55-
setTimeout(() => {
56-
if (os.platform() === 'linux') {
57-
// Display the version of the application
58-
execSync('./mind version', { stdio: 'inherit' });
59-
} else {
60-
console.log('MSC CORE Node CLI app is incompatible with this device. Please try Linux.');
61-
}
62-
}, 1000);
63-
});
47+
// Handle the end of the stream and close the progress bar
48+
await new Promise<void>((resolve, reject) => {
49+
responseStream.data.on('end', () => {
50+
writer.end();
51+
progressBar.stop();
52+
console.log('Binary downloaded successfully.');
53+
// Set execute permission
54+
fs.chmodSync(targetPath, '755');
55+
console.log('Mind installed successfully.');
56+
57+
// Add a delay before executing the binary
58+
setTimeout(() => {
59+
if (os.platform() === 'linux') {
60+
// Display the version of the application
61+
execSync('./mind version', { stdio: 'inherit' });
62+
} else {
63+
console.log('MSC CORE Node CLI app is incompatible with this device. Please try Linux.');
64+
}
65+
}, 1000);
66+
resolve();
67+
});
6468

65-
responseStream.data.on('error', (error: Error) => {
66-
progressBar.stop();
67-
fs.unlink(targetPath, () => {
68-
throw new Error(`Failed to download file: ${error.message}`);
69+
responseStream.data.on('error', (error: Error) => {
70+
progressBar.stop();
71+
fs.unlink(targetPath, () => {
72+
reject(new Error(`Failed to download file: ${error.message}`));
73+
});
6974
});
7075
});
7176
} catch (error: any) {
@@ -77,14 +82,14 @@ function installMind(): void {
7782
const targetFileName = 'mind';
7883
const targetPath = `${process.cwd()}/${targetFileName}`;
7984

80-
console.log('Downloading binary...');
85+
if (fs.existsSync(targetPath)) {
86+
console.log('Updating binary...');
87+
fs.removeSync(targetPath); // Delete the existing binary
88+
} else {
89+
console.log('Downloading binary...');
90+
}
8191

82-
downloadAndInstallBinary('', targetPath)
83-
.then(() => {
84-
console.log('Binary downloaded successfully.');
85-
// Set execute permission
86-
fs.chmodSync(targetPath, '755');
87-
})
92+
downloadAndInstallBinary(targetPath)
8893
.catch((error) => {
8994
console.error('An error occurred:', error);
9095
});

0 commit comments

Comments
 (0)