1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00

Developing the 'somehow' in 'This list [of commands] needs to be updated, and perhaps auto-updated somehow'

This commit is contained in:
Dave Hoover
2011-06-02 21:12:13 -05:00
parent c73af8d477
commit e210755b52
3 changed files with 173 additions and 23 deletions

43
generate_commands.js Normal file
View File

@@ -0,0 +1,43 @@
var http = require("http"),
sys = require("sys"),
fs = require("fs");
http.get({host: "redis.io", path: "/commands.json"}, function(res) {
console.log("Response from redis.io/commands.json: " + res.statusCode);
var commandString = "";
res.on('data', function(chunk) {
commandString += chunk;
});
res.on('end', function() {
var commands = JSON.parse(commandString);
writeCommandsToFile(commands, "lib/commands.js");
})
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
function writeCommandsToFile(commands, path) {
console.log("Writing " + path);
var fileContents = "// This file was generated by ./generate_commands.js on ";
fileContents += prettyCurrentTime();
fileContents += "\nCommands = [\n";
var lowerCommands = [];
for (var command in commands) {
lowerCommands.push(" \"" + command.toLowerCase() + "\"");
}
fileContents += lowerCommands.join(",\n");
fileContents += "\n];\n\n"
fileContents += "exports.Commands = Commands;"
fs.writeFile(path, fileContents);
}
function prettyCurrentTime() {
var date = new Date();
return date.toLocaleString();
}