diff options
author | isaacs <i@izs.me> | 2010-05-02 04:13:43 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-05-02 04:13:43 +0400 |
commit | a9ab525f8c12609a3f79a0b33c0e1d9938394cd9 (patch) | |
tree | b8f973e16d38d46c2d15726ae1403b52125b1e8f /lib | |
parent | bbc2cd346302a53f852dbd4100b48defccbe2bae (diff) |
comma first
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils/registry.js | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/lib/utils/registry.js b/lib/utils/registry.js index ce5d6f857..643944984 100644 --- a/lib/utils/registry.js +++ b/lib/utils/registry.js @@ -1,18 +1,18 @@ // utilities for working with the js-registry site. -exports.publish = publish; -exports.tag = tag; -exports.adduser = adduser; +exports.publish = publish +exports.tag = tag +exports.adduser = adduser -var npm = require("../../npm"), - http = require("http"), - url = require("url"), - log = require("./log"), - uuid = require("./uuid"), - sha = require("./sha"), - sys = require("sys"), - ini = require("./ini"); +var npm = require("../../npm") + , http = require("http") + , url = require("url") + , log = require("./log") + , uuid = require("./uuid") + , sha = require("./sha") + , sys = require("sys") + , ini = require("./ini") function tag (project, version, tag, cb) { PUT(project+"/"+tag, version, cb) } @@ -23,9 +23,9 @@ function publish (data, tarball, cb) { // then: // PUT the data to {config.registry}/{data.name}/{data.version} try { - reg(); + reg() } catch (ex) { - return cb(ex); + return cb(ex) } var fullData = { "_id" : data.name @@ -33,15 +33,15 @@ function publish (data, tarball, cb) { , "description" : data.description , "dist-tags" : {} , "versions" : {} - }; - fullData.versions[ data.version ] = data; - data._id = data.name+"-"+data.version; - data.dist = { "tarball" : tarball }; + } + fullData.versions[ data.version ] = data + data._id = data.name+"-"+data.version + data.dist = { "tarball" : tarball } // first try to just PUT the whole fullData, and this will fail if it's // already there, because it'll be lacking a _rev, so couch'll bounce it. PUT(data.name, fullData, function (er) { - if (!er) return cb(); + if (!er) return cb() // there was an error, so assume the fullData is already there. // now try to create just this version. This time, failure // is not ok. @@ -50,66 +50,66 @@ function publish (data, tarball, cb) { // first req, but now it's up, then this may fail for not having the // project created yet, or because the user doesn't have access to it. PUT(data.name+"/"+data.version, data, function (er) { - if (er) return cb(er); - cb(); - }); - }); + if (er) return cb(er) + cb() + }) + }) } function PUT (where, what, cb) { - reg(); - what = JSON.stringify(what); - log(where, "registryPUT"); - where = ini.config.registry + where; + reg() + what = JSON.stringify(what) + log(where, "registryPUT") + where = ini.config.registry + where - var u = url.parse(where), - headers = { "content-type" : "application/json" - , "host" : u.host - , "content-length" : what.length - }; + var u = url.parse(where) + , headers = { "content-type" : "application/json" + , "host" : u.host + , "content-length" : what.length + } if (ini.config.auth) { - headers.authorization = 'Basic ' + ini.config.auth; + headers.authorization = 'Basic ' + ini.config.auth } - log(sys.inspect(u), "registryPUT"); - log(u.port || (u.protocol === "https:" ? 443 : 80), "registryPUT port"); + log(sys.inspect(u), "registryPUT") + log(u.port || (u.protocol === "https:" ? 443 : 80), "registryPUT port") - var client = http.createClient(u.port || (u.protocol === "https:" ? 443 : 80), u.hostname); + var client = http.createClient(u.port || (u.protocol === "https:" ? 443 : 80), u.hostname) if (u.protocol === "https:") { - client.setSecure("X509_PEM"); + client.setSecure("X509_PEM") } - var request = client.request("PUT", u.pathname, headers); + var request = client.request("PUT", u.pathname, headers) - log(sys.inspect(headers), "registryPUT headers"); + log(sys.inspect(headers), "registryPUT headers") request.addListener("response", function (response) { // if (response.statusCode !== 200) return cb(new Error( - // "Status code " + response.statusCode + " from PUT "+where)); - var data = ""; - response.setBodyEncoding("utf8"); - response.addListener("data", function (chunk) { data += chunk }); + // "Status code " + response.statusCode + " from PUT "+where)) + var data = "" + response.setBodyEncoding("utf8") + response.addListener("data", function (chunk) { data += chunk }) response.addListener("end", function () { - log(data, "registryPUT"); + log(data, "registryPUT") try { - data = JSON.parse(data); + data = JSON.parse(data) } catch (ex) { - ex.message += "\n" + data; - return cb(ex, data, response); + ex.message += "\n" + data + return cb(ex, data, response) } if (data.error) return cb(new Error( - data.error + (" "+data.reason || ""))); - cb(null, data, response); - }); - }); - request.write(what, "utf8"); - request.end(); + data.error + (" "+data.reason || ""))) + cb(null, data, response) + }) + }) + request.write(what, "utf8") + request.end() } function reg () { if (!ini.config.registry) throw new Error( - "Must define registry before publishing."); - log(ini.config.registry, "registry"); + "Must define registry before publishing.") + log(ini.config.registry, "registry") if (ini.config.registry.substr(-1) !== "/") { - ini.config.registry += "/"; + ini.config.registry += "/" } } @@ -123,14 +123,14 @@ function adduser (username, password, email, callback) { , salt : salt , password_sha : sha.hex_sha1(password + salt) , email : email - }; + } PUT('/adduser/org.couchdb.user:'+username, userobj, function (error, data, response) { // if the error is a 409, then update the rev. if (error || response.statusCode !== 201) { callback(new Error( - "Could not create user "+error+'\n'+data)); + "Could not create user "+error+'\n'+data)) } else { - callback(); + callback() } - }); + }) } |