generate_commands.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. var http = require("http"),
  2. fs = require("fs");
  3. function prettyCurrentTime() {
  4. var date = new Date();
  5. return date.toLocaleString();
  6. }
  7. function write_file(commands, path) {
  8. var file_contents, out_commands;
  9. console.log("Writing " + Object.keys(commands).length + " commands to " + path);
  10. file_contents = "// This file was generated by ./generate_commands.js on " + prettyCurrentTime() + "\n";
  11. out_commands = Object.keys(commands).map(function (key) {
  12. return key.toLowerCase();
  13. });
  14. file_contents += "module.exports = " + JSON.stringify(out_commands, null, " ") + ";\n";
  15. fs.writeFile(path, file_contents);
  16. }
  17. http.get({host: "redis.io", path: "/commands.json"}, function (res) {
  18. var body = "";
  19. console.log("Response from redis.io/commands.json: " + res.statusCode);
  20. res.on('data', function (chunk) {
  21. body += chunk;
  22. });
  23. res.on('end', function () {
  24. write_file(JSON.parse(body), "lib/commands.js");
  25. });
  26. }).on('error', function (e) {
  27. console.log("Error fetching command list from redis.io: " + e.message);
  28. });