Added message command and verbose mode for cli and fixes output for zip and tar.gz

pull/85/head
Ruben Daniels 2015-04-27 19:07:00 +00:00 zatwierdzone przez nightwing
rodzic 09b19b4557
commit af9d420266
6 zmienionych plików z 189 dodań i 146 usunięć

Wyświetl plik

@ -83,6 +83,7 @@ return [
"./c9.ide.installer/commands/gem", "./c9.ide.installer/commands/gem",
"./c9.ide.installer/commands/zip", "./c9.ide.installer/commands/zip",
"./c9.ide.installer/commands/symlink", "./c9.ide.installer/commands/symlink",
"./c9.ide.installer/commands/message",
{ {
packagePath: "./c9.ide.installer/commands/tar.gz", packagePath: "./c9.ide.installer/commands/tar.gz",
bashBin: "bash" bashBin: "bash"
@ -93,7 +94,8 @@ return [
packagePath: "./c9.ide.installer/installer", packagePath: "./c9.ide.installer/installer",
homeDir: process.env.HOME, homeDir: process.env.HOME,
installSelfCheck: false, installSelfCheck: false,
installPath: process.env.HOME + "/.c9" installPath: process.env.HOME + "/.c9",
cli: true
}, },
// "./c9.cli.sync/sync", // "./c9.cli.sync/sync",
//"./c9.ide.keys/commands", //"./c9.ide.keys/commands",
@ -108,6 +110,7 @@ return [
debug: true, debug: true,
hosted: false, hosted: false,
local: true, local: true,
home: process.env.HOME,
setStatus: function(){} setStatus: function(){}
}, },
error_handler: { error_handler: {

Wyświetl plik

@ -529,6 +529,7 @@ module.exports = function(options) {
"plugins/c9.ide.installer/commands/gem", "plugins/c9.ide.installer/commands/gem",
"plugins/c9.ide.installer/commands/zip", "plugins/c9.ide.installer/commands/zip",
"plugins/c9.ide.installer/commands/symlink", "plugins/c9.ide.installer/commands/symlink",
"plugins/c9.ide.installer/commands/message",
{ {
packagePath: "plugins/c9.ide.installer/commands/tar.gz", packagePath: "plugins/c9.ide.installer/commands/tar.gz",
bashBin: options.bashBin bashBin: options.bashBin

Wyświetl plik

@ -83,7 +83,7 @@
"c9.ide.help.support": "#60e88f5680", "c9.ide.help.support": "#60e88f5680",
"c9.ide.imgeditor": "#08bbc53578", "c9.ide.imgeditor": "#08bbc53578",
"c9.ide.immediate": "#6845a93705", "c9.ide.immediate": "#6845a93705",
"c9.ide.installer": "#564748e5e7", "c9.ide.installer": "#2dc739e7e3",
"c9.ide.mount": "#32e79866ee", "c9.ide.mount": "#32e79866ee",
"c9.ide.navigate": "#64156c7f4a", "c9.ide.navigate": "#64156c7f4a",
"c9.ide.newresource": "#f1f0624768", "c9.ide.newresource": "#f1f0624768",

Wyświetl plik

@ -1,5 +1,8 @@
define(function(require, exports, module) { define(function(require, exports, module) {
main.consumes = ["Plugin", "cli_commands", "proc", "api", "auth", "installer"]; main.consumes = [
"Plugin", "cli_commands", "proc", "api", "auth", "installer",
"installer.cli"
];
main.provides = ["cli.install"]; main.provides = ["cli.install"];
return main; return main;
@ -10,6 +13,7 @@ define(function(require, exports, module) {
var auth = imports.auth; var auth = imports.auth;
var api = imports.api; var api = imports.api;
var installer = imports.installer; var installer = imports.installer;
var installerCLI = imports["installer.cli"];
var TEST_MODE = !!process.env.C9_TEST_MODE; 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").toString("utf8");
@ -83,7 +87,7 @@ define(function(require, exports, module) {
"boolean": true "boolean": true
}, },
"dry-run" : { "dry-run" : {
"description": "Only build a test version", "description": "Installs current directory as a package",
"default": false, "default": false,
"boolean": true "boolean": true
}, },
@ -199,7 +203,7 @@ define(function(require, exports, module) {
var version = parts[1]; var version = parts[1];
var repository; var repository;
if (!version || options.debug) { if ((!version || options.debug) && !options.dryRun) {
if (verbose) if (verbose)
console.log("Retrieving package info"); console.log("Retrieving package info");
@ -242,117 +246,107 @@ define(function(require, exports, module) {
} }
function installPackage(){ function installPackage(){
if (!version) if (!version && !options.dryRun)
return callback(new Error("No version found for this package")); return callback(new Error("No version found for this package"));
if (options.local) { if (options.local) {
if (!options.dryRun) installLocal();
return callback(new Error("Dry run is not supported for local installation")); }
else if (options.debug) {
installDebug();
}
else {
installFull();
}
}
function installLocal(){
if (verbose)
console.log("Installing package locally");
prepareDirectory(function(err, packagePath){
if (err) return callback(err);
if (verbose) function installNPM(){
console.log("Installing package locally"); proc.spawn(join(process.env.HOME, ".c9/node/bin/npm"), {
args: ["install"],
prepareDirectory(function(err, packagePath){ cwd: packagePath
if (err) return callback(err); }, function(err, p){
if (err) return callback(err);
// Download package
var gzPath = join(os.tmpDir(), name + "@" + version + ".tar.gz");
var file = fs.createWriteStream(gzPath);
var path = "/packages/" + name + "/versions/" + version
+ "/download?access_token="
+ encodeURIComponent(auth.accessToken);
var host = APIHOST.split(":")[0];
var port = parseInt(APIHOST.split(":")[1]) || null;
var request = http.get({
agent: false,
method: "get",
host: host,
port: port,
auth: BASICAUTH,
path: path
}, function(response){
response.pipe(file);
});
if (verbose)
console.log("Downloading package to", gzPath);
request.on('response', function(res) {
if (res.statusCode != 200)
return callback(new Error("Unknown Error:" + res.statusCode));
});
file.on('finish', function() {
if (verbose)
console.log("Unpacking", gzPath, "to", packagePath);
// Untargz package if (verbose) {
proc.spawn(TAR, { p.stdout.on("data", function(c){
args: ["-C", normalizePath(packagePath), "-zxvf", normalizePath(gzPath)] process.stdout.write(c.toString("utf8"));
}, function(err, p){ });
if (err) return callback(err); p.stderr.on("data", function(c){
process.stderr.write(c.toString("utf8"));
if (verbose) { });
p.stdout.on("data", function(c){ }
process.stdout.write(c.toString("utf8"));
}); p.on("exit", function(code){
p.stderr.on("data", function(c){ // Done
process.stderr.write(c.toString("utf8")); callback(err, {
}); version: version
}
p.on("exit", function(code){
var err = code !== 0
? new Error("Failed to unpack package")
: null;
if (err) return callback(err);
proc.spawn(join(process.env.HOME, ".c9/node/bin/npm"), {
args: ["install"],
cwd: packagePath
}, function(err, p){
if (err) return callback(err);
if (verbose) {
p.stdout.on("data", function(c){
process.stdout.write(c.toString("utf8"));
});
p.stderr.on("data", function(c){
process.stderr.write(c.toString("utf8"));
});
}
p.on("exit", function(code){
// Done
callback(err, {
version: version
});
});
});
}); });
}); });
}); });
}); }
}
else if (options.debug) {
if (verbose)
console.log("Installing debug version of package");
if (!options.dryRun) if (options.dryRun) {
return callback(new Error("Dry run is not supported for debug installation")); try {
var json = JSON.parse(fs.readFileSync(join(process.cwd(), "package.json")));
prepareDirectory(function(err, packagePath){ if (json.private)
if (err) return callback(err); return callback(new Error("ERROR: Private flag in package.json prevents from installing"));
}
if (verbose) catch(e) {
console.log("Cloning repository: ", repository); return callback(new Error("ERROR: Invalid package"));
}
// Git clone repository proc.execFile("bash", { args: ["-c", "cp -a " + join(process.cwd(), "/*") + " " + packagePath] }, function(err){
var scm = SCM[repository.type]; if (err) return callback(err);
proc.spawn(scm.binary, {
args: [scm.clone, repository.url, packagePath] installNPM();
});
return;
}
// Download package
var gzPath = join(os.tmpDir(), name + "@" + version + ".tar.gz");
var file = fs.createWriteStream(gzPath);
var path = "/packages/" + name + "/versions/" + version
+ "/download?access_token="
+ encodeURIComponent(auth.accessToken);
var host = APIHOST.split(":")[0];
var port = parseInt(APIHOST.split(":")[1]) || null;
var request = http.get({
agent: false,
method: "get",
host: host,
port: port,
auth: BASICAUTH,
path: path
}, function(response){
response.pipe(file);
});
if (verbose)
console.log("Downloading package to", gzPath);
request.on('response', function(res) {
if (res.statusCode != 200)
return callback(new Error("Unknown Error:" + res.statusCode));
});
file.on('finish', function() {
if (verbose)
console.log("Unpacking", gzPath, "to", packagePath);
// Untargz package
proc.spawn(TAR, {
args: ["-C", normalizePath(packagePath), "-zxvf", normalizePath(gzPath)]
}, function(err, p){ }, function(err, p){
if (err) return callback(err); if (err) return callback(err);
@ -367,58 +361,101 @@ define(function(require, exports, module) {
p.on("exit", function(code){ p.on("exit", function(code){
var err = code !== 0 var err = code !== 0
? new Error("Failed to clone package from repository. Do you have access?") ? new Error("Failed to unpack package")
: null; : null;
if (err) return callback(err);
// Done installNPM();
callback(err);
}); });
}); });
}); });
} });
else { }
function installDebug(){
if (verbose)
console.log("Installing debug version of package");
if (!options.dryRun)
return callback(new Error("Dry run is not supported for debug installations"));
prepareDirectory(function(err, packagePath){
if (err) return callback(err);
if (verbose) if (verbose)
console.log("Notifying c9.io that packages needs to be installed"); console.log("Cloning repository: ", repository);
var dryRun = options.dryRun; // Git clone repository
var scm = SCM[repository.type];
// Install Locally proc.spawn(scm.binary, {
options.local = true; args: [scm.clone, repository.url, packagePath]
install(name + "@" + version, options, function(err){ }, function(err, p){
if (err) return callback(err); if (err) return callback(err);
var path = "~/.c9/plugins/" + name; if (verbose) {
fs.readFile(path + "/package.json", "utf8", function(err, data){ p.stdout.on("data", function(c){
if (err) return callback(new Error("Package.json not found in " + path)); process.stdout.write(c.toString("utf8"));
});
var installPath; p.stderr.on("data", function(c){
try { installPath = JSON.parse(data).installer; } process.stderr.write(c.toString("utf8"));
catch(e){
return callback(new Error("Could not parse package.json in " + path));
}
if (installPath) {
installer.createSession(name, version, require(path + "/" + installPath), function(err){
if (err) return callback(new Error("Error Installing Package " + name + "@" + version));
installToDatabase();
});
}
else
installToDatabase();
});
function installToDatabase(){
var endpoint = options.global ? api.user : api.project;
var url = "install/" + packageName + "/" + version + "?mode=silent";
endpoint.post(url, function(err, info){
callback(err, info);
}); });
} }
p.on("exit", function(code){
var err = code !== 0
? new Error("Failed to clone package from repository. Do you have access?")
: null;
// Done
callback(err);
});
});
});
}
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){
return callback(new Error("Could not parse package.json in " + path));
}
if (installPath) {
installerCLI.verbose = verbose;
installer.createSession(name, version, require(path + "/" + installPath), function(err){
if (err) return callback(new Error("Error Installing Package " + name + "@" + version));
installToDatabase();
});
}
else
installToDatabase();
}); });
}
function installToDatabase(){
if (options.dryRun)
return callback(null, { version: "dry-run" });
var endpoint = options.global ? api.user : api.project;
var url = "install/" + packageName + "/" + version + "?mode=silent";
endpoint.post(url, function(err, info){
callback(err, info);
});
}
});
} }
} }

Wyświetl plik

@ -219,6 +219,8 @@ define(function(require, exports, module) {
} }
// Basic Validation // Basic Validation
if (json.private)
return callback(new Error("ERROR: Private flag in package.json prevents from publishing"));
if (!json.name) if (!json.name)
return callback(new Error("ERROR: Missing name property in package.json")); return callback(new Error("ERROR: Missing name property in package.json"));
if (basename(cwd) != json.name) { if (basename(cwd) != json.name) {

Wyświetl plik

@ -9,7 +9,7 @@ define(function(require, module, exports) {
var vfs = new localFs({ var vfs = new localFs({
root: "/", root: "/",
nopty: true, // nopty: true,
defaultEnv: { CUSTOM: 43 } defaultEnv: { CUSTOM: 43 }
}); });