From 6721b7edaef9b9f6472f402cf2c9f144a976e97a Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Thu, 16 Apr 2015 23:53:16 +0000 Subject: [PATCH] Loading bundles --- package.json | 2 +- plugins/c9.core/ext.js | 18 +++++----- plugins/c9.ide.plugins/debug.js | 35 +++++++++++-------- plugins/c9.ide.plugins/manager.js | 2 +- .../mock/c9.ide.example3/install.js | 2 +- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 45bfc7e4..1b3a007e 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "c9.ide.language.jsonalyzer": "#a1057f20db", "c9.ide.collab": "#7b09419b5c", "c9.ide.local": "#cf624506cc", - "c9.ide.find": "#4db399c1de", + "c9.ide.find": "#1b178751d7", "c9.ide.find.infiles": "#72582de3cd", "c9.ide.find.replace": "#e4daf722b8", "c9.ide.run.debug": "#638e6b00b3", diff --git a/plugins/c9.core/ext.js b/plugins/c9.core/ext.js index 5d613650..f5b90e52 100644 --- a/plugins/c9.core/ext.js +++ b/plugins/c9.core/ext.js @@ -121,7 +121,7 @@ define(function(require, exports, module) { } } - return usedBy + return usedBy; } function unloadAllPlugins(exclude) { @@ -184,7 +184,7 @@ define(function(require, exports, module) { if (!lut[name]) throw new Error("Could not find plugin: " + name); - var plugin = lut[name] + var plugin = lut[name]; if (plugin.unload({ keep: true }) === false) throw new Error("Failed unloading plugin: " + name); @@ -407,7 +407,7 @@ define(function(require, exports, module) { this.freezePublicAPI.baseclass = function(){ baseclass = true; }; function getElement(name, callback) { - //remove id's after storing them. + // remove id's after storing them. if (!callback) { // If we run without APF, just return a simple object if (typeof apf == "undefined") @@ -442,13 +442,13 @@ define(function(require, exports, module) { return; // Delete their global reference delete window[id]; - //delete apf.nameserver.lookup.all[node.id]; + // delete apf.nameserver.lookup.all[node.id]; // Keep their original name in a lookup table names[id] = node; // Set a new unique id - if (node.localName != "page") { //Temp hack, should fix in tabs + if (node.localName != "page") { // Temp hack, should fix in tabs node.id = "element" + node.$uniqueId; apf.nameserver.lookup.all[node.id] = node; } @@ -532,7 +532,7 @@ define(function(require, exports, module) { function cleanUp(keepElements) { if (!keepElements) { - //Loop through elements + // Loop through elements elements.forEach(function(element) { element.destroy(true, true); }); @@ -541,7 +541,7 @@ define(function(require, exports, module) { waiting = []; } - //Loop through events + // Loop through events events.forEach(function(eventRecord) { var event = eventRegistry[eventRecord[0]]; if (!event) return; // this happens with mock plugins during testing @@ -562,7 +562,7 @@ define(function(require, exports, module) { }); events = []; - //Loop through other + // Loop through other other.forEach(function(o) { o(); }); @@ -594,7 +594,7 @@ define(function(require, exports, module) { api[type].get("persistent/" + apiKey, function(err, data){ if (err) return callback(err); - try{ callback(null, JSON.stringify(data)); } + try { callback(null, JSON.stringify(data)); } catch(e){ return callback(e); } }); } diff --git a/plugins/c9.ide.plugins/debug.js b/plugins/c9.ide.plugins/debug.js index 4d78cfeb..2d1216b5 100644 --- a/plugins/c9.ide.plugins/debug.js +++ b/plugins/c9.ide.plugins/debug.js @@ -27,6 +27,7 @@ define(function(require, exports, module) { var notify = imports["dialog.notification"].show; var dirname = require("path").dirname; + var basename = require("path").basename; var join = require("path").join; var async = require("async"); @@ -126,13 +127,15 @@ define(function(require, exports, module) { var resourceHolder = new Plugin(); var resourceVersion = ""; + resourceHolder.on("load", function(){ load(); }); + resourceHolder.freezePublicAPI({ get version(){ return resourceVersion }, set version(v){ resourceVersion = v; } }); var inited = false; - resourceHolder.on("load", function(){ + function load(){ async.parallel([ function(next){ // Fetch package.json @@ -184,8 +187,8 @@ define(function(require, exports, module) { }); }, function(next){ - var path = join(c9.home, "plugins", name); - var rePath = new RegExp("^" + util.escapeRegExp(path), "g"); + var path = join("~/.c9/plugins", name); + var rePath = new RegExp("^" + util.escapeRegExp(path.replace(/^~/, c9.home) + "/"), "gm"); find.getFileList({ path: path, nocache: true, @@ -194,11 +197,10 @@ define(function(require, exports, module) { if (err) return next(err); - // Remove the base path data = data.replace(rePath, ""); - if (data.indexOf("/__installed__.js") !== -1) + if (data.match(/^__installed__.js/)) return next("installed"); // Process all the submodules @@ -207,6 +209,9 @@ define(function(require, exports, module) { if (err) return next(err); + if (!inited) + resourceHolder.load(name + ".bundle"); + // Done next(); }); @@ -220,9 +225,8 @@ define(function(require, exports, module) { inited = true; } }); - }); - - resourceHolder.load("Cloud9 Bundle"); + } + load(); } function finish(){ @@ -256,17 +260,17 @@ define(function(require, exports, module) { var filename = RegExp.$2; if (filename.indexOf("/") > -1) return; - if (type == "module" && filename.match(reModule)) + if (type == "modes" && filename.match(reModule)) return; parallel.push(function(next){ - fs.readFile(join(path, filename), function(err, data){ + fs.readFile(join(path, type, filename), function(err, data){ if (err) { console.error(err); return next(err); } - addStaticPlugin(type, path, filename, data, plugin); + addStaticPlugin(type, basename(path), filename, data, plugin); next(); }); @@ -282,13 +286,14 @@ define(function(require, exports, module) { + (type == "installer" ? "" : type + "/") + filename.replace(/\.js$/, ""); - if (!services[plugin.name] && type !== "installer") { - services[plugin.name] = plugin; + var bundleName = pluginName + ".bundle"; + if (!services[bundleName] && type !== "installer") { + services[bundleName] = plugin; architect.lut["~/.c9/plugins/" + pluginName] = { provides: [] }; - architect.pluginToPackage[plugin.name] = { - path: plugin.packagePath, + architect.pluginToPackage[bundleName] = { + path: "~/.c9/plugins/" + pluginName, package: pluginName, version: plugin.version, isAdditionalMode: true diff --git a/plugins/c9.ide.plugins/manager.js b/plugins/c9.ide.plugins/manager.js index ae190189..718310e7 100644 --- a/plugins/c9.ide.plugins/manager.js +++ b/plugins/c9.ide.plugins/manager.js @@ -391,7 +391,7 @@ define(function(require, exports, module) { var lut = ext.named; - ext.plugins.forEach(function(plugin) { + ext.plugins.forEach(function(plugin) { if (plugin.name == "Cloud9 Bundle") debugger; var info = architect.pluginToPackage[plugin.name]; var packageName = info && info.package || "runtime"; diff --git a/plugins/c9.ide.plugins/mock/c9.ide.example3/install.js b/plugins/c9.ide.plugins/mock/c9.ide.example3/install.js index c8fbc352..f87bdec5 100644 --- a/plugins/c9.ide.plugins/mock/c9.ide.example3/install.js +++ b/plugins/c9.ide.plugins/mock/c9.ide.example3/install.js @@ -10,7 +10,7 @@ module.exports = function(session, options){ "optional": true }, [ { - "npm": ["sqlite3@2.1.18"] + "npm": ["sqlite3@3.0.5"] }, { "tar.gz": {