diff --git a/Objective-J/Bootstrap.js b/Objective-J/Bootstrap.js
index 0bda2073c..abd530ff7 100644
--- a/Objective-J/Bootstrap.js
+++ b/Objective-J/Bootstrap.js
@@ -26,15 +26,19 @@ var cwd = FILE.cwd(),
StaticResource.root = rootResource;
#ifdef BROWSER
-if (rootResource.isResolved())
+
+exports.bootstrap = function()
{
- rootResource.nodeAtSubPath(FILE.dirname(cwd), YES);
- resolveCWD();
-}
-else
-{
- rootResource.resolve();
- rootResource.addEventListener("resolve", resolveCWD);
+ if (rootResource.isResolved())
+ {
+ rootResource.nodeAtSubPath(FILE.dirname(cwd), YES);
+ resolveCWD();
+ }
+ else
+ {
+ rootResource.resolve();
+ rootResource.addEventListener("resolve", resolveCWD);
+ }
}
function resolveCWD()
@@ -76,4 +80,9 @@ afterDocumentLoad(function()
{
documentLoaded = YES;
});
+
+
+if (typeof OBJJ_AUTO_BOOTSTRAP === "undefined" || OBJJ_AUTO_BOOTSTRAP)
+ exports.bootstrap();
+
#endif
diff --git a/Tools/flatten/flatten b/Tools/flatten/flatten
index c6b24eb9e..9854df81a 100755
--- a/Tools/flatten/flatten
+++ b/Tools/flatten/flatten
@@ -39,19 +39,15 @@ function main(args)
var root = flattener.require("objective-j").StaticResource.root;
+ // FIXME: shouldn't have to do this manually
var components = rootPath.split("/").slice(1, -1);
- print(components)
var node = root;
while (components.length) {
- print(node._path);
node = node._children[components.shift()];
}
applicationRoot = node;
- print("applicationRoot._children="+Object.keys(applicationRoot._children));
- print("rootPath="+rootPath);
- print("applicationRoot="+applicationRoot.toString());
- print("root="+root);
+ print(applicationRoot.toString());
var applicationJS = flattener.buildApplicationJS(applicationRoot);
@@ -59,8 +55,8 @@ function main(args)
outputPath.join("Application.js").write(applicationJS);
- addApplicationScriptTag(outputPath.join("index.html"));
- addApplicationScriptTag(outputPath.join("index-debug.html"));
+ rewriteMainHTML(outputPath.join("index.html"));
+ rewriteMainHTML(outputPath.join("index-debug.html"));
}
// ObjectiveJFlattener inherits from ObjectiveJRuntimeAnalyzer
@@ -95,6 +91,7 @@ ObjectiveJFlattener.prototype.buildApplicationJS = function(applicationRoot) {
buffer.push("console.log(ObjectiveJ.StaticResource.root);");
buffer.push("console.log(applicationRoot);");
+ buffer.push("ObjectiveJ.bootstrap();");
buffer.push("})();");
return buffer.join("\n");
@@ -150,16 +147,24 @@ ObjectiveJFlattener.prototype.serializeStaticResources = function(node, depth) {
this.resourceBuffer.push("currentNode = nodeStack.pop();");
}
-function addApplicationScriptTag(indexHTMLPath) {
+function rewriteMainHTML(indexHTMLPath) {
var indexHTML = indexHTMLPath.read();
- // attempt to append the Application.js script tag after
- var newIndexHTML = indexHTML.replace(/([ \t]+)');
+ // "$1" is the matching indentation
+ var scriptTagsBefore = '$1';
+ var scriptTagsAfter = '$1';
+
+ // attempt to find Objective-J script tag and add ours
+ var newIndexHTML = indexHTML.replace(/([ \t]+)