import 'dart:convert'; import 'dart:io'; import 'package:path/path.dart' as path; void main(List args) async { List val; List val2; final cwd = Directory.current.path; final binSafe = cwd.endsWith("/bin") ? ".." : ""; if (args.isEmpty) { throw ArgumentError("Expected 1-2 arguments but passed none"); } if (args.contains("--local")) { final secretFilePath = path.join(cwd, binSafe, "secrets.json"); final file = File(secretFilePath); if (!file.existsSync()) throw Exception("secrets.json file not found"); final data = jsonDecode(await file.readAsString()); val = List.castFrom(data["LYRICS_SECRET"]); val2 = List.castFrom(data["SPOTIFY_SECRET"]); } else { final decodedLyricSecret = utf8.decode(base64Decode(args.first)); final decodedSpotifySecrete = utf8.decode(base64Decode(args.last)); val = List.castFrom(jsonDecode(decodedLyricSecret)); val2 = List.castFrom(jsonDecode(decodedSpotifySecrete)); } await File(path.join(cwd, binSafe, "lib/models/generated_secrets.dart")) .writeAsString( "final List lyricsSecrets = ${jsonEncode(val)};\nfinal List> spotifySecrets = ${jsonEncode(val2)};", ); }