Skip to content

Commit

Permalink
Added repository and publish config work
Browse files Browse the repository at this point in the history
* Bumped package version to v1.4.1
  • Loading branch information
jzapdot committed Jan 2, 2025
2 parents bc47510 + e1c7d97 commit fa7d8fd
Show file tree
Hide file tree
Showing 19 changed files with 682 additions and 81 deletions.
33 changes: 18 additions & 15 deletions Unity/.gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# =============== #
# Unity generated #
# =============== #
[Ll]ogs/
[Tt]emp/
[Oo]bj/
[Bb]uild
/[Ll]ibrary/
sysinfo.txt
# =============== #
# Unity generated #
# =============== #
[Bb]in/
[Bb]uild/
[Bb]uilds/
[Oo]bj/
[Ll]ibrary/
[Ll]ogs/
[Tt]emp/
[Rr]ecordings/
[Mm]emoryCaptures/
BuildReports/
UserSettings/
sysinfo.txt
*.stackdump

# JetBrains Plugin
JetBrains/
JetBrains.meta

# ============================================= #
# Visual Studio / MonoDevelop / Rider generated #
Expand All @@ -22,11 +24,12 @@ JetBrains.meta
/*.csproj
/*.pidb
/*.suo
/*.sln*
/*.user
/*.unityproj
/*.booproj
/.idea*/
/.idea*/
**/Editor/JetBrains*
ProjectSettings/RiderScriptEditorPersistedState.asset

# ============ #
# OS generated #
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using UnityEditor;
using UnityEngine;

