internal static string GetCIUtilsScript() { var persistentDataPath = Path.GetFullPath(Path.Combine(Application.persistentDataPath, "../../Unity")); var upmTemplateUtilsPath = Path.Combine(persistentDataPath, UpmCIUtilsId); var buildScript = Path.Combine(upmTemplateUtilsPath, "node_modules/upm-ci-utils/index.js"); if (File.Exists(buildScript)) { return(buildScript); } if (!Directory.Exists(upmTemplateUtilsPath)) { Directory.CreateDirectory(upmTemplateUtilsPath); } var launcher = new NodeLauncher(); launcher.NpmLogLevel = "error"; launcher.NpmRegistry = NodeLauncher.BintrayNpmRegistryUrl; launcher.WorkingDirectory = upmTemplateUtilsPath; launcher.NpmPrefix = "."; try { launcher.NpmInstall(UpmCIUtilsId); } catch (ApplicationException exception) { exception.Data["code"] = "installFailed"; throw exception; } return(File.Exists(buildScript) ? buildScript : string.Empty); }
internal static string CreatePackage(string path, string workingDirectory) { //No Need to delete the file, npm pack always overwrite: https://docs.npmjs.com/cli/pack var packagePath = Path.Combine(Path.Combine(Application.dataPath, ".."), path); var launcher = new NodeLauncher(); launcher.WorkingDirectory = workingDirectory; launcher.NpmPack(packagePath); var packageName = launcher.OutputLog.ToString().Trim(); return(packageName); }
internal static List <string> _Pack(string command, string path, string destinationPath) { //Create a copy of the package on the temp folder so that it can be modified var launcher = new NodeLauncher(); launcher.WorkingDirectory = path; launcher.Script = GetCIUtilsScript(); launcher.Args = command + " pack --npm-path \"" + NodeLauncher.NpmScriptPath + "\""; launcher.Launch(); List <string> packagePaths = new List <string>(); var paths = Directory.GetFiles(Path.Combine(path, "upm-ci~", "packages"), "*tgz"); foreach (var packagePath in paths) { //Copy the file to the destinationPath string packageName = Path.GetFileName(packagePath); string finalPackagePath = Path.Combine(destinationPath, packageName); if (File.Exists(finalPackagePath)) { File.Delete(finalPackagePath); } File.Move(packagePath, finalPackagePath); packagePaths.Add(finalPackagePath); } // TODO: Remove this part when we switch to Packman API pack function var packagesJsonPath = Path.Combine(path, "packages.json"); if (File.Exists(packagesJsonPath)) { File.Delete(packagesJsonPath); } //See if upm-ci~ exists and remove if (Directory.Exists(Path.Combine(path, "upm-ci~"))) { Directory.Delete(Path.Combine(path, "upm-ci~"), true); } return(packagePaths); }
internal static string DownloadPackage(string packageId, string workingDirectory) { //No Need to delete the file, npm pack always overwrite: https://docs.npmjs.com/cli/pack var launcher = new NodeLauncher(); launcher.WorkingDirectory = workingDirectory; launcher.NpmRegistry = NodeLauncher.ProductionRepositoryUrl; try { launcher.NpmPack(packageId); } catch (ApplicationException exception) { exception.Data["code"] = "fetchFailed"; throw exception; } var packageName = launcher.OutputLog.ToString().Trim(); return(packageName); }
internal static bool PackageExistsOnProduction(string packageId) { var launcher = new NodeLauncher(); launcher.NpmRegistry = NodeLauncher.ProductionRepositoryUrl; try { launcher.NpmView(packageId); } catch (ApplicationException exception) { if (exception.Message.Contains("npm ERR! code E404") && exception.Message.Contains("is not in the npm registry.")) { return(false); } exception.Data["code"] = "fetchFailed"; throw exception; } var packageData = launcher.OutputLog.ToString().Trim(); return(!string.IsNullOrEmpty(packageData)); }