@ -16,6 +16,7 @@ const toHost = require('../lib/to-host')
const { reAlias } = require ( '../lib/re-alias' )
const exit = require ( '../lib/utils/exit' )
const logo = require ( '../lib/utils/output/logo' )
const promptBool = require ( '../lib/utils/input/prompt-bool' )
const argv = minimist ( process . argv . slice ( 2 ) , {
string : [ 'config' , 'token' , 'rules' ] ,
@ -223,8 +224,8 @@ async function run(token) {
}
try {
const confirmation = ( await readConfirmation ( alias , _ alias , _ aliases ) ) . toLowerCase ( )
if ( confirmation !== 'y' && confirmation !== 'yes' ) {
const confirmation = await confirmDeploymentRemoval ( alias , _ alias )
if ( ! confirmation ) {
console . log ( '\n> Aborted' )
process . exit ( 0 )
}
@ -278,27 +279,20 @@ async function run(token) {
alias . close ( )
}
async function readConfirmation ( alias , _ alias ) {
async function confirmDeploymentRemoval ( alias , _ alias ) {
const deploymentsList = await alias . list ( )
const urls = new Map ( deploymentsList . map ( l => [ l . uid , l . url ] ) )
return new Promise ( resolve => {
const time = chalk . gray ( ms ( new Date ( ) - new Date ( _ alias . created ) ) + ' ago' )
const _ sourceUrl = chalk . underline ( ` https:// ${ urls . get ( _ alias . deploymentId ) } ` )
const tbl = table (
[ [ _ alias . uid , _ sourceUrl , chalk . underline ( ` https:// ${ _ alias . alias } ` ) , time ] ] ,
{ align : [ 'l' , 'r' , 'l' ] , hsep : ' ' . repeat ( 6 ) }
)
process . stdout . write ( '> The following alias will be removed permanently\n' )
process . stdout . write ( ' ' + tbl + '\n' )
process . stdout . write ( ` ${ chalk . bold . red ( '> Are you sure?' ) } ${ chalk . gray ( '[y/N] ' ) } ` )
process . stdin . on ( 'data' , d => {
process . stdin . pause ( )
resolve ( d . toString ( ) . trim ( ) )
} ) . resume ( )
} )
const time = chalk . gray ( ms ( new Date ( ) - new Date ( _ alias . created ) ) + ' ago' )
const _ sourceUrl = chalk . underline ( ` https:// ${ urls . get ( _ alias . deploymentId ) } ` )
const tbl = table (
[ [ _ alias . uid , _ sourceUrl , chalk . underline ( ` https:// ${ _ alias . alias } ` ) , time ] ] ,
{ align : [ 'l' , 'r' , 'l' ] , hsep : ' ' . repeat ( 6 ) }
)
const msg = '> The following alias will be removed permanently\n' +
` ${ tbl } \n Are you sure? `
return await promptBool ( msg )
}
function findAlias ( alias , list ) {
@ -341,7 +335,11 @@ async function updatePathAlias(alias, aliasName, rules) {
const start = new Date ( )
const res = await alias . updatePathBasedroutes ( String ( aliasName ) , rules )
const elapsed = ms ( new Date ( ) - start )
if ( ! res . error ) {
if ( res . error ) {
const err = new Error ( res . error . message )
err . userError = true
throw err
} else {
console . log ( ` ${ chalk . cyan ( '> Success!' ) } ${ res . ruleCount } rules configured for ${ chalk . underline ( res . alias ) } [ ${ elapsed } ] ` )
}
}