Last active
August 29, 2015 14:12
-
-
Save chamberlainpi/24a1fac7327cc63bcfc4 to your computer and use it in GitHub Desktop.
Macro for removing (comment-out) specific modules that are automatically created by Haxe compiler in JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package macros; | |
import sys.FileSystem; | |
import sys.io.File; | |
/** | |
* @author Pierre Chamberlain | |
* @usage In a compile.hxml file, you can call this command like so: | |
* | |
* --macro macros.MacroModuleFixer.run("yourFile.js", "MyModule") | |
* | |
*/ | |
class MacroModuleFixer | |
{ | |
public static function run(outputFile:String, moduleNames:String):Void { | |
if (!FileSystem.exists(outputFile)) { | |
throw "The file does not exists: " + outputFile; | |
} | |
var outputContent = File.getContent(outputFile); | |
var modules = moduleNames.split(","); | |
for (mod in modules) { | |
var keyMod = "var " + mod + " = {}"; | |
outputContent = StringTools.replace(outputContent, keyMod, "//" + keyMod); | |
} | |
File.saveContent(outputFile, outputContent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The purpose of this Macro is to remove module-initialization objects from a Haxe-generated JS file when it is already defined elsewhere in the larger scope of a project (from another JS file, or directly on an HTML / PHP page).
It does not simply remove ALL modules though - you have to specify them in a comma-delimited list.