Compile fix

This commit is contained in:
Joshua Granick
2018-07-24 16:24:23 -07:00
parent c0b3692402
commit 7ffd8f1bcf
2 changed files with 589 additions and 589 deletions

View File

@@ -25,373 +25,373 @@ import sys.FileSystem;
class HTML5Platform extends PlatformTarget { class HTML5Platform extends PlatformTarget {
private var dependencyPath:String; private var dependencyPath:String;
private var outputFile:String; private var outputFile:String;
public function new (command:String, _project:HXProject, targetFlags:Map<String, String> ) { public function new (command:String, _project:HXProject, targetFlags:Map<String, String> ) {
super (command, _project, targetFlags); super (command, _project, targetFlags);
initialize (command, _project); initialize (command, _project);
} }
public override function build ():Void { public override function build ():Void {
ModuleHelper.buildModules (project, targetDirectory + "/obj", targetDirectory + "/bin"); ModuleHelper.buildModules (project, targetDirectory + "/obj", targetDirectory + "/bin");
if (project.app.main != null) { if (project.app.main != null) {
var type = "release"; var type = "release";
if (project.debug) { if (project.debug) {
type = "debug"; type = "debug";
} else if (project.targetFlags.exists ("final")) { } else if (project.targetFlags.exists ("final")) {
type = "final"; type = "final";
} }
var hxml = targetDirectory + "/haxe/" + type + ".hxml"; var hxml = targetDirectory + "/haxe/" + type + ".hxml";
ProcessHelper.runCommand ("", "haxe", [ hxml ] ); ProcessHelper.runCommand ("", "haxe", [ hxml ] );
if (noOutput) return; if (noOutput) return;
HTML5Helper.encodeSourceMappingURL (targetDirectory + "/bin/" + project.app.file + ".js"); HTML5Helper.encodeSourceMappingURL (targetDirectory + "/bin/" + project.app.file + ".js");
if (project.targetFlags.exists ("webgl")) { if (project.targetFlags.exists ("webgl")) {
FileHelper.copyFile (targetDirectory + "/obj/ApplicationMain.js", outputFile); FileHelper.copyFile (targetDirectory + "/obj/ApplicationMain.js", outputFile);
} }
if (project.modules.iterator ().hasNext ()) { if (project.modules.iterator ().hasNext ()) {
ModuleHelper.patchFile (outputFile); ModuleHelper.patchFile (outputFile);
} }
if (project.targetFlags.exists ("minify") || type == "final") { if (project.targetFlags.exists ("minify") || type == "final") {
HTML5Helper.minify (project, targetDirectory + "/bin/" + project.app.file + ".js"); HTML5Helper.minify (project, targetDirectory + "/bin/" + project.app.file + ".js");
} }
} }
} }
public override function clean ():Void { public override function clean ():Void {
if (FileSystem.exists (targetDirectory)) { if (FileSystem.exists (targetDirectory)) {
PathHelper.removeDirectory (targetDirectory); PathHelper.removeDirectory (targetDirectory);
} }
} }
public override function deploy ():Void { public override function deploy ():Void {
var name = "HTML5"; var name = "HTML5";
if (targetFlags.exists ("electron")) { if (targetFlags.exists ("electron")) {
name = "Electron"; name = "Electron";
} }
DeploymentHelper.deploy (project, targetFlags, targetDirectory, name); DeploymentHelper.deploy (project, targetFlags, targetDirectory, name);
} }
public override function display ():Void { public override function display ():Void {
Sys.println (getDisplayHXML ()); Sys.println (getDisplayHXML ());
} }
private function getDisplayHXML ():String { private function getDisplayHXML ():String {
var type = "html5"; var type = "html5";
if (targetFlags.exists ("electron")) { if (targetFlags.exists ("electron")) {
type = "electron"; type = "electron";
} }
var hxml = PathHelper.findTemplate (project.templatePaths, type + "/hxml/" + buildType + ".hxml"); var hxml = PathHelper.findTemplate (project.templatePaths, type + "/hxml/" + buildType + ".hxml");
var context = project.templateContext; var context = project.templateContext;
context.OUTPUT_DIR = targetDirectory; context.OUTPUT_DIR = targetDirectory;
context.OUTPUT_FILE = outputFile; context.OUTPUT_FILE = outputFile;
var template = new Template (File.getContent (hxml)); var template = new Template (File.getContent (hxml));
return template.execute (context) + "\n-D display"; return template.execute (context) + "\n-D display";
} }
private function initialize (command:String, project:HXProject):Void { private function initialize (command:String, project:HXProject):Void {
if (targetFlags.exists ("electron")) { if (targetFlags.exists ("electron")) {
targetDirectory = PathHelper.combine (project.app.path, project.config.getString ("electron.output-directory", "electron")); targetDirectory = PathHelper.combine (project.app.path, project.config.getString ("electron.output-directory", "electron"));
} else { } else {
targetDirectory = PathHelper.combine (project.app.path, project.config.getString ("html5.output-directory", "html5")); targetDirectory = PathHelper.combine (project.app.path, project.config.getString ("html5.output-directory", "html5"));
} }
dependencyPath = project.config.getString ("html5.dependency-path", "lib"); dependencyPath = project.config.getString ("html5.dependency-path", "lib");
if (targetFlags.exists ("electron")) { if (targetFlags.exists ("electron")) {
dependencyPath = project.config.getString ("html5.dependency-path", dependencyPath); dependencyPath = project.config.getString ("html5.dependency-path", dependencyPath);
} }
outputFile = targetDirectory + "/bin/" + project.app.file + ".js"; outputFile = targetDirectory + "/bin/" + project.app.file + ".js";
} }
public override function run ():Void { public override function run ():Void {
if (targetFlags.exists ("electron")) { if (targetFlags.exists ("electron")) {
ElectronHelper.launch (project, targetDirectory + "/bin"); ElectronHelper.launch (project, targetDirectory + "/bin");
} else { } else {
HTML5Helper.launch (project, targetDirectory + "/bin"); HTML5Helper.launch (project, targetDirectory + "/bin");
} }
} }
public override function update ():Void { public override function update ():Void {
// project = project.clone (); // project = project.clone ();
var destination = targetDirectory + "/bin/"; var destination = targetDirectory + "/bin/";
PathHelper.mkdir (destination); PathHelper.mkdir (destination);
var webfontDirectory = targetDirectory + "/obj/webfont"; var webfontDirectory = targetDirectory + "/obj/webfont";
var useWebfonts = true; var useWebfonts = true;
for (haxelib in project.haxelibs) { for (haxelib in project.haxelibs) {
if (haxelib.name == "openfl-html5-dom" || haxelib.name == "openfl-bitfive") { if (haxelib.name == "openfl-html5-dom" || haxelib.name == "openfl-bitfive") {
useWebfonts = false; useWebfonts = false;
} }
} }
var fontPath; var fontPath;
for (asset in project.assets) { for (asset in project.assets) {
if (asset.type == AssetType.FONT && asset.targetPath != null) { if (asset.type == AssetType.FONT && asset.targetPath != null) {
if (useWebfonts) { if (useWebfonts) {
fontPath = PathHelper.combine (webfontDirectory, Path.withoutDirectory (asset.targetPath)); fontPath = PathHelper.combine (webfontDirectory, Path.withoutDirectory (asset.targetPath));
if (!FileSystem.exists (fontPath)) { if (!FileSystem.exists (fontPath)) {
PathHelper.mkdir (webfontDirectory); PathHelper.mkdir (webfontDirectory);
FileHelper.copyFile (asset.sourcePath, fontPath); FileHelper.copyFile (asset.sourcePath, fontPath);
var originalPath = asset.sourcePath; var originalPath = asset.sourcePath;
asset.sourcePath = fontPath; asset.sourcePath = fontPath;
HTML5Helper.generateWebfonts (project, asset); HTML5Helper.generateWebfonts (project, asset);
var ext = "." + Path.extension (asset.sourcePath); var ext = "." + Path.extension (asset.sourcePath);
var source = Path.withoutExtension (asset.sourcePath); var source = Path.withoutExtension (asset.sourcePath);
var extensions = [ ext, ".eot", ".woff", ".svg" ]; var extensions = [ ext, ".eot", ".woff", ".svg" ];
for (extension in extensions) { for (extension in extensions) {
if (!FileSystem.exists (source + extension)) { if (!FileSystem.exists (source + extension)) {
if (extension != ".eot" && extension != ".svg") { if (extension != ".eot" && extension != ".svg") {
LogHelper.warn ("Could not generate *" + extension + " web font for \"" + originalPath + "\""); LogHelper.warn ("Could not generate *" + extension + " web font for \"" + originalPath + "\"");
} }
} }
} }
} }
asset.sourcePath = fontPath; asset.sourcePath = fontPath;
asset.targetPath = Path.withoutExtension (asset.targetPath); asset.targetPath = Path.withoutExtension (asset.targetPath);
} else { } else {
project.haxeflags.push (HTML5Helper.generateFontData (project, asset)); // project.haxeflags.push (HTML5Helper.generateFontData (project, asset));
} }
} }
} }
if (project.targetFlags.exists ("xml")) { if (project.targetFlags.exists ("xml")) {
project.haxeflags.push ("-xml " + targetDirectory + "/types.xml"); project.haxeflags.push ("-xml " + targetDirectory + "/types.xml");
} }
if (LogHelper.verbose) { if (LogHelper.verbose) {
project.haxedefs.set ("verbose", 1); project.haxedefs.set ("verbose", 1);
} }
ModuleHelper.updateProject (project); ModuleHelper.updateProject (project);
var libraryNames = new Map<String, Bool> (); var libraryNames = new Map<String, Bool> ();
for (asset in project.assets) { for (asset in project.assets) {
if (asset.library != null && !libraryNames.exists (asset.library)) { if (asset.library != null && !libraryNames.exists (asset.library)) {
libraryNames[asset.library] = true; libraryNames[asset.library] = true;
} }
} }
//for (library in libraryNames.keys ()) { //for (library in libraryNames.keys ()) {
// //
//project.haxeflags.push ("-resource " + targetDirectory + "/obj/manifest/" + library + ".json@__ASSET_MANIFEST__" + library); //project.haxeflags.push ("-resource " + targetDirectory + "/obj/manifest/" + library + ".json@__ASSET_MANIFEST__" + library);
// //
//} //}
//project.haxeflags.push ("-resource " + targetDirectory + "/obj/manifest/default.json@__ASSET_MANIFEST__default"); //project.haxeflags.push ("-resource " + targetDirectory + "/obj/manifest/default.json@__ASSET_MANIFEST__default");
var context = project.templateContext; var context = project.templateContext;
context.WIN_FLASHBACKGROUND = project.window.background != null ? StringTools.hex (project.window.background, 6) : ""; context.WIN_FLASHBACKGROUND = project.window.background != null ? StringTools.hex (project.window.background, 6) : "";
context.OUTPUT_DIR = targetDirectory; context.OUTPUT_DIR = targetDirectory;
context.OUTPUT_FILE = outputFile; context.OUTPUT_FILE = outputFile;
if (project.targetFlags.exists ("webgl")) { if (project.targetFlags.exists ("webgl")) {
context.CPP_DIR = targetDirectory + "/obj"; context.CPP_DIR = targetDirectory + "/obj";
} }
context.favicons = []; context.favicons = [];
var icons = project.icons; var icons = project.icons;
if (icons.length == 0) { if (icons.length == 0) {
icons = [ new Icon (PathHelper.findTemplate (project.templatePaths, "default/icon.svg")) ]; icons = [ new Icon (PathHelper.findTemplate (project.templatePaths, "default/icon.svg")) ];
} }
//if (IconHelper.createWindowsIcon (icons, PathHelper.combine (destination, "favicon.ico"))) { //if (IconHelper.createWindowsIcon (icons, PathHelper.combine (destination, "favicon.ico"))) {
// //
//context.favicons.push ({ rel: "icon", type: "image/x-icon", href: "./favicon.ico" }); //context.favicons.push ({ rel: "icon", type: "image/x-icon", href: "./favicon.ico" });
// //
//} //}
if (IconHelper.createIcon (icons, 192, 192, PathHelper.combine (destination, "favicon.png"))) { if (IconHelper.createIcon (icons, 192, 192, PathHelper.combine (destination, "favicon.png"))) {
context.favicons.push ({ rel: "shortcut icon", type: "image/png", href: "./favicon.png" }); context.favicons.push ({ rel: "shortcut icon", type: "image/png", href: "./favicon.png" });
} }
context.linkedLibraries = []; context.linkedLibraries = [];
for (dependency in project.dependencies) { for (dependency in project.dependencies) {
if (StringTools.endsWith (dependency.name, ".js")) { if (StringTools.endsWith (dependency.name, ".js")) {
context.linkedLibraries.push (dependency.name); context.linkedLibraries.push (dependency.name);
} else if (StringTools.endsWith (dependency.path, ".js") && FileSystem.exists (dependency.path)) { } else if (StringTools.endsWith (dependency.path, ".js") && FileSystem.exists (dependency.path)) {
var name = Path.withoutDirectory (dependency.path); var name = Path.withoutDirectory (dependency.path);
context.linkedLibraries.push ("./" + dependencyPath + "/" + name); context.linkedLibraries.push ("./" + dependencyPath + "/" + name);
FileHelper.copyIfNewer (dependency.path, PathHelper.combine (destination, PathHelper.combine (dependencyPath, name))); FileHelper.copyIfNewer (dependency.path, PathHelper.combine (destination, PathHelper.combine (dependencyPath, name)));
} }
} }
for (asset in project.assets) { for (asset in project.assets) {
var path = PathHelper.combine (destination, asset.targetPath); var path = PathHelper.combine (destination, asset.targetPath);
if (asset.type != AssetType.TEMPLATE) { if (asset.type != AssetType.TEMPLATE) {
if (/*asset.embed != true &&*/ asset.type != AssetType.FONT) { if (/*asset.embed != true &&*/ asset.type != AssetType.FONT) {
PathHelper.mkdir (Path.directory (path)); PathHelper.mkdir (Path.directory (path));
FileHelper.copyAssetIfNewer (asset, path); FileHelper.copyAssetIfNewer (asset, path);
} else if (asset.type == AssetType.FONT && useWebfonts) { } else if (asset.type == AssetType.FONT && useWebfonts) {
PathHelper.mkdir (Path.directory (path)); PathHelper.mkdir (Path.directory (path));
var ext = "." + Path.extension (asset.sourcePath); var ext = "." + Path.extension (asset.sourcePath);
var source = Path.withoutExtension (asset.sourcePath); var source = Path.withoutExtension (asset.sourcePath);
var hasFormat = [ false, false, false, false ]; var hasFormat = [ false, false, false, false ];
var extensions = [ ext, ".eot", ".svg", ".woff" ]; var extensions = [ ext, ".eot", ".svg", ".woff" ];
var extension; var extension;
for (i in 0...extensions.length) { for (i in 0...extensions.length) {
extension = extensions[i]; extension = extensions[i];
if (FileSystem.exists (source + extension)) { if (FileSystem.exists (source + extension)) {
FileHelper.copyIfNewer (source + extension, path + extension); FileHelper.copyIfNewer (source + extension, path + extension);
hasFormat[i] = true; hasFormat[i] = true;
} }
} }
var shouldEmbedFont = false; var shouldEmbedFont = false;
for (embedded in hasFormat) { for (embedded in hasFormat) {
if (embedded) shouldEmbedFont = true; if (embedded) shouldEmbedFont = true;
} }
var embeddedAssets:Array<Dynamic> = cast context.assets; var embeddedAssets:Array<Dynamic> = cast context.assets;
for (embeddedAsset in embeddedAssets) { for (embeddedAsset in embeddedAssets) {
if (embeddedAsset.type == "font" && embeddedAsset.sourcePath == asset.sourcePath) { if (embeddedAsset.type == "font" && embeddedAsset.sourcePath == asset.sourcePath) {
#if lime #if lime
var font = Font.fromFile (asset.sourcePath); var font = Font.fromFile (asset.sourcePath);
embeddedAsset.ascender = font.ascender; embeddedAsset.ascender = font.ascender;
embeddedAsset.descender = font.descender; embeddedAsset.descender = font.descender;
embeddedAsset.height = font.height; embeddedAsset.height = font.height;
@@ -399,15 +399,15 @@ class HTML5Platform extends PlatformTarget {
embeddedAsset.underlinePosition = font.underlinePosition; embeddedAsset.underlinePosition = font.underlinePosition;
embeddedAsset.underlineThickness = font.underlineThickness; embeddedAsset.underlineThickness = font.underlineThickness;
embeddedAsset.unitsPerEM = font.unitsPerEM; embeddedAsset.unitsPerEM = font.unitsPerEM;
if (shouldEmbedFont) { if (shouldEmbedFont) {
var urls = []; var urls = [];
if (hasFormat[1]) urls.push ("url('" + embeddedAsset.targetPath + ".eot?#iefix') format('embedded-opentype')"); if (hasFormat[1]) urls.push ("url('" + embeddedAsset.targetPath + ".eot?#iefix') format('embedded-opentype')");
if (hasFormat[3]) urls.push ("url('" + embeddedAsset.targetPath + ".woff') format('woff')"); if (hasFormat[3]) urls.push ("url('" + embeddedAsset.targetPath + ".woff') format('woff')");
urls.push ("url('" + embeddedAsset.targetPath + ext + "') format('truetype')"); urls.push ("url('" + embeddedAsset.targetPath + ext + "') format('truetype')");
if (hasFormat[2]) urls.push ("url('" + embeddedAsset.targetPath + ".svg#" + StringTools.urlEncode (embeddedAsset.fontName) + "') format('svg')"); if (hasFormat[2]) urls.push ("url('" + embeddedAsset.targetPath + ".svg#" + StringTools.urlEncode (embeddedAsset.fontName) + "') format('svg')");
var fontFace = "\t\t@font-face {\n"; var fontFace = "\t\t@font-face {\n";
fontFace += "\t\t\tfont-family: '" + embeddedAsset.fontName + "';\n"; fontFace += "\t\t\tfont-family: '" + embeddedAsset.fontName + "';\n";
// if (hasFormat[1]) fontFace += "\t\t\tsrc: url('" + embeddedAsset.targetPath + ".eot');\n"; // if (hasFormat[1]) fontFace += "\t\t\tsrc: url('" + embeddedAsset.targetPath + ".eot');\n";
@@ -415,77 +415,77 @@ class HTML5Platform extends PlatformTarget {
fontFace += "\t\t\tfont-weight: normal;\n"; fontFace += "\t\t\tfont-weight: normal;\n";
fontFace += "\t\t\tfont-style: normal;\n"; fontFace += "\t\t\tfont-style: normal;\n";
fontFace += "\t\t}\n"; fontFace += "\t\t}\n";
embeddedAsset.cssFontFace = fontFace; embeddedAsset.cssFontFace = fontFace;
} }
break; break;
#end #end
} }
} }
} }
} }
} }
FileHelper.recursiveSmartCopyTemplate (project, "html5/template", destination, context); FileHelper.recursiveSmartCopyTemplate (project, "html5/template", destination, context);
if (project.app.main != null) { if (project.app.main != null) {
FileHelper.recursiveSmartCopyTemplate (project, "haxe", targetDirectory + "/haxe", context); FileHelper.recursiveSmartCopyTemplate (project, "haxe", targetDirectory + "/haxe", context);
FileHelper.recursiveSmartCopyTemplate (project, "html5/haxe", targetDirectory + "/haxe", context, true, false); FileHelper.recursiveSmartCopyTemplate (project, "html5/haxe", targetDirectory + "/haxe", context, true, false);
FileHelper.recursiveSmartCopyTemplate (project, "html5/hxml", targetDirectory + "/haxe", context); FileHelper.recursiveSmartCopyTemplate (project, "html5/hxml", targetDirectory + "/haxe", context);
} }
if (targetFlags.exists ("electron")) { if (targetFlags.exists ("electron")) {
FileHelper.recursiveSmartCopyTemplate (project, "electron/template", destination, context); FileHelper.recursiveSmartCopyTemplate (project, "electron/template", destination, context);
if (project.app.main != null) { if (project.app.main != null) {
FileHelper.recursiveSmartCopyTemplate (project, "electron/haxe", targetDirectory + "/haxe", context, true, false); FileHelper.recursiveSmartCopyTemplate (project, "electron/haxe", targetDirectory + "/haxe", context, true, false);
FileHelper.recursiveSmartCopyTemplate (project, "electron/hxml", targetDirectory + "/haxe", context); FileHelper.recursiveSmartCopyTemplate (project, "electron/hxml", targetDirectory + "/haxe", context);
} }
} }
for (asset in project.assets) { for (asset in project.assets) {
var path = PathHelper.combine (destination, asset.targetPath); var path = PathHelper.combine (destination, asset.targetPath);
if (asset.type == AssetType.TEMPLATE) { if (asset.type == AssetType.TEMPLATE) {
PathHelper.mkdir (Path.directory (path)); PathHelper.mkdir (Path.directory (path));
FileHelper.copyAsset (asset, path, context); FileHelper.copyAsset (asset, path, context);
} }
} }
} }
public override function watch ():Void { public override function watch ():Void {
// TODO: Use a custom live reload HTTP server for test/run instead // TODO: Use a custom live reload HTTP server for test/run instead
var dirs = WatchHelper.processHXML (project, getDisplayHXML ()); var dirs = WatchHelper.processHXML (project, getDisplayHXML ());
var command = WatchHelper.getCurrentCommand (); var command = WatchHelper.getCurrentCommand ();
WatchHelper.watch (project, command, dirs); WatchHelper.watch (project, command, dirs);
} }
@ignore public override function install ():Void {} @ignore public override function install ():Void {}
@ignore public override function rebuild ():Void {} @ignore public override function rebuild ():Void {}
@ignore public override function trace ():Void {} @ignore public override function trace ():Void {}
@ignore public override function uninstall ():Void {} @ignore public override function uninstall ():Void {}
} }

File diff suppressed because it is too large Load Diff