コード例 #1
0
        /// <summary>
        /// Packages the runtime to `runtime.js`
        /// </summary>
        private static void PackageRuntime(UTinyBuildOptions options, UTinyBuildResults results)
        {
            string buildFolderName;

            switch (options.Configuration)
            {
            case UTinyBuildConfiguration.Debug:
                buildFolderName = "build-js-debug";
                break;

            case UTinyBuildConfiguration.Development:
            case UTinyBuildConfiguration.Release:
                buildFolderName = "build-js-release";
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var runtimeVariant = UTinyBuildPipeline.GetJsRuntimeVariant(options);
            var distFolder     = UTinyBuildPipeline.GetRuntimeDistFolder();
            var runtimeFiles   = new DirectoryInfo(Path.Combine(distFolder.FullName, buildFolderName + "/runtime")).GetFiles(runtimeVariant + "*", SearchOption.TopDirectoryOnly);

            var reportRuntime = results.BuildReport.AddChild(UTinyBuildReport.RuntimeNode);

            foreach (var runtimeFile in runtimeFiles)
            {
                if (runtimeFile.Name.EndsWith(".js.symbols") || runtimeFile.Name.EndsWith(".js.map") || runtimeFile.Name.EndsWith(".dll"))
                {
                    continue;
                }
                var destPath = Path.Combine(results.BinaryFolder.FullName, $"runtime{runtimeFile.Extension}");

                if (runtimeFile.Name == "GeminiRuntime.js")
                {
                    var dependencies = options.Project.Module.Dereference(options.Project.Registry).EnumerateDependencies();
                    var regex        = new System.Text.RegularExpressions.Regex(@"\/\*if\(([\s\S]*?)\)\*\/([\s\S]*?)\/\*endif\(([\s\S]*?)\)\*\/");
                    var runtime      = File.ReadAllText(runtimeFile.FullName);
                    runtime = regex.Replace(runtime, match => match.Groups[match.Groups[1].Value.Split('|').Any(module => dependencies.WithName("UTiny." + module).Any()) ? 2 : 3].Value);
                    File.WriteAllText(destPath, runtime);
                    reportRuntime.AddChild(new FileInfo(destPath));
                }
                else
                {
                    reportRuntime.AddChild(runtimeFile.CopyTo(destPath));
                }
            }
        }