diff --git a/actions/killALL.js b/actions/killALL.js index 4b38147..b8905fa 100644 --- a/actions/killALL.js +++ b/actions/killALL.js @@ -22,4 +22,9 @@ function killALL () { // Symlink the default.conf file from confD to sites-enabled } -module.exports = killALL; +function noKill () { + console.log("\nkill-all was interrupted by user."); +} + +module.exports.kill = killALL; +module.exports.noKill = noKill; \ No newline at end of file diff --git a/actions/killAllConfirm.js b/actions/killAllConfirm.js index 59d8537..1d8a8e8 100644 --- a/actions/killAllConfirm.js +++ b/actions/killAllConfirm.js @@ -1,38 +1,21 @@ 'use strict'; -const { EOL } = require('os'); +const readline = require('readline'); +const killALL = require('./killALL').kill; +const noKill = require('./killALL').noKill; -const prompt = require('prompt'); -const shell = require('shelljs'); +function killAllConfirm() { + console.log("\nThis action will destroy all nginx servers and return to default configuration.\nAre you sure you want to do this?" + "\nConfirm y[es] / n[o]:"); + const rl = readline.createInterface({ input: process.stdin }); -const killAll = require('./killALL'); + const line = () => new Promise(resolve => rl.once('line', resolve)); -function killAllConfirm () { - // Start the prompt - - prompt.start(); - - const property = { - name: 'yesno', - message: 'This will completely destroy all configs and reset nginx. ' + - 'Are you sure?', - validator: /y[es]*|n[o]?/, - warning: 'Must respond yes or no', - default: 'no' - }; - - prompt.get(property, function (err, res) { - if(res.yesno == "no") { - console.log("Aborted!"); - shell.exit(0); - } - else { - console.log("Deleting all servers..."); - killAll(); - console.log(EOL + - "Done. All configs have been destroyed. Hope you're happy."); + line().then(line => { + line.trim(); + if((/^(y(es)?|n(o)?)$/).test(line)) { + line == "y" || "yes" ? killALL() : noKill(); } }); } -module.exports = killAllConfirm; +module.exports = killAllConfirm; \ No newline at end of file diff --git a/index.js b/index.js index a82bb4d..b7efe31 100755 --- a/index.js +++ b/index.js @@ -90,6 +90,7 @@ program .command('kill-all') .description('Warning! Will completely kill all servers and reset nginx') .action(function() { + //new Promise(resolve => killed\killAllConfirm(); killAllConfirm(); console.log(EOL + [ "A backup of your old servers.up is " + diff --git a/utils/isFQDN.js b/utils/isFQDN.js index fd0de97..3a43445 100644 --- a/utils/isFQDN.js +++ b/utils/isFQDN.js @@ -4,6 +4,7 @@ 'use strict'; const fs = require('fs-extra'); +const path = require('path'); // Official list of TLDs should be fetched from: // https://data.iana.org/TLD/tlds-alpha-by-domain.txt @@ -14,7 +15,8 @@ const fs = require('fs-extra'); function isFQDN(domain) { // Importing and parsing `tlds.txt` file - const tlds = fs.readFileSync('./assets/tlds.txt', 'utf8') + const tldspath = path.join(__dirname, '/../assets/tlds.txt'); + const tlds = fs.readFileSync(tldspath, 'utf8') .split(/[\r\n]+/) .filter(x => !x.startsWith('#'));