Ejemplo n.º 1
0
        internal static void CreatePackage(PackageManifest manifest)
        {   
            manifest.OnBeforeSerialize();

            try
            {
                AssetDatabase.StartAssetEditing();
                string PackageFolderName = manifest.package_name;
                string packageFolder = AssetDatabaseUtilities.CreateFolder(AssetDatabaseUtilities.GetRelativeToProjectRoot(Paths.PackagesFolder), PackageFolderName);


                AssemblyDefinition runtime = AssetDatabaseUtilities.CreateAssemblyFolder(packageFolder, Paths.RuntimeFolder, manifest.name, false, false, null);
                AssemblyDefinition editor = AssetDatabaseUtilities.CreateAssemblyFolder(packageFolder, Paths.EditorFolder, manifest.name, false, true, new List<string>{ runtime.name });

                string testFolder = AssetDatabaseUtilities.CreateFolder(packageFolder, Paths.TestFolder);


                AssemblyDefinition runtimeTests = AssetDatabaseUtilities.CreateAssemblyFolder(testFolder, Paths.RuntimeFolder, manifest.name, true, false, new List<string> { runtime.name });
                AssetDatabaseUtilities.CreateAssemblyFolder(testFolder, Paths.EditorFolder, manifest.name, true, true, new List<string> { runtime.name, editor.name });


                AssetDatabaseUtilities.CreateJSONFile(manifest, packageFolder, Paths.PackageManifest);
                AssetDatabaseUtilities.CreateTextFile(CreateReadme(manifest), packageFolder, Paths.Readme);
                AssetDatabaseUtilities.CreateTextFile(CreateLicense(manifest), packageFolder, Paths.License);
                AssetDatabaseUtilities.CreateTextFile(CreateChangelog(manifest), packageFolder, Paths.Changelog);

            }
            finally
            {
                AssetDatabase.StopAssetEditing();
                AssetDatabaseUtilities.UpdateAssetDatabase();
            }

            
        }
Ejemplo n.º 2
0
        internal static AssemblyDefinition CreateAssemblyFolder(string parentFolder, string folderName, string packageName, bool testFolder, bool editor, List <string> references)
        {
            string             name   = packageName + "." + folderName + (testFolder ? ".Tests" : "");
            string             folder = AssetDatabaseUtilities.CreateFolder(parentFolder, folderName);
            AssemblyDefinition def    = new AssemblyDefinition();

            def.name = name;

            if (editor)
            {
                def.includePlatforms.Add("Editor");
            }


            if (references != null)
            {
                def.references.AddRange(references);
            }

            if (testFolder)
            {
                def.optionalUnityReferences.Add("TestAssemblies");
            }

            AssetDatabaseUtilities.CreateJSONFile(def, folder, def.name + Paths.AssemblyDefinitionExtension);

            return(def);
        }
Ejemplo n.º 3
0
        internal static List <PackageManifest> LoadPackages()
        {
            DirectoryInfo packageDirectory = new DirectoryInfo(AssetDatabaseUtilities.GetRelativeToProjectRoot(Paths.PackagesFolder));

            List <PackageManifest> packages = new List <PackageManifest>();

            foreach (DirectoryInfo directory in packageDirectory.EnumerateDirectories())
            {
                string manifestPath = Path.Combine(packageDirectory.ToString(), directory.Name);
                if (File.Exists(Path.Combine(manifestPath, Paths.PackageManifest)))
                {
                    string halodiPackage = AssetDatabaseUtilities.ReadTextFile(manifestPath, Paths.PackageManifest);

                    if (halodiPackage == null)
                    {
                        continue;
                    }
                    else
                    {
                        PackageManifest manifest = JsonUtility.FromJson <PackageManifest>(halodiPackage);
                        manifest.OnAfterDeserialize();
                        manifest.filesystem_location = manifestPath;
                        packages.Add(manifest);
                    }
                }
            }

            return(packages);
        }
Ejemplo n.º 4
0
        internal static void Pack(PackageManifest manifest)
        {
            try
            {
                // Make sure the version information is updated before publishing
                VersionMaintainer.UpdateVersionInformation(true);

                CopySamples(manifest);
                manifest.OnAfterDeserialize();
                string packageFolder = Path.Combine(AssetDatabaseUtilities.GetRelativeToProjectRoot(Paths.PackagesFolder), manifest.package_name);


                string folder = FileUtil.GetUniqueTempPathInProject();


                try
                {
                    string tarballPath = PackageTarball.Create(packageFolder, folder);
                    EditorUtility.RevealInFinder(tarballPath);
                }
                catch (Exception e)
                {
                    EditorUtility.DisplayDialog("Failure", e.Message, "OK");
                }
            }
            finally
            {
                EmptySamplesDirectory(manifest);
            }
        }
