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