kopia lustrzana https://github.com/c9/core
load standalone plugins from __packed__
rodzic
003aea3d49
commit
a3edfaf181
|
@ -82,7 +82,8 @@ module.exports = function(options) {
|
|||
"plugins/c9.core/util",
|
||||
{
|
||||
packagePath: "plugins/c9.ide.plugins/loader",
|
||||
plugins: options.plugins || []
|
||||
plugins: options.plugins || [],
|
||||
loadFromDisk: options.standalone
|
||||
},
|
||||
{
|
||||
packagePath: "plugins/c9.ide.plugins/installer",
|
||||
|
|
|
@ -151,6 +151,7 @@ var activateModule = function(name) {
|
|||
return _require(name, path, callback);
|
||||
};
|
||||
req.toUrl = require.toUrl;
|
||||
req.config = require.config;
|
||||
|
||||
var modules = define.modules;
|
||||
var missing = checkMissing(module.deps);
|
||||
|
@ -253,7 +254,8 @@ var require = function(module, callback) {
|
|||
};
|
||||
|
||||
var config = require.config = function(cfg) {
|
||||
config.baseUrl = cfg.baseUrl.replace(/\/*$/, "/");
|
||||
if (cfg.baseUrl)
|
||||
config.baseUrl = cfg.baseUrl.replace(/\/*$/, "/");
|
||||
|
||||
cfg.packages && cfg.packages.forEach(function(pkg) {
|
||||
if (typeof pkg === "string") pkg = { name: pkg };
|
||||
|
|
|
@ -80,6 +80,10 @@ module.exports = function(mains, opts) {
|
|||
|
||||
opts.modules[id] = mod;
|
||||
|
||||
if (mod.source && mod.literal) {
|
||||
return cb(null, mod);
|
||||
}
|
||||
|
||||
idToPath(mod, function(err, path) {
|
||||
var filepath = absolutePath(root, path);
|
||||
mod.path = path;
|
||||
|
|
|
@ -454,7 +454,6 @@ define(function(require, exports, module) {
|
|||
async.series([
|
||||
function(next) {
|
||||
fs.readdir(cwd, function(err, files) {
|
||||
console.log(files)
|
||||
if (err)
|
||||
return next();
|
||||
var extraCode = [];
|
||||
|
@ -599,9 +598,24 @@ define(function(require, exports, module) {
|
|||
var build = require("architect-build/build");
|
||||
var paths = {};
|
||||
paths["plugins/" + packageName] = cwd;
|
||||
|
||||
|
||||
var additional = [];
|
||||
var packedConfig = Object.keys(config);
|
||||
if (staticPlugin) {
|
||||
additional.push(staticPlugin);
|
||||
packedConfig.push(staticPlugin.id);
|
||||
}
|
||||
var path = "plugins/" + packageName + "/__packed__";
|
||||
additional.push({
|
||||
id: path,
|
||||
source: 'define("' + path + '", [],' +
|
||||
JSON.stringify(config.concat(), null, 4) + ')',
|
||||
literal : true,
|
||||
order: -1
|
||||
});
|
||||
|
||||
build(config, {
|
||||
additional: staticPlugin ? [staticPlugin] : [],
|
||||
additional: additional,
|
||||
paths: paths,
|
||||
enableBrowser: true,
|
||||
includeConfig: false,
|
||||
|
@ -617,7 +631,7 @@ define(function(require, exports, module) {
|
|||
}, function(e, r) {
|
||||
result = r;
|
||||
result.sources.forEach(function(m) {
|
||||
packedFiles.push(m.file);
|
||||
m.file && packedFiles.push(m.file);
|
||||
});
|
||||
next();
|
||||
});
|
||||
|
@ -626,7 +640,7 @@ define(function(require, exports, module) {
|
|||
fs.writeFile("__packed__.js", result.code, "utf8", next);
|
||||
},
|
||||
function(next) {
|
||||
console.log(packedFiles)
|
||||
// console.log(packedFiles)
|
||||
zip(packedFiles);
|
||||
}
|
||||
]);
|
||||
|
|
|
@ -26,6 +26,7 @@ define(function(require, exports, module) {
|
|||
var HASSDK = c9.location.indexOf("sdk=0") === -1;
|
||||
|
||||
var plugins = options.plugins;
|
||||
var loadFromDisk = options.loadFromDisk
|
||||
var names = [];
|
||||
|
||||
var loaded = false;
|
||||
|
@ -36,18 +37,6 @@ define(function(require, exports, module) {
|
|||
if (!HASSDK) return;
|
||||
if (!ENABLED) return;
|
||||
|
||||
for (var i = 0; i < plugins.length; i++) {
|
||||
try {
|
||||
if (plugins[i].setup)
|
||||
plugins[i].setup = window.eval(plugins[i].setup);
|
||||
}
|
||||
catch(e) {
|
||||
console.error("Could not load plugin from cache: " + plugins[i].name);
|
||||
delete plugins[i].setup;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
loadPlugins(plugins);
|
||||
}
|
||||
|
||||
|
@ -60,47 +49,81 @@ define(function(require, exports, module) {
|
|||
}
|
||||
|
||||
var wait = 0;
|
||||
var host = vfs.baseUrl + "/";
|
||||
var base = join(String(c9.projectId), "plugins", auth.accessToken);
|
||||
|
||||
if (loadFromDisk) {
|
||||
fs.readdir("~/.c9/plugins", function(error, files){
|
||||
files.forEach(function(f) {
|
||||
loadOne({
|
||||
packageName: f.name,
|
||||
}, false);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
config.forEach(function(options){
|
||||
var name = options.packagePath.replace(/^plugins\/([^\/]*?)\/.*$/, "$1");
|
||||
names.push(name);
|
||||
// var name = options.packagePath.replace(/^plugins\/([^\/]*?)\/.*$/, "$1");
|
||||
// names.push(name);
|
||||
|
||||
var path = options.packagePath + ".js";
|
||||
var host = vfs.baseUrl + "/";
|
||||
var base = join(String(c9.projectId), "plugins", auth.accessToken);
|
||||
// var path = options.packagePath + ".js";
|
||||
|
||||
options.packagePath = host + join(base, path.replace(/^plugins\//, ""));
|
||||
options.staticPrefix = host + join(base, name);
|
||||
// options.packagePath = host + join(base, path.replace(/^plugins\//, ""));
|
||||
|
||||
if (!options.setup) {
|
||||
wait++;
|
||||
|
||||
// if (!options.setup) {
|
||||
// wait++;
|
||||
|
||||
var install = [];
|
||||
fs.exists("~/.c9/" + path, function(exists){
|
||||
if (!exists) {
|
||||
install.push(options);
|
||||
names.remove(name);
|
||||
}
|
||||
// var install = [];
|
||||
// fs.exists("~/.c9/" + path, function(exists){
|
||||
// if (!exists) {
|
||||
// install.push(options);
|
||||
// names.remove(name);
|
||||
// }
|
||||
|
||||
if (!--wait)
|
||||
done(install);
|
||||
});
|
||||
}
|
||||
// if (!--wait)
|
||||
// done(install);
|
||||
// });
|
||||
// }
|
||||
});
|
||||
|
||||
if (!wait)
|
||||
done([]);
|
||||
|
||||
function done(install){
|
||||
if (install.length)
|
||||
installer.installPlugins(install, function(err){
|
||||
if (err) console.error(err);
|
||||
});
|
||||
function loadOne(packageConfig, forceInstall) {
|
||||
wait++;
|
||||
|
||||
if (names.length)
|
||||
var packageName = packageConfig.packageName;
|
||||
var root = "plugins/" + packageName;
|
||||
var paths = {};
|
||||
paths[root] = host + base + "/" + root;
|
||||
requirejs.config({paths: paths});
|
||||
require.undef(root + "/__packed__.js");
|
||||
require([root + "/__packed__.js"], function(plugins) {
|
||||
var config = plugins.map(function(p) {
|
||||
return {
|
||||
staticPrefix: host + join(base, name),
|
||||
packagePath: p
|
||||
};
|
||||
});
|
||||
|
||||
architect.loadAdditionalPlugins(config, function(err){
|
||||
if (err) console.error(err);
|
||||
});
|
||||
|
||||
done();
|
||||
}, function(err) {
|
||||
if (forceInstall) {
|
||||
install.push(packageName)
|
||||
}
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
function done(){
|
||||
if (!--wait) return;
|
||||
if (install.length) {
|
||||
installer.installPlugins(install, function(err){
|
||||
if (err) console.error(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue