This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


The following commit(s) were added to refs/heads/develop by this push:
     new 8d68d8cd3 js-include-asset compiler options
8d68d8cd3 is described below

commit 8d68d8cd3eb61000663747ea8327cc71da792bdd
Author: Josh Tynjala <[email protected]>
AuthorDate: Wed Mar 12 13:51:24 2025 -0700

    js-include-asset compiler options
    
    Works with both mxmlc and compc. Allows specifying arbitary files that will 
be included in the SWC and copied to the output directory of a compiled app. 
These files may be loaded at run-time from AS3, or they can be referenced from 
.js or .css files included with js-include-script or js-include-css.
---
 .../codegen/mxml/royale/MXMLRoyalePublisher.java   | 19 +++++++++++++
 .../driver/js/goog/JSGoogCompcConfiguration.java   | 31 ++++++++++++++++++++++
 .../driver/js/goog/JSGoogConfiguration.java        | 25 +++++++++++++++++
 3 files changed, 75 insertions(+)

diff --git 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
index f99aa861c..d90cde607 100644
--- 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
+++ 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
@@ -1037,6 +1037,25 @@ public class MXMLRoyalePublisher extends JSPublisher 
implements IJSRoyalePublish
     {
         StringBuilder depsHTML = new StringBuilder();
 
+        // files included with -js-include-asset are copied to the "assets"
+        // sub-directory of the output directory.
+        for (ISWC swc : project.getLibraries())
+        {
+            for (String key : swc.getFiles().keySet())
+            {
+                if (key.startsWith("js/assets") || 
key.startsWith("js\\assets"))
+                {
+                    String assetPath = 
Paths.get("js").relativize(Paths.get(key)).toString();
+                    copyIncludeFileFromSwcToOutput(type, swc, key, assetPath, 
problems);
+                }
+            }
+        }
+        for (String asset : googConfiguration.getJSIncludeAsset())
+        {
+            String assetOutputPath = 
Paths.get("assets").resolve(Paths.get(asset).getFileName()).toString();
+            copyIncludeFileToOutput(type, asset, assetOutputPath, problems);
+        }
+
         // included CSS appears before included JS scripts
         // included CSS from SWC libraries appears before included CSS from 
the app
         for (ISWC swc : project.getLibraries())
diff --git 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogCompcConfiguration.java
 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogCompcConfiguration.java
index 231208aa2..ed43d5fb4 100644
--- 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogCompcConfiguration.java
+++ 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogCompcConfiguration.java
@@ -602,4 +602,35 @@ public class JSGoogCompcConfiguration extends 
JSConfiguration
         }
     }
 
+    //
+    // 'js-include-css'
+    //
+
+    protected List<String> jsIncludeAsset = new ArrayList<String>();
+
+    public List<String> getJSIncludeAsset()
+    {   
+        return jsIncludeAsset;
+    }
+
+    @Config(allowMultiple = true)
+    @Mapping("js-include-asset")
+    @Arguments(Arguments.PATH_ELEMENT)
+    @InfiniteArguments
+    public void setJSIncludeAsset(ConfigurationValue cv, List<String> value)
+            throws ConfigurationException
+    {
+        for (String current : value)
+        {
+            String name = "js/assets/" + 
Paths.get(current).getFileName().toString();
+            if (includeFilesNamePath.containsKey(name))
+            {
+                throw new ConfigurationException.RedundantFile(name, 
cv.getVar(), cv.getSource(), cv.getLine());
+            }
+            String path = resolvePathStrict(current, cv);
+            includeFilesNamePath.put(name, path);
+            jsIncludeAsset.add(path);
+        }
+    }
+
 }
diff --git 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java
 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java
index 68ea46004..6fcb85983 100644
--- 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java
+++ 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java
@@ -1102,4 +1102,29 @@ public class JSGoogConfiguration extends JSConfiguration
         }
     }
 
+    //
+    // 'js-include-asset'
+    //
+
+    protected List<String> jsIncludeAsset = new ArrayList<String>();
+
+    public List<String> getJSIncludeAsset()
+    {   
+        return jsIncludeAsset;
+    }
+
+    @Config(allowMultiple = true)
+    @Mapping("js-include-asset")
+    @Arguments(Arguments.PATH_ELEMENT)
+    @InfiniteArguments
+    public void setJSIncludeAsset(ConfigurationValue cv, List<String> value)
+            throws ConfigurationException
+    {
+        for (String current : value)
+        {
+            String path = resolvePathStrict(current, cv);
+            jsIncludeAsset.add(path);
+        }
+    }
+
 }

Reply via email to