fleetbo-cockpit-cli 1.0.246 → 1.0.248

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.
Files changed (2) hide show
  1. package/cli.js +89 -75
  2. 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
+ // 🟢 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
- const killNetworkService = () => {
913
- if (uplinkProcess) {
914
- try {
915
- if (process.platform === 'win32') {
916
- spawn('taskkill', ['/pid', String(uplinkProcess.pid), '/T', '/F'], {
917
- stdio: 'ignore', detached: true, shell: false
918
- }).unref();
919
- } else {
920
- uplinkProcess.kill('SIGINT');
921
- }
922
- console.log('[Fleetbo] Engine closed.');
923
- } catch (e) {
924
- console.error('[Fleetbo] Error closing tunnel:', e.message);
915
+ // 🟢 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;
@@ -931,15 +936,20 @@ else {
931
936
  async function cleanupAndExit(code = 0) {
932
937
  if (isExiting) return;
933
938
  isExiting = true;
934
- console.log('\x1b[33m[Fleetbo] Stopping environment & Cleaning Uplink...\x1b[0m');
939
+ console.log('\n\x1b[33m[Fleetbo] Stopping environment...\x1b[0m');
940
+
941
+ // On tue instantanément les processus pour libérer le terminal
942
+ killAllServices();
943
+ killProcessOnPort(PORT);
944
+
935
945
  try {
936
- await axios.post(UPDATE_NETWORK_URL, { keyApp, networkUrl: '', tester: testerEmail });
946
+ // 🟢 Timeout ultra-court (1s) pour ne jamais bloquer la sortie
947
+ await axios.post(UPDATE_NETWORK_URL, { keyApp, networkUrl: '', tester: testerEmail }, { timeout: 1000 });
937
948
  console.log('\x1b[32m[Fleetbo] Network status reset to offline.\x1b[0m');
938
949
  } catch (e) {
939
- console.error('[Fleetbo] Network cleanup warning:', e.message);
950
+ // On ignore silencieusement si ça échoue, le but principal est de quitter.
940
951
  }
941
- killNetworkService();
942
- killProcessOnPort(PORT);
952
+
943
953
  console.log('[Fleetbo] Bye.');
944
954
  process.exit(code);
945
955
  }
@@ -969,17 +979,17 @@ else {
969
979
  async function runDevEnvironment() {
970
980
  console.log(`[Fleetbo] Initializing Universal Dev Environment...\n`);
971
981
 
972
- killNetworkService();
982
+ killAllServices();
973
983
  killProcessOnPort(PORT);
974
984
 
975
985
  if (!testerEmail) {
976
- console.error('\x1b[31m[Error] FLEETBO_APP_TESTER_EMAIL missing in .env\x1b[0m');
986
+ console.error('\x1b[31m[Error] VITE_FLEETBO_TESTER_EMAIL missing in .env\x1b[0m');
977
987
  process.exit(1);
978
988
  }
979
989
 
980
990
  const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
981
991
 
982
- const devServer = spawn(`${npmCmd} run dev --silent -- --host 127.0.0.1 --port ${PORT}`, {
992
+ devServerProcess = spawn(npmCmd, ['run', 'dev', '--silent', '--', '--host', '127.0.0.1', '--port', String(PORT)], {
983
993
  stdio: ['ignore', 'pipe', 'pipe'],
984
994
  shell: true,
985
995
  env: {
@@ -988,15 +998,18 @@ else {
988
998
  }
989
999
  });
990
1000
 
991
- devServer.stderr.pipe(process.stderr);
1001
+ devServerProcess.stderr.pipe(process.stderr);
992
1002
 
993
1003
  let connectionStarted = false;
994
1004
  let detectedPort = PORT;
1005
+
1006
+ let viteBuffer = "";
995
1007
 
996
- devServer.stdout.on('data', (data) => {
997
- const output = data.toString();
1008
+ devServerProcess.stdout.on('data', (data) => {
1009
+ const chunkText = data.toString();
1010
+ viteBuffer += chunkText;
998
1011
 
999
- const lines = output.split('\n');
1012
+ const lines = chunkText.split('\n');
1000
1013
  const forbiddenTerms = [
1001
1014
  'Attempting to bind to HOST', 'If this was unintentional', 'Learn more here:',
1002
1015
  'Starting the development server', 'You can now view', 'vite v', 'VITE v', 'Port', 'is in use',
@@ -1012,12 +1025,11 @@ else {
1012
1025
  process.stdout.write(filteredOutput + '\n');
1013
1026
  }
1014
1027
 
1015
- const portMatch = output.match(/http:\/\/(?:localhost|127\.0\.0\.1):(\d+)/);
1028
+ if (!connectionStarted) {
1029
+ const portMatch = viteBuffer.match(/http:\/\/(?:localhost|127\.0\.0\.1):(\d+)/);
1016
1030
 
1017
- if (portMatch) {
1018
- detectedPort = portMatch[1];
1019
-
1020
- if (!connectionStarted) {
1031
+ if (portMatch) {
1032
+ detectedPort = portMatch[1];
1021
1033
  connectionStarted = true;
1022
1034
 
1023
1035
  console.log('\x1b[33mFleetbo OS ❯\x1b[0m ---------------------------------------------------');
@@ -1025,57 +1037,59 @@ else {
1025
1037
  console.log(`\x1b[33mFleetbo OS ❯\x1b[0m Please wait for the green message...`);
1026
1038
  console.log('\x1b[33mFleetbo OS ❯\x1b[0m ---------------------------------------------------\n');
1027
1039
 
1028
- const MAX_UPLINK_RETRIES = 5;
1029
- const RETRY_DELAYS = [0, 10, 20, 30, 45];
1030
- let uplinkFound = false;
1031
-
1032
- const startUplink = (attempt) => {
1033
- if (uplinkFound) return;
1040
+ const MAX_UPLINK_RETRIES = 5;
1041
+ const RETRY_DELAYS = [0, 10, 20, 30, 45];
1042
+ let uplinkFound = false;
1034
1043
 
1035
- const npxCmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
1036
-
1037
- if (attempt > 0) {
1038
- console.log(`\x1b[33m[Fleetbo] Uplink reconnection ${attempt}/${MAX_UPLINK_RETRIES - 1}...\x1b[0m`);
1039
- }
1040
-
1041
- const uplinkCommand = `${npxCmd} -y cloudflared tunnel --url http://127.0.0.1:${detectedPort} --http-host-header 127.0.0.1:${detectedPort}`;
1042
- uplinkProcess = spawn(uplinkCommand, { shell: true });
1043
-
1044
- const handleUplinkOutput = (chunk) => {
1045
- const text = chunk.toString();
1044
+ const startUplink = (attempt) => {
1046
1045
  if (uplinkFound) return;
1047
- const match = text.match(/https:\/\/[a-zA-Z0-9-]+\.trycloudflare\.com/);
1048
- if (match) {
1049
- uplinkFound = true;
1050
- setTimeout(() => {
1051
- syncFirebase(process.env.VITE_FLEETBO_KEY_APP, match[0], process.env.VITE_FLEETBO_TESTER_EMAIL);
1052
- }, 1500);
1053
- }
1054
- };
1055
1046
 
1056
- uplinkProcess.stdout.on('data', handleUplinkOutput);
1057
- uplinkProcess.stderr.on('data', handleUplinkOutput);
1058
-
1059
- uplinkProcess.on('error', () => {
1060
- if (uplinkFound) return;
1061
- console.error(`\x1b[31m[Fleetbo] Uplink Connection failed to establish.\x1b[0m`);
1062
- });
1047
+ const npxCmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
1063
1048
 
1064
- uplinkProcess.on('close', () => {
1065
- if (uplinkFound) return;
1066
- const nextAttempt = attempt + 1;
1067
- if (nextAttempt < MAX_UPLINK_RETRIES) {
1068
- const delay = RETRY_DELAYS[nextAttempt] || 30;
1069
- console.log(`\x1b[33m[Fleetbo] Uplink interrupted. Fleetbo OS retrying in ${delay}s... (${nextAttempt}/${MAX_UPLINK_RETRIES - 1})\x1b[0m`);
1070
- setTimeout(() => startUplink(nextAttempt), delay * 1000);
1071
- } else {
1072
- console.error(`\x1b[31m[Fleetbo] Secure Uplink could not be established.\x1b[0m`);
1049
+ if (attempt > 0) {
1050
+ console.log(`\x1b[33m[Fleetbo] Uplink reconnection ${attempt}/${MAX_UPLINK_RETRIES - 1}...\x1b[0m`);
1073
1051
  }
1074
- });
1075
- };
1076
1052
 
1077
- startUplink(0);
1053
+ uplinkProcess = spawn(npxCmd, ['-y', 'cloudflared', 'tunnel', '--url', `http://127.0.0.1:${detectedPort}`, '--http-host-header', `127.0.0.1:${detectedPort}`], { shell: true });
1054
+
1055
+ let uplinkBuffer = "";
1056
+
1057
+ const handleUplinkOutput = (chunk) => {
1058
+ if (uplinkFound) return;
1059
+
1060
+ uplinkBuffer += chunk.toString();
1061
+
1062
+ const match = uplinkBuffer.match(/https:\/\/[a-zA-Z0-9-]+\.trycloudflare\.com/i);
1063
+ if (match) {
1064
+ uplinkFound = true;
1065
+ setTimeout(() => {
1066
+ syncFirebase(process.env.VITE_FLEETBO_KEY_APP, match[0], process.env.VITE_FLEETBO_TESTER_EMAIL);
1067
+ }, 1500);
1068
+ }
1069
+ };
1070
+
1071
+ uplinkProcess.stdout.on('data', handleUplinkOutput);
1072
+ uplinkProcess.stderr.on('data', handleUplinkOutput);
1073
+
1074
+ uplinkProcess.on('error', () => {
1075
+ if (uplinkFound) return;
1076
+ console.error(`\x1b[31m[Fleetbo] Uplink Connection failed to establish.\x1b[0m`);
1077
+ });
1078
+
1079
+ uplinkProcess.on('close', () => {
1080
+ if (uplinkFound) return;
1081
+ const nextAttempt = attempt + 1;
1082
+ if (nextAttempt < MAX_UPLINK_RETRIES) {
1083
+ const delay = RETRY_DELAYS[nextAttempt] || 30;
1084
+ console.log(`\x1b[33m[Fleetbo] Uplink interrupted. Fleetbo OS retrying in ${delay}s... (${nextAttempt}/${MAX_UPLINK_RETRIES - 1})\x1b[0m`);
1085
+ setTimeout(() => startUplink(nextAttempt), delay * 1000);
1086
+ } else {
1087
+ console.error(`\x1b[31m[Fleetbo] Secure Uplink could not be established.\x1b[0m`);
1088
+ }
1089
+ });
1090
+ };
1078
1091
 
1092
+ startUplink(0);
1079
1093
  }
1080
1094
  }
1081
1095
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetbo-cockpit-cli",
3
- "version": "1.0.246",
3
+ "version": "1.0.248",
4
4
  "description": "Fleetbo CLI - Build native mobile apps with React",
5
5
  "author": "Fleetbo",
6
6
  "license": "MIT",