diff --git a/deploy.coffee b/deploy.coffee deleted file mode 100644 index dd177de..0000000 --- a/deploy.coffee +++ /dev/null @@ -1,65 +0,0 @@ -## Basic Deploy: Upload everything in /dist straight to S3 - -# Configuration Constants -AWS_PROFILE = "docs-deployer" # references ~/.aws/credentials -TARGET_BUCKET = 'docs.paperize.io' # S3 bucket name -CLOUDFRONT_DISTRIBUTION_ID = "E1G7A2XX5SSZTS" -DIRECTORY_TO_DEPLOY = "dist" # local directory containing static files - -# Utils -_ = require("lodash") - -# Setup AWS -process.env.AWS_PROFILE = AWS_PROFILE -AWS = require("aws-sdk") -s3 = new AWS.S3() -cloudfront = new AWS.CloudFront() - -# Filesystem stuff -mimeTypes = require("mime-types") -Promise = require("bluebird") -fs = Promise.promisifyAll(require("fs")) -recursiveReaddir = require("recursive-readdir") - -# For all files in deploy dir -recursiveReaddir("./#{DIRECTORY_TO_DEPLOY}").then (files) -> - 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...") - Promise.map files, uploadFileToS3, concurrency: 10 - - .then -> - console.log("Invalidating CloudFront cache...") - cloudfront.createInvalidation - DistributionId: CLOUDFRONT_DISTRIBUTION_ID - InvalidationBatch: - CallerReference: String(Date.now()) - Paths: - Quantity: 1 - Items: [ '/*' ] - .promise() - - .then -> - console.log("Done.") - -uploadFileToS3 = (file) -> - mimeType = mimeTypes.lookup(file) || 'application/octet-stream' - - 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 (error) -> - console.log(error) - throw error diff --git a/deploy.js b/deploy.js new file mode 100644 index 0000000..6404953 --- /dev/null +++ b/deploy.js @@ -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; + }); +}; diff --git a/package-lock.json b/package-lock.json index 7847eba..e39b1a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,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", @@ -5054,19 +5053,6 @@ "node": ">=0.10.0" } }, - "node_modules/coffeescript": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-2.5.0.tgz", - "integrity": "sha512-RgTKZhAeKVFuGtce/d3U1x1h5W75AoYFQszNlGrtSIbexC9jowaZo574uUvc9zoNQSDLMWXVtsus9usMtbFU+w==", - "dev": true, - "bin": { - "cake": "bin/cake", - "coffee": "bin/coffee" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/collapse-white-space": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/collapse-white-space/-/collapse-white-space-1.0.6.tgz", @@ -21576,12 +21562,6 @@ "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", "integrity": "sha512-RpAVKQA5T63xEj6/giIbUEtZwJ4UFIc3ZtvEkiaUERylqe8xb5IvqcgOurZLahv93CLKfxcw5YI+DZcUBRyLXA==" }, - "coffeescript": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-2.5.0.tgz", - "integrity": "sha512-RgTKZhAeKVFuGtce/d3U1x1h5W75AoYFQszNlGrtSIbexC9jowaZo574uUvc9zoNQSDLMWXVtsus9usMtbFU+w==", - "dev": true - }, "collapse-white-space": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/collapse-white-space/-/collapse-white-space-1.0.6.tgz", diff --git a/package.json b/package.json index 8750949..e855cab 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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",