com.elestrago.unity.package-tools 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CAHNGELOG.md +130 -0
- package/CAHNGELOG.md.meta +7 -0
- package/Documentation~/Inspector.png +0 -0
- package/Documentation~/PackageManifestConfigIcon.png +0 -0
- package/Editor/CIUtils.cs +247 -0
- package/Editor/CIUtils.cs.meta +11 -0
- package/Editor/Drawers/AuthorPropertyDrawer.cs +82 -0
- package/Editor/Drawers/AuthorPropertyDrawer.cs.meta +11 -0
- package/Editor/Drawers/DependencyPropertyDrawer.cs +60 -0
- package/Editor/Drawers/DependencyPropertyDrawer.cs.meta +3 -0
- package/Editor/Drawers/SamplePropertyDrawer.cs +62 -0
- package/Editor/Drawers/SamplePropertyDrawer.cs.meta +3 -0
- package/Editor/Drawers.meta +3 -0
- package/Editor/EditorConstants.cs +110 -0
- package/Editor/EditorConstants.cs.meta +3 -0
- package/Editor/IconMap/PackageManifestConfigIcon.png +0 -0
- package/Editor/IconMap/PackageManifestConfigIcon.png.meta +127 -0
- package/Editor/IconMap.meta +8 -0
- package/Editor/Inspectors/PackageManifestConfigInspector.cs +404 -0
- package/Editor/Inspectors/PackageManifestConfigInspector.cs.meta +3 -0
- package/Editor/Inspectors.meta +3 -0
- package/Editor/MenuItems.cs +11 -0
- package/Editor/MenuItems.cs.meta +11 -0
- package/Editor/PackageManifestConfig.cs +194 -0
- package/Editor/PackageManifestConfig.cs.meta +11 -0
- package/Editor/Playdarium.PackageTool.Editor.asmdef +16 -0
- package/Editor/Playdarium.PackageTool.Editor.asmdef.meta +7 -0
- package/Editor/Tools/CodeGenTools.cs +145 -0
- package/Editor/Tools/CodeGenTools.cs.meta +11 -0
- package/Editor/Tools/CommandLineTools.cs +68 -0
- package/Editor/Tools/CommandLineTools.cs.meta +11 -0
- package/Editor/Tools/FileTools.cs +328 -0
- package/Editor/Tools/FileTools.cs.meta +3 -0
- package/Editor/Tools/GUILayoutTools.cs +177 -0
- package/Editor/Tools/GUILayoutTools.cs.meta +3 -0
- package/Editor/Tools/GitTools.cs +66 -0
- package/Editor/Tools/GitTools.cs.meta +11 -0
- package/Editor/Tools/PackageJsonModel.cs +149 -0
- package/Editor/Tools/PackageJsonModel.cs.meta +3 -0
- package/Editor/Tools/PackageManifestTools.cs +77 -0
- package/Editor/Tools/PackageManifestTools.cs.meta +3 -0
- package/Editor/Tools/UnityFileTools.cs +132 -0
- package/Editor/Tools/UnityFileTools.cs.meta +3 -0
- package/Editor/Tools.meta +3 -0
- package/Editor/Utils/PackageInitialize/PackageInitializeTemplates.cs +171 -0
- package/Editor/Utils/PackageInitialize/PackageInitializeTemplates.cs.meta +3 -0
- package/Editor/Utils/PackageInitialize/PackageInitializeUtil.cs +111 -0
- package/Editor/Utils/PackageInitialize/PackageInitializeUtil.cs.meta +3 -0
- package/Editor/Utils/PackageInitialize/PackageInitializeWindow.cs +92 -0
- package/Editor/Utils/PackageInitialize/PackageInitializeWindow.cs.meta +3 -0
- package/Editor/Utils/PackageInitialize.meta +3 -0
- package/Editor/Utils.meta +3 -0
- package/Editor.meta +3 -0
- package/LICENSE +21 -0
- package/LICENSE.meta +7 -0
- package/README.md +204 -0
- package/README.md.meta +7 -0
- package/package.json +41 -0
- package/package.json.meta +7 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
using System.Collections.Generic;
|
|
2
|
+
using System.Linq;
|
|
3
|
+
using Newtonsoft.Json;
|
|
4
|
+
|
|
5
|
+
namespace Playdarium.PackageTool.Tools
|
|
6
|
+
{
|
|
7
|
+
public class PackageJsonModel
|
|
8
|
+
{
|
|
9
|
+
[JsonProperty("name")] public string Name;
|
|
10
|
+
[JsonProperty("version")] public string Version;
|
|
11
|
+
[JsonProperty("displayName")] public string DisplayName;
|
|
12
|
+
[JsonProperty("description")] public string Description;
|
|
13
|
+
[JsonProperty("category")] public string Category;
|
|
14
|
+
[JsonProperty("unity")] public string Unity;
|
|
15
|
+
[JsonProperty("homepage")] public string Homepage;
|
|
16
|
+
[JsonProperty("documentationUrl")] public string DocumentationUrl;
|
|
17
|
+
[JsonProperty("changelogUrl")] public string ChangelogUrl;
|
|
18
|
+
[JsonProperty("licensesUrl")] public string LicensesUrl;
|
|
19
|
+
[JsonProperty("license")] public string License;
|
|
20
|
+
[JsonProperty("keywords")] public string[] Keywords;
|
|
21
|
+
[JsonProperty("dependencies")] public Dictionary<string, string> Dependencies;
|
|
22
|
+
[JsonProperty("samples")] public Sample[] Samples;
|
|
23
|
+
[JsonProperty("author")] public Author Author;
|
|
24
|
+
[JsonProperty("repository")] public Repository Repository;
|
|
25
|
+
[JsonProperty("bugs")] public Bugs Bugs;
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
public static PackageJsonModel CreateFromManifest(PackageManifestConfig manifest)
|
|
29
|
+
{
|
|
30
|
+
var model = new PackageJsonModel
|
|
31
|
+
{
|
|
32
|
+
Name = manifest.packageName,
|
|
33
|
+
Version = manifest.packageVersion,
|
|
34
|
+
DisplayName = manifest.displayName,
|
|
35
|
+
Description = manifest.description,
|
|
36
|
+
Category = manifest.category,
|
|
37
|
+
Unity = manifest.unityVersion,
|
|
38
|
+
Homepage = manifest.homepage,
|
|
39
|
+
License = manifest.license
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
model.Keywords = manifest.keywords != null && manifest.keywords.Length > 0
|
|
43
|
+
? manifest.keywords
|
|
44
|
+
.Where(k => !string.IsNullOrEmpty(k))
|
|
45
|
+
.Distinct()
|
|
46
|
+
.ToArray()
|
|
47
|
+
: null;
|
|
48
|
+
|
|
49
|
+
model.Author = !string.IsNullOrEmpty(manifest.author.name)
|
|
50
|
+
? new Author(manifest.author.name, manifest.author.email, manifest.author.url)
|
|
51
|
+
: null;
|
|
52
|
+
|
|
53
|
+
model.Dependencies = manifest.dependencies != null && manifest.dependencies.Length > 0
|
|
54
|
+
? manifest.dependencies
|
|
55
|
+
.Where(d => !d.IsEmpty())
|
|
56
|
+
.ToDictionary(d => d.packageName, d => d.packageVersion)
|
|
57
|
+
: null;
|
|
58
|
+
|
|
59
|
+
model.Samples = manifest.samples != null && manifest.samples.Length > 0
|
|
60
|
+
? manifest.samples
|
|
61
|
+
.Where(s => !s.IsEmpty())
|
|
62
|
+
.Select(s => new Sample(s.displayName, s.description, s.path))
|
|
63
|
+
.ToArray()
|
|
64
|
+
: null;
|
|
65
|
+
|
|
66
|
+
if (!string.IsNullOrEmpty(manifest.homepage))
|
|
67
|
+
{
|
|
68
|
+
var homepage = manifest.homepage;
|
|
69
|
+
if (homepage.EndsWith("/"))
|
|
70
|
+
homepage = homepage.Remove(homepage.Length - 2, 1);
|
|
71
|
+
|
|
72
|
+
model.Homepage = homepage;
|
|
73
|
+
model.DocumentationUrl = $"{homepage}/-/blob/main/README.md";
|
|
74
|
+
model.ChangelogUrl = $"{homepage}/-/blob/main/CHANGELOG.md";
|
|
75
|
+
model.LicensesUrl = $"{homepage}/-/blob/main/LICENSE";
|
|
76
|
+
model.Repository = new Repository("git", $"{homepage}.git");
|
|
77
|
+
model.Bugs = new Bugs($"{homepage}/-/issues");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return model;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public class Author
|
|
85
|
+
{
|
|
86
|
+
[JsonProperty("name")] public string Name;
|
|
87
|
+
[JsonProperty("email")] public string Email;
|
|
88
|
+
[JsonProperty("url")] public string URL;
|
|
89
|
+
|
|
90
|
+
public Author()
|
|
91
|
+
{
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public Author(string name, string email, string url)
|
|
95
|
+
{
|
|
96
|
+
Name = name;
|
|
97
|
+
Email = email;
|
|
98
|
+
URL = url;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public class Repository
|
|
103
|
+
{
|
|
104
|
+
[JsonProperty("type")] public string Type;
|
|
105
|
+
[JsonProperty("url")] public string URL;
|
|
106
|
+
|
|
107
|
+
public Repository()
|
|
108
|
+
{
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public Repository(string type, string url)
|
|
112
|
+
{
|
|
113
|
+
Type = type;
|
|
114
|
+
URL = url;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public class Bugs
|
|
119
|
+
{
|
|
120
|
+
[JsonProperty("url")] public string URL;
|
|
121
|
+
|
|
122
|
+
public Bugs()
|
|
123
|
+
{
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public Bugs(string url)
|
|
127
|
+
{
|
|
128
|
+
URL = url;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public class Sample
|
|
133
|
+
{
|
|
134
|
+
[JsonProperty("displayName")] public string DisplayName;
|
|
135
|
+
[JsonProperty("description")] public string Description;
|
|
136
|
+
[JsonProperty("path")] public string Path;
|
|
137
|
+
|
|
138
|
+
public Sample()
|
|
139
|
+
{
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
public Sample(string displayName, string description, string path)
|
|
143
|
+
{
|
|
144
|
+
DisplayName = displayName;
|
|
145
|
+
Description = description;
|
|
146
|
+
Path = path;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2020 Jeff Campbell
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
using System.Collections.Generic;
|
|
26
|
+
using Newtonsoft.Json;
|
|
27
|
+
using UnityEditor;
|
|
28
|
+
|
|
29
|
+
namespace Playdarium.PackageTool.Tools
|
|
30
|
+
{
|
|
31
|
+
/// <summary>
|
|
32
|
+
/// Helper methods for the Package Manifest Tools
|
|
33
|
+
/// </summary>
|
|
34
|
+
internal static class PackageManifestTools
|
|
35
|
+
{
|
|
36
|
+
private static readonly JsonSerializerSettings Settings = new()
|
|
37
|
+
{
|
|
38
|
+
NullValueHandling = NullValueHandling.Ignore,
|
|
39
|
+
DefaultValueHandling = DefaultValueHandling.Ignore
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/// <summary>
|
|
43
|
+
/// Returns a Json <see cref="string"/> representation of the <see cref="PackageManifestConfig"/>
|
|
44
|
+
/// <paramref name="manifest"/>.
|
|
45
|
+
/// </summary>
|
|
46
|
+
/// <param name="manifest"></param>
|
|
47
|
+
/// <returns></returns>
|
|
48
|
+
public static string GenerateJson(PackageManifestConfig manifest)
|
|
49
|
+
{
|
|
50
|
+
var packageJsonModel = PackageJsonModel.CreateFromManifest(manifest);
|
|
51
|
+
return JsonConvert.SerializeObject(packageJsonModel, Formatting.Indented, Settings);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/// <summary>
|
|
55
|
+
/// Retrieves all <see cref="PackageManifestConfig"/> instances in the project.
|
|
56
|
+
/// </summary>
|
|
57
|
+
public static PackageManifestConfig[] GetAllConfigs()
|
|
58
|
+
{
|
|
59
|
+
var assetList = new List<PackageManifestConfig>();
|
|
60
|
+
|
|
61
|
+
const string TYPE_FILTER = "t:PackageManifestConfig";
|
|
62
|
+
|
|
63
|
+
var configGuids = AssetDatabase.FindAssets(TYPE_FILTER);
|
|
64
|
+
foreach (var configGuid in configGuids)
|
|
65
|
+
{
|
|
66
|
+
var assetPath = AssetDatabase.GUIDToAssetPath(configGuid);
|
|
67
|
+
var config = AssetDatabase.LoadAssetAtPath<PackageManifestConfig>(assetPath);
|
|
68
|
+
if (config != null)
|
|
69
|
+
{
|
|
70
|
+
assetList.Add(config);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return assetList.ToArray();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2020 Jeff Campbell
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
using System.Collections.Generic;
|
|
26
|
+
using System.IO;
|
|
27
|
+
using System.Linq;
|
|
28
|
+
using UnityEditor;
|
|
29
|
+
using UnityEngine;
|
|
30
|
+
|
|
31
|
+
namespace Playdarium.PackageTool.Tools
|
|
32
|
+
{
|
|
33
|
+
/// <summary>
|
|
34
|
+
/// Helper methods for dealing with files/directories in the Unity Assets folder.
|
|
35
|
+
/// </summary>
|
|
36
|
+
internal static class UnityFileTools
|
|
37
|
+
{
|
|
38
|
+
/// <summary>
|
|
39
|
+
/// Gather all of the files/folders for the package and export them to the pre-defined location
|
|
40
|
+
/// at <see cref="PackageManifestConfig.legacyPackageDestinationPath"/>.
|
|
41
|
+
/// </summary>
|
|
42
|
+
/// <param name="config"></param>
|
|
43
|
+
public static void CompileLegacyPackage(PackageManifestConfig config)
|
|
44
|
+
{
|
|
45
|
+
FileTools.CopyDocumentationToDirectory(config);
|
|
46
|
+
|
|
47
|
+
// Gathers all of the files/folders for export as a legacy package.
|
|
48
|
+
var assetPaths = new List<string>(GetAllAssetPathsRecursively(config));
|
|
49
|
+
var fileName = string.Format(
|
|
50
|
+
EditorConstants.UNITY_PACKAGE_NAME_FORMAT,
|
|
51
|
+
config.displayName.Replace(EditorConstants.EMPTY_SPACE, EditorConstants.UNDERSCORE),
|
|
52
|
+
config.packageVersion);
|
|
53
|
+
var finalFilePath = Path.GetFullPath(Path.Combine(
|
|
54
|
+
Path.Combine(
|
|
55
|
+
EditorConstants.ProjectPath,
|
|
56
|
+
config.legacyPackageDestinationPath),
|
|
57
|
+
fileName));
|
|
58
|
+
|
|
59
|
+
// Show the UI and kick off the package export.
|
|
60
|
+
if (!Application.isBatchMode)
|
|
61
|
+
{
|
|
62
|
+
EditorUtility.DisplayProgressBar(
|
|
63
|
+
EditorConstants.PROGRESS_BAR_TITLE_LEGACY,
|
|
64
|
+
EditorConstants.COMPILING_PROGRESS_MESSAGE,
|
|
65
|
+
0);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
AssetDatabase.ExportPackage(assetPaths.ToArray(), finalFilePath);
|
|
69
|
+
|
|
70
|
+
if (!Application.isBatchMode)
|
|
71
|
+
{
|
|
72
|
+
EditorUtility.RevealInFinder(finalFilePath);
|
|
73
|
+
EditorUtility.ClearProgressBar();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/// <summary>
|
|
78
|
+
/// Returns a list of relative Unity asset paths contained in
|
|
79
|
+
/// <see cref="PackageManifestConfig.sourcePaths"/> where each path begins with the Assets
|
|
80
|
+
/// folder.
|
|
81
|
+
/// </summary>
|
|
82
|
+
/// <param name="packageManifest"></param>
|
|
83
|
+
/// <returns></returns>
|
|
84
|
+
private static List<string> GetAllAssetPathsRecursively(PackageManifestConfig packageManifest)
|
|
85
|
+
{
|
|
86
|
+
var assetPaths = new List<string>();
|
|
87
|
+
var assetFolder = packageManifest.sourcePath;
|
|
88
|
+
// If any of the paths we're looking at match the ignore paths from the user, skip them
|
|
89
|
+
if (!packageManifest.packageIgnorePaths.Any(x =>
|
|
90
|
+
Path.GetFullPath(Path.Combine(EditorConstants.ProjectPath, assetFolder))
|
|
91
|
+
.Contains(Path.GetFullPath(Path.Combine(EditorConstants.ProjectPath, x)))))
|
|
92
|
+
assetPaths.AddRange(GetAllAssetPathsRecursively(assetFolder, packageManifest));
|
|
93
|
+
|
|
94
|
+
return assetPaths;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// <summary>
|
|
98
|
+
/// Returns a list of relative Unity asset paths contained in <paramref name="assetFolder"/>
|
|
99
|
+
/// where each path begins with the Assets folder.
|
|
100
|
+
/// </summary>
|
|
101
|
+
/// <param name="assetFolder"></param>
|
|
102
|
+
/// <param name="packageManifest"></param>
|
|
103
|
+
/// <returns></returns>
|
|
104
|
+
private static List<string> GetAllAssetPathsRecursively(string assetFolder,
|
|
105
|
+
PackageManifestConfig packageManifest)
|
|
106
|
+
{
|
|
107
|
+
var assetPaths = new List<string>
|
|
108
|
+
{
|
|
109
|
+
assetFolder,
|
|
110
|
+
string.Format(EditorConstants.META_FORMAT, assetFolder)
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
var fullProjectPath = Path.GetFullPath(EditorConstants.ProjectPath);
|
|
114
|
+
|
|
115
|
+
var allFilesFullPaths = FileTools.GetAllFilesRecursively(assetFolder);
|
|
116
|
+
foreach (var fileFullPath in allFilesFullPaths)
|
|
117
|
+
{
|
|
118
|
+
// If any of the paths we're looking at match the ignore paths from the user, skip them
|
|
119
|
+
if (packageManifest.packageIgnorePaths.Any(x =>
|
|
120
|
+
fileFullPath.Contains(Path.GetFullPath(Path.Combine(fullProjectPath, x)))))
|
|
121
|
+
{
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
var relativeAssetPath = fileFullPath.Replace(fullProjectPath, string.Empty);
|
|
126
|
+
assetPaths.Add(relativeAssetPath);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return assetPaths;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
|
|
3
|
+
namespace Playdarium.PackageTool.Utils.PackageInitialize
|
|
4
|
+
{
|
|
5
|
+
public static class PackageInitializeTemplates
|
|
6
|
+
{
|
|
7
|
+
public static string CreateChangelog(string homepage) => @$"# Changelog
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## [v0.0.0]({homepage}/-/tags/v0.0.0)
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- For new features.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- For changes in existing functionality.
|
|
20
|
+
|
|
21
|
+
### Deprecated
|
|
22
|
+
|
|
23
|
+
- For soon-to-be removed features.
|
|
24
|
+
|
|
25
|
+
### Removed
|
|
26
|
+
|
|
27
|
+
- For now removed features.
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
|
|
31
|
+
- For any bug fixes.
|
|
32
|
+
|
|
33
|
+
### Security
|
|
34
|
+
|
|
35
|
+
- In case of vulnerabilities.
|
|
36
|
+
";
|
|
37
|
+
|
|
38
|
+
public static string CreateReadme(
|
|
39
|
+
string authorName,
|
|
40
|
+
string scope,
|
|
41
|
+
string packageName,
|
|
42
|
+
string packageTitle,
|
|
43
|
+
string homepage,
|
|
44
|
+
string license
|
|
45
|
+
)
|
|
46
|
+
{
|
|
47
|
+
return $@"# {packageTitle}
|
|
48
|
+
|
|
49
|
+
[](https://www.npmjs.com/package/{packageName})
|
|
50
|
+
[}-yellow.svg)](https://opensource.org/licenses/{license})
|
|
51
|
+
|
|
52
|
+
## Installing
|
|
53
|
+
|
|
54
|
+
Using the native Unity Package Manager introduced in 2017.2, you can add this library as a package by modifying your
|
|
55
|
+
`manifest.json` file found at `/ProjectName/Packages/manifest.json` to include it as a dependency. See the example below
|
|
56
|
+
on how to reference it.
|
|
57
|
+
|
|
58
|
+
### Install via OpenUPM
|
|
59
|
+
|
|
60
|
+
The package is available on the [npmjs](https://www.npmjs.com/package/{packageName}/)
|
|
61
|
+
registry.
|
|
62
|
+
|
|
63
|
+
#### Add registry scope
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
{{
|
|
67
|
+
""dependencies"": {{
|
|
68
|
+
...
|
|
69
|
+
}},
|
|
70
|
+
""scopedRegistries"": [
|
|
71
|
+
{{
|
|
72
|
+
""name"": ""{authorName}"",
|
|
73
|
+
""url"": ""https://registry.npmjs.org"",
|
|
74
|
+
""scopes"": [
|
|
75
|
+
""{scope}""
|
|
76
|
+
]
|
|
77
|
+
}}
|
|
78
|
+
]
|
|
79
|
+
}}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### Add package in PackageManager
|
|
83
|
+
|
|
84
|
+
Open `Window -> Package Manager` choose `Packages: My Regestries` and install package
|
|
85
|
+
|
|
86
|
+
### Install via GIT URL
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
""{packageName}"": ""{homepage}.git#upm""
|
|
90
|
+
```
|
|
91
|
+
";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public static string CreateLicense(string authorName) => @$"MIT License
|
|
95
|
+
|
|
96
|
+
Copyright (c) {DateTimeOffset.Now.Year} {authorName}
|
|
97
|
+
|
|
98
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
99
|
+
of this software and associated documentation files (the ""Software""), to deal
|
|
100
|
+
in the Software without restriction, including without limitation the rights
|
|
101
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
102
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
103
|
+
furnished to do so, subject to the following conditions:
|
|
104
|
+
|
|
105
|
+
The above copyright notice and this permission notice shall be included in all
|
|
106
|
+
copies or substantial portions of the Software.
|
|
107
|
+
|
|
108
|
+
THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
109
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
110
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
111
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
112
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
113
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
114
|
+
SOFTWARE.";
|
|
115
|
+
|
|
116
|
+
public static string CiScript => @"
|
|
117
|
+
##############################################################
|
|
118
|
+
# #
|
|
119
|
+
# This file is auto generated by Playdarium.PackageTool #
|
|
120
|
+
# #
|
|
121
|
+
##############################################################
|
|
122
|
+
|
|
123
|
+
workflow:
|
|
124
|
+
rules:
|
|
125
|
+
- if: $CI_COMMIT_BRANCH =~ /^main$/
|
|
126
|
+
changes:
|
|
127
|
+
paths:
|
|
128
|
+
- 'Release/package.json'
|
|
129
|
+
when: always
|
|
130
|
+
- when: never
|
|
131
|
+
|
|
132
|
+
stages:
|
|
133
|
+
- deploy
|
|
134
|
+
|
|
135
|
+
deploy-npm:
|
|
136
|
+
stage: deploy
|
|
137
|
+
image: node:lts-alpine
|
|
138
|
+
before_script:
|
|
139
|
+
- |
|
|
140
|
+
export PACKAGE_VERSION=$(grep -o '""version"": ""[^""]*""' ./Release/package.json | awk -F'""' '{print $4}')
|
|
141
|
+
export GIT_URL=https://$GITLAB_USER_NAME:$GITLAB_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git
|
|
142
|
+
- apk update
|
|
143
|
+
- apk add git
|
|
144
|
+
- git config --global user.name ""$GITLAB_USER_NAME""
|
|
145
|
+
- git config --global user.email ""$GITLAB_USER_EMAIL""
|
|
146
|
+
- git clone -b upm $GIT_URL ./upm-package
|
|
147
|
+
script:
|
|
148
|
+
- echo ""Create package version $PACKAGE_VERSION""
|
|
149
|
+
- cd ./upm-package
|
|
150
|
+
- git rm -r *
|
|
151
|
+
- git rm .gitlab-ci.yml || true
|
|
152
|
+
- git rm -rf .idea || true
|
|
153
|
+
- cp -r ../Release/* .
|
|
154
|
+
- git add .
|
|
155
|
+
- git commit -m ""[$PACKAGE_VERSION] GitLab CI auto package publish""
|
|
156
|
+
- git push $GIT_URL upm
|
|
157
|
+
- cd ..
|
|
158
|
+
|
|
159
|
+
- echo ""Push tag v$PACKAGE_VERSION""
|
|
160
|
+
- git tag -a v$PACKAGE_VERSION -m 'GitLab CI auto tag publish'
|
|
161
|
+
- git push --tags $GIT_URL
|
|
162
|
+
|
|
163
|
+
- echo ""Publish to NPM""
|
|
164
|
+
- cd ./upm-package
|
|
165
|
+
- echo ""registry=https://registry.npmjs.org/"" >> "".npmrc""
|
|
166
|
+
- echo ""//registry.npmjs.org/:_authToken=$NPM_TOKEN"" >> "".npmrc""
|
|
167
|
+
- npm publish
|
|
168
|
+
|
|
169
|
+
";
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
using System.IO;
|
|
2
|
+
using UnityEditor;
|
|
3
|
+
using UnityEngine;
|
|
4
|
+
|
|
5
|
+
namespace Playdarium.PackageTool.Utils.PackageInitialize
|
|
6
|
+
{
|
|
7
|
+
public static class PackageInitializeUtil
|
|
8
|
+
{
|
|
9
|
+
public const string ASSETS_FOLDER_NAME = "Assets";
|
|
10
|
+
public const string RELEASE_FOLDER_NAME = "Release";
|
|
11
|
+
|
|
12
|
+
private const string DOCUMENTATION_FOLDER_NAME = "Documentation~";
|
|
13
|
+
|
|
14
|
+
private const string PACKAGE_MANIFEST_FOLDER_NAME = "PackageManifest";
|
|
15
|
+
private const string PACKAGE_MANIFEST_CONFIG_FILE_NAME = "PackageManifestConfig.asset";
|
|
16
|
+
|
|
17
|
+
private const string README_FILE_NAME = "README.md";
|
|
18
|
+
private const string CHANGELOG_FILE_NAME = "CHANGELOG.md";
|
|
19
|
+
private const string LICENSE_FILE_NAME = "LICENSE";
|
|
20
|
+
|
|
21
|
+
private const string CI_FILE_PATH = "./";
|
|
22
|
+
private const string CI_FILE_NAME = ".gitlab-ci.yml";
|
|
23
|
+
|
|
24
|
+
private static readonly string AssetPath = Application.dataPath;
|
|
25
|
+
|
|
26
|
+
private static readonly string ProjectPath = Application.dataPath
|
|
27
|
+
.Replace(ASSETS_FOLDER_NAME, string.Empty)
|
|
28
|
+
.TrimEnd('\\', '/');
|
|
29
|
+
|
|
30
|
+
public static void Init(string scope, PackageManifestConfig config)
|
|
31
|
+
{
|
|
32
|
+
config.sourcePath = Path.Combine(ASSETS_FOLDER_NAME, config.author.name);
|
|
33
|
+
|
|
34
|
+
CreateFolderInProject(config.sourcePath);
|
|
35
|
+
CreateFolderInProject(DOCUMENTATION_FOLDER_NAME);
|
|
36
|
+
CreateFolderInProject(config.packageDestinationPath);
|
|
37
|
+
|
|
38
|
+
CreatePackageManifestConfig(config);
|
|
39
|
+
CreateFileAtPath(
|
|
40
|
+
ProjectPath,
|
|
41
|
+
README_FILE_NAME,
|
|
42
|
+
PackageInitializeTemplates.CreateReadme(config.author.name, scope, config.packageName,
|
|
43
|
+
config.displayName, config.homepage, config.license)
|
|
44
|
+
);
|
|
45
|
+
CreateFileAtPath(ProjectPath, CHANGELOG_FILE_NAME,
|
|
46
|
+
PackageInitializeTemplates.CreateChangelog(config.homepage));
|
|
47
|
+
CreateFileAtPath(ProjectPath, LICENSE_FILE_NAME,
|
|
48
|
+
PackageInitializeTemplates.CreateLicense(config.author.name));
|
|
49
|
+
CreateFileAtPath(Path.Combine(ProjectPath, CI_FILE_PATH), CI_FILE_NAME,
|
|
50
|
+
PackageInitializeTemplates.CiScript);
|
|
51
|
+
|
|
52
|
+
AssetDatabase.Refresh();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private static void CreatePackageManifestConfig(PackageManifestConfig config)
|
|
56
|
+
{
|
|
57
|
+
var packageConfigPath = Path.Combine(Application.dataPath, PACKAGE_MANIFEST_FOLDER_NAME);
|
|
58
|
+
if (!Directory.Exists(packageConfigPath))
|
|
59
|
+
Directory.CreateDirectory(packageConfigPath);
|
|
60
|
+
|
|
61
|
+
var configPath = Path.Combine("Assets", PACKAGE_MANIFEST_FOLDER_NAME, PACKAGE_MANIFEST_CONFIG_FILE_NAME);
|
|
62
|
+
var asset = AssetDatabase.LoadAssetAtPath<PackageManifestConfig>(configPath);
|
|
63
|
+
if (asset != null)
|
|
64
|
+
{
|
|
65
|
+
Debug.Log(
|
|
66
|
+
$"[{nameof(PackageInitializeUtil)}] {nameof(PackageManifestConfig)} already exist at path '{configPath}'");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
AssetDatabase.CreateAsset(config, configPath);
|
|
71
|
+
AssetDatabase.SaveAssets();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public static void CreateFileAtPath(
|
|
75
|
+
string path,
|
|
76
|
+
string fileName,
|
|
77
|
+
string content
|
|
78
|
+
)
|
|
79
|
+
{
|
|
80
|
+
var filePath = Path.Combine(path, fileName);
|
|
81
|
+
if (File.Exists(filePath))
|
|
82
|
+
{
|
|
83
|
+
Debug.Log($"[{nameof(PackageInitializeUtil)}] File already exist '{filePath}'");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!Directory.Exists(path))
|
|
88
|
+
Directory.CreateDirectory(path);
|
|
89
|
+
|
|
90
|
+
File.WriteAllText(filePath, content);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public static void CreateFolderInProject(string directoryPath)
|
|
94
|
+
{
|
|
95
|
+
var dir = Path.Combine(ProjectPath, directoryPath);
|
|
96
|
+
if (Directory.Exists(dir))
|
|
97
|
+
return;
|
|
98
|
+
|
|
99
|
+
Directory.CreateDirectory(dir);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public static void CreateFolderInAssets(string directoryPath)
|
|
103
|
+
{
|
|
104
|
+
var dir = Path.Combine(AssetPath, directoryPath);
|
|
105
|
+
if (Directory.Exists(dir))
|
|
106
|
+
return;
|
|
107
|
+
|
|
108
|
+
Directory.CreateDirectory(dir);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|