@ -18,6 +18,7 @@ const exit = require('../lib/utils/exit')
const logo = require ( '../lib/utils/output/logo' )
const info = require ( '../lib/scale-info' )
const sort = require ( '../lib/sort-deployments' )
const success = require ( '../lib/utils/output/success' )
const argv = minimist ( process . argv . slice ( 2 ) , {
string : [ 'config' , 'token' ] ,
@ -139,9 +140,12 @@ async function run({ token, config: { currentTeam } }) {
process . exit ( 0 )
} else if ( id && isHostNameOrId ( id ) ) {
// Normalize URL by removing slash from the end
if ( isURL ( id ) && id . slice ( - 1 ) === '/' ) {
if ( isURL ( id ) ) {
id = id . replace ( /^https:\/\//i , '' )
if ( id . slice ( - 1 ) === '/' ) {
id = id . slice ( 0 , - 1 )
}
}
} else {
error ( 'Please specify a deployment: now scale <id|url>' )
help ( )
@ -150,7 +154,7 @@ async function run({ token, config: { currentTeam } }) {
const deployments = await scale . list ( )
cons t match = deployments . find ( d => {
le t match = deployments . find ( d => {
// `url` should match the hostname of the deployment
let u = id . replace ( /^https:\/\//i , '' )
@ -158,14 +162,22 @@ async function run({ token, config: { currentTeam } }) {
// `.now.sh` domain is implied if just the subdomain is given
u += '.now.sh'
}
return d . uid === id || d . name === id || d . url === u
} )
if ( ! match ) {
// Maybe it's an alias
const aliasDeployment = ( await scale . listAliases ( ) ) . find (
e => e . alias === id
)
if ( ! aliasDeployment ) {
error ( ` Could not find any deployments matching ${ id } ` )
return process . exit ( 1 )
}
match = deployments . find ( d => {
return d . uid === aliasDeployment . deploymentId
} )
}
const { min , max } = guessParams ( )
@ -199,7 +211,8 @@ async function run({ token, config: { currentTeam } }) {
Number . isInteger ( max ) &&
currentCurrent <= max
) {
console . log ( ` > Done ` )
// Nothing to do, let's print the rules
printScaleingRules ( match . url , currentCurrent , min , max )
return
}
@ -221,19 +234,24 @@ async function run({ token, config: { currentTeam } }) {
const elapsed = ms ( new Date ( ) - start )
const currentReplicas = match . scale . current
printScaleingRules ( match . url , currentReplicas , newMin , newMax , elapsed )
await info ( scale , match . url )
scale . close ( )
}
function printScaleingRules ( url , currentReplicas , min , max , elapsed ) {
const log = console . log
log ( ` > ${ chalk . cyan ( 'Success!' ) } Configured scaling rules [ ${ elapsed } ] ` )
success (
` Configured scaling rules ${ chalk . gray ( elapsed ? '[' + elapsed + ']' : '' ) } `
)
log ( )
log (
` ${ chalk . bold ( match . url ) } ( ${ chalk . gray ( currentReplicas ) } ${ chalk . gray ( 'current' ) } ) `
` ${ chalk . bold ( url ) } ( ${ chalk . gray ( currentReplicas ) } ${ chalk . gray ( 'current' ) } ) `
)
log ( printf ( '%6s %s' , 'min' , chalk . bold ( newM in) ) )
log ( printf ( '%6s %s' , 'max' , chalk . bold ( newM ax) ) )
log ( printf ( '%6s %s' , 'auto' , chalk . bold ( newMin === newM ax ? '✖' : '✔' ) ) )
log ( printf ( '%6s %s' , 'min' , chalk . bold ( m in) ) )
log ( printf ( '%6s %s' , 'max' , chalk . bold ( m ax) ) )
log ( printf ( '%6s %s' , 'auto' , chalk . bold ( min === m ax ? '✖' : '✔' ) ) )
log ( )
await info ( scale , match . url )
scale . close ( )
}
async function list ( scale ) {