fleetbo-cockpit-cli 1.0.245 → 1.0.247
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +85 -77
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -899,6 +899,9 @@ else if (['page', 'g', 'generate'].includes(command)) {
|
|
|
899
899
|
}
|
|
900
900
|
else {
|
|
901
901
|
const NULL_DEV = process.platform === 'win32' ? '>nul 2>&1' : '2>/dev/null';
|
|
902
|
+
|
|
903
|
+
// 🟢 FIX 1 : On crée une variable pour garder la trace du serveur Vite
|
|
904
|
+
let devServerProcess = null;
|
|
902
905
|
|
|
903
906
|
function killProcessOnPort(port) {
|
|
904
907
|
try {
|
|
@@ -909,21 +912,23 @@ else {
|
|
|
909
912
|
} catch (e) {}
|
|
910
913
|
}
|
|
911
914
|
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
915
|
+
// 🟢 FIX 2 : On tue TOUS les processus enfants (Cloudflare ET Vite) proprement
|
|
916
|
+
const killAllServices = () => {
|
|
917
|
+
const killProc = (proc) => {
|
|
918
|
+
if (proc && proc.pid) {
|
|
919
|
+
try {
|
|
920
|
+
if (process.platform === 'win32') {
|
|
921
|
+
spawn('taskkill', ['/pid', String(proc.pid), '/T', '/F'], {
|
|
922
|
+
stdio: 'ignore', detached: true, shell: false
|
|
923
|
+
}).unref();
|
|
924
|
+
} else {
|
|
925
|
+
proc.kill('SIGINT');
|
|
926
|
+
}
|
|
927
|
+
} catch (e) {}
|
|
925
928
|
}
|
|
926
|
-
}
|
|
929
|
+
};
|
|
930
|
+
killProc(uplinkProcess);
|
|
931
|
+
killProc(devServerProcess);
|
|
927
932
|
};
|
|
928
933
|
|
|
929
934
|
let isExiting = false;
|
|
@@ -940,6 +945,15 @@ else {
|
|
|
940
945
|
}
|
|
941
946
|
killNetworkService();
|
|
942
947
|
killProcessOnPort(PORT);
|
|
948
|
+
|
|
949
|
+
try {
|
|
950
|
+
// 🟢 FIX 3 : On met un timeout ultra-court (1s) pour ne jamais bloquer la sortie
|
|
951
|
+
await axios.post(UPDATE_NETWORK_URL, { keyApp, networkUrl: '', tester: testerEmail }, { timeout: 1000 });
|
|
952
|
+
console.log('\x1b[32m[Fleetbo] Network status reset to offline.\x1b[0m');
|
|
953
|
+
} catch (e) {
|
|
954
|
+
// On ignore silencieusement si ça échoue, le but principal est de quitter.
|
|
955
|
+
}
|
|
956
|
+
|
|
943
957
|
console.log('[Fleetbo] Bye.');
|
|
944
958
|
process.exit(code);
|
|
945
959
|
}
|
|
@@ -973,14 +987,14 @@ else {
|
|
|
973
987
|
killProcessOnPort(PORT);
|
|
974
988
|
|
|
975
989
|
if (!testerEmail) {
|
|
976
|
-
console.error('\x1b[31m[Error]
|
|
990
|
+
console.error('\x1b[31m[Error] FLEETBO_APP_TESTER_EMAIL missing in .env\x1b[0m');
|
|
977
991
|
process.exit(1);
|
|
978
992
|
}
|
|
979
993
|
|
|
980
994
|
const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
981
995
|
|
|
982
|
-
// 🟢
|
|
983
|
-
|
|
996
|
+
// 🟢 (Inclut la correction des arguments Arrays vue précédemment)
|
|
997
|
+
devServerProcess = spawn(npmCmd, ['run', 'dev', '--silent', '--', '--host', '127.0.0.1', '--port', String(PORT)], {
|
|
984
998
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
985
999
|
shell: true,
|
|
986
1000
|
env: {
|
|
@@ -993,15 +1007,14 @@ else {
|
|
|
993
1007
|
|
|
994
1008
|
let connectionStarted = false;
|
|
995
1009
|
let detectedPort = PORT;
|
|
996
|
-
|
|
997
|
-
// 🟢 FIX 2 : Un Buffer mémoire pour ne pas rater les textes coupés en deux !
|
|
998
|
-
let viteBuffer = "";
|
|
999
1010
|
|
|
1011
|
+
// 🟢 (Inclut la correction du Buffer de texte vue précédemment)
|
|
1012
|
+
let viteBuffer = "";
|
|
1013
|
+
|
|
1000
1014
|
devServer.stdout.on('data', (data) => {
|
|
1001
|
-
const
|
|
1002
|
-
viteBuffer += chunkText; // On accumule tout l'historique
|
|
1015
|
+
const output = data.toString();
|
|
1003
1016
|
|
|
1004
|
-
const lines =
|
|
1017
|
+
const lines = output.split('\n');
|
|
1005
1018
|
const forbiddenTerms = [
|
|
1006
1019
|
'Attempting to bind to HOST', 'If this was unintentional', 'Learn more here:',
|
|
1007
1020
|
'Starting the development server', 'You can now view', 'vite v', 'VITE v', 'Port', 'is in use',
|
|
@@ -1017,12 +1030,12 @@ else {
|
|
|
1017
1030
|
process.stdout.write(filteredOutput + '\n');
|
|
1018
1031
|
}
|
|
1019
1032
|
|
|
1020
|
-
|
|
1021
|
-
// On cherche l'URL de Vite dans l'historique COMPLET
|
|
1022
|
-
const portMatch = viteBuffer.match(/http:\/\/(?:localhost|127\.0\.0\.1):(\d+)/);
|
|
1033
|
+
const portMatch = output.match(/http:\/\/(?:localhost|127\.0\.0\.1):(\d+)/);
|
|
1023
1034
|
|
|
1024
|
-
|
|
1025
|
-
|
|
1035
|
+
if (portMatch) {
|
|
1036
|
+
detectedPort = portMatch[1];
|
|
1037
|
+
|
|
1038
|
+
if (!connectionStarted) {
|
|
1026
1039
|
connectionStarted = true;
|
|
1027
1040
|
|
|
1028
1041
|
console.log('\x1b[33mFleetbo OS ❯\x1b[0m ---------------------------------------------------');
|
|
@@ -1030,62 +1043,57 @@ else {
|
|
|
1030
1043
|
console.log(`\x1b[33mFleetbo OS ❯\x1b[0m Please wait for the green message...`);
|
|
1031
1044
|
console.log('\x1b[33mFleetbo OS ❯\x1b[0m ---------------------------------------------------\n');
|
|
1032
1045
|
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1046
|
+
const MAX_UPLINK_RETRIES = 5;
|
|
1047
|
+
const RETRY_DELAYS = [0, 10, 20, 30, 45];
|
|
1048
|
+
let uplinkFound = false;
|
|
1049
|
+
|
|
1050
|
+
const startUplink = (attempt) => {
|
|
1051
|
+
if (uplinkFound) return;
|
|
1052
|
+
|
|
1053
|
+
const npxCmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
|
|
1054
|
+
|
|
1055
|
+
if (attempt > 0) {
|
|
1056
|
+
console.log(`\x1b[33m[Fleetbo] Uplink reconnection ${attempt}/${MAX_UPLINK_RETRIES - 1}...\x1b[0m`);
|
|
1057
|
+
}
|
|
1036
1058
|
|
|
1037
|
-
const
|
|
1059
|
+
const uplinkCommand = `${npxCmd} -y cloudflared tunnel --url http://127.0.0.1:${detectedPort} --http-host-header 127.0.0.1:${detectedPort}`;
|
|
1060
|
+
uplinkProcess = spawn(uplinkCommand, { shell: true });
|
|
1061
|
+
|
|
1062
|
+
const handleUplinkOutput = (chunk) => {
|
|
1063
|
+
const text = chunk.toString();
|
|
1038
1064
|
if (uplinkFound) return;
|
|
1065
|
+
const match = text.match(/https:\/\/[a-zA-Z0-9-]+\.trycloudflare\.com/);
|
|
1066
|
+
if (match) {
|
|
1067
|
+
uplinkFound = true;
|
|
1068
|
+
setTimeout(() => {
|
|
1069
|
+
syncFirebase(process.env.VITE_FLEETBO_KEY_APP, match[0], process.env.VITE_FLEETBO_TESTER_EMAIL);
|
|
1070
|
+
}, 1500);
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
uplinkProcess.stdout.on('data', handleUplinkOutput);
|
|
1075
|
+
uplinkProcess.stderr.on('data', handleUplinkOutput);
|
|
1039
1076
|
|
|
1040
|
-
|
|
1077
|
+
uplinkProcess.on('error', () => {
|
|
1078
|
+
if (uplinkFound) return;
|
|
1079
|
+
console.error(`\x1b[31m[Fleetbo] Uplink Connection failed to establish.\x1b[0m`);
|
|
1080
|
+
});
|
|
1041
1081
|
|
|
1042
|
-
|
|
1043
|
-
|
|
1082
|
+
uplinkProcess.on('close', () => {
|
|
1083
|
+
if (uplinkFound) return;
|
|
1084
|
+
const nextAttempt = attempt + 1;
|
|
1085
|
+
if (nextAttempt < MAX_UPLINK_RETRIES) {
|
|
1086
|
+
const delay = RETRY_DELAYS[nextAttempt] || 30;
|
|
1087
|
+
console.log(`\x1b[33m[Fleetbo] Uplink interrupted. Fleetbo OS retrying in ${delay}s... (${nextAttempt}/${MAX_UPLINK_RETRIES - 1})\x1b[0m`);
|
|
1088
|
+
setTimeout(() => startUplink(nextAttempt), delay * 1000);
|
|
1089
|
+
} else {
|
|
1090
|
+
console.error(`\x1b[31m[Fleetbo] Secure Uplink could not be established.\x1b[0m`);
|
|
1044
1091
|
}
|
|
1092
|
+
});
|
|
1093
|
+
};
|
|
1045
1094
|
|
|
1046
|
-
|
|
1047
|
-
uplinkProcess = spawn(npxCmd, ['-y', 'cloudflared', 'tunnel', '--url', `http://127.0.0.1:${detectedPort}`, '--http-host-header', `127.0.0.1:${detectedPort}`], { shell: true });
|
|
1048
|
-
|
|
1049
|
-
// 🟢 FIX 4 : Buffer cumulatif pour l'URL Cloudflare
|
|
1050
|
-
let uplinkBuffer = "";
|
|
1051
|
-
|
|
1052
|
-
const handleUplinkOutput = (chunk) => {
|
|
1053
|
-
if (uplinkFound) return;
|
|
1054
|
-
|
|
1055
|
-
uplinkBuffer += chunk.toString(); // On accumule
|
|
1056
|
-
|
|
1057
|
-
// On cherche dans le buffer consolidé
|
|
1058
|
-
const match = uplinkBuffer.match(/https:\/\/[a-zA-Z0-9-]+\.trycloudflare\.com/i);
|
|
1059
|
-
if (match) {
|
|
1060
|
-
uplinkFound = true;
|
|
1061
|
-
setTimeout(() => {
|
|
1062
|
-
syncFirebase(process.env.VITE_FLEETBO_KEY_APP, match[0], process.env.VITE_FLEETBO_TESTER_EMAIL);
|
|
1063
|
-
}, 1500);
|
|
1064
|
-
}
|
|
1065
|
-
};
|
|
1066
|
-
|
|
1067
|
-
uplinkProcess.stdout.on('data', handleUplinkOutput);
|
|
1068
|
-
uplinkProcess.stderr.on('data', handleUplinkOutput);
|
|
1069
|
-
|
|
1070
|
-
uplinkProcess.on('error', () => {
|
|
1071
|
-
if (uplinkFound) return;
|
|
1072
|
-
console.error(`\x1b[31m[Fleetbo] Uplink Connection failed to establish.\x1b[0m`);
|
|
1073
|
-
});
|
|
1074
|
-
|
|
1075
|
-
uplinkProcess.on('close', () => {
|
|
1076
|
-
if (uplinkFound) return;
|
|
1077
|
-
const nextAttempt = attempt + 1;
|
|
1078
|
-
if (nextAttempt < MAX_UPLINK_RETRIES) {
|
|
1079
|
-
const delay = RETRY_DELAYS[nextAttempt] || 30;
|
|
1080
|
-
console.log(`\x1b[33m[Fleetbo] Uplink interrupted. Fleetbo OS retrying in ${delay}s... (${nextAttempt}/${MAX_UPLINK_RETRIES - 1})\x1b[0m`);
|
|
1081
|
-
setTimeout(() => startUplink(nextAttempt), delay * 1000);
|
|
1082
|
-
} else {
|
|
1083
|
-
console.error(`\x1b[31m[Fleetbo] Secure Uplink could not be established.\x1b[0m`);
|
|
1084
|
-
}
|
|
1085
|
-
});
|
|
1086
|
-
};
|
|
1095
|
+
startUplink(0);
|
|
1087
1096
|
|
|
1088
|
-
startUplink(0);
|
|
1089
1097
|
}
|
|
1090
1098
|
}
|
|
1091
1099
|
});
|