private void OnEnable() { target = this; serializedObject = new SerializedObject(target); packageManifest = PackageSettings.Manifest; Refresh(); }
public static string CreateLicenseText(string licenseText, PackageManifest packageManifest) { var licenseBuilder = new StringBuilder(licenseText); licenseBuilder.Replace("{DATE.YEAR}", DateTime.Now.Year.ToString()); licenseBuilder.Replace("{AUTHOR.NAME}", packageManifest.author.name); return(licenseBuilder.ToString()); }
private bool ValidatePackageManifest(PackageManifest manifest) { string error = null; if (string.IsNullOrEmpty(manifest.description)) { error = "Package Description Required"; } else if (string.IsNullOrEmpty(manifest.version)) { error = "Package Version Required"; } else if (string.IsNullOrEmpty(manifest.repositoryName)) { error = "Package Repository Name Required"; } else if (string.IsNullOrEmpty(manifest.displayName)) { error = "Package display Name Required"; } else if (string.IsNullOrEmpty(manifest.name)) { error = "Package Name Required"; } else if (string.IsNullOrEmpty(manifest.author.github)) { error = "Github username required to build github links"; } if (!string.IsNullOrEmpty(error)) { EditorUtility.DisplayDialog("Error", error, "OK"); EditorApplication.Beep(); return(false); } return(true); }
private async void UpdateReadme(PackageInfo packageInfo) { var myPkg = await GetMyPackageInfoAsync(); var readmeTemplatePath = $"{myPkg.assetPath}/Template/README_TEMPLATE.md"; var readmePath = $"{packageInfo.assetPath}/README"; if (!File.Exists(readmePath)) { readmePath = $"{packageInfo.assetPath}/README.md"; if (!File.Exists(readmePath)) { Debug.LogError("Unable to find README or README.md at package asset path"); return; } } var manifestPath = $"{packageInfo.assetPath}/package.json"; if (!File.Exists(manifestPath)) { Debug.LogError($"Unable to find package.json at {packageInfo.assetPath}"); return; } PackageManifest packageManifest = null; try { packageManifest = JsonUtility.FromJson <PackageManifest>(File.ReadAllText(manifestPath)); if (packageManifest == null) { Debug.LogError("Failed to read package manifest. FromJson returned null on file text."); return; } } catch (Exception e) { Debug.LogError("Failed to read package manifest format."); Debug.LogException(e); return; } if (!ValidatePackageManifest(packageManifest)) { Debug.LogError("Update package manifest with required values before updating the readme"); return; } var oldText = File.ReadAllText(readmePath); var templateText = File.ReadAllText(readmeTemplatePath); templateText = PackageUtility.PatchReadmeText(oldText, templateText); var readmeText = PackageUtility.CreateReadmeText(templateText, packageManifest); File.WriteAllText(readmePath, readmeText); EditorUtility.DisplayDialog("Update Readme", "Done", "OK"); }
private void MaintainPackageGUI() { EditorGUI.BeginChangeCheck(); selectedPackageIndex = EditorGUILayout.Popup("Package", selectedPackageIndex, packageNames); if (EditorGUI.EndChangeCheck()) { //Index Changed maintainPackageManifest = null; } //Validate index if (selectedPackageIndex < 0 || selectedPackageIndex >= embededPackages.Count) { return; } var package = embededPackages[selectedPackageIndex]; //Need to get the json for the package if (maintainPackageManifest == null) { var json = File.ReadAllText($"{package.assetPath}/package.json"); maintainPackageManifest = JsonUtility.FromJson <PackageManifest>(json); } var rect = EditorGUILayout.BeginVertical("box"); EditorGUILayout.LabelField("Name", package.name); EditorGUILayout.LabelField("DisplayName", package.displayName); EditorGUILayout.LabelField("Source", package.source.ToString()); EditorGUILayout.LabelField("Asset Path", package.assetPath); EditorGUILayout.LabelField("Resolved Path", package.resolvedPath); EditorGUILayout.LabelField("Type", package.type); EditorGUILayout.LabelField("Version", package.version); EditorGUILayout.LabelField("Status", package.status.ToString()); EditorGUILayout.EndVertical(); if (Event.current.type == EventType.MouseUp && Event.current.button == 0 && rect.Contains(Event.current.mousePosition)) { var asset = AssetDatabase.LoadAssetAtPath <TextAsset>($"{package.assetPath}/package.json"); Selection.activeObject = asset; } EditorGUILayout.BeginVertical("box"); maintainPackageManifest.repositoryName = EditorGUILayout.TextField("RepositoryName", maintainPackageManifest.repositoryName); maintainPackageManifest.author.name = EditorGUILayout.TextField("Author Name", maintainPackageManifest.author.name); maintainPackageManifest.author.email = EditorGUILayout.TextField("Author E-Mail", maintainPackageManifest.author.email); maintainPackageManifest.author.url = EditorGUILayout.TextField("Author URL", maintainPackageManifest.author.url); maintainPackageManifest.author.twitter = EditorGUILayout.TextField("Twitter", maintainPackageManifest.author.twitter); maintainPackageManifest.author.github = EditorGUILayout.TextField("GitHub", maintainPackageManifest.author.github); var linkStyle = new GUIStyle(EditorStyles.label); linkStyle.wordWrap = false; linkStyle.hover.textColor = new Color(0x00 / 255f, 0x78 / 255f, 0xDA / 255f, 1f); linkStyle.normal.textColor = new Color(0, 0, 1); if (!string.IsNullOrEmpty(maintainPackageManifest.author.twitter)) { var twitterUrl = PackageUtility.TwitterUrl(maintainPackageManifest.author.twitter); if (GUILayout.Button(twitterUrl, linkStyle)) { Application.OpenURL(twitterUrl); } } if (!string.IsNullOrEmpty(maintainPackageManifest.author.github)) { var githubUrl = PackageUtility.GithubUrl(maintainPackageManifest.author.github); if (GUILayout.Button(githubUrl, linkStyle)) { Application.OpenURL(githubUrl); } var packageUrl = PackageUtility.PackageUrl(maintainPackageManifest.author.github, maintainPackageManifest.repositoryName, maintainPackageManifest.version); if (GUILayout.Button(packageUrl, linkStyle)) { Application.OpenURL(packageUrl); } } EditorGUILayout.EndVertical(); if (GUILayout.Button("Update package.json")) { var path = $"{package.assetPath}/package.json"; var json = File.ReadAllText(path); var jsonNode = SimpleJSON.JSON.Parse(json); jsonNode["repositoryName"] = maintainPackageManifest.repositoryName; jsonNode["author"]["name"] = maintainPackageManifest.author.name; jsonNode["author"]["email"] = maintainPackageManifest.author.email; jsonNode["author"]["url"] = maintainPackageManifest.author.url; jsonNode["author"]["github"] = maintainPackageManifest.author.github; jsonNode["author"]["twitter"] = maintainPackageManifest.author.twitter; File.WriteAllText(path, jsonNode.ToString()); maintainPackageManifest = null; } if (GUILayout.Button("Update Readme")) { UpdateReadme(package); } RefreshGUI(); }