From 8592cfb89db05f0e52d8c1b8c7046e6f49e3522d Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 1 Feb 2012 00:09:27 -0800 Subject: Adding a montage framework copy for the user document Adding a new montage copy containing the latest version of montage to use the new native widgets Signed-off-by: Valerio Virgillito --- node_modules/montage-user/node.js | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 node_modules/montage-user/node.js (limited to 'node_modules/montage-user/node.js') diff --git a/node_modules/montage-user/node.js b/node_modules/montage-user/node.js new file mode 100644 index 00000000..5ac51ed7 --- /dev/null +++ b/node_modules/montage-user/node.js @@ -0,0 +1,79 @@ + +var FS = require("fs"); +var PATH = require("path"); + +var MontageBoot = require("./montage"); + +var Require = require("./require/require"); +var Promise = require("./core/promise"); +var URL = require("./core/url"); + +exports.bootstrap = function (callback) { + var command = process.argv.slice(0, 3); + var args = process.argv.slice(2); + var program = args.shift(); + FS.realpath(program, function (error, program) { + if (error) { + throw new Error(error); + } + findPackage(program, function (error, directory) { + if (error === "Can't find package") { + loadFreeModule(program, command, args); + } else if (error) { + throw new Error(error); + } else { + loadPackagedModule(directory, program, command, args); + } + }); + }); +}; + +MontageBoot.loadPackage = function (location, config) { + var config = {}; + + config.location = URL.resolve('file:/', location + '/'); + + // setup the reel loader + config.makeLoader = function (config) { + return MontageBoot.ReelLoader(config, + Require.DefaultLoaderConstructor(config)); + }; + + // setup serialization compiler + config.makeCompiler = function (config) { + return MontageBoot.TemplateCompiler(config, + MontageBoot.SerializationCompiler(config, + Require.DefaultCompilerConstructor(config))); + }; + + return Require.PackageSandbox(config.location, config); +}; + +var findPackage = function (path, callback) { + var directory = PATH.dirname(path); + if (directory === path) + return callback("Can't find package"); + var packageJson = PATH.join(directory, "package.json"); + FS.stat(path, function (error, stat) { + if (error) callback(error); + if (stat.isFile()) { + callback(null, directory); + } else { + findPackage(directory, callback); + } + }); +} + +var loadFreeModule = function (program, command, args) { + throw new Error("Can't load module that is not in a package"); +}; + +var loadPackagedModule = function (directory, program, command, args) { + MontageBoot.loadPackage(directory) + .then(function (require) { + var id = program.slice(directory.length + 1); + return require.async(id); + }) + .end(); +}; + -- cgit v1.2.3