Browse Source

Added json-beautify

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

5
package-lock.json

@ -121,6 +121,11 @@
"resolved": "https://registry.npmjs.org/interpret/-/interpret-1.0.4.tgz", "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.0.4.tgz",
"integrity": "sha1-ggzdWIuGj/sZGoCVBtbJyPISsbA=" "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": { "jsonfile": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",

1
package.json

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

20
utils/listFile.js

@ -1,5 +1,6 @@
var fs = require('fs-extra'); var fs = require('fs-extra');
var shell = require('shelljs'); 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. 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 = { jsonFile = {}
}
var newBlock = {
}
/*
Object.assign(jsonFile, domain.domBlock)
return jsonFile;
*/
if (fs.existsSync(listFilePath)) { if (fs.existsSync(listFilePath)) {
jsonFile = fs.readFileSync(listFilePath); jsonFile = fs.readFileSync(listFilePath);
@ -48,13 +39,12 @@ function appendToList(domain, outPort, inPort) {
} }
jsonFile[domain] = domBlock; jsonFile[domain] = domBlock;
jsonFile = JSON.stringify(jsonFile); jsonFile = beautifyJSON(jsonFile, null, 2, 30);
} }
else { else {
jsonFile = { jsonFile = {}
}
jsonFile[domain] = domBlock; jsonFile[domain] = domBlock;
jsonFile = JSON.stringify(jsonFile); jsonFile = beautifyJSON(jsonFile);
} }
fs.writeFileSync(listFilePath, jsonFile); fs.writeFileSync(listFilePath, jsonFile);

Loading…
Cancel
Save