filesafe/scripts/delete-expired.js
Bobby Wibowo 8ab77a6464
Updated
Removed version strings from _globals.njk,
in favor of src/versions.json.
That versions in that file can be bumped with "yarn bump-versions".
v1 is automatically bumped when doing "yarn build" as well.

Added README file in src directory, explaining versions.json file.

Added README file in scripts directory, detailing usage of each scripts.

Version strings will no longer be appended when cacheControl is disabled
in config file.
After all, version strings are only needed when the static assets are
cached indefinitely in users' browsers.

Initial Cloudflare's cache purging will no longer be executed when
cloudflare -> purgeCache is disabled, even if cacheControl is enabled.
Just in case someone wants to use version strings for other use cases.

Actually use custom metaDesc variable on meta description tag.
2019-09-19 19:10:37 +07:00

45 lines
1.1 KiB
JavaScript

const utils = require('../controllers/utilsController')
const self = {
mode: null
}
;(async () => {
const location = process.argv[1].replace(process.cwd() + '/', '')
const args = process.argv.slice(2)
if (args.includes('--help') || args.includes('-h'))
return console.log(utils.stripIndents(`
Bulk delete expired files.
Usage:
node ${location} [mode=0|1|2]
mode:
0 = Only list names of the expired files.
1 = Delete expired files (output file names).
2 = Delete expired files (no output).
`))
self.mode = parseInt(args[0]) || 0
const dryrun = self.mode === 0
const quiet = self.mode === 2
const result = await utils.bulkDeleteExpired(dryrun)
if (quiet) return
if (result.expired.length)
for (const expired of result.expired)
console.log(expired)
console.log(`Expired files: ${result.expired.length}`)
if (result.failed)
console.log(`Failed to delete: ${result.failed.length}`)
})()
.then(() => process.exit(0))
.catch(error => {
console.error(error)
process.exit(1)
})