Add support for embedded JS dependencies (embed Lime dependencies by default)

This commit is contained in:
Joshua Granick
2019-02-12 13:30:07 -08:00
parent 3e9f875eaf
commit cac82509da
5 changed files with 39 additions and 12 deletions

View File

@@ -81,11 +81,11 @@
<ndll name="lime" if="native" unless="lime-console static_link || lime-switch static_link" />
<dependency name="extension-api" path="dependencies/extension-api" if="android" />
<dependency path="dependencies/howler.min.js" if="html5 howlerjs" />
<dependency path="dependencies/pako.min.js" if="html5" />
<dependency path="dependencies/FileSaver.min.js" if="html5" />
<dependency path="dependencies/webgl-debug.js" if="html5 webgl-debug" />
<dependency path="dependencies/stats.min.js" if="html5 stats" />
<dependency path="dependencies/howler.min.js" if="html5 howlerjs" embed="true" />
<dependency path="dependencies/pako.min.js" if="html5" embed="true" />
<dependency path="dependencies/FileSaver.min.js" if="html5" embed="true" />
<dependency path="dependencies/webgl-debug.js" if="html5 webgl-debug" embed="true" />
<dependency path="dependencies/stats.min.js" if="html5 stats" embed="true" />
<dependency path="dependencies/angle/d3dcompiler_47.dll" if="windows angle" unless="static_link" />
<dependency path="dependencies/angle/libegl.dll" if="windows angle" unless="static_link" />
<dependency path="dependencies/angle/libglesv2.dll" if="windows angle" unless="static_link" />

View File

@@ -6,6 +6,7 @@ class Dependency {
// TODO: Is "forceLoad" the best name? Implement "whole-archive" on GCC
public var embed:Bool;
public var forceLoad:Bool;
public var name:String;
public var path:String;
@@ -22,6 +23,7 @@ class Dependency {
public function clone ():Dependency {
var dependency = new Dependency (name, path);
dependency.embed = embed;
dependency.forceLoad = forceLoad;
return dependency;

View File

@@ -1916,9 +1916,15 @@ class ProjectXMLParser extends HXProject {
var dependency = new Dependency (name, path);
if (element.has.embed) {
dependency.embed = parseBool (element.att.embed);
}
if (element.has.resolve ("force-load")) {
dependency.forceLoad = (substitute (element.att.resolve ("force-load")) == "true");
dependency.forceLoad = parseBool (element.att.resolve ("force-load"));
}

View File

@@ -1,3 +1,5 @@
::if embeddedLibraries::::foreach (embeddedLibraries)::
::__current__::::end::::end::
// lime.embed namespace wrapper
(function ($hx_exports, $global) { "use strict";
$hx_exports.lime = $hx_exports.lime || {};

View File

@@ -83,6 +83,19 @@ class HTML5Platform extends PlatformTarget {
var context = project.templateContext;
context.SOURCE_FILE = File.getContent (outputFile);
context.embeddedLibraries = [];
for (dependency in project.dependencies) {
if (dependency.embed && StringTools.endsWith (dependency.path, ".js") && FileSystem.exists (dependency.path)) {
var script = File.getContent (dependency.path);
context.embeddedLibraries.push (script);
}
}
System.copyFileTemplate (project.templatePaths, "html5/output.js", outputFile, context);
}
@@ -341,16 +354,20 @@ class HTML5Platform extends PlatformTarget {
for (dependency in project.dependencies) {
if (StringTools.endsWith (dependency.name, ".js")) {
if (!dependency.embed) {
context.linkedLibraries.push (dependency.name);
if (StringTools.endsWith (dependency.name, ".js")) {
} else if (StringTools.endsWith (dependency.path, ".js") && FileSystem.exists (dependency.path)) {
context.linkedLibraries.push (dependency.name);
var name = Path.withoutDirectory (dependency.path);
} else if (StringTools.endsWith (dependency.path, ".js") && FileSystem.exists (dependency.path)) {
context.linkedLibraries.push ("./" + dependencyPath + "/" + name);
System.copyIfNewer (dependency.path, Path.combine (destination, Path.combine (dependencyPath, name)));
var name = Path.withoutDirectory (dependency.path);
context.linkedLibraries.push ("./" + dependencyPath + "/" + name);
System.copyIfNewer (dependency.path, Path.combine (destination, Path.combine (dependencyPath, name)));
}
}