fleetbo-cockpit-cli 1.0.248 → 1.0.249

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 +77 -91
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -469,9 +469,9 @@ if (command === 'alex') {
469
469
  }
470
470
 
471
471
  if (aiData.status === 'message') {
472
- rawMsg = "\x1b[33m[Chat Mode]\x1b[0m " + rawMsg;
472
+ rawMsg = "[Chat Mode] " + rawMsg;
473
473
  }
474
-
474
+
475
475
  process.stdout.write(`[ALEX_START]${rawMsg}[ALEX_END]`);
476
476
  }
477
477
 
@@ -899,9 +899,6 @@ 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;
905
902
 
906
903
  function killProcessOnPort(port) {
907
904
  try {
@@ -912,23 +909,21 @@ else {
912
909
  } catch (e) {}
913
910
  }
914
911
 
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) {}
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);
928
925
  }
929
- };
930
- killProc(uplinkProcess);
931
- killProc(devServerProcess);
926
+ }
932
927
  };
933
928
 
934
929
  let isExiting = false;
@@ -936,20 +931,15 @@ else {
936
931
  async function cleanupAndExit(code = 0) {
937
932
  if (isExiting) return;
938
933
  isExiting = true;
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
-
934
+ console.log('\x1b[33m[Fleetbo] Stopping environment & Cleaning Uplink...\x1b[0m');
945
935
  try {
946
- // 🟢 Timeout ultra-court (1s) pour ne jamais bloquer la sortie
947
- await axios.post(UPDATE_NETWORK_URL, { keyApp, networkUrl: '', tester: testerEmail }, { timeout: 1000 });
936
+ await axios.post(UPDATE_NETWORK_URL, { keyApp, networkUrl: '', tester: testerEmail });
948
937
  console.log('\x1b[32m[Fleetbo] Network status reset to offline.\x1b[0m');
949
938
  } catch (e) {
950
- // On ignore silencieusement si ça échoue, le but principal est de quitter.
939
+ console.error('[Fleetbo] Network cleanup warning:', e.message);
951
940
  }
952
-
941
+ killNetworkService();
942
+ killProcessOnPort(PORT);
953
943
  console.log('[Fleetbo] Bye.');
954
944
  process.exit(code);
955
945
  }
@@ -979,17 +969,17 @@ else {
979
969
  async function runDevEnvironment() {
980
970
  console.log(`[Fleetbo] Initializing Universal Dev Environment...\n`);
981
971
 
982
- killAllServices();
972
+ killNetworkService();
983
973
  killProcessOnPort(PORT);
984
974
 
985
975
  if (!testerEmail) {
986
- console.error('\x1b[31m[Error] VITE_FLEETBO_TESTER_EMAIL missing in .env\x1b[0m');
976
+ console.error('\x1b[31m[Error] FLEETBO_APP_TESTER_EMAIL missing in .env\x1b[0m');
987
977
  process.exit(1);
988
978
  }
989
979
 
990
980
  const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
991
981
 
992
- devServerProcess = spawn(npmCmd, ['run', 'dev', '--silent', '--', '--host', '127.0.0.1', '--port', String(PORT)], {
982
+ const devServer = spawn(`${npmCmd} run dev --silent -- --host 127.0.0.1 --port ${PORT}`, {
993
983
  stdio: ['ignore', 'pipe', 'pipe'],
994
984
  shell: true,
995
985
  env: {
@@ -998,18 +988,15 @@ else {
998
988
  }
999
989
  });
1000
990
 
1001
- devServerProcess.stderr.pipe(process.stderr);
991
+ devServer.stderr.pipe(process.stderr);
1002
992
 
1003
993
  let connectionStarted = false;
1004
994
  let detectedPort = PORT;
1005
-
1006
- let viteBuffer = "";
1007
995
 
1008
- devServerProcess.stdout.on('data', (data) => {
1009
- const chunkText = data.toString();
1010
- viteBuffer += chunkText;
996
+ devServer.stdout.on('data', (data) => {
997
+ const output = data.toString();
1011
998
 
1012
- const lines = chunkText.split('\n');
999
+ const lines = output.split('\n');
1013
1000
  const forbiddenTerms = [
1014
1001
  'Attempting to bind to HOST', 'If this was unintentional', 'Learn more here:',
1015
1002
  'Starting the development server', 'You can now view', 'vite v', 'VITE v', 'Port', 'is in use',
@@ -1025,11 +1012,12 @@ else {
1025
1012
  process.stdout.write(filteredOutput + '\n');
1026
1013
  }
1027
1014
 
1028
- if (!connectionStarted) {
1029
- const portMatch = viteBuffer.match(/http:\/\/(?:localhost|127\.0\.0\.1):(\d+)/);
1015
+ const portMatch = output.match(/http:\/\/(?:localhost|127\.0\.0\.1):(\d+)/);
1030
1016
 
1031
- if (portMatch) {
1032
- detectedPort = portMatch[1];
1017
+ if (portMatch) {
1018
+ detectedPort = portMatch[1];
1019
+
1020
+ if (!connectionStarted) {
1033
1021
  connectionStarted = true;
1034
1022
 
1035
1023
  console.log('\x1b[33mFleetbo OS ❯\x1b[0m ---------------------------------------------------');
@@ -1037,59 +1025,57 @@ else {
1037
1025
  console.log(`\x1b[33mFleetbo OS ❯\x1b[0m Please wait for the green message...`);
1038
1026
  console.log('\x1b[33mFleetbo OS ❯\x1b[0m ---------------------------------------------------\n');
1039
1027
 
1040
- const MAX_UPLINK_RETRIES = 5;
1041
- const RETRY_DELAYS = [0, 10, 20, 30, 45];
1042
- let uplinkFound = false;
1028
+ const MAX_UPLINK_RETRIES = 5;
1029
+ const RETRY_DELAYS = [0, 10, 20, 30, 45];
1030
+ let uplinkFound = false;
1043
1031
 
1044
- const startUplink = (attempt) => {
1032
+ const startUplink = (attempt) => {
1033
+ if (uplinkFound) return;
1034
+
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();
1045
1046
  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
+ };
1046
1055
 
1047
- const npxCmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
1056
+ uplinkProcess.stdout.on('data', handleUplinkOutput);
1057
+ uplinkProcess.stderr.on('data', handleUplinkOutput);
1048
1058
 
1049
- if (attempt > 0) {
1050
- console.log(`\x1b[33m[Fleetbo] Uplink reconnection ${attempt}/${MAX_UPLINK_RETRIES - 1}...\x1b[0m`);
1059
+ uplinkProcess.on('error', () => {
1060
+ if (uplinkFound) return;
1061
+ console.error(`\x1b[31m[Fleetbo] Uplink Connection failed to establish.\x1b[0m`);
1062
+ });
1063
+
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`);
1051
1073
  }
1074
+ });
1075
+ };
1052
1076
 
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
- };
1077
+ startUplink(0);
1091
1078
 
1092
- startUplink(0);
1093
1079
  }
1094
1080
  }
1095
1081
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetbo-cockpit-cli",
3
- "version": "1.0.248",
3
+ "version": "1.0.249",
4
4
  "description": "Fleetbo CLI - Build native mobile apps with React",
5
5
  "author": "Fleetbo",
6
6
  "license": "MIT",