|
| 1 | +import 'dart:io'; |
| 2 | +import 'dart:convert'; |
| 3 | + |
| 4 | +Future<void> copyFile(String source, String destination) async { |
| 5 | + try { |
| 6 | + final sourceFile = File(source); |
| 7 | + final destinationFile = File(destination); |
| 8 | + |
| 9 | + if (await destinationFile.exists()) { |
| 10 | + print('Overwriting existing file: $destination'); |
| 11 | + await destinationFile.delete(); |
| 12 | + } |
| 13 | + |
| 14 | + await sourceFile.copy(destination); |
| 15 | + print('Successfully copied: $destination'); |
| 16 | + } catch (e) { |
| 17 | + throw 'Failed to copy $source to $destination: $e'; |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +Future<void> main() async { |
| 22 | + try { |
| 23 | + // Check if .keys-n-stuff directory exists |
| 24 | + final keysDir = Directory('.keys-n-stuff'); |
| 25 | + |
| 26 | + // Read the keys-n-stuff.json file |
| 27 | + final configFile = File('keys-n-stuff.json'); |
| 28 | + if (!await configFile.exists()) { |
| 29 | + throw 'Configuration file not found'; |
| 30 | + } |
| 31 | + |
| 32 | + final config = jsonDecode(await configFile.readAsString()); |
| 33 | + final String projectDir = config['dir']; |
| 34 | + final String projectType = config['type']; |
| 35 | + final String repo = config['repo']; |
| 36 | + |
| 37 | + print('Project directory: $projectDir'); |
| 38 | + print('Project type: $projectType'); |
| 39 | + print('Repository: $repo'); |
| 40 | + |
| 41 | + if (await keysDir.exists()) { |
| 42 | + print('Repository already exists, pulling latest changes...'); |
| 43 | + final pullResult = |
| 44 | + await Process.run('git', ['pull'], workingDirectory: '.keys-n-stuff'); |
| 45 | + |
| 46 | + if (pullResult.exitCode != 0) { |
| 47 | + throw 'Failed to pull repository: ${pullResult.stderr}'; |
| 48 | + } |
| 49 | + print('Successfully pulled latest changes'); |
| 50 | + } else { |
| 51 | + print('Cloning repository...'); |
| 52 | + final cloneResult = |
| 53 | + await Process.run('git', ['clone', repo, '.keys-n-stuff']); |
| 54 | + |
| 55 | + if (cloneResult.exitCode != 0) { |
| 56 | + throw 'Failed to clone repository: ${cloneResult.stderr}'; |
| 57 | + } |
| 58 | + print('Successfully cloned repository'); |
| 59 | + } |
| 60 | + |
| 61 | + if (projectType == 'flutter') { |
| 62 | + // Create necessary directories |
| 63 | + await Directory('android/app').create(recursive: true); |
| 64 | + await Directory('ios/Runner').create(recursive: true); |
| 65 | + await Directory('macos/Runner').create(recursive: true); |
| 66 | + |
| 67 | + // Copy Firebase config files |
| 68 | + // Android |
| 69 | + await copyFile('.keys-n-stuff/$projectDir/google-services.json', |
| 70 | + 'android/app/google-services.json'); |
| 71 | + |
| 72 | + // iOS |
| 73 | + await copyFile('.keys-n-stuff/$projectDir/GoogleService-Info.plist', |
| 74 | + 'ios/Runner/GoogleService-Info.plist'); |
| 75 | + |
| 76 | + // macOS |
| 77 | + await copyFile('.keys-n-stuff/$projectDir/GoogleService-Info.plist', |
| 78 | + 'macos/Runner/GoogleService-Info.plist'); |
| 79 | + |
| 80 | + // Copy keystore properties file to android root |
| 81 | + await copyFile('.keys-n-stuff/$projectDir/prod.properties', |
| 82 | + 'android/prod.properties'); |
| 83 | + |
| 84 | + // Copy keystore file to android/app |
| 85 | + final keystoreFile = File('.keys-n-stuff/$projectDir/prod.jks'); |
| 86 | + if (await keystoreFile.exists()) { |
| 87 | + await copyFile( |
| 88 | + '.keys-n-stuff/$projectDir/prod.jks', 'android/app/prod.jks'); |
| 89 | + } |
| 90 | + |
| 91 | + print( |
| 92 | + 'Successfully copied all configuration files to their respective directories'); |
| 93 | + } else { |
| 94 | + throw 'Unsupported project type: $projectType'; |
| 95 | + } |
| 96 | + |
| 97 | + print('Setup completed successfully'); |
| 98 | + } catch (e) { |
| 99 | + print('Error: $e'); |
| 100 | + exit(1); |
| 101 | + } |
| 102 | +} |
0 commit comments