Ejemplo n.º 5
0
        static MoveFromAssetsToPackagesFolder()
        {
            string packageText = AssetDatabaseUtilities.ReadTextFile(Application.dataPath, "HalodiPackage.json");

            if (packageText != null)
            {
                HalodiPackage packageDescription = JsonUtility.FromJson <HalodiPackage>(packageText);

                string dir      = Path.Combine(Application.dataPath, packageDescription.PackageFolder);
                string manifest = Path.Combine(dir, Paths.PackageManifest);

                if (File.Exists(manifest))
                {
                    Debug.Log("Found package in Assets/" + packageDescription.PackageFolder + ". Moving to Packages/.");

                    string target = Path.Combine(AssetDatabaseUtilities.GetProjectRoot(), Paths.PackagesFolder);
                    if (!Directory.Exists(target))
                    {
                        Directory.CreateDirectory(target);
                    }

                    string targetPackageFolder = Path.Combine(target, packageDescription.PackageFolder);
                    if (Directory.Exists(targetPackageFolder))
                    {
                        Debug.LogError("Found package " + packageDescription.PackageFolder + " in Assets/, but cannot move to Packages/ because a package with the same directory name already exists.");
                        return;
                    }

                    Directory.Move(dir, targetPackageFolder);
                }
                File.Delete(Path.Combine(Application.dataPath, "HalodiPackage.json"));

                AssetDatabaseUtilities.UpdateAssetDatabase();
            }
        }
Ejemplo n.º 6
0
        internal static void CopySamples(PackageManifest manifest)
        {
            string AssetSampleDirectory = HalodiPackageCreatorController.GetAssetsSampleDirectory(manifest);

            if (Directory.Exists(AssetSampleDirectory))
            {
                EmptySamplesDirectory(manifest);
                string SamplesDirectory = Path.Combine(HalodiPackageCreatorController.GetPackageDirectory(manifest), Paths.PackageSamplesFolder);
                AssetDatabaseUtilities.CopyDirectory(HalodiPackageCreatorController.GetAssetsSampleDirectory(manifest), SamplesDirectory, true);
            }
        }
Ejemplo n.º 7
0
        internal static void Publish(PackageManifest manifest, string registry)
        {
            try
            {
                CopySamples(manifest);

                manifest.OnAfterDeserialize();
                string PackageFolder = Path.Combine(AssetDatabaseUtilities.GetRelativeToProjectRoot(Paths.PackagesFolder), manifest.package_name);

                NPMPublish.Publish(PackageFolder, registry);
            }
            finally
            {
                EmptySamplesDirectory(manifest);
            }
        }
        internal void Store(PackageManifest manifest)
        {
            JObject manifestJSON = JObject.Parse(HalodiPackageCreatorController.GetPackageManifestObject(manifest).text);

            JObject author = new JObject(
                new JProperty("name", manifest.author.name),
                new JProperty("email", manifest.author.email),
                new JProperty("url", manifest.author.url));

            manifestJSON["author"] = author;


            manifestJSON["license"] = manifest.license;

            JObject publicationConfig = new JObject(
                new JProperty("registry", manifest.publishConfig.registry)
                );

            manifestJSON["publishConfig"] = publicationConfig;


            if (string.IsNullOrWhiteSpace(manifest.repository.url))
            {
                manifest.repository.type = "";
            }
            else
            {
                manifest.repository.type = "git";
            }

            JObject repo = new JObject(
                new JProperty("type", manifest.repository.type),
                new JProperty("url", manifest.repository.url)
                );

            manifestJSON["repository"] = repo;



            AssetDatabaseUtilities.CreateTextFile(manifestJSON.ToString(), HalodiPackageCreatorController.GetPackageDirectory(manifest), Paths.PackageManifest);
            AssetDatabaseUtilities.UpdateAssetDatabase();
        }
