From f5edf2a4c2bc348093bbefc8702c8975c470b9e1 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Thu, 25 Feb 2010 19:49:35 -0800 Subject: [PATCH] Cleanup press and flatten arguments. --- CommonJS/bin/flatten | 50 +++++++++++++++++++++++++++++++++++++++++--- CommonJS/bin/press | 18 +++++----------- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/CommonJS/bin/flatten b/CommonJS/bin/flatten index 760efc6c3..ff3b5602a 100755 --- a/CommonJS/bin/flatten +++ b/CommonJS/bin/flatten @@ -14,6 +14,26 @@ var parser = new (require("args").Parser)(); parser.usage("INPUT_PROJECT OUTPUT_PROJECT"); parser.help("Combine a Cappuccino application into a single JavaScript file."); +parser.option("-m", "--main", "main") + .def("main.j") + .set() + .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'])"); + +parser.option("-f", "--force", "force") + .def(false) + .set(true) + .help("Force overwriting OUTPUT_PROJECT if it exists"); + +parser.option("-v", "--verbose", "verbose") + .def(false) + .set(true) + .help("Verbose logging"); + parser.helpful(); function main(args) @@ -28,12 +48,36 @@ function main(args) var rootPath = FILE.path(options.args[0]).join("").absolute(); var outputPath = FILE.path(options.args[1]).join("").absolute(); + if (outputPath.exists()) { + if (options.force) { + // FIXME: why doesn't this work?! + //outputPath.rmtree(); + OS.system(["rm", "-rf", outputPath]); + } else { + CPLog.error("OUTPUT_PROJECT " + outputPath + " exists. Use -f to overwrite."); + OS.exit(1); + } + } + + var mainPath = String(rootPath.join(options.main)); + var frameworks = options.frameworks.map(function(framework) { return rootPath.join(framework); }); + var environment = "Browser"; + + stream.print("\0yellow("+Array(81).join("=")+"\0)"); + stream.print("Application root: \0green(" + rootPath + "\0)"); + stream.print("Output directory: \0green(" + outputPath + "\0)"); + + stream.print("\0yellow("+Array(81).join("=")+"\0)"); + stream.print("Main file: \0green(" + mainPath + "\0)"); + stream.print("Frameworks: \0green(" + frameworks + "\0)"); + stream.print("Environment: \0green(" + environment + "\0)"); + var flattener = new ObjectiveJFlattener(rootPath); - flattener.setIncludePaths([rootPath.join("Frameworks")]); - flattener.setEnvironments(["Browser", "ObjJ"]); + flattener.setIncludePaths(frameworks); + flattener.setEnvironments([environment, "ObjJ"]); - flattener.load(rootPath.join("main.j")); + flattener.load(mainPath); flattener.finishLoading(); var root = flattener.require("objective-j").StaticResource.root; diff --git a/CommonJS/bin/press b/CommonJS/bin/press index 632b0717f..c590a089e 100755 --- a/CommonJS/bin/press +++ b/CommonJS/bin/press @@ -26,11 +26,6 @@ parser.option("-F", "--framework", "frameworks") .push() .help("Add a frameworks directory, relative to INPUT_PROJECT (default: ['Frameworks'])"); -parser.option("-E", "--environment", "environments") - .def(['Browser']) - .push() - .help("Add a platform name (default: ['Browser'])"); - parser.option("-f", "--force", "force") .def(false) .set(true) @@ -85,13 +80,12 @@ function press(rootPath, outputPath, options) { var outputFiles = {}, totalBytes = {executable:0, data:0, mhtml:0}; + var environment = "Browser"; // analyze and gather files for each environment: - options.environments.forEach(function(environment) { - var returnedBytes = pressEnvironment(rootPath, outputFiles, environment, options); + var returnedBytes = pressEnvironment(rootPath, outputFiles, environment, options); - for (var i in returnedBytes) - totalBytes[i] += returnedBytes[i]; - }); + for (var i in returnedBytes) + totalBytes[i] += returnedBytes[i]; // phase 4: copy everything and write out the new files stream.print("\0red(PHASE 4:\0) copy to output \0green(" + rootPath + "\0) => \0green(" + outputPath + "\0)"); @@ -129,7 +123,7 @@ function press(rootPath, outputPath, options) { if (FILE.exists(themePath)) { - var themeEnvPath = FILE.join(themePath, options.environments[0] + ".environment"), + var themeEnvPath = FILE.join(themePath, environment + ".environment"), themeExecutablePath = FILE.join(themeEnvPath, themeName+".blend.sj"), themeDataPath = FILE.join(themeEnvPath, "dataURLs.txt"), themeMHTMLPath = FILE.join(themeEnvPath, "MHTMLPaths.txt"); @@ -168,9 +162,7 @@ function pressEnvironment(rootPath, outputFiles, environment, options) { var _OBJJ = analyzer.require("objective-j"); - // include paths: analyzer.setIncludePaths(frameworks); - // environments: analyzer.setEnvironments([environment, "ObjJ"]); // build list of cibs to inspect for dependent classes