kopia lustrzana https://github.com/c9/core
add example of resolving config on client side
rodzic
dc05adac25
commit
3d654fc187
|
@ -94,6 +94,11 @@ function plugin(options, imports, register) {
|
|||
source: "query",
|
||||
optional: true
|
||||
},
|
||||
settings: {
|
||||
type: "number",
|
||||
source: "query",
|
||||
optional: true
|
||||
},
|
||||
}
|
||||
}, function(req, res, next) {
|
||||
|
||||
|
@ -116,11 +121,18 @@ function plugin(options, imports, register) {
|
|||
});
|
||||
|
||||
opts.options.debug = req.params.debug !== undefined;
|
||||
var workspaceSettings = getSettings(configName, options);
|
||||
|
||||
res.setHeader("Cache-Control", "no-cache, no-store");
|
||||
|
||||
if (req.params.settings == 1)
|
||||
return res.json(workspaceSettings);
|
||||
|
||||
if (req.params.config == 1)
|
||||
return res.json(getConfig(configName, opts));
|
||||
return res.json(getConfig(configName, workspaceSettings));
|
||||
|
||||
res.render(__dirname + "/views/standalone.html.ejs", {
|
||||
architectConfig: getConfig(configName, opts),
|
||||
architectConfig: getConfig(configName, workspaceSettings),
|
||||
configName: configName,
|
||||
packed: opts.packed,
|
||||
standalone: true,
|
||||
|
@ -326,9 +338,7 @@ function getConfigName(requested, options) {
|
|||
return name;
|
||||
}
|
||||
|
||||
function getConfig(configName, options) {
|
||||
var filename = __dirname + "/../../configs/client-" + configName + ".js";
|
||||
|
||||
function getSettings(configName, options) {
|
||||
var installPath = options.settingDir || options.installPath || "";
|
||||
var workspaceDir = options.options.workspaceDir;
|
||||
var settings = {
|
||||
|
@ -347,6 +357,14 @@ function getConfig(configName, options) {
|
|||
settings[type] = data;
|
||||
}
|
||||
options.options.settings = settings;
|
||||
|
||||
return require(filename)(options.options);
|
||||
options.options.configName = configName;
|
||||
options.options.manifest = {
|
||||
version: options.options.manifest.version
|
||||
};
|
||||
return options.options;
|
||||
}
|
||||
|
||||
function getConfig(configName, options) {
|
||||
var filename = __dirname + "/../../configs/client-" + configName + ".js";
|
||||
return require(filename)(options);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var start = Date.now();
|
||||
var loadingIde = document.querySelector("#loadingide");
|
||||
document.body.className = "loading " + loadingIde.className;
|
||||
|
||||
|
@ -95,88 +96,89 @@
|
|||
<script src="/static/mini_require.js"></script>
|
||||
<script src="/configs/require_config.js"></script>
|
||||
<script>
|
||||
var start = Date.now();
|
||||
|
||||
var plugins;
|
||||
require(["lib/architect/architect", "text!/ide.html?config=1"], function (architect, pluginJSON) {
|
||||
plugins = JSON.parse(pluginJSON);
|
||||
plugins.push({
|
||||
consumes: [],
|
||||
provides: ["auth.bootstrap"],
|
||||
setup: function(options, imports, register) {
|
||||
register(null, {
|
||||
"auth.bootstrap": {
|
||||
login: function(callback) { callback(); }
|
||||
require(["text!/ide.html?settings=1"], function(workspaceSettings) {
|
||||
workspaceSettings = JSON.parse(workspaceSettings);
|
||||
require(["lib/architect/architect", "configs/ide/" + workspaceSettings.configName], function(architect, config) {
|
||||
plugins = config(workspaceSettings);
|
||||
plugins.push({
|
||||
consumes: [],
|
||||
provides: ["auth.bootstrap"],
|
||||
setup: function(options, imports, register) {
|
||||
register(null, {
|
||||
"auth.bootstrap": {
|
||||
login: function(callback) { callback(); }
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
architect.resolveConfig(plugins, function (err, config) {
|
||||
if (err) throw err;
|
||||
|
||||
var errored;
|
||||
var app = architect.createApp(config, function(err, app){
|
||||
if (err) {
|
||||
errored = true;
|
||||
console.error(err.stack);
|
||||
alert(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
architect.resolveConfig(plugins, function (err, config) {
|
||||
if (err) throw err;
|
||||
|
||||
var errored;
|
||||
var app = architect.createApp(config, function(err, app){
|
||||
if (err) {
|
||||
errored = true;
|
||||
|
||||
app.on("error", function(err){
|
||||
console.error(err.stack);
|
||||
alert(err);
|
||||
}
|
||||
});
|
||||
|
||||
app.on("error", function(err){
|
||||
console.error(err.stack);
|
||||
if (!errored)
|
||||
alert(err);
|
||||
});
|
||||
|
||||
app.on("service", function(name, plugin, options) {
|
||||
if (!plugin.name)
|
||||
plugin.name = name;
|
||||
});
|
||||
|
||||
app.on("ready", function() {
|
||||
window.app = app.services;
|
||||
window.app.__defineGetter__("_ace", function(){
|
||||
return this.tabManager.focussedTab.editor.ace;
|
||||
});
|
||||
Object.keys(window.app).forEach(function(n) {
|
||||
if (/[^\w]/.test(n))
|
||||
window.app[n.replace(/[^\w]/, "_") + "_"] = window.app[n];
|
||||
if (!errored)
|
||||
alert(err);
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
// For Development only
|
||||
function done() {
|
||||
var vfs = app.services.vfs;
|
||||
var c9 = app.services.c9;
|
||||
var settings = app.services.settings;
|
||||
app.on("service", function(name, plugin, options) {
|
||||
if (!plugin.name)
|
||||
plugin.name = name;
|
||||
});
|
||||
|
||||
c9.ready();
|
||||
c9.totalLoadTime = Date.now() - start;
|
||||
|
||||
console.warn("Total Load Time: ", Date.now() - start);
|
||||
|
||||
if (window.hideLoader) {
|
||||
var waitVfs = function(fn) {
|
||||
vfs.connected ? fn() : vfs.once("connect", fn);
|
||||
};
|
||||
var waitSettings = function(fn) {
|
||||
settings.inited ? fn() : settings.once("read", fn);
|
||||
};
|
||||
var waitTheme = function(fn) {
|
||||
var layout = app.services.layout;
|
||||
if (!layout || layout.hasTheme) return fn();
|
||||
layout.once("eachTheme", fn);
|
||||
};
|
||||
waitTheme(waitSettings.bind(null, window.hideLoader));
|
||||
app.on("ready", function() {
|
||||
window.app = app.services;
|
||||
window.app.__defineGetter__("_ace", function(){
|
||||
return this.tabManager.focussedTab.editor.ace;
|
||||
});
|
||||
Object.keys(window.app).forEach(function(n) {
|
||||
if (/[^\w]/.test(n))
|
||||
window.app[n.replace(/[^\w]/, "_") + "_"] = window.app[n];
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
// For Development only
|
||||
function done() {
|
||||
var vfs = app.services.vfs;
|
||||
var c9 = app.services.c9;
|
||||
var settings = app.services.settings;
|
||||
|
||||
c9.ready();
|
||||
c9.totalLoadTime = Date.now() - start;
|
||||
|
||||
console.warn("Total Load Time: ", Date.now() - start);
|
||||
|
||||
if (window.hideLoader) {
|
||||
var waitVfs = function(fn) {
|
||||
vfs.connected ? fn() : vfs.once("connect", fn);
|
||||
};
|
||||
var waitSettings = function(fn) {
|
||||
settings.inited ? fn() : settings.once("read", fn);
|
||||
};
|
||||
var waitTheme = function(fn) {
|
||||
var layout = app.services.layout;
|
||||
if (!layout || layout.hasTheme) return fn();
|
||||
layout.once("eachTheme", fn);
|
||||
};
|
||||
waitTheme(waitSettings.bind(null, window.hideLoader));
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function loadError(mod) {
|
||||
if (mod.id === "plugins/c9.ide.clipboard/html5")
|
||||
return alert("Unable to load html5.js.\n\nThis may be caused by a false positive in your virus scanner. Please try reloading with ?packed=1 added to the URL.");
|
||||
}, function loadError(mod) {
|
||||
if (mod.id === "plugins/c9.ide.clipboard/html5")
|
||||
return alert("Unable to load html5.js.\n\nThis may be caused by a false positive in your virus scanner. Please try reloading with ?packed=1 added to the URL.");
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
Ładowanie…
Reference in New Issue