fleetbo-cockpit-cli 1.0.181 → 1.0.183
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 +48 -30
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -120,49 +120,62 @@ const checkGitSecurity = () => {
|
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
const injectRouteIntoAppJs = (moduleName, subPath = '') => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
// 🔍 DÉTERMINATION DU FICHIER CIBLE SELON LE FRAMEWORK
|
|
124
|
+
const targetFile = JS_FRAMEWORK === 'vue'
|
|
125
|
+
? path.join(process.cwd(), 'src', 'router.js') // Cible Vue
|
|
126
|
+
: path.join(process.cwd(), 'src', 'App.jsx'); // Cible React
|
|
127
|
+
|
|
128
|
+
if (!fs.existsSync(targetFile)) {
|
|
129
|
+
console.error(` \x1b[31m[Safety Stop]\x1b[0m ${path.basename(targetFile)} missing.`);
|
|
128
130
|
return false;
|
|
129
131
|
}
|
|
130
132
|
|
|
131
|
-
let content = fs.readFileSync(
|
|
133
|
+
let content = fs.readFileSync(targetFile, 'utf8');
|
|
132
134
|
const importAnchor = '// FLEETBO_MORE_IMPORTS';
|
|
133
|
-
const routeAnchor =
|
|
135
|
+
const routeAnchor = JS_FRAMEWORK === 'vue'
|
|
136
|
+
? '/* FLEETBO_DYNAMIC ROUTES */'
|
|
137
|
+
: '{/* FLEETBO_DYNAMIC ROUTES */}';
|
|
134
138
|
|
|
135
139
|
if (!content.includes(importAnchor) || !content.includes(routeAnchor)) {
|
|
136
|
-
console.log(` \x1b[33m[Skipped]\x1b[0m Anchors missing in
|
|
140
|
+
console.log(` \x1b[33m[Skipped]\x1b[0m Anchors missing in ${path.basename(targetFile)}. Manual injection required.`);
|
|
137
141
|
return false;
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
const cleanSubPath = subPath ? `${subPath}/` : '';
|
|
141
|
-
|
|
142
|
-
|
|
145
|
+
let importLine, routeLine;
|
|
146
|
+
|
|
147
|
+
if (JS_FRAMEWORK === 'vue') {
|
|
148
|
+
// 🟢 SYNTAXE VUE
|
|
149
|
+
importLine = `import ${moduleName} from './app/${cleanSubPath}${moduleName}.vue';`;
|
|
150
|
+
routeLine = `{ path: '/${cleanSubPath}${moduleName.toLowerCase()}', component: ${moduleName} },`;
|
|
151
|
+
} else {
|
|
152
|
+
// 🔵 SYNTAXE REACT
|
|
153
|
+
importLine = `import ${moduleName} from './app/${cleanSubPath}${moduleName}';`;
|
|
154
|
+
routeLine = `<Route path="/${cleanSubPath}${moduleName.toLowerCase()}" element={<${moduleName} />} />`;
|
|
155
|
+
}
|
|
143
156
|
|
|
144
157
|
let modified = false;
|
|
145
158
|
|
|
146
159
|
// 1. Injection de l'import (Capture l'indentation d'origine)
|
|
147
160
|
if (!content.includes(importLine)) {
|
|
148
|
-
const importMatch = content.match(new RegExp(`(\\n[ \\t]*)${importAnchor.replace(/[.*+?^${}()|[
|
|
161
|
+
const importMatch = content.match(new RegExp(`(\\n[ \\t]*)${importAnchor.replace(/[.*+?^${}()|[\\]\\]/g, '\\$&')}`));
|
|
149
162
|
const importIndent = importMatch ? importMatch[1] : '\n';
|
|
150
163
|
content = content.replace(importAnchor, `${importLine}${importIndent}${importAnchor}`);
|
|
151
164
|
modified = true;
|
|
152
165
|
}
|
|
153
|
-
|
|
154
|
-
// 2. Injection de la route (Capture l'indentation d'origine
|
|
166
|
+
|
|
167
|
+
// 2. Injection de la route (Capture l'indentation d'origine)
|
|
155
168
|
if (!content.includes(routeLine)) {
|
|
156
|
-
const routeMatch = content.match(new RegExp(`(\\n[ \\t]*)${routeAnchor.replace(/[.*+?^${}()|[
|
|
169
|
+
const routeMatch = content.match(new RegExp(`(\\n[ \\t]*)${routeAnchor.replace(/[.*+?^${}()|[\\]\\]/g, '\\$&')}`));
|
|
157
170
|
const routeIndent = routeMatch ? routeMatch[1] : '\n';
|
|
158
171
|
content = content.replace(routeAnchor, `${routeLine}${routeIndent}${routeAnchor}`);
|
|
159
172
|
modified = true;
|
|
160
173
|
}
|
|
161
|
-
|
|
174
|
+
|
|
162
175
|
if (modified) {
|
|
163
|
-
fs.writeFileSync(
|
|
176
|
+
fs.writeFileSync(targetFile, content);
|
|
164
177
|
}
|
|
165
|
-
|
|
178
|
+
|
|
166
179
|
return modified;
|
|
167
180
|
};
|
|
168
181
|
|
|
@@ -231,34 +244,39 @@ const getModuleCache = async ({ projectId, moduleName }) => {
|
|
|
231
244
|
};
|
|
232
245
|
|
|
233
246
|
const removeRouteFromAppJs = (moduleName) => {
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if (!fs.existsSync(
|
|
247
|
+
const targetFile = JS_FRAMEWORK === 'vue'
|
|
248
|
+
? path.join(process.cwd(), 'src', 'router.js')
|
|
249
|
+
: path.join(process.cwd(), 'src', 'App.jsx');
|
|
250
|
+
if (!fs.existsSync(targetFile)) return false;
|
|
238
251
|
|
|
239
|
-
let content = fs.readFileSync(
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
252
|
+
let content = fs.readFileSync(targetFile, 'utf8');
|
|
253
|
+
|
|
254
|
+
let importLine, routeLine;
|
|
255
|
+
if (JS_FRAMEWORK === 'vue') {
|
|
256
|
+
importLine = `import ${moduleName} from './app/mocks/${moduleName}.vue';`;
|
|
257
|
+
routeLine = `{ path: '/mocks/${moduleName.toLowerCase()}', component: ${moduleName} },`;
|
|
258
|
+
} else {
|
|
259
|
+
importLine = `import ${moduleName} from './app/mocks/${moduleName}';`;
|
|
260
|
+
routeLine = `<Route path="/mocks/${moduleName.toLowerCase()}" element={<${moduleName} />} />`;
|
|
261
|
+
}
|
|
243
262
|
|
|
244
263
|
const originalContent = content;
|
|
245
|
-
|
|
246
|
-
// On supprime l'import ET le saut de ligne qui le suit
|
|
264
|
+
|
|
247
265
|
const importRegex = new RegExp(`${importLine.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\n?`, 'g');
|
|
248
266
|
content = content.replace(importRegex, '');
|
|
249
267
|
|
|
250
|
-
// On supprime la route ET tous les espaces/sauts de ligne qui la PRÉCÈDENT
|
|
251
268
|
const routeRegex = new RegExp(`\\n?\\s*${routeLine.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`, 'g');
|
|
252
269
|
content = content.replace(routeRegex, '');
|
|
253
270
|
|
|
254
271
|
if (content !== originalContent) {
|
|
255
|
-
fs.writeFileSync(
|
|
256
|
-
console.log(` \x1b[32m[Unrouted]\x1b[0m ${moduleName} removed from
|
|
272
|
+
fs.writeFileSync(targetFile, content);
|
|
273
|
+
console.log(` \x1b[32m[Unrouted]\x1b[0m ${moduleName} removed from ${path.basename(targetFile)}.`);
|
|
257
274
|
return true;
|
|
258
275
|
}
|
|
259
276
|
return false;
|
|
260
277
|
};
|
|
261
278
|
|
|
279
|
+
|
|
262
280
|
// ============================================
|
|
263
281
|
// COMMAND: alex
|
|
264
282
|
// ============================================
|