Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5 from stojanovic/fix/overriding-force-region
Browse files Browse the repository at this point in the history
Fix/overriding force region
  • Loading branch information
stojanovic authored Aug 18, 2017
2 parents 20d4060 + 53478aa commit 282e35c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ beam-me-up {options}
- _--source_ or _-s_ - Source of the folder that will be uploaded (default: current folder)
- _--bucket_ or _-b_ - Name of the S3 bucket (default: name of the current folder)
- _--region_ or _-r_ - AWS region where the files will be uploaded, default: saved region if exists or a list to choose one if it is not saved yet
- _--force_ or _-f_ - Update the bucket and pick "us-east-1" region without asking (default: false)
- _--force_ or _-f_ - Update the bucket without asking (default: false, forced region can be overridden with _-r_)
- _--update_ or _-u_ - Update existing bucket (default: false)

### Examples
Expand Down
20 changes: 13 additions & 7 deletions bin/scotty.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const AWS = require('aws-sdk')
const scotty = require('../index')
const inquirer = require('inquirer')
const colors = require('colors')
const clipboardy = require('clipboardy')

// Supported regions from http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
const AWS_REGIONS = [
Expand Down Expand Up @@ -48,7 +49,7 @@ function showHelp() {
${colors.magenta('--source')} ${colors.cyan('or')} ${colors.magenta('-s')} Source of the folder that will be uploaded ${colors.cyan('| default: current folder')}
${colors.magenta('--bucket')} ${colors.cyan('or')} ${colors.magenta('-b')} Name of the S3 bucket ${colors.cyan('| default: name of the current folder')}
${colors.magenta('--region')} ${colors.cyan('or')} ${colors.magenta('-r')} AWS region where the files will be uploaded ${colors.cyan('| default: saved region if exists or a list to choose one if it is not saved yet')}
${colors.magenta('--force')} ${colors.cyan('or')} ${colors.magenta('-f')} Update the bucket and pick "us-east-1" region without asking ${colors.cyan('| default: false')}
${colors.magenta('--force')} ${colors.cyan('or')} ${colors.magenta('-f')} Update the bucket without asking, region can be overridden with ${colors.magenta('-r')} ${colors.cyan('| default: false')}
${colors.magenta('--update')} ${colors.cyan('or')} ${colors.magenta('-u')} Update existing bucket ${colors.cyan('| default: false')}
✤ ✤ ✤
Expand Down Expand Up @@ -134,11 +135,11 @@ function cmd(console) {
if (!AWS.config.credentials)
return console.log(`Set AWS credentials first. Guide is available here: http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html`)

if (!AWS.config.region)
if (!args.region) {
return getDefaultRegion()
.catch(() => {
if (args.force)
return saveDefaultRegion('us-east-1')
return 'us-east-1'

return inquirer.prompt([{
type: 'list',
Expand All @@ -150,11 +151,16 @@ function cmd(console) {
.then(result => result.region)
.then(saveDefaultRegion)
})
.then(region => scotty(args.source, args.bucket, region, args.website, args.spa, args.update, args.force, args.quiet, console))
.then(() => process.exit(1))
.catch(() => process.exit(1))
.then(region => beamUp(args, region, console))
}

return scotty(args.source, args.bucket, AWS.config.region, args.website, args.spa, args.update, args.force, args.quiet, console)
return saveDefaultRegion(args.region)
.then(() => beamUp(args, args.region, console))
}

function beamUp (args, region, console) {
return scotty(args.source, args.bucket, region, args.website, args.spa, args.update, args.force, args.quiet, console)
.then(endpoint => clipboardy.write(endpoint))
.then(() => process.exit(1))
.catch(() => process.exit(1))
}
Expand Down
6 changes: 3 additions & 3 deletions lib/scotty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const colors = require('colors')
const getFolderSize = require('get-folder-size')
const clipboardy = require('clipboardy')

const createBucket = require('./create-bucket')
const reuseBucket = require('./reuse-bucket')
Expand Down Expand Up @@ -35,6 +34,8 @@ function createOrUpdateBucket(bucket, region, update, force, quiet, logger) {
if (err.code === 'BucketAlreadyExists')
err.message += '\n\nTry running the command with a new bucket name: \n scotty --bucket some-new-unique-name\n\nor change the name of your folder and re-run the same command.'

if (err.code === 'InvalidLocationConstraint')
err.message += '\n\nBucket already exists in a different region. Please change to: \n a) the correct region (using `-r region-name`) \n OR \n b) a different bucket name (using `-b bucket-name`)'
throw err
})
}
Expand Down Expand Up @@ -91,14 +92,13 @@ function scotty(source, bucket, region, website, spa, update, force, quiet, logg
.then(response => {
const cdnUrl = response && response.cdn ? response.url : null
const endpoint = website || spa ? `http://${bucket}.s3-website.${region}.amazonaws.com/` : `http://${bucket}.s3.amazonaws.com/`
clipboardy.writeSync(endpoint)

if (!quiet) {
logger.log('\nSuccessfully beamed up!'.magenta, colors.cyan(endpoint), '\nThis link should be copied to your clipboard now.'.magenta)
logger.log('\nCDN URL:'.magenta, colors.cyan(cdnUrl), '\nCloudFront is super slow, this link should be valid in next 10 minutes or so.'.magenta)
}

return true
return endpoint
})
.catch(err => {
if (!quiet)
Expand Down

0 comments on commit 282e35c

Please sign in to comment.