From b42d7a62f200ae03562f67c5a865670ed0985fd4 Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Wed, 29 Apr 2015 01:41:03 +0000 Subject: [PATCH 01/14] Change to , fix fs module and fix issue with flow. Also now installed is written properly --- configs/cli.js | 5 +++ package.json | 3 +- plugins/c9.cli.publish/install.js | 59 +++++++++++++++++++------------ plugins/c9.fs/fs.js | 5 ++- plugins/c9.fs/fs.streams.js | 14 +++++--- 5 files changed, 56 insertions(+), 30 deletions(-) diff --git a/configs/cli.js b/configs/cli.js index 08fac3d6..eeb5de2d 100644 --- a/configs/cli.js +++ b/configs/cli.js @@ -1,6 +1,11 @@ module.exports = function(options) { var EventEmitter = require("events").EventEmitter; +EventEmitter.prototype.emit = new Function("type", + EventEmitter.prototype.emit.toString() + .replace(/return false/g, "return") + .replace(/^.*\n/, "") + .replace(/\}$/, "")); var PID = process.env.C9_PID || 526; var APIHOST = process.env.C9_APIHOST || "api.c9.io"; // "api.c9.io"; diff --git a/package.json b/package.json index cdd2b9a1..7f6c70c1 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": "#63c3c021e3", + "c9.ide.installer": "#fd20938443", "c9.ide.mount": "#32e79866ee", "c9.ide.navigate": "#64156c7f4a", "c9.ide.newresource": "#f1f0624768", @@ -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", diff --git a/plugins/c9.cli.publish/install.js b/plugins/c9.cli.publish/install.js index 31311621..131ec69f 100644 --- a/plugins/c9.cli.publish/install.js +++ b/plugins/c9.cli.publish/install.js @@ -59,7 +59,7 @@ define(function(require, exports, module) { cmd.addCommand({ name: "install", info: " Installs a cloud9 package.", - usage: "[--verbose] [--force] [--global] [--local] [--debug] [--dry-run] [@]", + usage: "[--verbose] [--force] [--global] [--local] [--debug] [[@] | . ]", options: { "local": { description: "", @@ -86,11 +86,6 @@ define(function(require, exports, module) { "default": false, "boolean": true }, - "dry-run" : { - "description": "Installs current directory as a package", - "default": false, - "boolean": true - }, "force" : { "description": "Ignore warnings", "alias": "f", @@ -117,13 +112,17 @@ define(function(require, exports, module) { } var name = argv._[1]; + var test = name == "."; + if (test) + name = require("path").basename(process.cwd()); + install( name, { global: argv.global, local: argv.local, debug: argv.debug, - dryRun: argv["dry-run"] + test: test }, function(err, data){ if (err) { @@ -203,7 +202,7 @@ define(function(require, exports, module) { var version = parts[1]; var repository; - if ((!version || options.debug) && !options.dryRun) { + if ((!version || options.debug) && !options.test) { if (verbose) console.log("Retrieving package info"); @@ -226,9 +225,14 @@ define(function(require, exports, module) { function prepareDirectory(callback){ // Create package dir var packagePath = process.env.HOME + "/.c9/plugins/" + name; - var exists = fs.existsSync(packagePath) ; + var exists = fs.existsSync(packagePath); + + // Ignore when testing and in the same dir + if (options.test && process.cwd() == packagePath) + exists = false; + if (exists) { - if (!force) + if (!force && !options.test) return callback(new Error("WARNING: Directory not empty: " + packagePath + ". Use --force to overwrite.")); @@ -246,7 +250,7 @@ define(function(require, exports, module) { } function installPackage(){ - if (!version && !options.dryRun) + if (!version && !options.test) return callback(new Error("No version found for this package")); if (options.local) { @@ -292,7 +296,7 @@ define(function(require, exports, module) { }); } - if (options.dryRun) { + if (options.test) { try { var json = JSON.parse(fs.readFileSync(join(process.cwd(), "package.json"))); if (json.private) @@ -302,11 +306,20 @@ define(function(require, exports, module) { return callback(new Error("ERROR: Invalid package: " + e.message)); } - proc.execFile("bash", { args: ["-c", "cp -a " + join(process.cwd(), "/*") + " " + packagePath] }, function(err){ - if (err) return callback(err); - + if (process.cwd() == packagePath) installNPM(); - }); + else { + proc.execFile("bash", { + args: [ + "-c", "cp -a " + join(process.cwd(), "/*") + + " " + packagePath + ] + }, function(err){ + if (err) return callback(err); + + installNPM(); + }); + } return; } @@ -376,7 +389,7 @@ define(function(require, exports, module) { if (verbose) console.log("Installing debug version of package"); - if (!options.dryRun) + if (!options.test) return callback(new Error("Dry run is not supported for debug installations")); prepareDirectory(function(err, packagePath){ @@ -421,11 +434,11 @@ define(function(require, exports, module) { options.local = true; install(name + "@" + version, options, function(err){ if (err) return callback(err); - + var path = process.env.HOME + "/.c9/plugins/" + name; fs.readFile(path + "/package.json", "utf8", function(err, data){ if (err) return callback(new Error("Package.json not found in " + path)); - + var installPath; try { installPath = JSON.parse(data).installer; } catch(e){ @@ -434,10 +447,10 @@ define(function(require, exports, module) { if (installPath) { installerCLI.verbose = verbose; - installer.createSession(name, version, require(path + "/" + installPath), function(err){ + installer.createSession(name, version || "", require(path + "/" + installPath), function(err){ if (err) return callback(new Error("Error Installing Package " + name + "@" + version)); installToDatabase(); - }); + }, force || options.test); } else installToDatabase(); @@ -445,8 +458,8 @@ define(function(require, exports, module) { function installToDatabase(){ - if (options.dryRun) - return callback(null, { version: "dry-run" }); + if (options.test) + return callback(null, { version: "test" }); var endpoint = options.global ? api.user : api.project; var url = "install/" + packageName + "/" + version + "?mode=silent"; diff --git a/plugins/c9.fs/fs.js b/plugins/c9.fs/fs.js index e725d694..a3145076 100644 --- a/plugins/c9.fs/fs.js +++ b/plugins/c9.fs/fs.js @@ -18,7 +18,7 @@ define(function(require, exports, module) { var vfs = imports.vfs; var Plugin = imports.Plugin; - var stream = require("./fs.streams")(vfs, options.base, options.baseProc); + var stream = require("./fs.streams")(vfs, options.base, options.baseProc, options.cli); var xhr = options.cli ? stream : require("./fs.xhr")(vfs.rest); var uCaseFirst = require("c9/string").uCaseFirst; @@ -54,6 +54,8 @@ define(function(require, exports, module) { if (loaded) return false; loaded = true; + if (options.cli) + plugin.on("error", function(e){ console.error(e.error); }); } function wrap(name, fn) { @@ -104,6 +106,7 @@ define(function(require, exports, module) { original_callback.__cb__ = cb; var event = { path: path, args: args, fn: fn }; + if (emit("before" + uCaseFirst(name), event) === false) return false; diff --git a/plugins/c9.fs/fs.streams.js b/plugins/c9.fs/fs.streams.js index 8ab60423..19a5fbfe 100644 --- a/plugins/c9.fs/fs.streams.js +++ b/plugins/c9.fs/fs.streams.js @@ -3,10 +3,14 @@ define(function(require, exports, module) { var Stream = require("stream").Stream; var PATH = require("path"); -return function(vfs, base, baseProc) { +return function(vfs, base, baseProc, cli) { var resolvePath = function(path, basePath) { - if (path.charAt(0) == "~") return path; + if (path.charAt(0) == "~") { + if (cli) + return process.env.HOME + "/" + path.substr(1); + return path; + } if (!basePath) basePath = base; @@ -20,7 +24,7 @@ return function(vfs, base, baseProc) { }; function readFile(path, encoding, callback) { - if (!callback) { + if (!callback || typeof encoding == "function") { callback = encoding; encoding = null; } @@ -28,7 +32,7 @@ return function(vfs, base, baseProc) { var options = {}; if (encoding) options.encoding = encoding; - + vfs.readfile(resolvePath(path), options, function(err, meta) { if (err) return callback(err); @@ -54,7 +58,7 @@ return function(vfs, base, baseProc) { } function writeFile(path, data, encoding, callback) { - if (!callback) { + if (!callback || typeof encoding == "function") { callback = encoding; encoding = null; } From 561c28bb6f8cdd97a6396efa1e046ee4ecc9293a Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Wed, 29 Apr 2015 02:10:22 +0000 Subject: [PATCH 02/14] Improve verbose messaging --- plugins/c9.cli.publish/install.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/c9.cli.publish/install.js b/plugins/c9.cli.publish/install.js index 131ec69f..6b58a4a9 100644 --- a/plugins/c9.cli.publish/install.js +++ b/plugins/c9.cli.publish/install.js @@ -427,9 +427,6 @@ define(function(require, exports, module) { } function installFull(){ - if (verbose) - console.log("Notifying c9.io that packages needs to be installed"); - // Install Locally options.local = true; install(name + "@" + version, options, function(err){ @@ -460,6 +457,9 @@ define(function(require, exports, module) { function installToDatabase(){ if (options.test) return callback(null, { version: "test" }); + + if (verbose) + console.log("Notifying c9.io that packages needs to be installed"); var endpoint = options.global ? api.user : api.project; var url = "install/" + packageName + "/" + version + "?mode=silent"; From e4e6774e2c055316de8446db455af0ae9891fe0d Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Wed, 29 Apr 2015 12:56:08 +0000 Subject: [PATCH 03/14] Add extra quotes --- plugins/c9.cli.publish/install.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/c9.cli.publish/install.js b/plugins/c9.cli.publish/install.js index 6b58a4a9..b1b179db 100644 --- a/plugins/c9.cli.publish/install.js +++ b/plugins/c9.cli.publish/install.js @@ -311,8 +311,8 @@ define(function(require, exports, module) { else { proc.execFile("bash", { args: [ - "-c", "cp -a " + join(process.cwd(), "/*") - + " " + packagePath + "-c", "cp -a \"" + join(process.cwd(), "/\"*") + + " \"" + packagePath + "\"" ] }, function(err){ if (err) return callback(err); From c0596d9bda3a548ee16a5da387c2bedcbe78efbf Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Wed, 29 Apr 2015 20:18:39 +0000 Subject: [PATCH 04/14] Don't default to the open command --- plugins/c9.cli/cli.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/plugins/c9.cli/cli.js b/plugins/c9.cli/cli.js index ab533f32..4a5923fc 100755 --- a/plugins/c9.cli/cli.js +++ b/plugins/c9.cli/cli.js @@ -29,11 +29,6 @@ define(function(require, exports, module) { return false; }); - if (!commands[module] && process.argv.length > 2 && process.argv.every(function(n){ return !n.match(/^--/)})) { - process.argv.splice(2, 0, "open"); - module = "open"; - } - optimist = require('optimist'); if (!module || !commands[module]) { From 900de372334a3d8d6a4479b66cc4e929c764d2a1 Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 29 Apr 2015 18:48:58 +0000 Subject: [PATCH 05/14] fix typos --- plugins/c9.cli.publish/publish.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/c9.cli.publish/publish.js b/plugins/c9.cli.publish/publish.js index 0a4693b2..f38f7b75 100644 --- a/plugins/c9.cli.publish/publish.js +++ b/plugins/c9.cli.publish/publish.js @@ -312,7 +312,7 @@ define(function(require, exports, module) { // Write the package.json file var indent = data.match(/{\n\r?^ {4}"/) ? 4 : 2; var newData = JSON.stringify(json, null, indent); - fs.writeFile(cwd + "/.c9/.build/pacage.json", newData, function(){ + fs.writeFile(cwd + "/.c9/.build/package.json", newData, function(){ if (dryRun) return next(); // if dry-run is passed only update path in .build fs.writeFile(packagePath, newData, function(err){ @@ -446,7 +446,7 @@ define(function(require, exports, module) { extraCode.push({ type: "installer", filename: json.installer, - data: version + data: installerVersion }); } @@ -820,7 +820,7 @@ define(function(require, exports, module) { force = false; }); - /***** Register and definfe API *****/ + /***** Register and define API *****/ /** * From e3c93e9247d9544e189acd6d8b7e039db2f3e245 Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 29 Apr 2015 19:26:54 +0000 Subject: [PATCH 06/14] make handling of installer version numbers more consistent --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7f6c70c1..3877e02f 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": "#fd20938443", + "c9.ide.installer": "#5363500a49", "c9.ide.mount": "#32e79866ee", "c9.ide.navigate": "#64156c7f4a", "c9.ide.newresource": "#f1f0624768", From cc9f039843074b652b8b580513baa2e6ffffbf20 Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 29 Apr 2015 20:08:55 +0000 Subject: [PATCH 07/14] include modules required from config in dependency list --- node_modules/architect-build/npm_build.js | 3 ++- server.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/node_modules/architect-build/npm_build.js b/node_modules/architect-build/npm_build.js index 8912b0df..1bc1a643 100644 --- a/node_modules/architect-build/npm_build.js +++ b/node_modules/architect-build/npm_build.js @@ -157,8 +157,9 @@ function build(base, args, cb) { plugin.packagePath_orig = plugin.packagePath; }); }; - server(args, null, function(err, config) { + server(args, null, function(err, config, configPath) { addModule("server.js"); + addModule(configPath); config.forEach(function(plugin) { if (plugin.packagePath) addModule(relPath(plugin.packagePath)); diff --git a/server.js b/server.js index 311897ce..d8b5732f 100755 --- a/server.js +++ b/server.js @@ -120,7 +120,7 @@ function start(configName, options, callback) { } if (argv._getConfig) - return callback && callback(null, config); + return callback && callback(null, config, configPath); var app = architect.createApp(config, function (err, app) { if (err) { From 1f3c5a7a646f2247873409cb90ad3e9e4d9336be Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 30 Apr 2015 00:30:37 +0400 Subject: [PATCH 08/14] use installer version for checking installed state --- configs/cli.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configs/cli.js b/configs/cli.js index eeb5de2d..9df5c891 100644 --- a/configs/cli.js +++ b/configs/cli.js @@ -4,7 +4,7 @@ var EventEmitter = require("events").EventEmitter; EventEmitter.prototype.emit = new Function("type", EventEmitter.prototype.emit.toString() .replace(/return false/g, "return") - .replace(/^.*\n/, "") + .replace(/^[^{]*{/, "") .replace(/\}$/, "")); var PID = process.env.C9_PID || 526; diff --git a/package.json b/package.json index 3877e02f..e6a17ce7 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": "#5363500a49", + "c9.ide.installer": "#db436137e1", "c9.ide.mount": "#32e79866ee", "c9.ide.navigate": "#64156c7f4a", "c9.ide.newresource": "#f1f0624768", From a6c14e78985f20de3310b4ea69112928d4565823 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 30 Apr 2015 00:41:54 +0400 Subject: [PATCH 09/14] fix text plugin of amd-loader --- plugins/c9.cli.publish/install.js | 1 - plugins/c9.cli.publish/publish.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/c9.cli.publish/install.js b/plugins/c9.cli.publish/install.js index b1b179db..c16de698 100644 --- a/plugins/c9.cli.publish/install.js +++ b/plugins/c9.cli.publish/install.js @@ -16,7 +16,6 @@ define(function(require, exports, module) { var installerCLI = imports["installer.cli"]; var TEST_MODE = !!process.env.C9_TEST_MODE; - var SHELLSCRIPT = TEST_MODE ? "" : require("text!./publish.git.sh").toString("utf8"); var TAR = "tar"; var APIHOST = options.apiHost; var BASICAUTH = process.env.C9_TEST_AUTH; diff --git a/plugins/c9.cli.publish/publish.js b/plugins/c9.cli.publish/publish.js index f38f7b75..8bb04348 100644 --- a/plugins/c9.cli.publish/publish.js +++ b/plugins/c9.cli.publish/publish.js @@ -11,7 +11,7 @@ define(function(require, exports, module) { var api = imports.api; var TEST_MODE = !!process.env.C9_TEST_MODE; - var SHELLSCRIPT = TEST_MODE ? "" : require("text!./publish.git.sh").toString("utf8"); + var SHELLSCRIPT = TEST_MODE ? "" : require("text!./publish.git.sh"); var TAR = "tar"; var APIHOST = options.apiHost; var BASICAUTH = process.env.C9_TEST_AUTH; From f8ec16f93538fcf81ea59a22dad2edf1393e1537 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 30 Apr 2015 00:48:06 +0400 Subject: [PATCH 10/14] update package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e6a17ce7..2aef02ab 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "acorn": ">=0.11.0", - "amd-loader": "~0.0.5", + "amd-loader": "", "async": "^0.9.0", "base64id": "~0.1.0", "c9": "", @@ -83,7 +83,7 @@ "c9.ide.help.support": "#60e88f5680", "c9.ide.imgeditor": "#08bbc53578", "c9.ide.immediate": "#6845a93705", - "c9.ide.installer": "#db436137e1", + "c9.ide.installer": "#8c5c8701e5", "c9.ide.mount": "#32e79866ee", "c9.ide.navigate": "#64156c7f4a", "c9.ide.newresource": "#f1f0624768", From 9f4c1b98e1c8024bbb532088eff491e9b98ef3c6 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 30 Apr 2015 01:41:33 +0400 Subject: [PATCH 11/14] use cp instead of bash spawn cp --- plugins/c9.cli.publish/install.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/c9.cli.publish/install.js b/plugins/c9.cli.publish/install.js index c16de698..ae1b1012 100644 --- a/plugins/c9.cli.publish/install.js +++ b/plugins/c9.cli.publish/install.js @@ -308,11 +308,8 @@ define(function(require, exports, module) { if (process.cwd() == packagePath) installNPM(); else { - proc.execFile("bash", { - args: [ - "-c", "cp -a \"" + join(process.cwd(), "/\"*") - + " \"" + packagePath + "\"" - ] + proc.execFile("cp", { + args: ["-R", process.cwd(), dirname(packagePath)] }, function(err){ if (err) return callback(err); From 50d68e78f1ad471861be2e8b001ccd5236be0412 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 30 Apr 2015 01:44:23 +0400 Subject: [PATCH 12/14] do not use pty.js in cli mode --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2aef02ab..9a66ff8c 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": "#8c5c8701e5", + "c9.ide.installer": "#7993ca3181", "c9.ide.mount": "#32e79866ee", "c9.ide.navigate": "#64156c7f4a", "c9.ide.newresource": "#f1f0624768", From 9264039711c43c3af766dfb9856f2de1f0baaf97 Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Wed, 29 Apr 2015 22:06:32 +0000 Subject: [PATCH 13/14] Small fixes and typos --- package.json | 2 +- plugins/c9.cli.publish/install.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 9a66ff8c..06ac5112 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": "#7993ca3181", + "c9.ide.installer": "#a69136d696", "c9.ide.mount": "#32e79866ee", "c9.ide.navigate": "#64156c7f4a", "c9.ide.newresource": "#f1f0624768", diff --git a/plugins/c9.cli.publish/install.js b/plugins/c9.cli.publish/install.js index ae1b1012..b1643e22 100644 --- a/plugins/c9.cli.publish/install.js +++ b/plugins/c9.cli.publish/install.js @@ -15,6 +15,8 @@ define(function(require, exports, module) { var installer = imports.installer; var installerCLI = imports["installer.cli"]; + var dirname = require("path").dirname; + var TEST_MODE = !!process.env.C9_TEST_MODE; var TAR = "tar"; var APIHOST = options.apiHost; From e704f45e66b162ebad3344f577bd2e0e9866e1bf Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Wed, 29 Apr 2015 22:07:05 +0000 Subject: [PATCH 14/14] cleanup --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 06ac5112..e2bcf6c2 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": "#a69136d696", + "c9.ide.installer": "#86392483b6", "c9.ide.mount": "#32e79866ee", "c9.ide.navigate": "#64156c7f4a", "c9.ide.newresource": "#f1f0624768",