Skip to content

Commit 9c2729e

Browse files
committed
simplify deploy scripts
1 parent 241bc59 commit 9c2729e

File tree

4 files changed

+17
-23
lines changed

4 files changed

+17
-23
lines changed

scripts/clear-cloudfront-cache.js

100644100755
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
const {
1+
#!/usr/bin/env node
2+
'use strict'
3+
4+
import {
25
CloudFrontClient,
36
CreateInvalidationCommand
4-
} = require('@aws-sdk/client-cloudfront')
7+
} from '@aws-sdk/client-cloudfront'
58

6-
module.exports = async function () {
9+
async function clearCloudfrontCache() {
710
const {
811
CLOUDFRONT_DISTRIBUTION_ID,
912
CONTEXT,
@@ -47,3 +50,5 @@ module.exports = async function () {
4750
`Cleared CloudFront cache successfully: ${response.Invalidation.Id}`
4851
)
4952
}
53+
54+
await clearCloudfrontCache()

scripts/deploy-with-s3.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@
22
'use strict'
33

44
require('dotenv').config()
5-
const { rm, rename } = require('node:fs/promises')
65
const { exit } = require('node:process')
76
const path = require('path')
87

9-
const { s3Prefix } = require('../src/server/config')
10-
11-
const clearCloudfrontCache = require('./clear-cloudfront-cache')
12-
const { uploadToS3 } = require('./s3-utils')
13-
14-
const rootDir = process.cwd()
15-
const publicDir = path.join(rootDir, 'public')
16-
const cacheDir = path.join(rootDir, '.cache')
8+
const { uploadToS3, s3Prefix } = require('./s3-utils')
179

1810
/**
1911
* Deploy public/ to s3.
@@ -31,16 +23,9 @@ const cacheDir = path.join(rootDir, '.cache')
3123
* - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY: auth token to access the bucket.
3224
* - HEROKU_APP_NAME: (optional) app name to specify the ID of the PR if any.
3325
**/
34-
async function main() {
35-
await uploadToS3(publicDir, '/', s3Prefix)
36-
// Move the 404 HTML file from public into the root dir for Heroku
37-
await rename(path.join(publicDir, '404.html'), '404.html')
38-
// await rm(publicDir, { recursive: true, force: true })
39-
await rm(cacheDir, { recursive: true, force: true })
40-
await clearCloudfrontCache()
41-
}
42-
43-
main().catch(e => {
26+
const rootDir = process.cwd()
27+
const publicDir = path.join(rootDir, 'public')
28+
uploadToS3(publicDir, '/', s3Prefix).catch(e => {
4429
console.error(e)
4530
exit(1)
4631
})

scripts/heroku-deploy.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ mv $OLDPWD $NEWPWD
77
ln -s $NEWPWD $OLDPWD
88
cd $NEWPWD
99
yarn build
10+
rm -rf static .cache
1011
./scripts/deploy-with-s3.js
11-
rm -rf static
12+
# Move the 404 HTML file from public into the root dir for Heroku
13+
mv public/404.html 404.html
14+
./scripts/clear-cloudfront-cache.js

scripts/s3-utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ async function uploadToS3(dir, childPrefix, basePrefix = s3Prefix) {
4646
}
4747

4848
module.exports = {
49+
s3Prefix,
4950
uploadToS3
5051
}

0 commit comments

Comments
 (0)