Browse Source

Added json-beautify

pull/3/head
Muthu Kumar 7 years ago
parent
commit
af115cb81c
  1. 6
      index.js
  2. 5
      package-lock.json
  3. 1
      package.json
  4. 20
      utils/listFile.js

6
index.js

@ -15,9 +15,9 @@ var createStaticServer = require('./actions/createStaticServer');
var killServer = require('./actions/killServer');
var jsonFile;
// appendToList("example.com", "80");
// appendToList("example2.com", "80", "4000");
// appendToList("example2.com", "80", "4444");
//appendToList("example.com", "80");
//appendToList("example2.com", "80", "4000");
//appendToList("example2.com", "80", "4444");
console.log(jsonFile);
// Check for requirements such as OS version and nginx install. Throw and exit if requirements not found. #Roadmap: Add ability to satisfy any possible requirements.

5
package-lock.json

@ -121,6 +121,11 @@
"resolved": "https://registry.npmjs.org/interpret/-/interpret-1.0.4.tgz",
"integrity": "sha1-ggzdWIuGj/sZGoCVBtbJyPISsbA="
},
"json-beautify": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/json-beautify/-/json-beautify-1.0.1.tgz",
"integrity": "sha1-WYtQ1Mjqm4/KWru0C34svTrUwvw="
},
"jsonfile": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",

1
package.json

@ -30,6 +30,7 @@
"chalk": "^2.3.0",
"commander": "^2.11.0",
"fs-extra": "^4.0.2",
"json-beautify": "^1.0.1",
"shelljs": "^0.7.8",
"validator": "^9.1.1"
}

20
utils/listFile.js

@ -1,5 +1,6 @@
var fs = require('fs-extra');
var shell = require('shelljs');
var beautifyJSON = require("json-beautify");
var EOL = require('os').EOL; // \n if used on Linux, \r\n if used on Windows.
@ -24,17 +25,7 @@ function appendToList(domain, outPort, inPort) {
}
}
jsonFile = {
}
var newBlock = {
}
/*
Object.assign(jsonFile, domain.domBlock)
return jsonFile;
*/
jsonFile = {}
if (fs.existsSync(listFilePath)) {
jsonFile = fs.readFileSync(listFilePath);
@ -48,13 +39,12 @@ function appendToList(domain, outPort, inPort) {
}
jsonFile[domain] = domBlock;
jsonFile = JSON.stringify(jsonFile);
jsonFile = beautifyJSON(jsonFile, null, 2, 30);
}
else {
jsonFile = {
}
jsonFile = {}
jsonFile[domain] = domBlock;
jsonFile = JSON.stringify(jsonFile);
jsonFile = beautifyJSON(jsonFile);
}
fs.writeFileSync(listFilePath, jsonFile);

Loading…
Cancel
Save