samre-cli 1.0.2 → 1.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "samre-cli",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "CLI officiel d'injection automatique du SDK Samré dans les applications mobiles (Flutter, React Native)",
5
5
  "main": "bin/samre.js",
6
6
  "bin": {
@@ -82,8 +82,28 @@ export const FlutterUtil = {
82
82
  modified = importStatement + modified;
83
83
  }
84
84
 
85
- // 2. Tenter d'envelopper builder ou home dans MaterialApp
86
- // Exemple de pattern courant : home: QuelqueChose() -> home: SamreOverlay(child: QuelqueChose())
85
+ // 2. Tenter d'injecter dans builder de MaterialApp (Idéal pour tous les écrans et le routage)
86
+ if (modified.includes('MaterialApp(') && !modified.includes('SamreOverlay')) {
87
+ // Si MaterialApp a déjà une propriété builder
88
+ const builderRegex = /builder\s*:\s*\(([^)]*)\)\s*=>\s*([^,\n;]+)/;
89
+ if (builderRegex.test(modified)) {
90
+ modified = modified.replace(builderRegex, (match, args, body) => {
91
+ return `builder: (${args}) => SamreOverlay(child: ${body.trim()})`;
92
+ });
93
+ fs.writeFileSync(mainPath, modified, 'utf-8');
94
+ return { injected: true, modifiedBuilder: true, backupPath };
95
+ }
96
+
97
+ // Sinon insérer la propriété builder juste après MaterialApp(
98
+ modified = modified.replace(
99
+ /MaterialApp\s*\(/,
100
+ 'MaterialApp(\n builder: (context, child) => SamreOverlay(child: child ?? const SizedBox()),'
101
+ );
102
+ fs.writeFileSync(mainPath, modified, 'utf-8');
103
+ return { injected: true, modifiedBuilder: true, backupPath };
104
+ }
105
+
106
+ // Fallback : injection sur home:
87
107
  const homeRegex = /home\s*:\s*([^,\n\);]+)/;
88
108
  if (homeRegex.test(modified) && !modified.includes('SamreOverlay')) {
89
109
  modified = modified.replace(homeRegex, (match, p1) => {
@@ -93,8 +113,6 @@ export const FlutterUtil = {
93
113
  return { injected: true, modifiedHome: true, backupPath };
94
114
  }
95
115
 
96
- // Si injection automatique du widget home n'a pas pu matcher le pattern exact,
97
- // on sauvegarde le fichier avec l'import et on informe le dev
98
116
  fs.writeFileSync(mainPath, modified, 'utf-8');
99
117
  return { injected: false, importAdded: true, backupPath };
100
118
  },
@@ -121,6 +139,7 @@ export const FlutterUtil = {
121
139
  // Nettoyage manuel si pas de backup
122
140
  let content = fs.readFileSync(mainPath, 'utf-8');
123
141
  content = content.replace(/import\s+['"]samre_sdk\.dart['"];\s*\n?/g, '');
142
+ content = content.replace(/builder\s*:\s*\([^)]*\)\s*=>\s*SamreOverlay\s*\(\s*child\s*:\s*child\s*\?\?\s*const\s*SizedBox\(\)\s*\),?\s*\n?/g, '');
124
143
  content = content.replace(/SamreOverlay\s*\(\s*child\s*:\s*([^)]+)\)/g, '$1');
125
144
  fs.writeFileSync(mainPath, content, 'utf-8');
126
145
  mainRestored = true;