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

Commit

Permalink
Add force flag
Browse files Browse the repository at this point in the history
  • Loading branch information
stojanovic committed Aug 17, 2017
1 parent d7d584c commit 01c23ff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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 "eu-central-1" region without asking

### Examples

Expand Down
23 changes: 18 additions & 5 deletions bin/scotty.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ function showHelp() {
${colors.magenta('--help')} ${colors.cyan('or')} ${colors.magenta('-h')} Print this help
${colors.magenta('--version')} ${colors.cyan('or')} ${colors.magenta('-v')} Print the current version
${colors.magenta('--quiet')} ${colors.cyan('or')} ${colors.magenta('-q')} Suppress output when executing commands
${colors.magenta('--quiet')} ${colors.cyan('or')} ${colors.magenta('-q')} Suppress output when executing commands ${colors.cyan('| default: false')}
${colors.magenta('--website')} ${colors.cyan('or')} ${colors.magenta('-w')} Set uploaded folder as a static website ${colors.cyan('| default: false')}
${colors.magenta('--spa')} Set uploaded folder as a single page app and redirect all non-existing pages to index.html ${colors.cyan('| default: false')}
${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 "eu-central-1" region without asking ${colors.cyan('| default: false')}
✤ ✤ ✤
Expand All @@ -72,9 +73,18 @@ function showHelp() {

function readArgs() {
return minimist(process.argv.slice(2), {
alias: { h: 'help', v: 'version', q: 'quiet', w: 'website', s: 'source', b: 'bucket', r: 'region' },
alias: {
h: 'help',
v: 'version',
q: 'quiet',
w: 'website',
s: 'source',
b: 'bucket',
r: 'region',
f: 'force'
},
string: ['source', 'bucket', 'region'],
boolean: ['quiet', 'website', 'spa'],
boolean: ['quiet', 'website', 'spa', 'force'],
default: {
source: process.cwd(),
bucket: path.parse(process.cwd()).name
Expand Down Expand Up @@ -114,6 +124,9 @@ function cmd(console) {
if (!AWS.config.region)
return getDefaultRegion()
.catch(() => {
if (args.force)
return saveDefaultRegion('eu-central-1')

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

return scotty(args.source, args.bucket, AWS.config.region, args.website, args.spa, args.quiet, console)
return scotty(args.source, args.bucket, AWS.config.region, args.website, args.spa, args.force, args.quiet, console)
.then(() => process.exit(1))
.catch(() => process.exit(1))
}
Expand Down
8 changes: 6 additions & 2 deletions lib/scotty.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const setCdn = require('./set-cdn')

let time = new Date()

function scotty(source, bucket, region, website, spa, quiet, logger) {
function scotty(source, bucket, region, website, spa, force, quiet, logger) {
if (!source || !bucket || !region)
return Promise.reject('Source, bucket and region are required')

Expand All @@ -25,8 +25,12 @@ function scotty(source, bucket, region, website, spa, quiet, logger) {
return bucket
})
.catch(err => {
if (err.code === 'BucketAlreadyOwnedByYou')
if (err.code === 'BucketAlreadyOwnedByYou') {
if (force)
return bucket

return reuseBucket(bucket)
}

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.'
Expand Down

0 comments on commit 01c23ff

Please sign in to comment.