.bin/cache-bust
#!/usr/bin/env node
/**
* Cachebust the openapi.json file powering the static html page
*
* Adds a version query string variable to the deployed static html index file
* and, in doing so, ensures that the latest version will be loaded (instead of a
* possibly outdated cached version).
*
* @since [version]
* @version [version]
*/
const
fs = require( 'fs' ),
file = `${ process.cwd() }/web_deploy/index.html`,
html = fs.readFileSync( `${ process.cwd() }/web_deploy/index.html` ).toString(),
mtime = fs.statSync( `${ process.cwd() }/web_deploy/openapi.json`, { bigint: true } ).mtimeMs;
fs.writeFileSync( file, html.replace( `'./openapi.json'`, `'./openapi.json?v=${ mtime }'` ) );