Skip to content

Instantly share code, notes, and snippets.

@andreybleme
Created April 11, 2019 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreybleme/9ab361cdbda4d5c30f72198fa6d2a5d4 to your computer and use it in GitHub Desktop.
Save andreybleme/9ab361cdbda4d5c30f72198fa6d2a5d4 to your computer and use it in GitHub Desktop.
andreybleme.com | Criando uma CLI para fazer deploy de sites estáticos
#!/usr/bin/env node
const program = require('commander')
const s3Services = require('./app/s3Services')
const awsCredentials = {
region: 'us-east-1',
accessKeyId: '',
secretAccessKey: ''
}
const bucketParams = {
Bucket : ''
}
const staticHostParams = {
Bucket: '',
WebsiteConfiguration: {
ErrorDocument: {
Key: 'error.html'
},
IndexDocument: {
Suffix: 'index.html'
},
}
}
program
.command('create')
.option('-b, --bucket <s>', 'Bucket name', setBucket)
.option('-k, --key <s>', 'AWS Key', setKey)
.option('-s, --secret <s>', 'AWS Secret', setSecret)
.action(function () {
s3Services.setAwsCredentials(awsCredentials)
staticHostParams.Bucket = bucketParams.Bucket
s3Services.createBucket(bucketParams, staticHostParams)
})
// comando deploy
function setKey(val) {
awsCredentials.accessKeyId = val
}
function setSecret(val) {
awsCredentials.secretAccessKey = val
}
function setBucket(val) {
bucketParams.Bucket = val
}
program.parse(process.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment