forked from davglass/nodejs-yui3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
versions.js
executable file
·107 lines (92 loc) · 3.2 KB
/
versions.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env node
var netBinding = process.binding('net'),
net = require('net'),
fds = netBinding.socketpair(),
npm = require('npm'),
config = {
exit: false,
loglevel: 'silent',
outfd: new net.Stream(fds[0], 'unix'),
logfd: new net.Stream(fds[1], 'unix')
};
console.log('Fetching YUI versions from npm, this may take a moment...');
npm.load(config, function() {
npm.commands.ls(['yui3'], function(err, data) {
var installed = {};
for (var i in data) {
if (i.match(/yui3-/)) {
var c = i.split('@');
installed[c[0]] = data[i].data.versions;
}
}
start(installed);
});
});
var express = require('express'),
app = express.createServer();
var start = function(mods) {
var qs = require('querystring');
var items = {
'core': {
q: 'v'
},
'gallery': {
q: 'g'
},
'2in3': {
q: 'yui2'
}
};
app.get('/', function(req, res) {
var p = req.query,
out = '',
helpers = {};
var modules = '<h1>Installed Packages</h1>';
for (var i in items) {
var name = 'yui3-' + i;
modules += '<h3>' + name + '</h3><ul>';
for (var v in mods[name]) {
var m = mods[name][v];
modules += '<li>' + ((m.installed) ? '<a href="/?' + items[i].q + '=' + v + '">' + v + '</a>' : v) + ((m.installed) ? ' <strong>Installed</strong>' : ' <strong>Not Installed</strong> install via: <code>npm install ' + name + '@' + v + '</code>') + '</li>';
if (m.installed) {
if (!helpers[items[i].q]) {
if (p[items[i].q] !== v) {
helpers[items[i].q] = v;
}
}
}
}
modules += '</ul>';
}
var YUIConfig = {};
if (p.v) {
YUIConfig.core = p.v;
}
if (p.g) {
YUIConfig.gallery = p.g;
}
if (p.yui2) {
YUIConfig['2in3'] = p.yui2;
}
var yui3 = require('yui3');
var YUI = yui3.configure(YUIConfig).YUI;
out += '<h1>YUI Loaded From Config</h1>';
out += 'Core: ' + YUI.GlobalConfig.base + '<br>';
if (YUI.GlobalConfig.groups && YUI.GlobalConfig.groups.gallery) {
out += 'Gallery: ' + YUI.GlobalConfig.groups.gallery.base + '<br>';
} else {
out += 'Gallery is not installed: <code>npm install yui3-gallery</code>';
}
if (YUI.GlobalConfig.groups && YUI.GlobalConfig.groups.yui2) {
out += '2in3: ' + YUI.GlobalConfig.groups.yui2.base + '<br><br>';
} else {
out += '2in3 is not installed: <code>npm install yui3-2in3</code>';
}
var u = 'http:/'+'/localhost:8181/?' + qs.stringify(helpers);
out += '<strong>Hint:</strong> Try passing a config to the url: <a href="' + u + '">' + u + '</a><br><br>';
out += modules;
res.send(out);
});
console.log('Done, Server listening: http:/'+'/localhost:8181/');
app.listen(8181);
};