Browse Source

Working on kill-all confirmation prompt

pull/7/head
Muthu Kumar 7 years ago
parent
commit
629cc9f0a9
  1. 7
      actions/killALL.js
  2. 41
      actions/killAllConfirm.js
  3. 1
      index.js
  4. 4
      utils/isFQDN.js

7
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;

41
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;

1
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 " +

4
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('#'));

Loading…
Cancel
Save