Merge pull request +12703 from c9/c9-cli

fix c9 cli not working with npm 3
pull/272/head
Harutyun Amirjanyan 2016-03-16 22:50:34 +04:00
commit 11d73b7b72
4 zmienionych plików z 176 dodań i 4 usunięć

69
node_modules/architect-build/npm_freeze.js wygenerowano vendored 100644
Wyświetl plik

@ -0,0 +1,69 @@
var patchTemplate = ";(" +function() {
// automatically generated by architect-build
// bundle all dependencies in the main package
var Module = require("module");
var path = require("path");
var _resolveFilename_orig = Module._resolveFilename
var root = path.join(__dirname, "{root}");
Module._resolveFilename = function(id, parent) {
if (parent && parent.paths && parent.paths[0] && parent.paths[0].indexOf(root) == 0) {
parent.paths = parent.paths.map(function(p) {
if (p.indexOf(root) != 0) return
p = p.slice(root.length);
return root + p.replace(/([\\\/]|^)node_modules([\\\/]|$)/g, "$1n_m$2");
}).filter(Boolean);
}
return _resolveFilename_orig.call(Module, id, parent);
};
} + ")();";
//////////////////////////////////////////////////////////////////////////
var fs = require("fs");
var copy = require("architect-build/copy");
var pathLib = require("path");
function freeze(path, mode) {
path = copy.convertPath(path);
var pkgs = {};
function freezePkg(path) {
if (!pkgs[path]) {
pkgs[path] = JSON.parse(fs.readFileSync(path + "/package.json"))
Object.keys(pkgs[path]).forEach(function(k) {
if (/Dependencies/i.test(k)) delete pkgs[path][k];
})
}
pkgs[path].dependencies = {};
var deps = fs.existsSync(path + "/node_modules") ? fs.readdirSync(path + "/node_modules") : [];
deps.forEach(function(n) {
if (n == ".bin") return;
var depPath = path + "/node_modules/" + n;
freezePkg(depPath);
pkgs[path].dependencies[n] = pkgs[depPath].version;
});
if (mode == "rename") {
if (deps.length) {
fs.renameSync(path + "/node_modules/", path + "/n_m")
delete pkgs[path].dependencies
if (pkgs[path].files)
pkgs[path].files.push("n_m")
}
} else {
pkgs[path].bundledDependencies = Object.keys(pkgs[path].dependencies);
}
fs.writeFileSync(path + "/package.json", JSON.stringify(pkgs[path], null, "\t"), "utf8");
}
freezePkg(path);
var bin = pkgs[path].bin;
Object.keys(bin).forEach(function(key) {
var p = bin[key];
var root = pathLib.relative(pathLib.dirname(p), "").replace(/[\\]/g, "/");
var src = fs.readFileSync(path + "/" + p, "utf8");
src = src.replace(/^(#.*|"use strict";?|\s)*/, function(a) {
return a.trim() + "\n\n" + patchTemplate.replace(/{root}/g, root) + "\n\n";
});
fs.writeFileSync(path + "/" + p, src, "utf8");
});
}
module.exports = freeze;

Wyświetl plik

@ -59,7 +59,7 @@ define(function(require, exports, module) {
if (done) return;
callback(new Error("No Response"));
done = true;
})
});
});
}

Wyświetl plik

@ -36,6 +36,12 @@ define(function(require, exports, module) {
case "open":
open(message, e.respond);
break;
case "pipe":
createPipe(message, e.respond);
break;
case "pipeData":
updatePipe(message, e.respond);
break;
case "ping":
e.respond(null, true);
break;
@ -66,6 +72,30 @@ define(function(require, exports, module) {
}
/***** Methods *****/
function createPipe(message, callback) {
tabManager.once("ready", function(){
tabManager.open({
focus: true,
editorType: "ace",
path: message.path && c9.toInternalPath(message.path),
document: { meta : { newfile: true } }
}, function(err, tab) {
if (err)
return callback(err);
callback(null, tab.path || tab.name);
});
});
}
function updatePipe(message, callback) {
tabManager.once("ready", function() {
var tab = tabManager.findTab(message.tab);
var c9Session = tab && tab.document.getSession();
if (c9Session && c9Session.session)
c9Session.session.insert({row: Number.MAX_VALUE, column: Number.MAX_VALUE} , message.data);
callback(null, true);
});
}
function open(message, callback) {
var i = -1;
@ -102,12 +132,22 @@ define(function(require, exports, module) {
}
else {
tabManager.once("ready", function(){
var m = /:(\d*)(?::(\d*))?$/.exec(path);
var jump = {};
if (m) {
if (m[1])
jump.row = parseInt(m[1], 10) - 1;
if (m[2])
jump.column = parseInt(m[2], 10);
path = path.slice(0, m.index);
}
fs.exists(path, function(existing) {
var tab = tabManager.open({
path: path,
focus: i === 0,
document: existing
? undefined
? { ace: { jump: jump } }
: { meta : { newfile: true } }
}, function(){
next();

Wyświetl plik

@ -25,19 +25,28 @@ define(function(require, exports, module) {
cmd.addCommand({
name: "open",
info: " Opens a file or directory.",
usage: "[--wait] <path>",
usage: "[--wait] [--pipe] <path>",
options: {
"wait": {
description: "Wait until the file(s) are closed",
"default": false,
"boolean": true
},
"pipe": {
description: "Pipe data from a command into c9",
"default": false,
"boolean": true
}
},
check: function(argv) {
if (argv._.length < 2 && !argv["path"])
if (argv._.length < 2 && !argv["path"] && !argv.pipe)
throw new Error("Missing path");
},
exec: function(argv) {
if (argv.pipe) {
openWithPipe(function(){});
return;
}
open(
argv._.slice(1), // Remove "open" from the paths
argv.wait,
@ -126,6 +135,60 @@ define(function(require, exports, module) {
});
}
function openWithPipe(callback) {
bridge.send({
type: "pipe",
path: process.cwd() + "/" + "Pipe " + (new Date()).toLocaleString().replace(/:/g, "."),
}, function cb(err, response) {
if (err) {
if (err.code == "ECONNREFUSED") {
// Seems Cloud9 is not running, lets start it up
startCloud9Local({}, function(success) {
if (success)
bridge.send({ type: "pipe" }, cb);
else {
console.log("Could not start Cloud9. "
+ "Please check your configuration.");
callback(err);
process.exit(40); // This appears to be needed; let's return something useful
}
});
return;
}
else {
console.log(err.message);
return;
}
}
var stdin = process.openStdin();
stdin.setEncoding("utf8");
var finished = 0;
stdin.on("data", function(chunk) {
finished++;
bridge.send({
type: "pipeData",
data: chunk,
tab: response
}, function(err, message) {
// Dunno why, but this always returns No Response...
// Escaping that error so end users aren't confused...
if (err && err.message !== "No Response")
console.log(err.message);
finished--;
});
});
stdin.on("end", function() {
(function retry() {
if (finished === 0)
process.exit();
setTimeout(retry, 100);
})();
});
});
}
function startCloud9Local(opts, callback) {
if (options.platform == "darwin") {
proc.spawn("open", {