You've already forked node-redis
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:
43
generate_commands.js
Normal file
43
generate_commands.js
Normal 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();
|
||||
}
|
Reference in New Issue
Block a user