Skip to content

Commit

Permalink
Modified package.json generation
Browse files Browse the repository at this point in the history
* Modified package.json generation to allow for creating the file locally in the dev source.
* Modified package source export to overwrite the end destination files.
  • Loading branch information
jzapdot committed Jan 22, 2025
1 parent fb7743b commit 7f07efd
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 14 deletions.
25 changes: 21 additions & 4 deletions Unity/Assets/JCMG/PackageTools/Scripts/Editor/EditorConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,20 @@ internal static class EditorConstants
public const string DEPENDENCY_HEADER_LABEL = "Dependencies";
public const string DEPENDENCY_ELEMENT_LABEL_FORMAT = "Dependency {0}:";

public const string GENERATE_VERSION_CONSTANTS_BUTTON_TEXT = "Generate VersionConstants.cs";
public const string GENERATE_VERSION_CONSTANTS_TOOLTIP = "If an output path is specified, a [VersionConstants.cs] file " +
"will be created containing descriptive information about the " +
"package. This can be output to an Runtime or Editor folder.";
public const string GENERATE_VERSION_CONSTANTS_BUTTON_TEXT
= "Generate VersionConstants.cs.";

public const string GENERATE_VERSION_CONSTANTS_TOOLTIP
= "If an output path is specified, a [VersionConstants.cs] file will be created containing descriptive " +
"information about the package. This can be output to an Runtime or Editor folder.";

public const string GENERATE_VERSION_CONSTANTS_AND_PACKAGE_JSON_BUTTON_TEXT
= "Generate VersionConstants.cs and root package.json file.";

public const string GENERATE_VERSION_CONSTANTS_AND_PACKAGE_JSON_BUTTON_TOOLTIP
= "If an output path is specified, a [VersionConstants.cs] file will be created containing descriptive " +
"information about the package. This can be output to an Runtime or Editor folder. In addition, a " +
"package.json file will be created at the first source folder.";

public const string UPDATE_PACKAGE_BUTTON_TEXT = "Export Package Source";
public const string EXPORT_LEGACY_PACKAGE_BUTTON_TEXT = "Export as Legacy Package";
Expand All @@ -93,11 +103,18 @@ internal static class EditorConstants
public const float FOLDER_PATH_PICKER_HEIGHT = 26f;
public const float FOLDER_PATH_PICKER_BUFFER = 36f;

// Errors
public const string NO_SOURCE_PATH_FOUND_ERROR =
"A single source path must be specified in order to create a package json at that location.";

// Logging
public const string PACKAGE_UPDATE_ERROR_FORMAT =
"[Package Tools] Failed to update package source for [{0}].";

public const string PACKAGE_UPDATE_SUCCESS_FORMAT =
"[Package Tools] Successfully updated package source for [{0}].";

public const string PACKAGE_JSON_UPDATE_SUCCESS_FORMAT =
"[Package Tools] Successfully generated/updated the package.json file at source folder: [{0}].";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,20 @@ public override void OnInspectorGUI()
EditorGUILayout.LabelField(EditorConstants.PACKAGE_ACTIONS_HEADER, EditorStyles.boldLabel);

if (GUILayout.Button(new GUIContent(
EditorConstants.GENERATE_VERSION_CONSTANTS_BUTTON_TEXT,
EditorConstants.GENERATE_VERSION_CONSTANTS_TOOLTIP)))
EditorConstants.GENERATE_VERSION_CONSTANTS_BUTTON_TEXT,
EditorConstants.GENERATE_VERSION_CONSTANTS_TOOLTIP)))
{
CodeGenTools.GenerateVersionConstants(config);
}

if (GUILayout.Button(new GUIContent(
EditorConstants.GENERATE_VERSION_CONSTANTS_AND_PACKAGE_JSON_BUTTON_TEXT,
EditorConstants.GENERATE_VERSION_CONSTANTS_AND_PACKAGE_JSON_BUTTON_TOOLTIP)))
{
FileTools.CreatePackageJsonAtSourceFolder(config);
CodeGenTools.GenerateVersionConstants(config);
}

