Skip to content

Commit 90dbef3

Browse files
committed
start a local-network
Signed-off-by: urgetolearn <[email protected]>
1 parent f41d750 commit 90dbef3

5 files changed

+77
-52
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
*.vsix
33
.DS_Store
4+
.hidden/

extension.js

+51-50
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,58 @@ const { exec } = require('child_process');
1111
const path = require('path');
1212
const os = require('os');
1313
const fabricsamples = require('./src/fabricsamples');
14+
const { Console } = require("console");
1415
const outputChannel = vscode.window.createOutputChannel("Function Arguments Logger");
1516

1617
function activate(context) {
18+
const fabricDebuggerPath = 'C:\\Users\\Public\\fabric-debugger';
19+
20+
let greenButton = vscode.commands.registerCommand('myview.button1', () => {
21+
const platform = process.platform;
22+
const scriptUpPath = path.join(fabricDebuggerPath, 'local-networkup.sh');
23+
// Command to execute based on the platform
24+
let command;
25+
if (platform === 'win32') {
26+
command = `wsl bash "${scriptUpPath}"`;
27+
} else {
28+
command = `bash "${scriptUpPath}"`;
29+
}
30+
31+
exec(command, (err, stdout, stderr) => {
32+
if (err) {
33+
vscode.window.showErrorMessage(`Error: ${stderr}`);
34+
return;
35+
}
36+
vscode.window.showInformationMessage(`Output: ${stdout}`);
37+
console.log("network is up and running");
38+
});
39+
});
40+
41+
// Command for the red button
42+
let redButton = vscode.commands.registerCommand('myview.button2', () => {
43+
const platform = process.platform;
44+
45+
const scriptDownPath = path.join(fabricDebuggerPath, 'local-networkdown.sh');
46+
let command;
47+
if (platform === 'win32') {
48+
command = `wsl bash "${scriptDownPath}"`;
49+
} else {
50+
command = `bash "${scriptDownPath}"`;
51+
}
52+
53+
// Execute the command
54+
exec(command, (err, stdout, stderr) => {
55+
if (err) {
56+
vscode.window.showErrorMessage(`Error: ${stderr}`);
57+
return;
58+
}
59+
vscode.window.showInformationMessage(`Output: ${stdout}`);
60+
console.log("network is down");
61+
});
62+
});
63+
64+
context.subscriptions.push(greenButton);
65+
context.subscriptions.push(redButton);
1766
let disposable5 = vscode.commands.registerCommand('extension.extractFunctions', function () {
1867
const editor = vscode.window.activeTextEditor;
1968
if (!editor) {
@@ -57,58 +106,10 @@ function activate(context) {
57106
"fabric-network",
58107
context
59108
);
109+
60110
const treeViewProviderDesc = new TreeViewProvider("network-desc", context);
61111
const treeViewProviderWallet = new TreeViewProvider("wallets", context);
62-
function runCommand(command, callback) {
63-
const platform = os.platform(); // Detect the OS platform
64-
65-
if (platform === 'win32') {
66-
command = `bash -c "${command}"`;
67-
} else if (platform === 'darwin' || platform === 'linux') {
68-
// For macOS no need to modify the command
69-
}
70-
71-
exec(command, (err, stdout, stderr) => {
72-
if (err) {
73-
console.error(`Error: ${err.message}`);
74-
return;
75-
}
76-
console.log(stdout);
77-
if (stderr) {
78-
console.error(`Stderr: ${stderr}`);
79-
}
80-
if (callback) callback();
81-
});
82-
}
83-
84-
function ensureRepoCloned(commandToRun) {
85-
if (!fs.existsSync('fabric-samples')) {
86-
console.log('Cloning the repository...');
87-
runCommand('git clone https://github.com/urgetolearn/fabric-samples.git', () => {
88-
console.log('Repository cloned. Executing the next command...');
89-
runCommand(commandToRun);
90-
});
91-
} else {
92-
console.log('Repository already cloned. Executing the command...');
93-
runCommand(commandToRun);
94-
}
95-
}
96-
97-
const setupNetwork = () => {
98-
const command = 'cd fabric-samples/test-network && ./network.sh up';
99-
ensureRepoCloned(command);
100-
};
101-
102-
const shutDownNetwork = () => {
103-
const command = 'cd fabric-samples/test-network && ./network.sh down';
104-
ensureRepoCloned(command);
105-
};
106-
107-
const disposableUp = vscode.commands.registerCommand('myview.button1', setupNetwork);
108-
const disposableDown = vscode.commands.registerCommand('myview.button2', shutDownNetwork);
109-
110-
context.subscriptions.push(disposableUp);
111-
context.subscriptions.push(disposableDown);
112+
112113

113114
vscode.window.createTreeView("fabric-network", {
114115
treeDataProvider: treeViewProviderFabric,

local-networkdown.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
if [ ! -d ".hidden/fabric-samples" ]; then
3+
curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh -o .hidden/install-fabric.sh && chmod +x .hidden/install-fabric.sh
4+
# Clone into the hidden directory
5+
git clone https://github.com/hyperledger/fabric-samples.git ".hidden/fabric-samples"
6+
7+
# Run the install script
8+
.hidden/install-fabric.sh docker samples binary
9+
fi
10+
cd .hidden/fabric-samples/test-network
11+
./network.sh down

local-networkup.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
if [ ! -d ".hidden/fabric-samples" ]; then
3+
curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh -o .hidden/install-fabric.sh && chmod +x .hidden/install-fabric.sh
4+
# Clone into the hidden directory
5+
git clone https://github.com/hyperledger/fabric-samples.git ".hidden/fabric-samples"
6+
7+
# Run the install script
8+
.hidden/install-fabric.sh docker samples binary
9+
fi
10+
cd .hidden/fabric-samples/test-network
11+
./network.sh up
12+

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@
205205
},
206206
{
207207
"command": "myview.button1",
208-
"title": "🔴"
208+
"title": "🟢"
209209
},
210210
{
211211
"command": "myview.button2",
212-
"title": "🟢"
212+
"title": "🔴"
213213
}
214214
]
215215
},

0 commit comments

Comments
 (0)