From 77a3e445477514a0df4a18043b78f91951059e46 Mon Sep 17 00:00:00 2001 From: Nikolai Onken Date: Fri, 24 Apr 2015 18:25:20 +0000 Subject: [PATCH 1/8] Add new cs50 plugin --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index e9cd8bce..84dc1331 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,7 @@ "c9.ide.readonly": "#f6f07bbe42", "c9.ide.recentfiles": "#7c099abf40", "c9.ide.remote": "#cd45e81d2f", + "c9.ide.processlist": "#bc11818bb5", "c9.ide.run": "#71c5562e42", "c9.ide.run.build": "#ad45874c88", "c9.ide.run.debug.xdebug": "#b91d23f48b", From 3bbff9b45b91da4eb89d0a5474a07425973b5754 Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Tue, 28 Apr 2015 22:16:55 +0000 Subject: [PATCH 2/8] Remove a heading at the top of the readme --- plugins/c9.cli.publish/publish.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/c9.cli.publish/publish.js b/plugins/c9.cli.publish/publish.js index 37ae956c..d120a885 100644 --- a/plugins/c9.cli.publish/publish.js +++ b/plugins/c9.cli.publish/publish.js @@ -246,7 +246,8 @@ define(function(require, exports, module) { console.warn("WARNING: Description property in package.json will be ignored. README.md will be used."); var originalDesc = json.description; - json.description = fs.readFileSync(join(cwd, "README.md"), "utf8"); + json.description = fs.readFileSync(join(cwd, "README.md"), "utf8") + .replace(/^\#.*\n*/, ""); // Validate plugins var plugins = {}; From 16136f2c474e3a3e0b4b09e900c107481621b0a0 Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 29 Apr 2015 02:27:11 +0400 Subject: [PATCH 3/8] do not destroy package.json of published plugin --- configs/cli.js | 3 ++- package.json | 2 +- plugins/c9.cli.publish/publish.js | 13 ++++--------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/configs/cli.js b/configs/cli.js index ba843516..08fac3d6 100644 --- a/configs/cli.js +++ b/configs/cli.js @@ -112,7 +112,8 @@ return [ hosted: false, local: true, home: process.env.HOME, - setStatus: function(){} + setStatus: function(){}, + location: "" }, error_handler: { log: function(){} diff --git a/package.json b/package.json index fa35e43b..cdd2b9a1 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "c9.ide.help.support": "#60e88f5680", "c9.ide.imgeditor": "#08bbc53578", "c9.ide.immediate": "#6845a93705", - "c9.ide.installer": "#02e7018bf6", + "c9.ide.installer": "#63c3c021e3", "c9.ide.mount": "#32e79866ee", "c9.ide.navigate": "#64156c7f4a", "c9.ide.newresource": "#f1f0624768", diff --git a/plugins/c9.cli.publish/publish.js b/plugins/c9.cli.publish/publish.js index d120a885..0a4693b2 100644 --- a/plugins/c9.cli.publish/publish.js +++ b/plugins/c9.cli.publish/publish.js @@ -245,8 +245,7 @@ define(function(require, exports, module) { if (json.description) console.warn("WARNING: Description property in package.json will be ignored. README.md will be used."); - var originalDesc = json.description; - json.description = fs.readFileSync(join(cwd, "README.md"), "utf8") + var description = fs.readFileSync(join(cwd, "README.md"), "utf8") .replace(/^\#.*\n*/, ""); // Validate plugins @@ -310,13 +309,9 @@ define(function(require, exports, module) { if (!version) return next(); - // Reset description - var pkgJson = Object.create(json); - pkgJson.description = originalDesc; - // Write the package.json file var indent = data.match(/{\n\r?^ {4}"/) ? 4 : 2; - var newData = JSON.stringify(pkgJson, null, indent); + var newData = JSON.stringify(json, null, indent); fs.writeFile(cwd + "/.c9/.build/pacage.json", newData, function(){ if (dryRun) return next(); // if dry-run is passed only update path in .build @@ -651,7 +646,7 @@ define(function(require, exports, module) { contentType: "application/json", body: { name: json.name, - description: json.description, + description: description, owner_type: "user", // @TODO implement this when adding orgs owner_id: parseInt(user.id), permissions: json.permissions || "world", @@ -683,7 +678,7 @@ define(function(require, exports, module) { repository: json.repository, longname: json.longname, website: json.website, - description: json.description, + description: description, screenshots: json.screenshots, pricing: json.pricing, enabled: true From 7dd8b141aee15f91bacc5fa8af942ade72088afd Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Tue, 28 Apr 2015 22:41:55 +0000 Subject: [PATCH 4/8] Fix installer error reporting --- plugins/c9.cli.publish/install.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/c9.cli.publish/install.js b/plugins/c9.cli.publish/install.js index eb14b7b2..31311621 100644 --- a/plugins/c9.cli.publish/install.js +++ b/plugins/c9.cli.publish/install.js @@ -299,7 +299,7 @@ define(function(require, exports, module) { return callback(new Error("ERROR: Private flag in package.json prevents from installing")); } catch(e) { - return callback(new Error("ERROR: Invalid package")); + return callback(new Error("ERROR: Invalid package: " + e.message)); } proc.execFile("bash", { args: ["-c", "cp -a " + join(process.cwd(), "/*") + " " + packagePath] }, function(err){ From b8fc691bea98a36e589e0e63c8638bfaaea5a353 Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 29 Apr 2015 04:19:20 +0400 Subject: [PATCH 5/8] more c9 cli tweaks --- plugins/c9.cli.publish/list.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/c9.cli.publish/list.js b/plugins/c9.cli.publish/list.js index a937e903..c1511530 100644 --- a/plugins/c9.cli.publish/list.js +++ b/plugins/c9.cli.publish/list.js @@ -69,7 +69,8 @@ define(function(require, exports, module) { console.error("ERROR: Could not get list: ", stringifyError(err)); return callback(err); } - + // TODO if tty.isatty(process.stdout) use process.stdout.columns process.stdout.rows + // to give nicely wrapped output if (asJson) { console.log(JSON.stringify(list, 4, " ")); return callback(null, list); @@ -87,7 +88,7 @@ define(function(require, exports, module) { pad(item.name, max[0] + PADDING), pad(item.description.split(".")[0], max[1] + PADDING), LIGHTBlUE + pad("https://c9.io/profile/packages/" + item.name, max[2] + PADDING) + RESETCOLOR, - pad(item.website || item.repository.url, max[3])); + item.website || item.repository.url); // do not pad last item }); return callback(null, list); } From 58afdf088c2c4bfda58e5faab8063239fc3375de Mon Sep 17 00:00:00 2001 From: Lennart Kats Date: Wed, 29 Apr 2015 11:32:32 +0200 Subject: [PATCH 6/8] Allow optional parameters to be falsy --- node_modules/frontdoor/lib/route.js | 12 +++-- node_modules/frontdoor/lib/route_test.js | 60 +++++++++++++++++++++++- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/node_modules/frontdoor/lib/route.js b/node_modules/frontdoor/lib/route.js index 0c699ab7..d8276197 100644 --- a/node_modules/frontdoor/lib/route.js +++ b/node_modules/frontdoor/lib/route.js @@ -137,6 +137,10 @@ module.exports = function Route(route, options, handler, types) { var key = keys[i]; var param = params[key]; var type = param.type; + if (param.optional && value == null) { + match[key] = value; + continue; + } try { value = type.parse(value); } catch (e) { @@ -157,7 +161,7 @@ module.exports = function Route(route, options, handler, types) { * the decoded and validated parameters are stored in `req.params` * otherwhise an error is returned. */ - function decodeParams(req, res, next) { + var decodeParams = this.decodeParams = function(req, res, next) { var urlParams = req.match; if (!urlParams) return; @@ -197,10 +201,12 @@ module.exports = function Route(route, options, handler, types) { break; value = body[key]; // body is already JSON parsed + if (param.optional && value == null) + break; isValid = type.check(value); break; case "query": - if (param.optional && !(key in query)) + if (param.optional && query[key] == null) break; try { @@ -211,7 +217,7 @@ module.exports = function Route(route, options, handler, types) { isValid = isValid === false ? false : type.check(value); break; case "url": - if (param.optional && !(key in urlParams)) + if (param.optional && urlParams[key] == null) break; value = urlParams[key]; // is already parsed and checked diff --git a/node_modules/frontdoor/lib/route_test.js b/node_modules/frontdoor/lib/route_test.js index 9e11be1c..d1a1bacd 100644 --- a/node_modules/frontdoor/lib/route_test.js +++ b/node_modules/frontdoor/lib/route_test.js @@ -133,7 +133,65 @@ module.exports = { assert.ok(!route.match(req, "/ts/353676299181")); assert.ok(!route.match(req, "/ts/abc")); - } + }, + + "test router: decode parameter in body": function(next) { + var route = new Route("/user", { + params: { + id: { + type: "int", + optional: true, + source: "body" + } + } + }, sinon.stub()); + + var req = { + match: "match", + parsedUrl: { + query: "" + }, + body: { id: 15 } + }; + var res = {}; + + // Note: usually optionals would say 'source: "body",' + // but this should work + route.decodeParams(req, res, function(err, result) { + assert.equal(err, null); + assert.equal(req.params.id, 15); + next(); + }); + }, + + "test router: optional number argument can be falsy": function(next) { + var route = new Route("/user", { + params: { + id: { + type: "int", + optional: true, + source: "body" + } + } + }, sinon.stub()); + + var req = { + match: "match", + parsedUrl: { + query: "" + }, + body: { id: null } + }; + var res = {}; + + // Note: usually optionals would say 'source: "body",' + // but this should work + route.decodeParams(req, res, function(err, result) { + assert.equal(err, null); + assert.equal(req.params.id, null); + next(); + }); + }, }; !module.parent && require("asyncjs").test.testcase(module.exports).exec(); From 22cc05a80c0e425e62eb8d3d56ef9b3f01615ad9 Mon Sep 17 00:00:00 2001 From: Lennart Kats Date: Wed, 29 Apr 2015 11:37:41 +0200 Subject: [PATCH 7/8] Send Accept header when needed --- plugins/c9.core/http-xhr.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/c9.core/http-xhr.js b/plugins/c9.core/http-xhr.js index aeb2e9d1..9d8eafcd 100644 --- a/plugins/c9.core/http-xhr.js +++ b/plugins/c9.core/http-xhr.js @@ -29,6 +29,8 @@ define(function(require, module, exports) { var timeout = options.hasOwnProperty("timeout") ? options.timeout : 10000; var async = options.sync !== true; var parsedUrl = parseUrl(url, options.query); + if (contentType === "application/json") + headers.Accept = headers.Accept || "application/json"; if (options.username) { headers.Authorization = "Basic " + btoa(options.username + ":" + options.password); From d6d19ff38eabff74aedfab491411ed165ea5ca9c Mon Sep 17 00:00:00 2001 From: Lennart Kats Date: Wed, 29 Apr 2015 12:05:28 +0200 Subject: [PATCH 8/8] Fix test --- node_modules/frontdoor/lib/route.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/node_modules/frontdoor/lib/route.js b/node_modules/frontdoor/lib/route.js index d8276197..56343a48 100644 --- a/node_modules/frontdoor/lib/route.js +++ b/node_modules/frontdoor/lib/route.js @@ -161,7 +161,8 @@ module.exports = function Route(route, options, handler, types) { * the decoded and validated parameters are stored in `req.params` * otherwhise an error is returned. */ - var decodeParams = this.decodeParams = function(req, res, next) { + this.decodeParams = decodeParams; + function decodeParams(req, res, next) { var urlParams = req.match; if (!urlParams) return;