85 lines
3.0 KiB
Dart
85 lines
3.0 KiB
Dart
import 'dart:io';
|
|
|
|
void main() async {
|
|
var sourceDir = Directory("/Users/hamzaaleghwairyeen/development/App");
|
|
var targetDir = Directory("/Users/hamzaaleghwairyeen/development/App/Siro");
|
|
|
|
var mappings = [
|
|
{"src": "Intaleq", "dst": "siro_rider", "old_pkg": "Intaleq", "new_pkg": "siro_rider"},
|
|
{"src": "intaleq_driver", "dst": "siro_driver", "old_pkg": "sefer_driver", "new_pkg": "siro_driver"},
|
|
{"src": "intaleq_admin", "dst": "siro_admin", "old_pkg": "sefer_admin1", "new_pkg": "siro_admin"},
|
|
{"src": "service_intaleq", "dst": "siro_service", "old_pkg": "service", "new_pkg": "siro_service"}
|
|
];
|
|
|
|
for (var m in mappings) {
|
|
var srcPath = "\${sourceDir.path}/\${m['src']}";
|
|
var dstPath = "\${targetDir.path}/\${m['dst']}";
|
|
|
|
// 1. Delete destination lib and assets
|
|
for (var folder in ['lib', 'assets', 'secure_string_operations']) {
|
|
var dFolder = Directory("\$dstPath/\$folder");
|
|
if (dFolder.existsSync()) {
|
|
dFolder.deleteSync(recursive: true);
|
|
}
|
|
}
|
|
|
|
// 2. Copy lib and assets
|
|
for (var folder in ['lib', 'assets', 'secure_string_operations']) {
|
|
var sFolder = Directory("\$srcPath/\$folder");
|
|
var dFolder = Directory("\$dstPath/\$folder");
|
|
if (sFolder.existsSync()) {
|
|
copyDirectorySync(sFolder, dFolder);
|
|
}
|
|
}
|
|
|
|
// 3. Copy pubspec.yaml
|
|
var sPubspec = File("\$srcPath/pubspec.yaml");
|
|
var dPubspec = File("\$dstPath/pubspec.yaml");
|
|
if (sPubspec.existsSync()) {
|
|
sPubspec.copySync(dPubspec.path);
|
|
}
|
|
|
|
// 4. Replace package name in pubspec.yaml
|
|
if (dPubspec.existsSync()) {
|
|
var content = dPubspec.readAsStringSync();
|
|
content = content.replaceAll(RegExp(r"^name:\s*" + m["old_pkg"]! + r"\s*$", multiLine: true), "name: \${m['new_pkg']}");
|
|
dPubspec.writeAsStringSync(content);
|
|
}
|
|
|
|
// 5. Replace imports
|
|
for (var rootFolder in ['lib', 'test']) {
|
|
var rootPath = Directory("\$dstPath/\$rootFolder");
|
|
if (!rootPath.existsSync()) continue;
|
|
|
|
var files = rootPath.listSync(recursive: true).whereType<File>();
|
|
for (var file in files) {
|
|
if (file.path.endsWith('.dart')) {
|
|
try {
|
|
var content = file.readAsStringSync();
|
|
var newContent = content.replaceAll("package:\${m['old_pkg']}/", "package:\${m['new_pkg']}/");
|
|
if (newContent != content) {
|
|
file.writeAsStringSync(newContent);
|
|
}
|
|
} catch (e) {
|
|
print("Error reading \${file.path}: \$e");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
print("Done");
|
|
}
|
|
|
|
void copyDirectorySync(Directory source, Directory destination) {
|
|
destination.createSync(recursive: true);
|
|
for (var entity in source.listSync(recursive: false)) {
|
|
if (entity is Directory) {
|
|
var newDirectory = Directory("\${destination.absolute.path}/\${entity.path.split('/').last}");
|
|
newDirectory.createSync();
|
|
copyDirectorySync(entity.absolute, newDirectory);
|
|
} else if (entity is File) {
|
|
entity.copySync("\${destination.path}/\${entity.path.split('/').last}");
|
|
}
|
|
}
|
|
}
|