Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Coffeescript, Clean Deployment Script #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 0 additions & 65 deletions deploy.coffee

This file was deleted.

69 changes: 69 additions & 0 deletions deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
//# Basic Deploy: Upload everything in /dist straight to S3

// Configuration Constants
const AWS_PROFILE = "docs-deployer"; // references ~/.aws/credentials
const TARGET_BUCKET = 'docs.paperize.io'; // S3 bucket name
const CLOUDFRONT_DISTRIBUTION_ID = "E1G7A2XX5SSZTS";
const DIRECTORY_TO_DEPLOY = "dist"; // local directory containing static files

// Utils
const _ = require("lodash");

// Setup AWS
process.env.AWS_PROFILE = AWS_PROFILE;
const AWS = require("aws-sdk");
const s3 = new AWS.S3();
const cloudfront = new AWS.CloudFront();

// Filesystem stuff
const mimeTypes = require("mime-types");
const Promise = require("bluebird");
const fs = Promise.promisifyAll(require("fs"));
const recursiveReaddir = require("recursive-readdir");

// For all files in deploy dir
recursiveReaddir(`./${DIRECTORY_TO_DEPLOY}`).then(function(files) {
const itemCount = files.length;
// Strip the deploy dir from the path
files = files.map(file => file.replace(`${DIRECTORY_TO_DEPLOY}/`, ""));
// Start uploading in parallel
console.log(`Uploading ${itemCount} files...`);
return Promise.map(files, uploadFileToS3, {concurrency: 10})

.then(function() {
console.log("Invalidating CloudFront cache...");
return cloudfront.createInvalidation({
DistributionId: CLOUDFRONT_DISTRIBUTION_ID,
InvalidationBatch: {
CallerReference: String(Date.now()),
Paths: {
Quantity: 1,
Items: [ '/*' ]
}
}})
.promise();}).then(() => console.log("Done."));
});

var uploadFileToS3 = function(file) {
const mimeType = mimeTypes.lookup(file) || 'application/octet-stream';

return s3.putObject({
Bucket: TARGET_BUCKET,
Key: file,
Body: fs.createReadStream(`./${DIRECTORY_TO_DEPLOY}/${file}`),
ACL: 'public-read',
ContentDisposition: 'inline',
ContentType: mimeType

}).promise()

.then(() => console.log(`Uploaded ${file}, ${mimeType}`)).catch(function(error) {
console.log(error);
throw error;
});
};
20 changes: 0 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "npx gridsome build",
"develop": "npx gridsome develop",
"explore": "npx gridsome explore",
"deploy": "npx coffee deploy.coffee",
"deploy": "node deploy.js",
"bump-prod": "npm run build && npm run deploy"
},
"dependencies": {
Expand All @@ -19,7 +19,6 @@
"devDependencies": {
"aws-sdk": "^2.814.0",
"bluebird": "^3.7.2",
"coffeescript": "^2.5.0",
"core-js": "3.8.1",
"eslint": "^4.18.1",
"eslint-plugin-vue": "^4.3.0",
Expand Down