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. 39
      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 // 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;

39
actions/killAllConfirm.js

@ -1,36 +1,19 @@
'use strict'; 'use strict';
const { EOL } = require('os'); const readline = require('readline');
const killALL = require('./killALL').kill;
const noKill = require('./killALL').noKill;
const prompt = require('prompt'); function killAllConfirm() {
const shell = require('shelljs'); 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 () { line().then(line => {
// Start the prompt line.trim();
if((/^(y(es)?|n(o)?)$/).test(line)) {
prompt.start(); line == "y" || "yes" ? killALL() : noKill();
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.");
} }
}); });
} }

1
index.js

@ -90,6 +90,7 @@ program
.command('kill-all') .command('kill-all')
.description('Warning! Will completely kill all servers and reset nginx') .description('Warning! Will completely kill all servers and reset nginx')
.action(function() { .action(function() {
//new Promise(resolve => killed\killAllConfirm();
killAllConfirm(); killAllConfirm();
console.log(EOL + [ console.log(EOL + [
"A backup of your old servers.up is " + "A backup of your old servers.up is " +

4
utils/isFQDN.js

@ -4,6 +4,7 @@
'use strict'; 'use strict';
const fs = require('fs-extra'); const fs = require('fs-extra');
const path = require('path');
// Official list of TLDs should be fetched from: // Official list of TLDs should be fetched from:
// https://data.iana.org/TLD/tlds-alpha-by-domain.txt // https://data.iana.org/TLD/tlds-alpha-by-domain.txt
@ -14,7 +15,8 @@ const fs = require('fs-extra');
function isFQDN(domain) { function isFQDN(domain) {
// Importing and parsing `tlds.txt` file // 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]+/) .split(/[\r\n]+/)
.filter(x => !x.startsWith('#')); .filter(x => !x.startsWith('#'));

Loading…
Cancel
Save