Created
April 11, 2019 19:43
-
-
Save andreybleme/195ab8db57761631e2ccd82e669176d9 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 filesystem = require('./app/filesystem') | |
const awsCredentials = { | |
region: 'us-east-1', | |
accessKeyId: '', | |
secretAccessKey: '' | |
} | |
const bucketParams = { | |
Bucket : '' | |
} | |
const staticHostParams = { | |
Bucket: '', | |
WebsiteConfiguration: { | |
ErrorDocument: { | |
Key: 'error.html' | |
}, | |
IndexDocument: { | |
Suffix: 'index.html' | |
}, | |
} | |
} | |
// comando create | |
program | |
.command('deploy') | |
.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) | |
filesystem.getAllFilesFrom('.', function (filePath, data) { | |
s3Services.uploadObject(bucketParams.Bucket, filePath, data) | |
}) | |
}); | |
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