import 'dart:io'; void main(List args) { if (args.isEmpty) { print('Usage: dart transform_links.dart '); return; } File file = File(args[0]); if (!file.existsSync()) { print('File not found: ${args[0]}'); return; } List lines = file.readAsLinesSync(); List 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 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]}'); }