mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-28 13:17:42 +00:00
Merge branch 'loader' of github.com:280north/cappuccino into loader
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
|
||||
makeExportsGlobal();
|
||||
|
||||
var rootNode = new StaticResourceNode("", NULL, StaticResourceNode.DirectoryType, YES),
|
||||
cwd = FILE.cwd();
|
||||
#ifndef COMMONJS
|
||||
@@ -46,3 +43,7 @@ afterDocumentLoad(function()
|
||||
documentLoaded = YES;
|
||||
});
|
||||
#endif
|
||||
|
||||
exports.rootNode = rootNode;
|
||||
|
||||
makeExportsGlobal();
|
||||
|
||||
Executable
+86
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env objj
|
||||
|
||||
require("narwhal").ensureEngine("rhino");
|
||||
|
||||
@import <Foundation/Foundation.j>
|
||||
@import <AppKit/AppKit.j>
|
||||
|
||||
@import "../press/objj-analysis-tools.j"
|
||||
|
||||
var FILE = require("file");
|
||||
|
||||
var parser = new (require("args").Parser)();
|
||||
|
||||
parser.usage("INPUT_PROJECT OUTPUT_PROJECT");
|
||||
parser.help("Combine a Cappuccino application into a single JavaScript file.");
|
||||
|
||||
parser.helpful();
|
||||
|
||||
function main(args)
|
||||
{
|
||||
var options = parser.parse(args);
|
||||
|
||||
if (options.args.length < 2) {
|
||||
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")]);
|
||||
analyzer.setEnvironments(["Browser", "ObjJ"]);
|
||||
|
||||
analyzer.load(rootPath.join("main.j"));
|
||||
analyzer.finishLoading();
|
||||
|
||||
var rootNode = analyzer.require("objective-j").rootNode;
|
||||
print("rootNode="+rootNode);
|
||||
|
||||
var buffer = [];
|
||||
buffer.push("(function(){");
|
||||
buffer.push("var nodeStack = [];");
|
||||
buffer.push("var currentNode = null;");
|
||||
buffer.push("var newNode;")
|
||||
serializeStaticResourceNodes(buffer, rootNode);
|
||||
buffer.push("})();");
|
||||
|
||||
var code = buffer.join("\n");
|
||||
|
||||
print(code);
|
||||
rootPath.join("Application.js").write(code);
|
||||
}
|
||||
|
||||
function serializeStaticResourceNodes(buffer, node, depth) {
|
||||
depth = depth || 0;
|
||||
|
||||
//print(Array(depth+1).join(" ") + node);
|
||||
|
||||
// not the root node:
|
||||
if (node.parentNode()) {
|
||||
buffer.push("newNode = new StaticResourceNode(" +
|
||||
JSON.stringify(node.name()) +
|
||||
", currentNode, " +
|
||||
JSON.stringify(node.type()) + ", " +
|
||||
JSON.stringify(node.isResolved()) + ");");
|
||||
} else {
|
||||
buffer.push("newNode = rootNode;");
|
||||
}
|
||||
|
||||
if (node.contents())
|
||||
buffer.push("newNode._contents = " + JSON.stringify(node.contents()) + ";");
|
||||
|
||||
if (!node._childNodes)
|
||||
return;
|
||||
|
||||
buffer.push("nodeStack.push(currentNode);");
|
||||
buffer.push("currentNode = newNode;");
|
||||
|
||||
for (var name in node._childNodes) {
|
||||
serializeStaticResourceNodes(buffer, node._childNodes[name], depth+1);
|
||||
}
|
||||
|
||||
buffer.push("currentNode = nodeStack.pop();");
|
||||
}
|
||||
+4
-6
@@ -6,16 +6,14 @@ require("narwhal").ensureEngine("rhino");
|
||||
@import "objj-analysis-tools.j"
|
||||
@import "cib-analysis-tools.j"
|
||||
|
||||
var ARGS = require("args");
|
||||
var FILE = require("file");
|
||||
var OS = require("os");
|
||||
|
||||
var stream = require("term").stream;
|
||||
|
||||
var parser = new ARGS.Parser();
|
||||
var parser = new (require("args").Parser)();
|
||||
|
||||
parser.usage("INPUT_PROJECT OUTPUT_PROJECT");
|
||||
parser.help("Optimizes Cappuccino applications for deployment to the web.");
|
||||
parser.help("Analyze and strip unused files from a Cappuccino project's .sj bundles.");
|
||||
|
||||
parser.option("-m", "--main", "main")
|
||||
.def("main.j")
|
||||
@@ -138,9 +136,9 @@ function pressEnvironment(rootPath, outputFiles, environment, options) {
|
||||
var _OBJJ = analyzer.require("objective-j");
|
||||
|
||||
// include paths:
|
||||
analyzer.context.global.OBJJ_INCLUDE_PATHS = frameworks;
|
||||
analyzer.setIncludePaths(frameworks);
|
||||
// environments:
|
||||
_OBJJ.environments = function() { return [environment, "ObjJ"] };
|
||||
analyzer.setEnvironments([environment, "ObjJ"]);
|
||||
|
||||
// build list of cibs to inspect for dependent classes
|
||||
// FIXME: what's the best way to determine which cibs to look in?
|
||||
|
||||
@@ -12,6 +12,14 @@ function ObjectiveJRuntimeAnalyzer(rootPath)
|
||||
this.require = this.context.global.require;
|
||||
}
|
||||
|
||||
ObjectiveJRuntimeAnalyzer.prototype.setIncludePaths = function(includePaths) {
|
||||
this.context.global.OBJJ_INCLUDE_PATHS = includePaths;
|
||||
}
|
||||
|
||||
ObjectiveJRuntimeAnalyzer.prototype.setEnvironments = function(environments) {
|
||||
this.require("objective-j").environments = function() { return environments; };
|
||||
}
|
||||
|
||||
ObjectiveJRuntimeAnalyzer.prototype.initializeGlobalRecorder = function()
|
||||
{
|
||||
this.initializeGlobalRecorder = function(){}; // run once
|
||||
|
||||
Reference in New Issue
Block a user