From da770f9c239bcf7b85f52d6128683bb97c7c5a17 Mon Sep 17 00:00:00 2001 From: shunmusanjay Date: Tue, 7 Nov 2017 02:31:04 +0530 Subject: [PATCH] listFile.js file creation and append --- utils/listFile.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/utils/listFile.js b/utils/listFile.js index b0ab224..477acfa 100644 --- a/utils/listFile.js +++ b/utils/listFile.js @@ -1,13 +1,22 @@ // These functions just return paths. -var list = 'etc/up-serve/servers.up'; +var fs = require('fs-extra'); +var shell = require('shelljs'); +var EOL = require('os').EOL; // \n if used on Linux, \r\n if used on Windows. + +var listFilePath = 'etc/up-serve/servers.up'; function list(domain, inPort, outPort) { + fs.ensureFileSync(listFilePath) // Creates directory if doesn't exist + if (inPort) { - return (list + ' ' + domain + ':' + outPort + ' ' + 'proxy' + ' ' + inPort); + var addr = domain + ':' + outPort + ' ' + 'proxy' + ' ' + inPort + EOL; } else { - return (list + ' ' + domain + ':' + outPort + ' ' + 'static'); + var addr = domain + ':' + outPort + ' ' + 'static' + EOL; } + + //wirtes to the file in path + fs.appendFileSync(listFilePath, addr); } module.exports = listFile; \ No newline at end of file