@@ -11,9 +11,58 @@ const { exec } = require('child_process');
11
11
const path = require ( 'path' ) ;
12
12
const os = require ( 'os' ) ;
13
13
const fabricsamples = require ( './src/fabricsamples' ) ;
14
+ const { Console } = require ( "console" ) ;
14
15
const outputChannel = vscode . window . createOutputChannel ( "Function Arguments Logger" ) ;
15
16
16
17
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 ) ;
17
66
let disposable5 = vscode . commands . registerCommand ( 'extension.extractFunctions' , function ( ) {
18
67
const editor = vscode . window . activeTextEditor ;
19
68
if ( ! editor ) {
@@ -57,58 +106,10 @@ function activate(context) {
57
106
"fabric-network" ,
58
107
context
59
108
) ;
109
+
60
110
const treeViewProviderDesc = new TreeViewProvider ( "network-desc" , context ) ;
61
111
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
+
112
113
113
114
vscode . window . createTreeView ( "fabric-network" , {
114
115
treeDataProvider : treeViewProviderFabric ,
0 commit comments