Merge branch 'master' of github.com:280north/cappuccino

This commit is contained in:
Ross Boucher committed 2010-02-17 16:08:58 -08:00
commit c750b696d2
3 files changed
+78 -20

No files matched your search

+2
View File
@@ -378,4 +378,6 @@ exports.includePaths = function()
return global.OBJJ_INCLUDE_PATHS || ["Frameworks", "Frameworks/Debug"];
}
StaticResource.cwd = FILE.cwd();
exports.StaticResource = StaticResource;
+63 -19
View File
@@ -24,10 +24,10 @@ function main(args)
parser.printUsage(options);
return;
}
var rootPath = FILE.path(options.args[0]).join("").absolute();
var outputPath = FILE.path(options.args[1]).join("").absolute();
var analyzer = new ObjectiveJRuntimeAnalyzer(rootPath);
analyzer.setIncludePaths([rootPath.join("Frameworks")]);
@@ -35,52 +35,96 @@ function main(args)
analyzer.load(rootPath.join("main.j"));
analyzer.finishLoading();
var rootNode = analyzer.require("objective-j").StaticResource.root;
print("rootNode="+rootNode);
var root = analyzer.require("objective-j").StaticResource.root;
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);
var applicationJS = buildApplicationJS(applicationRoot);
FILE.copyTree(rootPath, outputPath);
outputPath.join("Application.js").write(applicationJS);
addApplicationScriptTag(outputPath.join("index.html"));
addApplicationScriptTag(outputPath.join("index-debug.html"));
}
function buildApplicationJS(applicationRoot) {
print(applicationRoot);
var buffer = [];
buffer.push("(function(){");
buffer.push("var nodeStack = [];");
buffer.push("var applicationRoot = StaticResource.root.nodeAtSubPath(StaticResource.cwd, YES);");
buffer.push("var currentNode = null;");
buffer.push("var newNode;")
serializeStaticResources(buffer, rootNode);
buffer.push("var newNode;");
serializeStaticResources(buffer, applicationRoot);
buffer.push("console.log(StaticResource.root);");
buffer.push("console.log(applicationRoot);");
buffer.push("})();");
var code = buffer.join("\n");
print(code);
rootPath.join("Application.js").write(code);
return code;
}
function serializeStaticResources(buffer, node, depth) {
depth = depth || 0;
//print(Array(depth+1).join(" ") + node);
// not the root node:
if (node.parent()) {
if (depth > 0) {
buffer.push("newNode = new StaticResource(" +
JSON.stringify(node.name()) +
", currentNode, " +
JSON.stringify(node.type()) + ", " +
JSON.stringify(node.isResolved()) + ");");
} else {
buffer.push("newNode = StaticResource.root;");
buffer.push("newNode = applicationRoot;");
}
if (node.contents())
buffer.push("newNode._contents = " + JSON.stringify(node.contents()) + ";");
if (!node.children())
return;
buffer.push("nodeStack.push(currentNode);");
buffer.push("currentNode = newNode;");
for (var name in node.children()) {
serializeStaticResources(buffer, node.children()[name], depth+1);
}
buffer.push("currentNode = nodeStack.pop();");
}
function addApplicationScriptTag(indexHTMLPath) {
var indexHTML = indexHTMLPath.read();
// attempt to append the Application.js script tag after
var newIndexHTML = indexHTML.replace(/([ \t]+)<script[^>]+Objective-J.js[^>]+>(?:\s*<\/script>)?/,
'$&\n$1<script src = "Application.js" type = "text/javascript"></script>');
if (newIndexHTML === indexHTML) {
print("Unable to automatically add Application.js script tag.");
}
indexHTMLPath.write(newIndexHTML);
}
+13 -1
View File
@@ -88,7 +88,17 @@ ask_remove_dir "/usr/local/share/objj"
ask_remove_dir "/usr/local/share/narwhal"
ask_remove_dir "/usr/local/narwhal"
if which "narwhal" > /dev/null; then
dir=$(dirname -- $(dirname -- $(which "narwhal")))
narwhal_path=$(which "narwhal")
# resolve symlinks
while [ -h "$narwhal_path" ]; do
dir=$(dirname -- "$narwhal_path")
sym=$(readlink -- "$narwhal_path")
narwhal_path=$(cd -- "$dir" && cd -- $(dirname -- "$sym") && pwd)/$(basename -- "$sym")
done
# NARWHAL_HOME is the 2nd ancestor directory of this shell script
dir=$(dirname -- "$(dirname -- "$narwhal_path")")
ask_remove_dir "$dir"
fi
@@ -187,10 +197,12 @@ if [ `uname` = "Darwin" ]; then
echo "================================================================================"
echo "Would you like to install the JavaScriptCore engine for Narwhal?"
echo "This is optional but will make building and running Objective-J much faster."
echo "NOTE: this is currently broken on versions of OS X before 10.6."
if prompt; then
tusk $tusk_install_command narwhal-jsc
if ! (cd "$install_directory/packages/narwhal-jsc" && make webkit); then
rm -rf "$install_directory/packages/narwhal-jsc"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "WARNING: building narwhal-jsc failed. Hit enter to continue."
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"