Esempio n. 1
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);
            }
Esempio n. 3
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);
            }
        }