blob: f717ceaadca1fb2bb72d03d80eb6575fb9b3586e (
plain)
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
78
79
|
var tusk = require("../tusk");
var util = require("util");
var args = require("args");
var http = require("http");
var json = require("json");
var parser = exports.parser = new args.Parser();
parser.help('creates a catalog of packages from sources.json');
parser.action(function (options) {
var self = this;
var sources = tusk.readSources();
var catalog = {};
catalog['!'] = "This file is generated by 'tusk create-catalog', copied from '.tusk', and committed only so that it may be downloaded from Github with 'tusk update'.";
catalog.version = util.copy(sources.version);
var packages = catalog.packages = {};
util.forEachApply(
util.items(sources.packages || {}),
function (name, source) {
var info;
if (source['package.json'])
info = util.copy(source['package.json']);
if (source.type == "inline") {
if (!info) {
self.print(
"\0red(dropped:\0) " + name +
" \0blue(because it did not provide a " +
"package.json inline.\0)"
);
return;
}
} else if (source.type == "github") {
var githubName = source.name || name;
if (!source.user)
throw new Error("package source " + util.enquote(name) + " did not have a github user name");
var project = source.user + '/' + githubName;
var url = "http://github.com/" + project + "/raw/master/package.json";
// download package.json if not already provided
if (!info) {
try {
var text = http.read(url).toString('utf-8');
} catch (exception) {
self.print("\0red(dropped:\0) " + name + " \0blue(because of an HTTP error\0)");
return;
}
try {
info = json.decode(text);
} catch (exception) {
self.print("\0red(dropped:\0) " + name + " \0blue(because of a JSON error\0)");
return;
}
}
info.githubName = githubName;
info.type = "zip";
info.location = 'http://github.com/' + source.user + '/' + githubName + '/zipball/master';
} else {
throw new Error(
"Project " + util.enquote(name) +
" has an urecognized type: " +
util.enquote(source.type)
);
}
self.print('\0green(' + name + '\0)');
packages[name] = info;
}
);
tusk.writeCatalog(catalog);
});
|