diff --git a/configs/cli.js b/configs/cli.js index 5fc657da..49d59327 100644 --- a/configs/cli.js +++ b/configs/cli.js @@ -83,6 +83,7 @@ return [ "./c9.ide.installer/commands/gem", "./c9.ide.installer/commands/zip", "./c9.ide.installer/commands/symlink", + "./c9.ide.installer/commands/message", { packagePath: "./c9.ide.installer/commands/tar.gz", bashBin: "bash" @@ -93,7 +94,8 @@ return [ packagePath: "./c9.ide.installer/installer", homeDir: process.env.HOME, installSelfCheck: false, - installPath: process.env.HOME + "/.c9" + installPath: process.env.HOME + "/.c9", + cli: true }, // "./c9.cli.sync/sync", //"./c9.ide.keys/commands", @@ -108,6 +110,7 @@ return [ debug: true, hosted: false, local: true, + home: process.env.HOME, setStatus: function(){} }, error_handler: { diff --git a/configs/client-default.js b/configs/client-default.js index c40b349b..f693e944 100644 --- a/configs/client-default.js +++ b/configs/client-default.js @@ -529,6 +529,7 @@ module.exports = function(options) { "plugins/c9.ide.installer/commands/gem", "plugins/c9.ide.installer/commands/zip", "plugins/c9.ide.installer/commands/symlink", + "plugins/c9.ide.installer/commands/message", { packagePath: "plugins/c9.ide.installer/commands/tar.gz", bashBin: options.bashBin diff --git a/package.json b/package.json index cc33563f..f745d60c 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": "#564748e5e7", + "c9.ide.installer": "#2dc739e7e3", "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 54580eb8..eb14b7b2 100644 --- a/plugins/c9.cli.publish/install.js +++ b/plugins/c9.cli.publish/install.js @@ -1,5 +1,8 @@ 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"]; return main; @@ -10,6 +13,7 @@ define(function(require, exports, module) { var auth = imports.auth; var api = imports.api; var installer = imports.installer; + var installerCLI = imports["installer.cli"]; var TEST_MODE = !!process.env.C9_TEST_MODE; var SHELLSCRIPT = TEST_MODE ? "" : require("text!./publish.git.sh").toString("utf8"); @@ -83,7 +87,7 @@ define(function(require, exports, module) { "boolean": true }, "dry-run" : { - "description": "Only build a test version", + "description": "Installs current directory as a package", "default": false, "boolean": true }, @@ -199,7 +203,7 @@ define(function(require, exports, module) { var version = parts[1]; var repository; - if (!version || options.debug) { + if ((!version || options.debug) && !options.dryRun) { if (verbose) console.log("Retrieving package info"); @@ -242,117 +246,107 @@ define(function(require, exports, module) { } function installPackage(){ - if (!version) + if (!version && !options.dryRun) return callback(new Error("No version found for this package")); if (options.local) { - if (!options.dryRun) - return callback(new Error("Dry run is not supported for local installation")); + installLocal(); + } + 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) - console.log("Installing package locally"); - - prepareDirectory(function(err, packagePath){ - 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); + function installNPM(){ + proc.spawn(join(process.env.HOME, ".c9/node/bin/npm"), { + args: ["install"], + cwd: packagePath + }, function(err, p){ + if (err) return callback(err); - // Untargz package - proc.spawn(TAR, { - args: ["-C", normalizePath(packagePath), "-zxvf", normalizePath(gzPath)] - }, 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){ - 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 - }); - }); - }); + 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) - return callback(new Error("Dry run is not supported for debug installation")); - - prepareDirectory(function(err, packagePath){ - if (err) return callback(err); - - if (verbose) - console.log("Cloning repository: ", repository); + if (options.dryRun) { + try { + var json = JSON.parse(fs.readFileSync(join(process.cwd(), "package.json"))); + if (json.private) + return callback(new Error("ERROR: Private flag in package.json prevents from installing")); + } + catch(e) { + return callback(new Error("ERROR: Invalid package")); + } - // Git clone repository - var scm = SCM[repository.type]; - proc.spawn(scm.binary, { - args: [scm.clone, repository.url, packagePath] + proc.execFile("bash", { args: ["-c", "cp -a " + join(process.cwd(), "/*") + " " + packagePath] }, function(err){ + if (err) return callback(err); + + 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){ if (err) return callback(err); @@ -367,58 +361,101 @@ define(function(require, exports, module) { p.on("exit", function(code){ var err = code !== 0 - ? new Error("Failed to clone package from repository. Do you have access?") + ? new Error("Failed to unpack package") : null; + if (err) return callback(err); - // Done - callback(err); + installNPM(); }); }); }); - } - 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) - console.log("Notifying c9.io that packages needs to be installed"); + console.log("Cloning repository: ", repository); - var dryRun = options.dryRun; - - // Install Locally - options.local = true; - install(name + "@" + version, options, function(err){ + // Git clone repository + var scm = SCM[repository.type]; + proc.spawn(scm.binary, { + args: [scm.clone, repository.url, packagePath] + }, function(err, p){ if (err) return callback(err); - var path = "~/.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) { - 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); + 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){ + 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); + }); + } + }); } } diff --git a/plugins/c9.cli.publish/publish.js b/plugins/c9.cli.publish/publish.js index 338ed487..37e20cda 100644 --- a/plugins/c9.cli.publish/publish.js +++ b/plugins/c9.cli.publish/publish.js @@ -219,6 +219,8 @@ define(function(require, exports, module) { } // Basic Validation + if (json.private) + return callback(new Error("ERROR: Private flag in package.json prevents from publishing")); if (!json.name) return callback(new Error("ERROR: Missing name property in package.json")); if (basename(cwd) != json.name) { diff --git a/plugins/c9.vfs.client/vfs.cli.js b/plugins/c9.vfs.client/vfs.cli.js index 915200fe..92d339e8 100644 --- a/plugins/c9.vfs.client/vfs.cli.js +++ b/plugins/c9.vfs.client/vfs.cli.js @@ -9,7 +9,7 @@ define(function(require, module, exports) { var vfs = new localFs({ root: "/", - nopty: true, + // nopty: true, defaultEnv: { CUSTOM: 43 } });