Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Commit

Permalink
fix: better error if aws-sdk is missing (#43)
Browse files Browse the repository at this point in the history
Fixes #42
  • Loading branch information
jdx committed Jun 16, 2018
1 parent 9234291 commit 3694551
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/aws.ts
Expand Up @@ -28,7 +28,14 @@ const aws = {
if (!creds.secretAccessKey) throw new Error('AWS_SECRET_ACCESS_KEY not set')
return creds
},
get s3() { return cache.s3 = cache.s3 || new (require('aws-sdk/clients/s3') as typeof S3)(this.creds) },
get s3() {
try {
return cache.s3 = cache.s3 || new (require('aws-sdk/clients/s3') as typeof S3)(this.creds)
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') throw new Error(`${err.message}\naws-sdk is needed to run this command.\nInstall aws-sdk as a devDependency in your CLI. \`yarn add -D aws-sdk\``)
throw err
}
},
get cloudfront() { return cache.cloudfront = cache.cloudfront || new (require('aws-sdk/clients/cloudfront') as typeof CloudFront)(this.creds) },
}

Expand Down
5 changes: 4 additions & 1 deletion src/commands/publish/index.ts
Expand Up @@ -7,7 +7,10 @@ import {log} from '../../log'
import * as Tarballs from '../../tarballs'

export default class Publish extends Command {
static description = 'publish an oclif CLI to S3'
static description = `publish an oclif CLI to S3
"aws-sdk" will need to be installed as a devDependency to publish.
`

static flags = {
root: flags.string({char: 'r', description: 'path to oclif CLI root', default: '.', required: true}),
Expand Down

0 comments on commit 3694551

Please sign in to comment.