private static async Task Main(string[] args) { if (args.Length == 0) { PrintError("Pass the command as an argument"); return; } var appDataFolder = GetAppDataFolder(); if (!string.IsNullOrEmpty(appDataFolder)) { Directory.CreateDirectory(appDataFolder); } Directory.CreateDirectory("tmp"); var command = args[0]; switch (command) { case "install": Directory.CreateDirectory("libs"); Directory.CreateDirectory("extensions"); _projectPackage = JsonConvert.DeserializeObject <Package>(await File.ReadAllTextAsync("air_package.json")); PackageResolved.Load(); GetManifestMerger(); LoadAppDescriptor(); await Install(); break; case "clear-config": await ClearConfig(); break; case "clear-cache": if (!string.IsNullOrEmpty(appDataFolder)) { Directory.Delete(appDataFolder, true); Directory.CreateDirectory(appDataFolder); } break; case "apply-firebase-config": if (args.Length < 2) { PrintError( "You need to pass the path to the google-services.json file after `apply-firebase-config`."); return; } await ApplyFirebaseConfig(args[1]); break; case "convert-firebase-config": if (args.Length < 2) { PrintError( "You need to pass the path to the google-services.json file after `convert-firebase-config`."); return; } await ConvertFirebaseConfig(args[1]); break; case "add-raw-asset": if (args.Length < 2) { PrintError("You need to pass the path to the file after `add-raw-asset`."); return; } await AddRawAsset(args[1]); break; case "create-assets-car": if (args.Length < 2) { PrintError( "You need to pass the path to the 1024x1024px png file."); return; } await AssetsCar.Create(args[1]); break; default: PrintError("Command not recognized."); break; } Directory.Delete("tmp", true); }
private static async Task ParseDependencies(Package package) { foreach (var(packageId, value) in package.Dependencies) { if (value.StartsWith("http")) { try { await DownloadDependency(value); await ProcessDependency(packageId, GetFileNameFromUrl(value)); } catch (Exception e) { PrintError($"{e.Message} - {e.InnerException?.Message}"); } } else if (value.StartsWith("file:")) { var path = value.Replace("file:", ""); var fn = Path.GetFileName(path); var fileType = Path.GetExtension(fn); var outputFolder = fileType switch { ".ane" => "extensions", ".swc" => "libs", _ => "" }; if (Path.GetFullPath(path) != Path.Combine(CurrentDirectory, outputFolder, fn)) { File.Copy(path, Path.Combine(outputFolder, fn)); } await ProcessDependency(packageId, GetFileNameFromUrl(value)); } else { var repoUrl = package.Repository["url"]; if (string.IsNullOrEmpty(repoUrl)) { PrintError( $"The {packageId} package file references versioned dependencies but has no repository url"); return; } if (!RepositoryDict.ContainsKey(repoUrl)) { var client = new HttpClient(); RepositoryDict[repoUrl] = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, string> > >( await client.GetStringAsync(new Uri(repoUrl))); } var packages = RepositoryDict[repoUrl]; if (!packages.ContainsKey(packageId)) { PrintError($"Cannot find package for: {packageId}"); return; } if (!packages[packageId].ContainsKey(value)) { PrintError($"Cannot find url for: {packageId} {value}"); return; } var url = packages[packageId][value]; if (PackageResolved.IsCurrent(packageId, value)) { PrintInfo($"Using existing version of {packageId} version {value}"); } else { var previousVersion = PackageResolved.PreviousVersion(packageId); if (!string.IsNullOrEmpty(previousVersion)) { var previousUrl = packages[packageId][previousVersion]; var previousFileName = GetFileNameFromUrl(previousUrl); var fileType = Path.GetExtension(previousFileName); var outputFolder = fileType switch { ".ane" => "extensions", ".swc" => "libs", _ => "" }; var previousFilePath = Path.Combine(outputFolder, previousFileName); if (!string.IsNullOrEmpty(previousFileName) && File.Exists(previousFilePath)) { File.Delete(previousFilePath); } PrintInfo($"Upgrading: {packageId} from {previousVersion} to {value}"); } try { var fileName = GetFileNameFromUrl(url); var fileType = Path.GetExtension(fileName); if (!string.IsNullOrEmpty(GetAppDataFolder())) // hasAppDataFolder { if (!File.Exists(Path.Combine(GetAppDataFolder(), packageId, value, fileName))) { await DownloadDependencyToShared(url, packageId, value); } var outputFolder = fileType switch { ".ane" => "extensions", ".swc" => "libs", _ => "" }; PrintInfo($"Using cached AppData version of {packageId} version {value}"); File.Copy(Path.Combine(GetAppDataFolder(), packageId, value, fileName), Path.Combine(outputFolder, fileName), true); } else { await DownloadDependency(url); } PackageResolved.Update(packageId, value); PackageResolved.Save(); } catch (Exception e) { PrintError($"{e.Message} - {e.InnerException?.Message}"); } } await ProcessDependency(packageId, GetFileNameFromUrl(url)); } } }