mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-05 12:15:32 +00:00
Merge branch 'master' of git@github.com:280north/cappuccino
This commit is contained in:
commit
62b1dbbc74
5 files changed
+70
-27
No files matched your search
+14
-13
@@ -21,7 +21,6 @@ parser.option("-m", "--main", "main")
|
||||
.help("The relative path (from INPUT_PROJECT) to the main file (default: 'main.j')");
|
||||
|
||||
parser.option("-F", "--framework", "frameworks")
|
||||
.def(["Frameworks"])
|
||||
.push()
|
||||
.help("Add a frameworks directory, relative to INPUT_PROJECT (default: ['Frameworks'])");
|
||||
|
||||
@@ -65,6 +64,8 @@ function main(args)
|
||||
}
|
||||
}
|
||||
|
||||
options.frameworks.push("Frameworks");
|
||||
|
||||
var mainPath = String(rootPath.join(options.main));
|
||||
var frameworks = options.frameworks.map(function(framework) { return rootPath.join(framework); });
|
||||
var environment = "Browser";
|
||||
@@ -86,13 +87,16 @@ function main(args)
|
||||
flattener.load(mainPath);
|
||||
flattener.finishLoading();
|
||||
|
||||
var root = flattener.require("objective-j").StaticResource.root;
|
||||
var rootResources = flattener.require("objective-j").StaticResource.rootResources();
|
||||
|
||||
var root = rootResources["file:"];
|
||||
|
||||
// FIXME: shouldn't have to do this manually
|
||||
var components = rootPath.split("/").slice(1, -1);
|
||||
var components = rootPath.split("/").slice(0, -1);
|
||||
components[0] = "/";
|
||||
var node = root;
|
||||
while (components.length) {
|
||||
node = node._children[components.shift()];
|
||||
node = node.children()[components.shift()];
|
||||
}
|
||||
applicationRoot = node;
|
||||
|
||||
@@ -121,8 +125,6 @@ function ObjectiveJFlattener(rootPath) {
|
||||
ObjectiveJFlattener.prototype = Object.create(ObjectiveJRuntimeAnalyzer.prototype);
|
||||
|
||||
ObjectiveJFlattener.prototype.buildApplicationJS = function(applicationRoot) {
|
||||
print(applicationRoot);
|
||||
|
||||
this.serializeStaticResources(applicationRoot);
|
||||
this.serializeStaticFileExecutables();
|
||||
|
||||
@@ -133,7 +135,8 @@ ObjectiveJFlattener.prototype.buildApplicationJS = function(applicationRoot) {
|
||||
buffer.push(this.bundleBuffer.join("\n"));
|
||||
|
||||
buffer.push("var nodeStack = [];");
|
||||
buffer.push("var applicationRoot = ObjectiveJ.StaticResource.root.nodeAtSubPath(ObjectiveJ.StaticResource.cwd, YES);");
|
||||
buffer.push("var appURL = new CFURL('.', ObjectiveJ.pageURL);")
|
||||
buffer.push("var applicationRoot = ObjectiveJ.StaticResource.resourceAtURL(appURL, true);");
|
||||
buffer.push("var currentNode = null;");
|
||||
buffer.push("var newNode;");
|
||||
|
||||
@@ -151,14 +154,14 @@ ObjectiveJFlattener.prototype.buildApplicationJS = function(applicationRoot) {
|
||||
ObjectiveJFlattener.prototype.serializeStaticFileExecutables = function() {
|
||||
this.require("objective-j").FileExecutable.allFileExecutables().forEach(function(aFileExecutable) {
|
||||
var deps = aFileExecutable.fileDependencies().map(function(dependency) {
|
||||
return "new ObjectiveJ.FileDependency("+JSON.stringify(dependency.path())+","+JSON.stringify(dependency.isLocal())+")"
|
||||
return "new ObjectiveJ.FileDependency(new CFURL("+JSON.stringify(dependency.path())+"),"+JSON.stringify(dependency.isLocal())+")"
|
||||
}).join(",");
|
||||
|
||||
var func = aFileExecutable._function.toString();
|
||||
// HACK
|
||||
func = func.replace(", require, exports, module, system, print, window", "");
|
||||
|
||||
this.functionsBuffer.push("var path = ObjectiveJ.StaticResource.cwd + "+JSON.stringify("/"+this.rootPath.relative(aFileExecutable.path()))+";");
|
||||
this.functionsBuffer.push("var path = "+JSON.stringify(this.rootPath.relative(aFileExecutable.path()).toString())+";");
|
||||
this.functionsBuffer.push("new ObjectiveJ.FileExecutable(path,"+
|
||||
"new ObjectiveJ.Executable(null, ["+deps+"], path, "+func+"));");
|
||||
}, this);
|
||||
@@ -167,11 +170,9 @@ ObjectiveJFlattener.prototype.serializeStaticFileExecutables = function() {
|
||||
ObjectiveJFlattener.prototype.serializeStaticResources = function(node, depth) {
|
||||
depth = depth || 0;
|
||||
|
||||
//print(Array(depth+1).join(" ") + node);
|
||||
|
||||
var bundle = this.context.global.CFBundle.bundleContainingPath(node.path());
|
||||
var bundle = this.context.global.CFBundle.bundleContainingURL(node.URL());
|
||||
if (!bundle) {
|
||||
stream.print("\0yellow(Warning:\0) No bundle for path: \0cyan("+node.path()+"\0)");
|
||||
stream.print("\0yellow(Warning:\0) No bundle for path: \0cyan("+node.URL()+"\0)");
|
||||
}
|
||||
else if (!this._outputBundles[bundle.path()]) {
|
||||
this._outputBundles[bundle.path()] = bundle;
|
||||
|
||||
+7
-4
@@ -254,7 +254,7 @@ function pressEnvironment(rootPath, outputFiles, environment, options) {
|
||||
for (var path in requiredFiles)
|
||||
{
|
||||
var executable = analyzer.executableForImport(path),
|
||||
bundle = analyzer.context.global.CFBundle.bundleContainingPath(executable.path()),
|
||||
bundle = analyzer.context.global.CFBundle.bundleContainingURL(executable.path()),
|
||||
relativePath = FILE.relative(FILE.join(bundle.path(), ""), executable.path());
|
||||
|
||||
if (executable.path() !== path)
|
||||
@@ -274,7 +274,7 @@ function pressEnvironment(rootPath, outputFiles, environment, options) {
|
||||
for (var i = 0; i < dependencies.length; i++) {
|
||||
var dependency = dependencies[i];
|
||||
var dependencyExecutable = new _OBJJ.FileExecutableSearch(
|
||||
dependency.isLocal() ? FILE.join(FILE.dirname(path), dependency.path()) : dependency.path(),
|
||||
new analyzer.context.global.CFURL(dependency.isLocal() ? FILE.join(FILE.dirname(path), dependency.path()) : dependency.path()),
|
||||
dependency.isLocal()
|
||||
).result();
|
||||
var dependencyPath = dependencyExecutable.path();
|
||||
@@ -286,11 +286,14 @@ function pressEnvironment(rootPath, outputFiles, environment, options) {
|
||||
RegExp.escape("("),
|
||||
"[\"']"+RegExp.escape(dependency.path())+"[\"']",
|
||||
RegExp.escape(","),
|
||||
RegExp.escape(dependency.isLocal() ? "true" : "false"),
|
||||
dependency.isLocal() ? "(true|YES)" : "(false|NO)",
|
||||
RegExp.escape(")")
|
||||
].join("\\s*"), "g");
|
||||
// replace instances of "objj_executeFile()" with "(undefined)"
|
||||
code = code.replace(regex, "/* $& */ (undefined)");
|
||||
newCode = code.replace(regex, "/* $& */ (undefined)");
|
||||
if (newCode === code)
|
||||
stream.print("\0yellow(Warning:\0) Unable to strip import for \0cyan(" + dependency.path() + "\0) (" + dependency.isLocal() + ")");
|
||||
code = newCode;
|
||||
// remove from dependencies list (decrement i since we're removing an item)
|
||||
dependencies.splice(i--, 1);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,24 @@ ObjectiveJRuntimeAnalyzer = function(rootPath)
|
||||
this.scope = setupObjectiveJ(this.context);
|
||||
|
||||
this.require = this.context.global.require;
|
||||
|
||||
this.mainBundleURL = new this.context.global.CFURL("file:" + this.rootPath);
|
||||
|
||||
var _OBJJ = this.require("objective-j");
|
||||
|
||||
// TODO: deprecate these
|
||||
_OBJJ.Executable.prototype.path = function() {
|
||||
var url = this.URL();
|
||||
return url ? url.absoluteURL().path() : null;
|
||||
}
|
||||
_OBJJ.FileDependency.prototype.path = function() {
|
||||
var url = this.URL();
|
||||
return url ? url.path() : null;
|
||||
}
|
||||
this.context.global.CFBundle.prototype.executablePath = function() {
|
||||
var url = this.executableURL();
|
||||
return url ? url.absoluteURL().path() : null;
|
||||
}
|
||||
}
|
||||
|
||||
ObjectiveJRuntimeAnalyzer.prototype.setIncludePaths = function(includePaths) {
|
||||
@@ -20,6 +38,14 @@ ObjectiveJRuntimeAnalyzer.prototype.setEnvironments = function(environments) {
|
||||
this.context.global.CFBundle.environments = function() { return environments; };
|
||||
}
|
||||
|
||||
ObjectiveJRuntimeAnalyzer.prototype.makeAbsoluteURL = function(/*CFURL|String*/ aURL)
|
||||
{
|
||||
if (aURL instanceof this.context.global.CFURL && aURL.scheme())
|
||||
return aURL;
|
||||
|
||||
return new this.context.global.CFURL(aURL, this.mainBundleURL);
|
||||
}
|
||||
|
||||
ObjectiveJRuntimeAnalyzer.prototype.initializeGlobalRecorder = function()
|
||||
{
|
||||
this.initializeGlobalRecorder = function(){}; // run once
|
||||
@@ -40,7 +66,7 @@ ObjectiveJRuntimeAnalyzer.prototype.initializeGlobalRecorder = function()
|
||||
|
||||
var after = cloneProperties(self.scope);
|
||||
|
||||
if (before) {
|
||||
if (before && currentFile) {
|
||||
self.files[currentFile] = self.files[currentFile] || {};
|
||||
self.files[currentFile].globals = self.files[currentFile].global || {};
|
||||
|
||||
@@ -52,15 +78,22 @@ ObjectiveJRuntimeAnalyzer.prototype.initializeGlobalRecorder = function()
|
||||
changed : self.files[currentFile].globals
|
||||
});
|
||||
}
|
||||
else if (!currentFile) {
|
||||
CPLog.warn("currentFile is null. WTF.")
|
||||
}
|
||||
|
||||
before = after;
|
||||
}
|
||||
|
||||
var _OBJJ = this.require("objective-j");
|
||||
var _fileExecuterForPath = _OBJJ.Executable.fileExecuterForPath;
|
||||
_OBJJ.Executable.fileExecuterForPath = function(/*String*/ referencePath) {
|
||||
var fileExecutor = _fileExecuterForPath.apply(this, arguments);
|
||||
return function(/*String*/ aPath, /*BOOL*/ isLocal, /*BOOL*/ shouldForce) {
|
||||
var _fileExecuterForURL = _OBJJ.Executable.fileExecuterForURL;
|
||||
_OBJJ.Executable.fileExecuterForURL = function(/*CFURL*/ referenceURL) {
|
||||
referenceURL = self.makeAbsoluteURL(referenceURL);
|
||||
var referencePath = referenceURL.absoluteURL().path()
|
||||
var fileExecutor = _fileExecuterForURL.apply(this, arguments);
|
||||
return function(/*CFURL*/ aURL, /*BOOL*/ isQuoted, /*BOOL*/ shouldForce) {
|
||||
var aPath = typeof aURL === "string" ? aURL : aURL.absoluteURL().path();
|
||||
|
||||
recordAndReset();
|
||||
|
||||
evaluatingPaths.push(currentFile);
|
||||
@@ -68,7 +101,7 @@ ObjectiveJRuntimeAnalyzer.prototype.initializeGlobalRecorder = function()
|
||||
// NOTE: we distinguish local and library imports using absolute and relative paths.
|
||||
// we resolve the library paths later (in "mergeLibraryImports()") since doing it here seems
|
||||
// to change the resulting recorded globals.
|
||||
if (isLocal && !FILE.isAbsolute(aPath))
|
||||
if (isQuoted && !FILE.isAbsolute(aPath))
|
||||
currentFile = FILE.normal(FILE.join(referencePath, aPath));
|
||||
else
|
||||
currentFile = aPath;
|
||||
@@ -137,7 +170,7 @@ ObjectiveJRuntimeAnalyzer.prototype.mergeLibraryImports = function()
|
||||
for (var relativePath in this.files) {
|
||||
if (FILE.isRelative(relativePath)) {
|
||||
var absolutePath = this.executableForImport(relativePath, false).path();
|
||||
// CPLog.debug("Merging " + relativePath + " => " + absolutePath);
|
||||
CPLog.debug("Merging " + relativePath + " => " + absolutePath);
|
||||
|
||||
this.files[absolutePath] = this.files[absolutePath] || {};
|
||||
this.files[absolutePath].globals = this.files[absolutePath].globals || {};
|
||||
@@ -155,7 +188,7 @@ ObjectiveJRuntimeAnalyzer.prototype.executableForImport = function(path, isLocal
|
||||
{
|
||||
if (isLocal === undefined) isLocal = true;
|
||||
var _OBJJ = this.require("objective-j");
|
||||
return new _OBJJ.FileExecutableSearch(path, isLocal).result();
|
||||
return new _OBJJ.FileExecutableSearch(new this.context.global.CFURL(path), isLocal).result();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -60,6 +60,8 @@ if (mainBundleURL === assumedResolvedURL)
|
||||
|
||||
StaticResource.resourceAtURL(assumedResolvedURL, YES);
|
||||
|
||||
exports.pageURL = pageURL;
|
||||
|
||||
exports.bootstrap = function()
|
||||
{
|
||||
resolveMainBundleURL();
|
||||
|
||||
@@ -625,11 +625,15 @@ CFBundle.prototype.onerror = function(/*Event*/ anEvent)
|
||||
throw anEvent.error;
|
||||
}
|
||||
|
||||
//
|
||||
CFBundle.prototype.bundlePath = function()
|
||||
{
|
||||
return this._bundleURL.absoluteURL().path();
|
||||
}
|
||||
|
||||
CFBundle.prototype.path = function()
|
||||
{
|
||||
return this._bundleURL.absoluteString();
|
||||
CPLog.warn("CFBundle.prototype.path is deprecated, use CFBundle.prototype.bundlePath instead.");
|
||||
return this.bundlePath.apply(this, arguments);
|
||||
}
|
||||
|
||||
CFBundle.prototype.pathForResource = function(aResource)
|
||||
|
||||
Reference in new issue
Block a user