Update: 2026-06-11 18:22:57
This commit is contained in:
55
transform_links.dart
Normal file
55
transform_links.dart
Normal file
@@ -0,0 +1,55 @@
|
||||
import 'dart:io';
|
||||
|
||||
void main(List<String> args) {
|
||||
if (args.isEmpty) {
|
||||
print('Usage: dart transform_links.dart <path_to_links.dart>');
|
||||
return;
|
||||
}
|
||||
|
||||
File file = File(args[0]);
|
||||
if (!file.existsSync()) {
|
||||
print('File not found: ${args[0]}');
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> lines = file.readAsLinesSync();
|
||||
List<String> newLines = [];
|
||||
|
||||
for (String line in lines) {
|
||||
// We only want to transform static String declarations inside the class.
|
||||
if (line.trim().startsWith('static String ') || line.trim().startsWith('static final String ') || line.trim().startsWith('static const String ')) {
|
||||
// Don't transform appDomain or if it's already a getter
|
||||
if (line.contains(' get ') || line.contains('appDomain')) {
|
||||
newLines.add(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
String modified = line;
|
||||
// Remove 'final ' and 'const ' since getters can't be final/const
|
||||
modified = modified.replaceAll('static final String ', 'static String ');
|
||||
modified = modified.replaceAll('static const String ', 'static String ');
|
||||
|
||||
// Replace '=' with '=>' and remove ';' to add it later?
|
||||
// Actually, it's easier: `static String X = Y;` -> `static String get X => Y;`
|
||||
int eqIndex = modified.indexOf('=');
|
||||
if (eqIndex != -1) {
|
||||
String beforeEq = modified.substring(0, eqIndex).trimRight(); // e.g. "static String paymentServer"
|
||||
String afterEq = modified.substring(eqIndex + 1); // e.g. " 'https://...';"
|
||||
|
||||
// Insert 'get ' before the variable name
|
||||
List<String> parts = beforeEq.split(' ');
|
||||
String varName = parts.last;
|
||||
parts.removeLast();
|
||||
beforeEq = parts.join(' ') + ' get ' + varName;
|
||||
|
||||
modified = beforeEq + ' =>' + afterEq;
|
||||
}
|
||||
newLines.add(modified);
|
||||
} else {
|
||||
newLines.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
file.writeAsStringSync(newLines.join('\n'));
|
||||
print('Transformed ${args[0]}');
|
||||
}
|
||||
Reference in New Issue
Block a user