@gauntface/cli
Advanced tools
Comparing version 0.0.8 to 0.1.0
@@ -13,5 +13,6 @@ const spawn = require('child_process').spawn; | ||
.version('0.0.1') | ||
.option('--delete_exclude <type>', 'Directories to exclude in the sync') | ||
.requiredOption('--directory <type>', 'Directory of the site to upload') | ||
.requiredOption('--bucket_name <type>', 'The name of the bucket to upload to'); | ||
program.parse(process.argv); | ||
@@ -23,9 +24,10 @@ | ||
const bucketName = opts['bucket_name']; | ||
const deleteExclude = opts['delete_exclude']; | ||
logMetadata(directory, bucketName); | ||
logMetadata(directory, deleteExclude, bucketName); | ||
await publishToS3Bucket(directory, bucketName); | ||
await publishToS3Bucket(directory, deleteExclude, bucketName); | ||
} | ||
function logMetadata(directory, bucketName) { | ||
function logMetadata(directory, deleteExclude, bucketName) { | ||
console.log(` | ||
@@ -36,2 +38,3 @@ | ||
📂 Directory: ${directory} | ||
📂 Delete Exclude: ${deleteExclude} | ||
🗑️ Bucket: ${bucketName} | ||
@@ -42,7 +45,7 @@ | ||
async function publishToS3Bucket(dir, bucketName) { | ||
async function publishToS3Bucket(dir, deleteExclude, bucketName) { | ||
const s3Bucket = `s3://${bucketName}/`; | ||
const shortTermCacheExt = ['html', 'xml', 'json', 'svg']; | ||
const longTermCacheExt = ['css', 'js', 'png', 'jpg', 'jpeg', 'gif', 'webp', 'woff', 'woff2', 'mp3', 'pdf']; | ||
const longTermCacheExt = ['css', 'js', 'png', 'jpg', 'jpeg', 'gif', 'webp', 'avif', 'woff', 'woff2', 'mp3', 'pdf']; | ||
const deleteExt = shortTermCacheExt.concat(longTermCacheExt); | ||
@@ -57,3 +60,3 @@ const steps = [ | ||
// Delete any files we no longer need | ||
makeSyncDelete(dir, s3Bucket, deleteExt), | ||
makeSyncDelete(dir, deleteExclude, s3Bucket, deleteExt), | ||
]; | ||
@@ -81,8 +84,8 @@ | ||
function makeSyncDelete(dir, s3Bucket, extensions) { | ||
function makeSyncDelete(dir, deleteExclude, s3Bucket, extensions) { | ||
const parts = [ | ||
`aws s3 sync ${dir} ${s3Bucket}`, | ||
'--delete', | ||
'--exclude', '*', | ||
] | ||
for (const e of extensions) { | ||
@@ -92,2 +95,9 @@ parts.push(`--include`, `*.${e}`) | ||
// Exclude at the end to ensure the generated files are excluded | ||
if (deleteExclude) { | ||
parts.push('--exclude', deleteExclude) | ||
} else { | ||
parts.push('--exclude', '*') | ||
} | ||
return parts.join(" ") | ||
@@ -103,11 +113,11 @@ } | ||
const cmdProcess = spawn(cmdPieces[0], cmdPieces.splice(1)) | ||
cmdProcess.stdout.on('data', function (data) { | ||
console.log(`${data}`); | ||
}); | ||
cmdProcess.stderr.on('data', function (data) { | ||
console.error(`${data}`); | ||
}); | ||
cmdProcess.on('close', function (code) { | ||
@@ -114,0 +124,0 @@ if (code != 0) { |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "0.0.8", | ||
"version": "0.1.0", | ||
"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
15912
109