- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.js
More file actions
Latest commit
248 lines (215 loc) · 6.15 KB
/
Copy pathstart.js
File metadata and controls
248 lines (215 loc) · 6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env node
const{ spawn }=require("child_process");
constreadline=require("readline");
constpath=require("path");
constfs=require("fs");
// Create readline interface
constrl=readline.createInterface({
input: process.stdin,
output: process.stdout,
});
// ANSI color codes for terminal output
constcolors={
reset: "\x1b[0m",
bright: "\x1b[1m",
green: "\x1b[32m",
yellow: "\x1b[33m",
blue: "\x1b[34m",
cyan: "\x1b[36m",
red: "\x1b[31m",
};
// Check for command line arguments
constargs=process.argv.slice(2);
if(args.length>0){
// Handle command line arguments
switch(args[0]){
case"quick":
startFullApp();
break;
case"frontend":
startFrontend();
break;
case"backend":
startBackend();
break;
case"build":
buildFrontend();
break;
case"config":
editConfig();
break;
default:
// Show menu for unknown arguments
showMenu();
break;
}
}else{
// No arguments, show the menu
// Print welcome message
console.log(`
${colors.bright}${colors.cyan}=======================================
RUSTSHARK LAUNCHER
=======================================
A packet capture and analysis tool
=======================================
${colors.reset}
`);
showMenu();
}
// Display menu
functionshowMenu(){
console.log(`${colors.bright}Choose an option:${colors.reset}`);
console.log(
`${colors.green}1.${colors.reset} Start Full Application (Frontend & Backend)`
);
console.log(`${colors.green}2.${colors.reset} Start Frontend Only`);
console.log(`${colors.green}3.${colors.reset} Start Backend Only`);
console.log(`${colors.green}4.${colors.reset} Build Frontend`);
console.log(`${colors.green}5.${colors.reset} Edit Configuration`);
console.log(`${colors.green}6.${colors.reset} Exit`);
rl.question(
`\n${colors.yellow}Enter your choice (1-6):${colors.reset} `,
(answer)=>{
switch(answer.trim()){
case"1":
startFullApp();
break;
case"2":
startFrontend();
break;
case"3":
startBackend();
break;
case"4":
buildFrontend();
break;
case"5":
editConfig();
break;
case"6":
console.log(`${colors.blue}Goodbye!${colors.reset}`);
rl.close();
break;
default:
console.log(
`${colors.red}Invalid option. Please try again.${colors.reset}\n`
);
showMenu();
break;
}
}
);
}
// Function to run a command
functionrunCommand(command,args,cwd=process.cwd()){
constchildProcess=spawn(command,args,{
cwd,
stdio: "inherit",
shell: process.platform==="win32",
});
childProcess.on("error",(error)=>{
console.error(
`${colors.red}Error executing command:${colors.reset}`,
error.message
);
});
returnchildProcess;
}
// Start full application
functionstartFullApp(){
console.log(
`${colors.blue}Starting full application (Frontend & Backend)...${colors.reset}`
);
constfrontendDir=path.join(__dirname,"frontend");
// Check if we should use npm or yarn
constuseYarn=fs.existsSync(path.join(frontendDir,"yarn.lock"));
constcommand=useYarn ? "yarn" : "npm";
runCommand(command,["run","dev:integrated"],frontendDir);
}
// Start frontend only
functionstartFrontend(){
console.log(`${colors.blue}Starting frontend only...${colors.reset}`);
constfrontendDir=path.join(__dirname,"frontend");
constuseYarn=fs.existsSync(path.join(frontendDir,"yarn.lock"));
constcommand=useYarn ? "yarn" : "npm";
runCommand(command,["run","dev"],frontendDir);
}
// Start backend only
functionstartBackend(){
console.log(`${colors.blue}Starting backend only...${colors.reset}`);
constbackendDir=path.join(__dirname,"backend");
runCommand("cargo",["run"],backendDir);
}
// Build frontend
functionbuildFrontend(){
console.log(`${colors.blue}Building frontend...${colors.reset}`);
constfrontendDir=path.join(__dirname,"frontend");
constuseYarn=fs.existsSync(path.join(frontendDir,"yarn.lock"));
constcommand=useYarn ? "yarn" : "npm";
constbuildProcess=runCommand(command,["run","build"],frontendDir);
buildProcess.on("close",(code)=>{
if(code===0){
console.log(
`${colors.green}Build completed successfully!${colors.reset}`
);
}else{
console.log(`${colors.red}Build failed with code ${code}${colors.reset}`);
}
// Return to menu after build completes
console.log("\n");
showMenu();
});
return;// Don't show menu immediately for build
}
// Edit configuration
functioneditConfig(){
console.log(`${colors.blue}Opening configuration file...${colors.reset}`);
constconfigPath=path.join(__dirname,"rustshark.config.json");
// Check if config file exists, create it if not
if(!fs.existsSync(configPath)){
constdefaultConfig={
interface: null,
frontend: {port: 3000},
backend: {port: 8080,autostart: true},
capture: {promiscuous: true,buffer_size: 10000},
};
fs.writeFileSync(
configPath,
JSON.stringify(defaultConfig,null,2),
"utf8"
);
console.log(
`${colors.green}Created new configuration file.${colors.reset}`
);
}
// Open with default editor or print path
leteditorCmd;
if(process.platform==="win32"){
editorCmd="notepad";
}elseif(process.env.EDITOR){
editorCmd=process.env.EDITOR;
}else{
editorCmd="nano";
}
try{
runCommand(editorCmd,[configPath]);
console.log(
`${colors.green}Opening ${configPath} with ${editorCmd}${colors.reset}`
);
}catch(err){
console.log(
`${colors.red}Could not open editor. Please edit manually at: ${configPath}${colors.reset}`
);
}
// Return to menu after a short delay
setTimeout(()=>{
console.log("\n");
showMenu();
},1000);
return;// Don't show menu immediately
}
// Handle CTRL+C
process.on("SIGINT",()=>{
console.log(`\n${colors.blue}Exiting Rustshark Launcher...${colors.reset}`);
rl.close();
});