diff --git a/index.js b/index.js index 90fcdc1..d69294e 100755 --- a/index.js +++ b/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. diff --git a/package-lock.json b/package-lock.json index bf62478..27e3a0c 100644 --- a/package-lock.json +++ b/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", diff --git a/package.json b/package.json index 471228b..e4f5998 100644 --- a/package.json +++ b/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" } diff --git a/utils/listFile.js b/utils/listFile.js index 2572705..4331a5e 100644 --- a/utils/listFile.js +++ b/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);