File: generate_commands.js

package info (click to toggle)
node-redis 0.12.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 628 kB
  • ctags: 502
  • sloc: sh: 22; makefile: 5
file content (39 lines) | stat: -rw-r--r-- 1,107 bytes parent folder | download
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
var http = require("http"),
    fs = require("fs");

function prettyCurrentTime() {
    var date = new Date();
    return date.toLocaleString();
}

function write_file(commands, path) {
    var file_contents, out_commands;

    console.log("Writing " + Object.keys(commands).length + " commands to " + path);

    file_contents = "// This file was generated by ./generate_commands.js on " + prettyCurrentTime() + "\n";

    out_commands = Object.keys(commands).map(function (key) {
        return key.toLowerCase();
    });

    file_contents += "module.exports = " + JSON.stringify(out_commands, null, "    ") + ";\n";

    fs.writeFile(path, file_contents);
}

http.get({host: "redis.io", path: "/commands.json"}, function (res) {
    var body = "";

    console.log("Response from redis.io/commands.json: " + res.statusCode);

    res.on('data', function (chunk) {
        body += chunk;
    });

    res.on('end', function () {
        write_file(JSON.parse(body), "lib/commands.js");
    });
}).on('error', function (e) {
    console.log("Error fetching command list from redis.io: " + e.message);
});