Skip to content

Commit 43c9413

Browse files
committed
chore: unify config files creation
1 parent b7d2c5a commit 43c9413

File tree

1 file changed

+37
-24
lines changed

1 file changed

+37
-24
lines changed

src/Uno.Wasm.Bootstrap/ShellTask.cs

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ public override bool Execute()
155155
BuildServiceWorkers();
156156
GenerateEmbeddedJs();
157157
GenerateIndexHtml();
158-
GenerateConfig();
159-
GenerateConfigScript();
158+
GenerateConfigFiles();
160159
RemoveDuplicateAssets();
161160
}
162161
finally
@@ -533,9 +532,9 @@ static string BuildDependencyPath(string dep, string baseLookup)
533532
? $"\"{baseLookup}{Path.GetFileName(dep)}\""
534533
: $"\"{baseLookup}{Path.GetFileNameWithoutExtension(dep)}\"";
535534

536-
private void GenerateConfig()
535+
private void GenerateConfigFiles()
537536
{
538-
var unoConfigJsPath = Path.Combine(_intermediateAssetsPath, "uno-config.js");
537+
GenerateConfigFile("uno-config.js", isModule: true);
539538

540539
using (var w = new StreamWriter(unoConfigJsPath, false, _utf8Encoding))
541540
{
@@ -635,11 +634,11 @@ private void GenerateConfig()
635634
}
636635
}
637636

638-
639-
640-
private void GenerateConfigScript()
637+
private void GenerateConfigFile(string fileName, bool isModule)
641638
{
642-
var unoConfigJsPath = Path.Combine(_intermediateAssetsPath, "uno-config-script.js");
639+
var self = isModule ? "" : "self.";
640+
641+
var unoConfigJsPath = Path.Combine(_intermediateAssetsPath, fileName);
643642

644643
using (var w = new StreamWriter(unoConfigJsPath, false, _utf8Encoding))
645644
{
@@ -660,7 +659,7 @@ private void GenerateConfigScript()
660659
.Select(f => f.GetMetadata("Link")
661660
.Replace("\\", "/")
662661
.Replace("wwwroot/", ""))
663-
.Concat([$"uno-config-script.js", "_framework/blazor.boot.json", "."]);
662+
.Concat([fileName, "_framework/blazor.boot.json", "."]);
664663

665664
var offlineFiles = enablePWA ? string.Join(", ", sanitizedOfflineFiles.Select(f => $"\"{WebAppBasePath}{f}\"")) : "";
666665

@@ -670,27 +669,36 @@ private void GenerateConfigScript()
670669

671670
var runtimeOptionsSet = string.Join(",", (RuntimeOptions?.Split(' ') ?? []).Select(f => $"\'{f}\'"));
672671

673-
config.AppendLine($"self.config = {{}};");
674-
config.AppendLine($"self.config.uno_remote_managedpath = \"_framework\";");
675-
config.AppendLine($"self.config.uno_app_base = \"{WebAppBasePath}{PackageAssetsFolder}\";");
676-
config.AppendLine($"self.config.uno_dependencies = [{dependencies}];");
677-
config.AppendLine($"self.config.uno_runtime_options = [{runtimeOptionsSet}];");
678-
config.AppendLine($"self.config.enable_pwa = {enablePWA.ToString().ToLowerInvariant()};");
679-
config.AppendLine($"self.config.offline_files = ['{WebAppBasePath}', {offlineFiles}];");
680-
config.AppendLine($"self.config.uno_shell_mode = \"{_shellMode}\";");
681-
config.AppendLine($"self.config.uno_debugging_enabled = {(!Optimize).ToString().ToLowerInvariant()};");
682-
config.AppendLine($"self.config.uno_enable_tracing = {EnableTracing.ToString().ToLowerInvariant()};");
683-
config.AppendLine($"self.config.uno_load_all_satellite_resources = {LoadAllSatelliteResources.ToString().ToLowerInvariant()};");
684-
config.AppendLine($"self.config.emcc_exported_runtime_methods = [{emccExportedRuntimeMethodsParams}];");
672+
673+
if (isModule)
674+
{
675+
config.AppendLine($"let config = {{}};");
676+
}
677+
else
678+
{
679+
config.AppendLine($"{self}config = {{}};");
680+
}
681+
682+
config.AppendLine($"{self}config.uno_remote_managedpath = \"_framework\";");
683+
config.AppendLine($"{self}config.uno_app_base = \"{WebAppBasePath}{PackageAssetsFolder}\";");
684+
config.AppendLine($"{self}config.uno_dependencies = [{dependencies}];");
685+
config.AppendLine($"{self}config.uno_runtime_options = [{runtimeOptionsSet}];");
686+
config.AppendLine($"{self}config.enable_pwa = {enablePWA.ToString().ToLowerInvariant()};");
687+
config.AppendLine($"{self}config.offline_files = ['{WebAppBasePath}', {offlineFiles}];");
688+
config.AppendLine($"{self}config.uno_shell_mode = \"{_shellMode}\";");
689+
config.AppendLine($"{self}config.uno_debugging_enabled = {(!Optimize).ToString().ToLowerInvariant()};");
690+
config.AppendLine($"{self}config.uno_enable_tracing = {EnableTracing.ToString().ToLowerInvariant()};");
691+
config.AppendLine($"{self}config.uno_load_all_satellite_resources = {LoadAllSatelliteResources.ToString().ToLowerInvariant()};");
692+
config.AppendLine($"{self}config.emcc_exported_runtime_methods = [{emccExportedRuntimeMethodsParams}];");
685693

686694
if (GenerateAOTProfile)
687695
{
688-
config.AppendLine($"self.config.generate_aot_profile = true;");
696+
config.AppendLine($"{self}config.generate_aot_profile = true;");
689697
}
690698

691-
config.AppendLine($"self.config.environmentVariables = self.config.environmentVariables || {{}};");
699+
config.AppendLine($"{self}config.environmentVariables = {self}config.environmentVariables || {{}};");
692700

693-
void AddEnvironmentVariable(string name, string value) => config.AppendLine($"self.config.environmentVariables[\"{name}\"] = \"{value}\";");
701+
void AddEnvironmentVariable(string name, string value) => config.AppendLine($"{self}config.environmentVariables[\"{name}\"] = \"{value}\";");
694702

695703
if (MonoEnvironment != null)
696704
{
@@ -722,6 +730,11 @@ private void GenerateConfigScript()
722730
AddEnvironmentVariable("UNO_BOOTSTRAP_LOG_PROFILER_OPTIONS", LogProfilerOptions);
723731
}
724732

733+
if (isModule)
734+
{
735+
config.AppendLine("export { config };");
736+
}
737+
725738
w.Write(config.ToString());
726739

727740
TaskItem indexMetadata = new(

0 commit comments

Comments
 (0)