private void OnEnable()
        {
            Selection.selectionChanged += OnSelectionChanged;
            NpmPublishAssetProcessor.PackageImported += PackageImported;

            if (!UpmClientUtils.IsListed)
            {
                UpmClientUtils.ListPackages(() => Refresh(false));
            }
        }
        private void DoPublish()
        {
            var header = $"Npm: {Registry}";
            var msg    = $"Are you really want to publish package {package.name}: {package.version}?";

            if (!EditorUtility.DisplayDialog(header, msg, "Publish", "Cancel"))
            {
                return;
            }

            NpmPublishCommand.Execute(packageAsset, () =>
            {
                //
                UpmClientUtils.ListPackages(() => Refresh(false));
            });
        }
        private void DrawContentPackageJson()
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(package.displayName, Styles.HeaderDisplayNameLabel);
            GUILayout.Label(package.version, Styles.HeaderVersionLabel);
            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Check updates"))
            {
                UpmClientUtils.ListPackages(() => Refresh(false));
            }

            GUILayout.EndHorizontal();
            GUILayout.Label(package.name, Styles.HeaderNameLabel);

            GUILayout.BeginHorizontal();
            GUILayout.Label("Package.json", EditorStyles.boldLabel);
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Open", EditorStyles.miniButton))
            {
                AssetDatabase.OpenAsset(packageAsset);
            }

            GUILayout.EndHorizontal();
            GUILayout.Space(3);

            packageJsonScroll = GUILayout.BeginScrollView(packageJsonScroll, Styles.BigTitle);

            bool dependenciesBlock = false;

            foreach (var line in packageJsonLines)
            {
                if (line.Contains("}"))
                {
                    dependenciesBlock = false;
                }

                if (dependenciesBlock &&
                    ExtractPackageInfoFromJsonLine(line, out string packageName, out string packageVersion))
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(line, Styles.RichNoPaddingLabel);
                    GUILayout.Space(5);
                    DrawDependencyQuickActions(packageName, packageVersion);
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }
Beispiel #4
0
        public static Dictionary <TextAsset, Package> GetAllLocalPackages()
        {
            var toPublish = new Dictionary <TextAsset, Package>();

            try
            {
                var locals = UpmClientUtils.FindLocalPackages();
                foreach (var localAsset in locals)
                {
                    var local = JsonUtility.FromJson <Package>(localAsset.text);
                    toPublish.Add(localAsset, local);
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }

            return(toPublish);
        }
            protected override TreeViewItem BuildRoot()
            {
                var root = new TreeViewItem {
                    id = -1, depth = -1, displayName = "Root"
                };

                var search = searchString.ToLower();

                var children = UpmClientUtils.FindLocalPackages()
                               .Select((packageAsset, index) => new PackageTreeViewItem(index, packageAsset))
                               .Where(item => MatchSearch(item, search))
                               .ToList()
                               .OrderBy(item => item.displayName)
                               .ToList()
                               .Select(item => (TreeViewItem)item)
                               .ToList();

                SetupParentsAndChildrenFromDepths(root, children);

                return(root);
            }
 private void PackageImported()
 {
     UpmClientUtils.ListLocalPackages();
     Refresh(false);
 }
Beispiel #7
0
        public static void UpdateVersionRecursively(TextAsset package, NpmVersion version)
        {
            try
            {
                var localPackages = UpmClientUtils.FindLocalPackages()
                                    .Select(pkg => new
                {
                    package = pkg,
                    json    = (Dictionary <string, object>)MiniJSON.Json.Deserialize(pkg.text),
                })
                                    .ToList();

                var packageJson           = JsonUtility.FromJson <Package>(package.text);
                var packageJsonNewVersion = SemVerHelper.GenerateVersion(packageJson.version, version);

                var newVersions = new Dictionary <string, string>
                {
                    { packageJson.name, packageJsonNewVersion }
                };

                localPackages.Single(o => o.package == package).json["version"] = packageJsonNewVersion;

                var patchInfos = new List <Tuple <string, string, string> >();

                bool dirty = true;
                int  limit = 1000;
                while (dirty && limit-- > 0)
                {
                    dirty = false;
                    foreach (var current in localPackages)
                    {
                        if (!current.json.ContainsKey("dependencies"))
                        {
                            continue;
                        }

                        var currentName     = (string)current.json["name"];
                        var currentVersion  = (string)current.json["version"];
                        var currentDepsJson = (Dictionary <string, object>)current.json["dependencies"];

                        foreach (var newVer in newVersions)
                        {
                            if (!currentDepsJson.ContainsKey(newVer.Key) ||
                                (string)currentDepsJson[newVer.Key] == newVer.Value)
                            {
                                continue;
                            }

                            currentDepsJson[newVer.Key] = newVer.Value;

                            if (!newVersions.ContainsKey(currentName))
                            {
                                var oldVersion = currentVersion;

                                currentVersion          = SemVerHelper.GenerateVersion(currentVersion, NpmVersion.Patch);
                                current.json["version"] = currentVersion;
                                newVersions.Add(currentName, currentVersion);

                                patchInfos.Add(Tuple.Create(currentName, oldVersion, currentVersion));
                            }

                            dirty = true;
                            break;
                        }
                    }
                }

                if (limit == 0)
                {
                    Debug.LogError("UpdateVersionRecursively: Max recursion limit reached");
                    return;
                }

                var nl  = Environment.NewLine;
                var msg = $"Following package version would be updated:" +
                          $"{nl}- {packageJson.name}: {packageJson.version} -> {packageJsonNewVersion}" +
                          $"{nl}" +
                          $"{nl}Following dependent packages would be patched:" +
                          patchInfos.Aggregate("", (s, c) => s + $"{nl}- {c.Item1}: {c.Item2} -> {c.Item3}");

                if (EditorUtility.DisplayDialog("Update versions?", msg, "Update", "Cancel"))
                {
                    foreach (var current in localPackages)
                    {
                        var currentName = (string)current.json["name"];
                        if (!newVersions.ContainsKey(currentName))
                        {
                            continue;
                        }

                        var packageContent = MiniJSON.Json.Serialize(current.json);
                        var path           = AssetDatabase.GetAssetPath(current.package);
                        File.WriteAllText(path, packageContent);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }