From 90dbef3e9ca6e897453d55fb9a583dfe67cd4592 Mon Sep 17 00:00:00 2001 From: urgetolearn Date: Sat, 5 Oct 2024 18:41:34 +0530 Subject: [PATCH] start a local-network Signed-off-by: urgetolearn --- .gitignore | 1 + extension.js | 101 ++++++++++++++++++++++--------------------- local-networkdown.sh | 11 +++++ local-networkup.sh | 12 +++++ package.json | 4 +- 5 files changed, 77 insertions(+), 52 deletions(-) create mode 100644 local-networkdown.sh create mode 100644 local-networkup.sh diff --git a/.gitignore b/.gitignore index 6289b62..458b7b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules *.vsix .DS_Store +.hidden/ \ No newline at end of file diff --git a/extension.js b/extension.js index 12ae122..84f073a 100644 --- a/extension.js +++ b/extension.js @@ -11,9 +11,58 @@ const { exec } = require('child_process'); const path = require('path'); const os = require('os'); const fabricsamples = require('./src/fabricsamples'); +const { Console } = require("console"); const outputChannel = vscode.window.createOutputChannel("Function Arguments Logger"); function activate(context) { + const fabricDebuggerPath = 'C:\\Users\\Public\\fabric-debugger'; + + let greenButton = vscode.commands.registerCommand('myview.button1', () => { + const platform = process.platform; + const scriptUpPath = path.join(fabricDebuggerPath, 'local-networkup.sh'); + // Command to execute based on the platform + let command; + if (platform === 'win32') { + command = `wsl bash "${scriptUpPath}"`; + } else { + command = `bash "${scriptUpPath}"`; + } + + exec(command, (err, stdout, stderr) => { + if (err) { + vscode.window.showErrorMessage(`Error: ${stderr}`); + return; + } + vscode.window.showInformationMessage(`Output: ${stdout}`); + console.log("network is up and running"); + }); + }); + + // Command for the red button + let redButton = vscode.commands.registerCommand('myview.button2', () => { + const platform = process.platform; + + const scriptDownPath = path.join(fabricDebuggerPath, 'local-networkdown.sh'); + let command; + if (platform === 'win32') { + command = `wsl bash "${scriptDownPath}"`; + } else { + command = `bash "${scriptDownPath}"`; + } + + // Execute the command + exec(command, (err, stdout, stderr) => { + if (err) { + vscode.window.showErrorMessage(`Error: ${stderr}`); + return; + } + vscode.window.showInformationMessage(`Output: ${stdout}`); + console.log("network is down"); + }); + }); + + context.subscriptions.push(greenButton); + context.subscriptions.push(redButton); let disposable5 = vscode.commands.registerCommand('extension.extractFunctions', function () { const editor = vscode.window.activeTextEditor; if (!editor) { @@ -57,58 +106,10 @@ function activate(context) { "fabric-network", context ); + const treeViewProviderDesc = new TreeViewProvider("network-desc", context); const treeViewProviderWallet = new TreeViewProvider("wallets", context); - function runCommand(command, callback) { - const platform = os.platform(); // Detect the OS platform - - if (platform === 'win32') { - command = `bash -c "${command}"`; - } else if (platform === 'darwin' || platform === 'linux') { - // For macOS no need to modify the command - } - - exec(command, (err, stdout, stderr) => { - if (err) { - console.error(`Error: ${err.message}`); - return; - } - console.log(stdout); - if (stderr) { - console.error(`Stderr: ${stderr}`); - } - if (callback) callback(); - }); - } - - function ensureRepoCloned(commandToRun) { - if (!fs.existsSync('fabric-samples')) { - console.log('Cloning the repository...'); - runCommand('git clone https://github.com/urgetolearn/fabric-samples.git', () => { - console.log('Repository cloned. Executing the next command...'); - runCommand(commandToRun); - }); - } else { - console.log('Repository already cloned. Executing the command...'); - runCommand(commandToRun); - } - } - - const setupNetwork = () => { - const command = 'cd fabric-samples/test-network && ./network.sh up'; - ensureRepoCloned(command); - }; - - const shutDownNetwork = () => { - const command = 'cd fabric-samples/test-network && ./network.sh down'; - ensureRepoCloned(command); - }; - - const disposableUp = vscode.commands.registerCommand('myview.button1', setupNetwork); - const disposableDown = vscode.commands.registerCommand('myview.button2', shutDownNetwork); - - context.subscriptions.push(disposableUp); - context.subscriptions.push(disposableDown); + vscode.window.createTreeView("fabric-network", { treeDataProvider: treeViewProviderFabric, diff --git a/local-networkdown.sh b/local-networkdown.sh new file mode 100644 index 0000000..4484287 --- /dev/null +++ b/local-networkdown.sh @@ -0,0 +1,11 @@ +#!/bin/bash +if [ ! -d ".hidden/fabric-samples" ]; then + curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh -o .hidden/install-fabric.sh && chmod +x .hidden/install-fabric.sh + # Clone into the hidden directory + git clone https://github.com/hyperledger/fabric-samples.git ".hidden/fabric-samples" + + # Run the install script + .hidden/install-fabric.sh docker samples binary +fi +cd .hidden/fabric-samples/test-network +./network.sh down diff --git a/local-networkup.sh b/local-networkup.sh new file mode 100644 index 0000000..d55a470 --- /dev/null +++ b/local-networkup.sh @@ -0,0 +1,12 @@ +#!/bin/bash +if [ ! -d ".hidden/fabric-samples" ]; then + curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh -o .hidden/install-fabric.sh && chmod +x .hidden/install-fabric.sh + # Clone into the hidden directory + git clone https://github.com/hyperledger/fabric-samples.git ".hidden/fabric-samples" + + # Run the install script + .hidden/install-fabric.sh docker samples binary +fi +cd .hidden/fabric-samples/test-network +./network.sh up + diff --git a/package.json b/package.json index d1350ca..aa9c74f 100644 --- a/package.json +++ b/package.json @@ -205,11 +205,11 @@ }, { "command": "myview.button1", - "title": "🔴" + "title": "🟢" }, { "command": "myview.button2", - "title": "🟢" + "title": "🔴" } ] },