UNPKG

site-validator-cli

Version:

A command line tool that takes a URL or a file, then uses html-validator (a wrapper for https://validator.w3.org/nu/) to validate each page.

28 lines (25 loc) 814 B
'use strict' const fs = require('fs') const path = require('path') module.exports = (subfolder) => { var cachePath = path.resolve(`${__dirname}/../cache/${subfolder}`) // consulted SharpCoder's answer at // https://stackoverflow.com/questions/18052762/remove-directory-which-is-not-empty const deleteFolderRecursive = function (path) { if (fs.existsSync(path)) { fs.readdirSync(path).forEach(function (file, index) { const curPath = path + '/' + file if (fs.lstatSync(curPath).isDirectory()) { // recurse deleteFolderRecursive(curPath) } else { // delete file fs.unlinkSync(curPath) } }) if (path !== cachePath) { fs.rmdirSync(path) } } } deleteFolderRecursive(cachePath) console.log('\nCache cleared!') }