From 82a31c815049a26aa37494ec0a4e13eebfb2f08c Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 13 Apr 2015 23:44:42 +0400 Subject: [PATCH] start adding build step for static plugins --- plugins/c9.cli.publish/publish.js | 73 +++++++++++++++++-- plugins/c9.ide.plugins/debug.js | 112 ++++++++++++++++-------------- 2 files changed, 124 insertions(+), 61 deletions(-) diff --git a/plugins/c9.cli.publish/publish.js b/plugins/c9.cli.publish/publish.js index e298f266..79b8f43a 100644 --- a/plugins/c9.cli.publish/publish.js +++ b/plugins/c9.cli.publish/publish.js @@ -474,16 +474,75 @@ define(function(require, exports, module) { async.series([ function(next) { - fs.writeFile("__packed__.js", result.code, "utf8", next); - }, - function(next) { - fs.readdir(cwd, function(files) { - if (files.indexOf("themes") != -1) { - + fs.readdir(cwd, function(err, files) { + console.log(files) + if (err) + return next(); + var extraCode = []; + function forEachFile(dir, f) { + try { + fs.readdirSync(dir).forEach(f); + } catch(e) { + console.log(e); + } } + if (files.indexOf("builders") != -1) { + forEachFile(cwd + "/builders", function(p) { + console.log(p, "***"); + extraCode.push() + + }); + } + if (files.indexOf("keymaps") != -1) { + forEachFile(cwd + "/keymaps", function(p) { + console.log(p, "***"); + }); + } + if (files.indexOf("modes") != -1) { + forEachFile(cwd + "/modes", function(p) { + console.log(p, "***"); + }); + } + if (files.indexOf("outline") != -1) { + forEachFile(cwd + "/outline", function(p) { + console.log(p, "***"); + }); + } + if (files.indexOf("runners") != -1) { + forEachFile(cwd + "/runners", function(p) { + console.log(p, "***"); + }); + } + if (files.indexOf("snippets") != -1) { + forEachFile(cwd + "/snippets", function(p) { + console.log(p, "***"); + }); + } + if (files.indexOf("themes") != -1) { + forEachFile(cwd + "/themes", function(p) { + console.log(p, "***"); + }); + } + if (files.indexOf("template") != -1) { + forEachFile(cwd + "/template", function(p) { + console.log(p, "***"); + }); + } + + + result.code += (function() { + extraCode + + }).toString().replace(/^.*{|}$/g, "") + .replace("extraCode", extraCode); + + next(); }); }, + function(next) { + fs.writeFile("__packed__.js", result.code, "utf8", next); + }, function(next) { packedFiles.push(cwd + "/themes"); zip(packedFiles); @@ -510,7 +569,7 @@ define(function(require, exports, module) { tarArgs.push("--exclude=./" + p); } }); - console.log(tarArgs) + // console.log(tarArgs) proc.spawn(TAR, { args: tarArgs, cwd: cwd diff --git a/plugins/c9.ide.plugins/debug.js b/plugins/c9.ide.plugins/debug.js index c8fc3cc7..b5ce7925 100644 --- a/plugins/c9.ide.plugins/debug.js +++ b/plugins/c9.ide.plugins/debug.js @@ -230,7 +230,6 @@ define(function(require, exports, module) { function processModules(path, data){ var parallel = []; - var services = architect.services; var placeholder = new Plugin(); @@ -251,59 +250,7 @@ define(function(require, exports, module) { return next(err); } - switch (type) { - case "builders": - data = util.safeParseJson(data, next); - if (!data) return; - - services.build.addBuilder(filename, data, placeholder); - break; - case "keymaps": - data = util.safeParseJson(data, next); - if (!data) return; - - services["preferences.keybindings"].addCustomKeymap(filename, data, placeholder); - break; - case "modes": - var mode = {}; - var firstLine = data.split("\n", 1)[0].replace(/\/\*|\*\//g, "").trim(); - firstLine.split(";").forEach(function(n){ - if (!n) return; - var info = n.split(":"); - mode[info[0].trim()] = info[1].trim(); - }); - - services.ace.defineSyntax({ - name: join(path, "modes", data.name), - caption: mode.caption, - extensions: (mode.extensions || "").trim() - .split(",") - .map(function(n){ return n.trim(); }) - .filter(function(n){ return n; }) - }); - break; - case "outline": - data = util.safeParseJson(data, next); - if (!data) return; - - services.outline.addOutlinePlugin(filename, data, placeholder); - break; - case "runners": - data = util.safeParseJson(data, next); - if (!data) return; - - services.run.addRunner(filename, data, placeholder); - break; - case "snippets": - services.complete.addSnippet(data, plugin); - break; - case "themes": - services.ace.addTheme(data, placeholder); - break; - case "template": - services.newresource.addFileTemplate(data, placeholder); - break; - } + addStaticPlugin(type, path, filename, data, placeholder); next(); }); @@ -313,6 +260,63 @@ define(function(require, exports, module) { return parallel; } + function addStaticPlugin(type, pluginName, filename, data, plugin) { + var services = architect.services; + switch (type) { + case "builders": + data = util.safeParseJson(data, function() {}); + if (!data) return; + + services.build.addBuilder(filename, data, plugin); + break; + case "keymaps": + data = util.safeParseJson(data, function() {}); + if (!data) return; + + services["preferences.keybindings"].addCustomKeymap(filename, data, plugin); + break; + case "modes": + var mode = {}; + var firstLine = data.split("\n", 1)[0].replace(/\/\*|\*\//g, "").trim(); + firstLine.split(";").forEach(function(n){ + if (!n) return; + var info = n.split(":"); + mode[info[0].trim()] = info[1].trim(); + }); + + services.ace.defineSyntax({ + name: join(pluginName, "modes", data.name), + caption: mode.caption, + extensions: (mode.extensions || "").trim() + .split(",") + .map(function(n){ return n.trim(); }) + .filter(function(n){ return n; }) + }); + break; + case "outline": + data = util.safeParseJson(data, function() {}); + if (!data) return; + + services.outline.addOutlinePlugin(filename, data, plugin); + break; + case "runners": + data = util.safeParseJson(data, function() {}); + if (!data) return; + + services.run.addRunner(filename, data, plugin); + break; + case "snippets": + services.complete.addSnippet(data, plugin); + break; + case "themes": + services.ace.addTheme(data, plugin); + break; + case "template": + services.newresource.addFileTemplate(data, plugin); + break; + } + } + // Check if require.s.contexts._ can help watching all dependencies function watch(path){ watcher.watch(path);