fleetbo-cockpit-cli 1.0.93 → 1.0.95
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 +30 -19
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -99,9 +99,9 @@ const checkGitSecurity = () => {
|
|
|
99
99
|
const injectRouteIntoAppJs = (moduleName, subPath = '') => {
|
|
100
100
|
const appJsPath = fs.existsSync(path.join(process.cwd(), 'src', 'App.jsx'))
|
|
101
101
|
? path.join(process.cwd(), 'src', 'App.jsx')
|
|
102
|
-
: path.join(process.cwd(), 'src', 'App.
|
|
102
|
+
: path.join(process.cwd(), 'src', 'App.jsx');
|
|
103
103
|
if (!fs.existsSync(appJsPath)) {
|
|
104
|
-
console.error(` \x1b[31m[Safety Stop]\x1b[0m App.
|
|
104
|
+
console.error(` \x1b[31m[Safety Stop]\x1b[0m App.jsx missing.`);
|
|
105
105
|
return false;
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -110,7 +110,7 @@ const injectRouteIntoAppJs = (moduleName, subPath = '') => {
|
|
|
110
110
|
const routeAnchor = '{/* FLEETBO_DYNAMIC ROUTES */}';
|
|
111
111
|
|
|
112
112
|
if (!content.includes(importAnchor) || !content.includes(routeAnchor)) {
|
|
113
|
-
console.log(` \x1b[33m[Skipped]\x1b[0m Anchors missing in App.
|
|
113
|
+
console.log(` \x1b[33m[Skipped]\x1b[0m Anchors missing in App.jsx. Manual injection required.`);
|
|
114
114
|
return false;
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -120,14 +120,22 @@ const injectRouteIntoAppJs = (moduleName, subPath = '') => {
|
|
|
120
120
|
|
|
121
121
|
let modified = false;
|
|
122
122
|
|
|
123
|
+
// 1. Injection de l'import (Capture l'indentation d'origine)
|
|
123
124
|
if (!content.includes(importLine)) {
|
|
124
|
-
|
|
125
|
+
const importMatch = content.match(new RegExp(`(\\n[ \\t]*)${importAnchor.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`));
|
|
126
|
+
const importIndent = importMatch ? importMatch[1] : '\n';
|
|
127
|
+
content = content.replace(importAnchor, `${importLine}${importIndent}${importAnchor}`);
|
|
125
128
|
modified = true;
|
|
126
129
|
}
|
|
130
|
+
|
|
131
|
+
// 2. Injection de la route (Capture l'indentation d'origine, fini les espaces en dur !)
|
|
127
132
|
if (!content.includes(routeLine)) {
|
|
128
|
-
|
|
133
|
+
const routeMatch = content.match(new RegExp(`(\\n[ \\t]*)${routeAnchor.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`));
|
|
134
|
+
const routeIndent = routeMatch ? routeMatch[1] : '\n';
|
|
135
|
+
content = content.replace(routeAnchor, `${routeLine}${routeIndent}${routeAnchor}`);
|
|
129
136
|
modified = true;
|
|
130
137
|
}
|
|
138
|
+
|
|
131
139
|
if (modified) {
|
|
132
140
|
fs.writeFileSync(appJsPath, content);
|
|
133
141
|
}
|
|
@@ -202,24 +210,27 @@ const getModuleCache = async ({ projectId, moduleName }) => {
|
|
|
202
210
|
const removeRouteFromAppJs = (moduleName) => {
|
|
203
211
|
const appJsPath = fs.existsSync(path.join(process.cwd(), 'src', 'App.jsx'))
|
|
204
212
|
? path.join(process.cwd(), 'src', 'App.jsx')
|
|
205
|
-
: path.join(process.cwd(), 'src', 'App.
|
|
213
|
+
: path.join(process.cwd(), 'src', 'App.jsx');
|
|
206
214
|
if (!fs.existsSync(appJsPath)) return false;
|
|
207
215
|
|
|
208
216
|
let content = fs.readFileSync(appJsPath, 'utf8');
|
|
209
217
|
|
|
210
|
-
// Pattern exact pour l'import et la route (gestion du sous-dossier mocks/)
|
|
211
218
|
const importLine = `import ${moduleName} from './app/mocks/${moduleName}';`;
|
|
212
219
|
const routeLine = `<Route path="/mocks/${moduleName.toLowerCase()}" element={<${moduleName} />} />`;
|
|
213
220
|
|
|
214
221
|
const originalContent = content;
|
|
215
222
|
|
|
216
|
-
// On
|
|
217
|
-
|
|
218
|
-
content = content.replace(
|
|
223
|
+
// On supprime l'import ET le saut de ligne qui le suit
|
|
224
|
+
const importRegex = new RegExp(`${importLine.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\n?`, 'g');
|
|
225
|
+
content = content.replace(importRegex, '');
|
|
226
|
+
|
|
227
|
+
// On supprime la route ET tous les espaces/sauts de ligne qui la PRÉCÈDENT
|
|
228
|
+
const routeRegex = new RegExp(`\\n?\\s*${routeLine.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`, 'g');
|
|
229
|
+
content = content.replace(routeRegex, '');
|
|
219
230
|
|
|
220
231
|
if (content !== originalContent) {
|
|
221
232
|
fs.writeFileSync(appJsPath, content);
|
|
222
|
-
console.log(` \x1b[32m[Unrouted]\x1b[0m ${moduleName} removed from App.
|
|
233
|
+
console.log(` \x1b[32m[Unrouted]\x1b[0m ${moduleName} removed from App.jsx.`);
|
|
223
234
|
return true;
|
|
224
235
|
}
|
|
225
236
|
return false;
|
|
@@ -477,13 +488,13 @@ if (command === 'alex') {
|
|
|
477
488
|
};
|
|
478
489
|
|
|
479
490
|
// ============================================================
|
|
480
|
-
// CLI PATCH — startAlexSession (cli.js)
|
|
481
|
-
//
|
|
482
|
-
// Remplace le bloc ENTIER de startAlexSession, depuis :
|
|
483
|
-
// const startAlexSession = async () => {
|
|
484
|
-
// Jusqu'à (NON INCLUS) :
|
|
485
|
-
// const rl = readline.createInterface({
|
|
486
|
-
// ============================================================
|
|
491
|
+
// CLI PATCH — startAlexSession (cli.js)
|
|
492
|
+
//
|
|
493
|
+
// Remplace le bloc ENTIER de startAlexSession, depuis :
|
|
494
|
+
// const startAlexSession = async () => {
|
|
495
|
+
// Jusqu'à (NON INCLUS) :
|
|
496
|
+
// const rl = readline.createInterface({
|
|
497
|
+
// ============================================================
|
|
487
498
|
|
|
488
499
|
const startAlexSession = async () => {
|
|
489
500
|
process.stdout.write('\x1b[33m🛡️ Alex is checking runtime state...\x1b[0m\r');
|
|
@@ -690,7 +701,7 @@ else if (command === 'rm') {
|
|
|
690
701
|
actionsDone++;
|
|
691
702
|
}
|
|
692
703
|
|
|
693
|
-
// 4. Disinfect System Core (App.
|
|
704
|
+
// 4. Disinfect System Core (App.jsx)
|
|
694
705
|
const unrouted = removeRouteFromAppJs(moduleName);
|
|
695
706
|
if (unrouted) actionsDone++;
|
|
696
707
|
|