@gauntface/cli
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -42,11 +42,14 @@ const spawn = require('child_process').spawn; | ||
const shortTermCacheExt = ['html', 'xml', 'json', 'svg']; | ||
const longTermCacheExt = ['css', 'js', 'png', 'jpg', 'jpeg', 'gif', 'webp', 'woff', 'woff2', 'mp3']; | ||
const deleteExt = shortTermCacheExt.concat(longTermCacheExt); | ||
const steps = [ | ||
// Sync latest files with the s3 bucket | ||
`aws s3 sync ${dir} ${s3Bucket} --delete --acl public-read`, | ||
// Add cache headers for assets that do not have a hash | ||
makeCopyCmd(s3Bucket, 86400, ['html', 'xml', 'json', 'svg']), | ||
makeSyncCmd(dir, s3Bucket, 86400, shortTermCacheExt), | ||
// Add cache headers for assets that do have a hash | ||
makeCopyCmd(s3Bucket, 31104000, ['css', 'js', 'png', 'jpg', 'jpeg', 'gif', 'webp', 'woff', 'woff2', 'mp3']), | ||
makeSyncCmd(dir, s3Bucket, 31104000, longTermCacheExt), | ||
// Delete any files we no longer need | ||
makeSyncDelete(dir, s3Bucket, deleteExt), | ||
]; | ||
@@ -59,16 +62,13 @@ | ||
function makeCopyCmd(s3Bucket, maxAge, extensions) { | ||
function makeSyncCmd(dir, s3Bucket, maxAge, extensions) { | ||
const parts = [ | ||
`aws s3 cp ${s3Bucket} ${s3Bucket}`, | ||
'--exclude="*"', | ||
`aws s3 sync ${dir} ${s3Bucket}`, | ||
'--acl', 'public-read', | ||
'--exclude', '*', | ||
] | ||
for (const e of extensions) { | ||
parts.push(`--include="*.${e}"`) | ||
parts.push(`--include`, `*.${e}`) | ||
} | ||
// --cache-control Set cache control headers | ||
parts.push(`--cache-control 'max-age=${maxAge}'`); | ||
// --acl public-read Makes files accessible via web browser | ||
parts.push(`--acl public-read`); | ||
// --recursive Copy subdirectories and files | ||
parts.push(`--recursive`); | ||
@@ -78,2 +78,15 @@ return parts.join(" ") | ||
function makeSyncDelete(dir, s3Bucket, extensions) { | ||
const parts = [ | ||
`aws s3 sync ${dir} ${s3Bucket}`, | ||
'--delete', | ||
'--exclude', '*', | ||
] | ||
for (const e of extensions) { | ||
parts.push(`--include`, `*.${e}`) | ||
} | ||
return parts.join(" ") | ||
} | ||
async function runCmd(cmd) { | ||
@@ -80,0 +93,0 @@ console.log(`🤖 Running \`${cmd}\``); |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "A CLI tool to help with repetitive tasks.", | ||
@@ -9,0 +9,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15498
101