This repository has been archived by the owner on Aug 11, 2022. It is now read-only.
/
npm.js
executable file
·77 lines (65 loc) · 1.88 KB
/
npm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// the main guts
var npm = exports,
queue = require("./src/queue.js").queue,
http = require("/http.js");
include("/utils.js");
npm.install = function npm_install () {
return dummyPromise()
};
npm.refresh = function npm_refresh () {
// return dummyPromise()
// get my list of sources.
var p = new node.Promise();
npm.getSources().addCallback(function (srcArr) {
queue(srcArr, function (src) {
return npm.refreshSource(src)
}).addCallback(function () {
p.emitSuccess();
}).addErrback(function () {
p.emitError();
});
});
return p;
};
npm.getSources = function npm_getSources () {
var p = new node.Promise();
node.fs.cat(node.path.join(ENV.HOME, ".npm", "sources.json"))
.addErrback(function () {
p.emitError(new Error(
"Couldn't read " + node.path.join(ENV.HOME, ".npm", "sources.json") + "\n"
));
})
.addCallback(function (data) {
try {
data = JSON.parse(data);
if (data) p.emitSuccess(data);
} catch (ex) { p.emitError(ex); return; }
});
return p;
};
npm.refreshSource = function npm_refreshSource (src) {
debug("refresh the source: "+src);
var p = new node.Promise();
// var u = http.parseUri(src);
// var httpClient = http.createClient(uri.port || 80, uri.host);
// client.get(uri.path || "/", headers || {})
http.cat(src, "utf-8", { "User-Agent" : "nodejs" })
.addCallback(function (data) {
debug("do something");
p.emitSuccess(data);
})
.addErrback(function (er) {
debug("error "+JSON.stringify(er)+ " " + JSON.stringify(res));
p.emitError(er);
});
return p;
};
function dummyPromise (name) {
var promise = new node.Promise();
name = name || arguments.callee.caller.name;
setTimeout(function () {
node.stdio.writeError("TODO: implement "+ name + "\n");
promise.emitSuccess("dummy");
});
return promise;
};