Merge pull request +7078 from c9/fix/install-cli

Installer fixes
pull/85/head
Ruben Daniels 2015-04-29 15:23:21 -07:00
commit 9fea731052
9 zmienionych plików z 65 dodań i 46 usunięć

Wyświetl plik

@ -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(/^[^{]*{/, "")
.replace(/\}$/, ""));
var PID = process.env.C9_PID || 526;
var APIHOST = process.env.C9_APIHOST || "api.c9.io"; // "api.c9.io";

Wyświetl plik

@ -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));

Wyświetl plik

@ -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": "#0b915c68e9",
"c9.ide.installer": "#80d050b6de",
"c9.ide.mount": "#32e79866ee",
"c9.ide.navigate": "#64156c7f4a",
"c9.ide.newresource": "#f1f0624768",

Wyświetl plik

@ -15,8 +15,9 @@ 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 SHELLSCRIPT = TEST_MODE ? "" : require("text!./publish.git.sh").toString("utf8");
var TAR = "tar";
var APIHOST = options.apiHost;
var BASICAUTH = process.env.C9_TEST_AUTH;
@ -59,7 +60,7 @@ define(function(require, exports, module) {
cmd.addCommand({
name: "install",
info: " Installs a cloud9 package.",
usage: "[--verbose] [--force] [--global] [--local] [--debug] [--dry-run] <package>[@<version>]",
usage: "[--verbose] [--force] [--global] [--local] [--debug] [<package>[@<version>] | . ]",
options: {
"local": {
description: "",
@ -86,11 +87,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 +113,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 +203,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 +226,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 +251,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 +297,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 +307,17 @@ 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("cp", {
args: ["-R", process.cwd(), dirname(packagePath)]
}, function(err){
if (err) return callback(err);
installNPM();
});
}
return;
}
@ -376,7 +387,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){
@ -414,18 +425,15 @@ 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){
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 +442,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 +453,11 @@ define(function(require, exports, module) {
function installToDatabase(){
if (options.dryRun)
return callback(null, { version: "dry-run" });
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";

Wyświetl plik

@ -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;
@ -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 *****/
/**
*

Wyświetl plik

@ -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]) {

Wyświetl plik

@ -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;

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -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) {