Created
April 11, 2019 18:34
-
-
Save andreybleme/9ab361cdbda4d5c30f72198fa6d2a5d4 to your computer and use it in GitHub Desktop.
andreybleme.com | Criando uma CLI para fazer deploy de sites estáticos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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