I have a build script that uses the Dropbox SDK to download a ZIP file, then using AdmZip to extract it into the Node file system. It works great on local, but on Netlify it seems to only work the first time, then after that I suspect some caching is getting in the way and it seems to only extract the old ZIP file. If I make a change to a file in Dropbox, and re-deploy it won’t have the new file in the deploy.
Code:
// Init Dropbox SDK
const dbx = new Dropbox({
accessToken: process.env.DBX_ACCESS_TOKEN,
})
// Clean up any directory we made previously
const DIST_PATH = path.resolve(__dirname, "../dist")
const DECK_PATH = path.resolve(__dirname, `..${process.env.DBX_PATH}`)
fs.removeSync(DIST_PATH)
fs.removeSync(DECK_PATH)
// Download ZIP file of folder from Dropbox, and extract everything
dbx.filesDownloadZip({ path: process.env.DBX_PATH })
.then((response) => {
// Download dropbox folder as ZIP, unzip
console.log("Recieved ZIP from Dropbox:", response.result.metadata.name)
var zip = new AdmZip(response.result.fileBinary)
zip.extractAllTo("./", true)
// Rename folder now
fs.renameSync(DECK_PATH, DIST_PATH)
// Logout file count
console.log("Added following folders:")
fs.readdirSync(DIST_PATH).forEach((file, index) => {
console.log("[" + index + "] " + file)
})
// Copy templates to dist for things like admin and robots.txt
// This does not overwrite files, so the user can have a custom root index file for example
fs.copySync("./src/templates", DIST_PATH, {
overwrite: false,
})
})
.catch((error) => {
console.error(error)
})