From b42d7a62f200ae03562f67c5a865670ed0985fd4 Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Wed, 29 Apr 2015 01:41:03 +0000 Subject: [PATCH] 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; }