Skip to content

Commit

Permalink
Add support for *.bundle child libraries support
Browse files Browse the repository at this point in the history
  • Loading branch information
jgranick committed May 9, 2018
1 parent bfaef88 commit 09923d5
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 67 deletions.
105 changes: 66 additions & 39 deletions lime/project/ProjectXMLParser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import lime.project.AssetType;
import lime.project.Dependency;
import lime.project.Haxelib;
import lime.project.HXProject;
import lime.utils.AssetManifest;
import sys.io.File;
import sys.FileSystem;

Expand Down Expand Up @@ -604,29 +605,7 @@ class ProjectXMLParser extends HXProject {

} else if (Path.extension (path) == "bundle") {

var includePath = findIncludeFile (path);

if (includePath != null && includePath != "" && FileSystem.exists (includePath) && !FileSystem.isDirectory (includePath)) {

var includeProject = new ProjectXMLParser (includePath, defines);
merge (includeProject);

}

if (FileSystem.exists (PathHelper.combine (path, "library.json"))) {

var asset = new Asset (path, targetPath, type, embed);
asset.library = library;

if (element.has.id) {

asset.id = substitute (element.att.id);

}

assets.push (asset);

}
parseAssetsElementLibrary (path, targetPath, null, null, type, embed, library, glyphs, true);

} else {

Expand Down Expand Up @@ -808,22 +787,7 @@ class ProjectXMLParser extends HXProject {

if (Path.extension (file) == "bundle") {

var includePath = findIncludeFile (path + "/" + file);

if (includePath != null && includePath != "" && FileSystem.exists (includePath) && !FileSystem.isDirectory (includePath)) {

var includeProject = new ProjectXMLParser (includePath, defines);
merge (includeProject);

}

if (FileSystem.exists (PathHelper.combine (path + "/" + file, "library.json"))) {

var asset = new Asset (path + "/" + file, targetPath + file, type, embed);
asset.library = library;
assets.push (asset);

}
parseAssetsElementLibrary (path + "/" + file, targetPath + file, include, exclude, type, embed, library, glyphs, true);

} else if (recursive) {

Expand Down Expand Up @@ -859,6 +823,69 @@ class ProjectXMLParser extends HXProject {
}


private function parseAssetsElementLibrary (path:String, targetPath:String, include:String, exclude:String, type:AssetType, embed:Null<Bool>, library:String, glyphs:String, recursive:Bool):Void {

var includePath = findIncludeFile (path);

if (includePath != null && includePath != "" && FileSystem.exists (includePath) && !FileSystem.isDirectory (includePath)) {

var includeProject = new ProjectXMLParser (includePath, defines);
merge (includeProject);

}

var processedLibrary = false;
var jsonPath = PathHelper.combine (path, "library.json");

if (FileSystem.exists (jsonPath)) {

try {

var manifest = AssetManifest.fromFile (jsonPath);

if (manifest != null) {

library = targetPath;
manifest.rootPath = targetPath;

var asset = new Asset ("", PathHelper.combine (targetPath, "library.json"), AssetType.MANIFEST);
asset.id = "libraries/" + library + ".json";
asset.library = library;
asset.data = manifest.serialize ();
asset.embed = embed;
assets.push (asset);

for (manifestAsset in manifest.assets) {

if (Reflect.hasField (manifestAsset, "path")) {

var asset = new Asset (PathHelper.combine (path, manifestAsset.path), PathHelper.combine (targetPath, manifestAsset.path), type, embed);
asset.id = manifestAsset.id;
asset.library = library;
asset.embed = embed;
assets.push (asset);

}

}

processedLibrary = true;

}

} catch (e:Dynamic) {}

}

if (!processedLibrary) {

parseAssetsElementDirectory (path, targetPath, include, exclude, type, embed, library, glyphs, true);

}

}


private function parseBool (attribute:String):Bool {

return substitute (attribute) == "true";
Expand Down
81 changes: 55 additions & 26 deletions lime/tools/helpers/AssetHelper.hx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class AssetHelper {
public static function createManifests (project:HXProject, targetDirectory:String = null):Array<AssetManifest> {

var libraryNames = new Map<String, Bool> ();
var hasManifest = new Map<String, Bool> ();

for (asset in project.assets) {

Expand All @@ -76,20 +77,37 @@ class AssetHelper {

}

if (asset.type == MANIFEST) {

hasManifest.set (asset.library != null ? asset.library : DEFAULT_LIBRARY_NAME, true);

}

}

var manifest = createManifest (project);
manifest.name = DEFAULT_LIBRARY_NAME;
var manifests = [ manifest ];
var manifest = null;
var manifests = [];

for (library in libraryNames.keys ()) {
if (!hasManifest.exists (DEFAULT_LIBRARY_NAME)) {

manifest = createManifest (project, library);
manifest.name = library;
manifest = createManifest (project);
manifest.name = DEFAULT_LIBRARY_NAME;
manifests.push (manifest);

}

for (library in libraryNames.keys ()) {

if (!hasManifest.exists (library)) {

manifest = createManifest (project, library);
manifest.name = library;
manifests.push (manifest);

}

}

if (targetDirectory != null) {

PathHelper.mkdir (targetDirectory);
Expand Down Expand Up @@ -336,6 +354,7 @@ class AssetHelper {

public static function processLibraries (project:HXProject, targetDirectory:String = null):Void {

var hasManifest = new Map<String, Bool> ();
var libraryMap = new Map<String, Bool> ();

for (library in project.libraries) {
Expand All @@ -357,6 +376,12 @@ class AssetHelper {

}

if (asset.type == MANIFEST) {

hasManifest.set (asset.library != null ? asset.library : DEFAULT_LIBRARY_NAME, true);

}

}

if (!libraryMap.exists (DEFAULT_LIBRARY_NAME)) {
Expand Down Expand Up @@ -471,45 +496,49 @@ class AssetHelper {

if (library.type == null || (project.target == FLASH && library.embed != false && ["pak", "pack", "gzip", "zip", "deflate"].indexOf (library.type) > -1)) {

manifest = createManifest (project, library.name != DEFAULT_LIBRARY_NAME ? library.name : null);

if (library.name == DEFAULT_LIBRARY_NAME) {

library.preload = true;

}

asset = new Asset ("", "manifest/" + library.name + ".json", AssetType.MANIFEST);
asset.library = library.name;
asset.data = manifest.serialize ();

if (manifest.assets.length == 0 || (project.target == HTML5 && library.name == DEFAULT_LIBRARY_NAME)) {

asset.embed = true;
if (!hasManifest.exists (library.name)) {

} else {
manifest = createManifest (project, library.name != DEFAULT_LIBRARY_NAME ? library.name : null);

// TODO: Make this assumption elsewhere?
asset = new Asset ("", "manifest/" + library.name + ".json", AssetType.MANIFEST);
asset.library = library.name;
asset.data = manifest.serialize ();

var allEmbedded = true;

for (childAsset in manifest.assets) {
if (manifest.assets.length == 0 || (project.target == HTML5 && library.name == DEFAULT_LIBRARY_NAME)) {

asset.embed = true;

} else {

if (!Reflect.hasField (childAsset, "className") || childAsset.className == null) {
// TODO: Make this assumption elsewhere?

var allEmbedded = true;

for (childAsset in manifest.assets) {

allEmbedded = false;
break;
if (!Reflect.hasField (childAsset, "className") || childAsset.className == null) {

allEmbedded = false;
break;

}

}

if (allEmbedded) asset.embed = true;

}

if (allEmbedded) asset.embed = true;
project.assets.push (asset);

}

project.assets.push (asset);

}

}
Expand Down
19 changes: 17 additions & 2 deletions lime/utils/AssetManifest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,23 @@ class AssetManifest {
manifest.libraryArgs = manifestData.libraryArgs;
manifest.assets = Unserializer.run (manifestData.assets);

if (rootPath != null) {
if (Reflect.hasField (manifestData, "rootPath")) {

manifest.rootPath = rootPath;
manifest.rootPath = manifestData.rootPath;

}

if (rootPath != null && rootPath != "") {

if (manifest.rootPath == null || manifest.rootPath == "") {

manifest.rootPath = rootPath;

} else {

manifest.rootPath = rootPath + "/" + manifest.rootPath;

}

}

Expand All @@ -128,6 +142,7 @@ class AssetManifest {
manifestData.libraryArgs = libraryArgs;
manifestData.name = name;
manifestData.assets = Serializer.run (assets);
manifestData.rootPath = rootPath;

return Json.stringify (manifestData);

Expand Down

0 comments on commit 09923d5

Please sign in to comment.