Beispiel #1
0
        public static void GenerateVersionConstants(PackageManifestConfig config)
        {
            if (string.IsNullOrEmpty(config.versionConstantsPath))
            {
                Debug.LogWarning(NO_PATH_SPECIFIED);
                return;
            }

            // Create folder/file path info
            var folderPath = Path.GetFullPath(config.versionConstantsPath);
            var filePath   = Path.Combine(folderPath, FILENAME);

            // Create file contents
            var template = string.IsNullOrEmpty(config.versionConstantsNamespace)
                                ? GLOBAL_TEMPLATE
                                : TEMPLATE;

            var fileContents = template
                               .Replace("${namespace}", config.versionConstantsNamespace)
                               .Replace("${version}", config.packageVersion)
                               .Replace("${git_branch}", GitTools.GetBranch())
                               .Replace("${git_commit}", GitTools.GetLongHeadHash())
                               .Replace("${publish_date}", DateTime.UtcNow.ToLongDateString())
                               .Replace("${publish_utc_time}", DateTime.UtcNow.ToString(CultureInfo.InvariantCulture));

            File.WriteAllText(filePath, fileContents);

            var importPath = Path.Combine(config.versionConstantsPath, FILENAME);

            AssetDatabase.ImportAsset(importPath);
        }
Beispiel #2
0
        public static void GenerateVersionConstants(PackageManifestConfig config)
        {
            if (string.IsNullOrEmpty(config.versionConstantsPath))
            {
                Debug.LogWarning(NO_PATH_SPECIFIED);
                return;
            }

            // Create folder/file path info
            var folderPath = Path.GetFullPath(config.versionConstantsPath);
            var filePath   = Path.Combine(folderPath, FILENAME);

            // Create file contents. If we have a user-supplied template
            string template;

            if (!string.IsNullOrEmpty(config.versionTemplateGuid))
            {
                var assetPath = AssetDatabase.GUIDToAssetPath(config.versionTemplateGuid);
                template = AssetDatabase.LoadAssetAtPath <TextAsset>(assetPath).text;
            }
            else if (string.IsNullOrEmpty(AssetDatabase.GUIDToAssetPath(VERSION_CONSTANTS_TEMPLATE_GUID)))
            {
                var assetPath = AssetDatabase.GUIDToAssetPath(VERSION_CONSTANTS_TEMPLATE_GUID);
                template = AssetDatabase.LoadAssetAtPath <TextAsset>(assetPath).text;
            }
            else
            {
                throw new FileNotFoundException(NO_TEMPLATE_SPECIFIED);
            }

            var fileContents = template
                               .Replace("${version}", config.packageVersion)
                               .Replace("${git_branch}", GitTools.GetBranch())
                               .Replace("${git_commit}", GitTools.GetLongHeadHash())
                               .Replace("${publish_date}", DateTime.UtcNow.ToLongDateString())
                               .Replace("${publish_utc_time}", DateTime.UtcNow.ToString(CultureInfo.InvariantCulture));

            Debug.LogFormat(WRITE_FILE_LOG_FORMAT, config.versionConstantsPath);

            File.WriteAllText(filePath, fileContents);

            var importPath = Path.Combine(config.versionConstantsPath, FILENAME);

            AssetDatabase.ImportAsset(importPath);
        }