if (GUILayout.Button(EditorConstants.UPDATE_PACKAGE_BUTTON_TEXT))
{
FileTools.CreateOrUpdatePackageSource(config);
Expand Down
26 changes: 23 additions & 3 deletions Unity/Assets/JCMG/PackageTools/Scripts/Editor/Tools/FileTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ public static void CreateOrUpdatePackageSource(PackageManifestConfig packageMani
var parentDirectoryPath = fileInfo.Directory.FullName;
var newPath = normalizedSourcePath.Replace(parentDirectoryPath, normalizedDestinationPath);

File.Copy(normalizedSourcePath, newPath);
File.Copy(normalizedSourcePath, newPath, overwrite:true);

var sourceMetaPath = string.Format(EditorConstants.META_FORMAT, normalizedSourcePath);
if (File.Exists(sourceMetaPath))
{
var newMetaPath = sourceMetaPath.Replace(parentDirectoryPath, normalizedDestinationPath);
File.Copy(sourceMetaPath, newMetaPath);
File.Copy(sourceMetaPath, newMetaPath, overwrite:true);
}
}
// Otherwise if this is a folder, copy it and all the contents over to the destination folder.
Expand Down Expand Up @@ -170,6 +170,26 @@ public static void CreateOrUpdatePackageSource(PackageManifestConfig packageMani
}
}

/// <summary>
/// Creates a package json file at the first source path in the config.
/// </summary>
public static void CreatePackageJsonAtSourceFolder(PackageManifestConfig packageManifest)
{
if (packageManifest.packageSourcePaths.Length == 0)
{
throw new Exception(EditorConstants.NO_SOURCE_PATH_FOUND_ERROR);
}

var firstSourcePath = packageManifest.packageSourcePaths[0];
var packageJsonAssetPath = Path.Combine(firstSourcePath, EditorConstants.PACKAGE_JSON_FILENAME);
var fullPackageJsonAssetPath = Path.GetFullPath(packageJsonAssetPath);

File.WriteAllText(fullPackageJsonAssetPath, packageManifest.GenerateJson());
AssetDatabase.ImportAsset(packageJsonAssetPath, ImportAssetOptions.ForceUpdate);

Debug.LogFormat(EditorConstants.PACKAGE_JSON_UPDATE_SUCCESS_FORMAT, packageManifest.packageName);
}

/// <summary>
/// Returns true if the <paramref name="path"/> is for a file, otherwise false.
/// </summary>
Expand Down Expand Up @@ -223,7 +243,7 @@ private static void RecursivelyCopyDirectoriesAndFiles(
}

var newPath = Path.GetFullPath(fi.FullName).Replace(normalizedSourcePath, normalizedDestinationPath);
File.Copy(fi.FullName, newPath);
File.Copy(fi.FullName, newPath, overwrite:true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal static class VersionConstants
/// <summary>
/// The semantic version
/// </summary>
public const string VERSION = "1.6.0";
public const string VERSION = "1.6.1";

/// <summary>
/// The branch of GIT this package was published from.
Expand All @@ -42,16 +42,16 @@ internal static class VersionConstants
/// <summary>
/// The current GIT commit hash this package was published on.
/// </summary>
public const string GIT_COMMIT = "fa7d8fd73a599b02b5f3ac9cf0dc34b9e04cc0ab";
public const string GIT_COMMIT = "fb7743b9fd6a885686713cf5cf8d7c5b1b08295b";

/// <summary>
/// The UTC human-readable date this package was published at.
/// </summary>
public const string PUBLISH_DATE = "Thursday, January 2, 2025";
public const string PUBLISH_DATE = "Tuesday, January 21, 2025";

/// <summary>
/// The UTC time this package was published at.
/// </summary>
public const string PUBLISH_TIME = "01/02/2025 19:03:40";
public const string PUBLISH_TIME = "01/21/2025 16:08:14";
}
}
1 change: 1 addition & 0 deletions Unity/Assets/JCMG/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"com.jeffcampbellmakesgames.packagetools","displayName":"JCMG Package Tools","version":"1.6.1","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":""}}
7 changes: 7 additions & 0 deletions Unity/Assets/JCMG/package.json.meta

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

2 changes: 1 addition & 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.6.0
packageVersion: 1.6.1
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 Down
7 changes: 7 additions & 0 deletions Unity/ProjectSettings/MultiplayerManager.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!655991488 &1
MultiplayerManager:
m_ObjectHideFlags: 0
m_EnableMultiplayerRoles: 0
m_StrippingTypes: {}

0 comments on commit 7f07efd

Please sign in to comment.