Hi @realCyberJunkie,
Deploys on Netlify can’t be deleted, unless you delete the site of course.
You can try this code:
const FS = require('fs')
const Chalk = require('chalk')
const Fetch = require('node-fetch')
const Inquirer = require('inquirer')
const NetlifyAPI = require('netlify')
const ByteSize = require('byte-size')
const Pluralize = require('pluralize')
const authToken = 'token'
const netlifyAuth = new NetlifyAPI(authToken)
const byteSizeOptions = {
units: 'iec',
precision: 2
}
netlifyAuth.listSites().then(sites => {
console.log(Chalk.yellow('Fetching all websites...'))
const siteList = []
sites.forEach(site => {
siteList.push({
value: site.id,
name: site.name
})
})
Inquirer.prompt([{
loop: false,
name: 'site',
type: 'list',
pageSize: 10,
choices: siteList,
message: 'Choose a website:'
}]).then(answer => {
const siteName = siteList.filter(site => {
return site.value === answer.site
})
netlifyAuth.listSiteDeploys({
site_id: answer.site
}).then(deploys => {
console.log(Chalk.yellow('Fetching all successful deploys for the selected website...'))
const deploysList = []
deploys.forEach(deploy => {
if (deploy.state != 'error' && !deploy.skipped) {
deploysList.push({
value: deploy.id,
name: deploy.title
})
}
})
Inquirer.prompt([{
loop: false,
type: 'list',
pageSize: 10,
name: 'deploy',
choices: deploysList,
message: 'Choose a deploy:'
}]).then(answer => {
console.log(Chalk.yellow('Fetching all files for the selected deploy...'))
const deployID = answer.deploy
Fetch(`https://api.netlify.com/api/v1/deploys/${deployID}/files`, {
headers: {
Authorization: `Bearer ${authToken}`
}
}).then(response => response.json()).then(files => {
let deploySize = 0
const downloadableFiles = []
let baseMarkup = `<!doctype html><html lang=en><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1.0"><title>Deploy details for #${deployID}</title><style>*{font-family:sans-serif}table{border:1px solid black}table *{padding:5px}td:first-child,td:last-child{text-align:right}th:nth-child(2),td:nth-child(2){border:1px solid black;border-top:0;border-bottom:0}</style></head><body><p>View the <a href="https://app.netlify.com/sites/${siteName[0].name}/deploys/${deployID}/" target="_blank" rel="nofollow noopener noreferrer">deploy log</a>.</p><table><thead><tr><th>#</th><th>Path</th><th>Size</th></tr></thead><tbody>`
files.forEach(file => {
if (file.path != ('/netlify.toml' || '/_redirects' || '/_headers')) {
downloadableFiles.push(file)
}
})
downloadableFiles.forEach((file, index) => {
deploySize += file.size
baseMarkup += `<tr><td>${index + 1}</td><td><a href="https://${deployID}--${siteName[0].name}.netlify.app${file.path}" target="_blank" rel="nofollow noopener noreferrer">${file.path}</a></td><td>${ByteSize(file.size, byteSizeOptions)}</td></tr>`
})
baseMarkup += `</tbody></table><p>The deploy contains ${Pluralize('files', downloadableFiles.length, true)} amounting to ~${ByteSize(deploySize, byteSizeOptions)}</p></body></html>`
FS.writeFileSync('./index.html', baseMarkup)
console.log(Chalk.green('File list saved as ./index.html.'))
Inquirer.prompt([{
type: 'confirm',
name: 'confirm',
message: `Are you sure you wish to download the deploy? ${Chalk.red(`It will cost you ~${ByteSize(deploySize, byteSizeOptions)} of your Netlify bandwidth!`)}`
}]).then(answer => {
if (answer.confirm) {
const downloadList = FS.createWriteStream('./files.txt')
downloadableFiles.forEach(file => {
downloadList.write(`https://${deployID}--${siteName[0].name}.netlify.app${file.path}\n\tdir=./download${file.path.substring(0, file.path.lastIndexOf('/') + 1).slice(0, -1)}\n`)
})
downloadList.end()
} else {
console.log(Chalk.green('Okay. Exiting...'))
}
})
})
})
})
})
})
You’d have to use aria2c
to download the files: https://aria2.github.io. The files.txt
file that gets generated is the one that you can ask aria2c
to download. I had tried to integrate that tool in this code, but that never worked (it worked on Windows, not on macOS or Linux). So, I dropped the plan, but I believe this would still be useful for you.
You need to run npm i byte-size chalk inquirer netlify node-fetch pluralize
to install all the required dependencies.
In this, you only need to add your API key, rest would be done by the code itself.