namespace JCMG.PackageTools.Editor
{
/// <summary>
/// A custom property drawer for <see cref="PackageManifestConfig.PublishConfig"/>.
/// </summary>
[CustomPropertyDrawer(typeof(PackageManifestConfig.PublishConfig))]
internal sealed class PublishConfigPropertyDrawer : PropertyDrawer
{
private const string PUBLISH_CONFIG_REGISTRY_PROPERTY_NAME = "registry";

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var titleRect = new Rect(position)
{
height = EditorGUIUtility.singleLineHeight
};

var registryRect = new Rect(titleRect)
{
position = new Vector2(position.x, titleRect.y + titleRect.height)
};

EditorGUI.LabelField(titleRect, nameof(PackageManifestConfig.PublishConfig), EditorStyles.boldLabel);
EditorGUI.PropertyField(registryRect, property.FindPropertyRelative(PUBLISH_CONFIG_REGISTRY_PROPERTY_NAME));
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUIUtility.singleLineHeight * 2f;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using UnityEditor;
using UnityEngine;

namespace JCMG.PackageTools.Editor
{
/// <summary>
/// A property drawer for <see cref="PackageManifestConfig.Repository"/>.
/// </summary>
[CustomPropertyDrawer(typeof(PackageManifestConfig.Repository))]
internal sealed class RepositoryPropertyDrawer : PropertyDrawer
{
private const string REPOSITORY_TYPE_PROPERTY_NAME = "type";
private const string REPOSITORY_URL_PROPERTY_NAME = "url";
private const string REPOSITORY_DIRECTORY_PROPERTY_NAME = "directory";

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var titleRect = new Rect(position)
{
height = EditorGUIUtility.singleLineHeight
};

var typeRect = new Rect(titleRect)
{
position = new Vector2(position.x, titleRect.y + titleRect.height)
};

var urlRect = new Rect(typeRect)
{
position = new Vector2(position.x, typeRect.y + typeRect.height)
};

var directoryRect = new Rect(typeRect)
{
position = new Vector2(position.x, urlRect.y + urlRect.height)
};

EditorGUI.LabelField(titleRect, nameof(PackageManifestConfig.Repository), EditorStyles.boldLabel);
EditorGUI.PropertyField(typeRect, property.FindPropertyRelative(REPOSITORY_TYPE_PROPERTY_NAME));
EditorGUI.PropertyField(urlRect, property.FindPropertyRelative(REPOSITORY_URL_PROPERTY_NAME));
EditorGUI.PropertyField(directoryRect, property.FindPropertyRelative(REPOSITORY_DIRECTORY_PROPERTY_NAME));
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUIUtility.singleLineHeight * 4f;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ internal sealed class PackageManifestConfigInspector : UnityEditor.Editor
private const string CATEGORY_PROPERTY_NAME = "category";
private const string KEYWORDS_PROPERTY_NAME = "keywords";
private const string DEPENDENCIES_PROPERTY_NAME = "dependencies";
private const string REPOSITORY_PROPERTY_NAME = "repository";
private const string PUBLISH_CONFIG_PROPERTY_NAME = "publishConfig";
private const string AUTHOR_PROPERTY_NAME = "author";
private const string VERSION_CONSTANTS_PATH_PROPERTY_NAME = "versionConstantsPath";
private const string VERSION_TEMPLATE_GUID_PROPERTY_NAME = "versionTemplateGuid";
Expand Down Expand Up @@ -111,6 +113,16 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(serializedObject.FindProperty(CATEGORY_PROPERTY_NAME));
EditorGUILayout.PropertyField(serializedObject.FindProperty(AUTHOR_PROPERTY_NAME));

using (new EditorGUILayout.VerticalScope(EditorConstants.GROUP_BOX))
{
EditorGUILayout.PropertyField(serializedObject.FindProperty(REPOSITORY_PROPERTY_NAME));
}

using (new EditorGUILayout.VerticalScope(EditorConstants.GROUP_BOX))
{
EditorGUILayout.PropertyField(serializedObject.FindProperty(PUBLISH_CONFIG_PROPERTY_NAME));
}

_keywordReorderableList.DoLayoutList();
_dependenciesReorderableList.DoLayoutList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using System;
using System.Security.Policy;
using UnityEngine;

namespace JCMG.PackageTools.Editor
Expand Down Expand Up @@ -51,6 +52,42 @@ public sealed class Dependency
public string packageVersion;
}

/// <summary>
/// Contains the configuration for where the package should be published to.
/// </summary>
[Serializable]
public sealed class PublishConfig
{
/// <summary>
/// The url where the registry is located at.
/// </summary>
public string registry;
}

/// <summary>
/// Contains helpful information for developers where the development of this package is located. See
/// https://docs.npmjs.com/cli/v11/configuring-npm/package-json#repository for more info.
/// </summary>
[Serializable]
public sealed class Repository
{
/// <summary>
/// The type of repository where the
/// </summary>
public string type;
public string url;
public string directory;

/// <summary>
/// Returns true if this has any repository information, otherwise false.
/// </summary>
public bool HasContent()
{
return !string.IsNullOrEmpty(type) &&
!string.IsNullOrEmpty(url);
}
}

/// <summary>
/// Describes the author of this package.
/// </summary>
Expand Down Expand Up @@ -132,6 +169,16 @@ public sealed class Author
/// </summary>
public Dependency[] dependencies;

/// <summary>
/// The publishing config describing where the package is published to.
/// </summary>
public PublishConfig publishConfig;

/// <summary>
/// Contains helpful information for developers where the development of this package is located.
/// </summary>
public Repository repository;

/// <summary>
/// A path to the where the VersionConstants.cs file should be created/updated
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ internal static class PackageManifestTools
private const string AUTHOR_EMAIL = @" ""email"":""{0}""";
private const string AUTHOR_URL = @" ""url"":""{0}""";

// publish config
private const string PUBLISH_CONFIG = @"""publishConfig"":";
private const string REGISTRY_URL = @" ""registry"":""{0}""";

// repository
private const string REPOSITORY = @"""repository"":";
private const string REPOSITORY_TYPE = @" ""type"":""{0}""";
private const string REPOSITORY_URL = @" ""url"":""{0}""";
private const string REPOSITORY_DIRECTORY = @" ""directory"":""{0}""";

static PackageManifestTools()
{
JSON_STRING_BUILDER = new StringBuilder(8192);
Expand Down Expand Up @@ -155,6 +165,34 @@ public static string GenerateJson(PackageManifestConfig packageManifest)
JSON_STRING_BUILDER.Append(CLOSED_BRACES);
}

// Add the publishing config, if present.
if (!string.IsNullOrEmpty(packageManifest.publishConfig.registry))
{
JSON_STRING_BUILDER.Append(COMMA);
JSON_STRING_BUILDER.Append(PUBLISH_CONFIG);
JSON_STRING_BUILDER.Append(OPEN_BRACES);

JSON_STRING_BUILDER.AppendFormat(REGISTRY_URL, packageManifest.publishConfig.registry);

JSON_STRING_BUILDER.Append(CLOSED_BRACES);
}

// Add the repository config, if present.
if (packageManifest.repository.HasContent())
{
JSON_STRING_BUILDER.Append(COMMA);
JSON_STRING_BUILDER.Append(REPOSITORY);
JSON_STRING_BUILDER.Append(OPEN_BRACES);

JSON_STRING_BUILDER.AppendFormat(REPOSITORY_TYPE, packageManifest.repository.type);
JSON_STRING_BUILDER.Append(COMMA);
JSON_STRING_BUILDER.AppendFormat(REPOSITORY_URL, packageManifest.repository.url);
JSON_STRING_BUILDER.Append(COMMA);
JSON_STRING_BUILDER.AppendFormat(REPOSITORY_DIRECTORY, packageManifest.repository.directory);

JSON_STRING_BUILDER.Append(CLOSED_BRACES);
}

JSON_STRING_BUILDER.Append(CLOSED_BRACES);

return JSON_STRING_BUILDER.ToString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"com.jeffcampbellmakesgames.packagetools","displayName":"JCMG Package Tools","version":"1.3.2","unity":"2019.4","description":"Contains a set of Unity development tools to help support exporting and/or updating package contents. \n\nFor more information, see https://github.com/jeffcampbellmakesgames/unity-package-tools for more information.","keywords":["package","package manager"],"category":"Tools","author":{ "name":"Jeff Campbell", "email":"[email protected]", "url":"https://github.com/jeffcampbellmakesgames"}}
{"name":"com.jeffcampbellmakesgames.packagetools","displayName":"JCMG Package Tools","version":"1.6.0","unity":"2019.4","description":"Contains a set of Unity development tools to help support exporting and/or updating package contents. \n\nFor more information, see https://github.com/jeffcampbellmakesgames/unity-package-tools for more information.","keywords":["package","package manager"],"category":"Tools","author":{ "name":"Jeff Campbell", "email":"[email protected]", "url":"https://github.com/jeffcampbellmakesgames"},"publishConfig":{ "registry":"https://npm.pkg.github.com/@jcampbell"},"repository":{ "type":"git", "url":"https://github.com/jeffcampbellmakesgames/unity-package-tools", "directory":""}}
8 changes: 7 additions & 1 deletion Unity/Assets/PackageManifests/PackageManifestConfig.asset
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ MonoBehaviour:
legacyPackageDestinationPath: ../Builds
packageName: com.jeffcampbellmakesgames.packagetools
displayName: JCMG Package Tools
packageVersion: 1.5.1
packageVersion: 1.6.0
unityVersion: 2019.4
description: Contains a set of Unity development tools to help support exporting
and/or updating package contents. \n\nFor more information, see https://github.com/jeffcampbellmakesgames/unity-package-tools
Expand All @@ -34,6 +34,12 @@ MonoBehaviour:
- package
- package manager
dependencies: []
publishConfig:
registry: https://npm.pkg.github.com/@jcampbell
repository:
type: git
url: https://github.com/jeffcampbellmakesgames/unity-package-tools
directory:
versionConstantsPath: Assets/JCMG/PackageTools/Scripts/Editor
versionTemplateGuid: 060df89e9e8e1824095f90e93df5fd29
_id: cb87cda2-0bfa-44dc-b583-ae61ff81efcb
7 changes: 4 additions & 3 deletions Unity/Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"dependencies": {
"com.unity.ide.rider": "1.1.4",
"com.unity.ide.vscode": "1.2.3",
"com.unity.test-framework": "1.1.18",
"com.unity.ide.rider": "3.0.34",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.test-framework": "1.4.5",
"com.unity.modules.accessibility": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
}
}
24 changes: 16 additions & 8 deletions Unity/Packages/packages-lock.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
{
"dependencies": {
"com.unity.ext.nunit": {
"version": "1.0.0",
"version": "2.0.5",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.ide.rider": {
"version": "1.1.4",
"version": "3.0.34",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.test-framework": "1.1.1"
"com.unity.ext.nunit": "1.0.6"
},
"url": "https://packages.unity.com"
},
"com.unity.ide.vscode": {
"version": "1.2.3",
"com.unity.ide.visualstudio": {
"version": "2.0.22",
"depth": 0,
"source": "registry",
"dependencies": {},
"dependencies": {
"com.unity.test-framework": "1.1.9"
},
"url": "https://packages.unity.com"
},
"com.unity.test-framework": {
"version": "1.1.18",
"version": "1.4.5",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ext.nunit": "1.0.0",
"com.unity.ext.nunit": "2.0.3",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.modules.accessibility": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.imgui": {
"version": "1.0.0",
"depth": 1,
Expand Down
Loading

0 comments on commit fa7d8fd

Please sign in to comment.