Ejemplo n.º 9
0
        private static void UpdateManifest(UnityEditor.PackageManager.PackageInfo package)
        {
            JObject manifestJSON = JObject.Parse(AssetDatabaseUtilities.ReadTextFile(Paths.PackagesFolder, Paths.ProjectManifest));

            var dependencies = (JObject)manifestJSON["dependencies"];

            bool   changed = false;
            string changes = "";

            if (dependencies.ContainsKey(package.name))
            {
                string version = dependencies[package.name].ToObject <string>();

                if (SemVer.Parse(version).ToString() == version)
                {
                    if (package.version != version)
                    {
                        changes += "\t" + package.name + "@" + version + "=>" + package.version;

                        dependencies[package.name] = package.version;
                        changed = true;
                    }
                }
            }
            else
            {
                changes += "+\t" + package.name + "@" + package.version;

                JProperty property = new JProperty(package.name, package.version);
                dependencies.Add(property);

                changed = true;
            }
            if (changed)
            {
                AssetDatabaseUtilities.CreateTextFile(manifestJSON.ToString(), Paths.PackagesFolder, Paths.ProjectManifest);
                Debug.Log("Updated project dependencies" + Environment.NewLine + changes);
            }
        }
        internal static AssemblyDefinition CreateAssemblyFolder(string parentFolder, string folderName, string packageName, bool testFolder, bool editor, List <string> references)
        {
            string             name   = packageName + "." + folderName + (testFolder ? ".Tests" : "");
            string             folder = AssetDatabaseUtilities.CreateFolder(parentFolder, folderName);
            AssemblyDefinition def    = new AssemblyDefinition();

            def.name = name;

            if (editor)
            {
                def.includePlatforms.Add("Editor");
            }


            if (references != null)
            {
                def.references.AddRange(references);
            }

            if (testFolder)
            {
                def.optionalUnityReferences.Add("TestAssemblies");
            }


            AssetDatabaseUtilities.CreateJSONFile(def, folder, def.name + Paths.AssemblyDefinitionExtension);

            string AssemblyDefinition = @"
using System.Reflection;

[assembly: AssemblyTitle(""" + def.name + @""")]
[assembly: AssemblyProduct(""" + packageName + @""")]
";

            AssetDatabaseUtilities.CreateTextFile(AssemblyDefinition, folder, "AssemblyInfo.cs");


            return(def);
        }
Ejemplo n.º 11
0
        internal static void AddSample(PackageManifest manifest, PackageManifest.Sample sample)
        {
            string assetDirectory   = GetAssetDirectory(manifest);
            string samplesDirectory = GetAssetsSampleDirectory(manifest);

            if (!sample.path.StartsWith(Paths.PackageSamplesFolder + "/"))
            {
                throw new System.Exception("Invalid sample directory");
            }


            Directory.CreateDirectory(samplesDirectory);

            string sampleFolderName = sample.path.Substring(Paths.PackageSamplesFolder.Length + 1);
            string sampleFolder     = Path.Combine(samplesDirectory, sampleFolderName);

            Directory.CreateDirectory(sampleFolder);
            CreateGitKeep.Create(sampleFolder);



            JObject manifestJSON = JObject.Parse(GetPackageManifestObject(manifest).text);

            var samplesJSON = (JArray)manifestJSON["samples"];


            JObject next = new JObject(
                new JProperty("displayName", sample.displayName),
                new JProperty("description", sample.description),
                new JProperty("path", sample.path));

            samplesJSON.Add(next);


            AssetDatabaseUtilities.CreateTextFile(manifestJSON.ToString(), GetPackageDirectory(manifest), Paths.PackageManifest);
            AssetDatabaseUtilities.UpdateAssetDatabase();
        }
        internal static void EmbedPackageFromGit(PackageManifest manifest)
        {
            string targetDirectory = Path.Combine(AssetDatabaseUtilities.GetRelativeToProjectRoot(Paths.PackagesFolder), manifest.package_name);

            if (File.Exists(targetDirectory))
            {
                Debug.LogWarning("Package directory " + targetDirectory + " already exists");
                return;
            }

            string gitCommand = "clone \"" + manifest.repository.url + "\"" + " " + "\"" + targetDirectory + "\"";

            try
            {
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.FileName               = "git";
                process.StartInfo.Arguments              = gitCommand;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;

                process.OutputDataReceived += StdOut;
                process.ErrorDataReceived  += StdErr;


                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();

                EditorApplication.delayCall += () => EmbedPackageProgress(process, manifest);
            }
            catch (Exception e)
            {
                Debug.Log("Cannot find git executable: " + e.Message);
            }
        }
Ejemplo n.º 13
0
 internal static bool PackageExists(string name)
 {
     return AssetDatabaseUtilities.IsValidFolder(Path.Combine(Paths.PackagesFolder, name));
 }
 private static string GetGroupConfigFile()
 {
     return(Path.Combine(AssetDatabaseUtilities.GetRelativeToProjectRoot(Paths.PackagesFolder), CommonConfig));
 }