Skip to content

Instantly share code, notes, and snippets.

@andreybleme
Created April 11, 2019 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreybleme/6e25ad8c2b10595022f7492ba6999771 to your computer and use it in GitHub Desktop.
Save andreybleme/6e25ad8c2b10595022f7492ba6999771 to your computer and use it in GitHub Desktop.
andreybleme.com | Criando uma CLI para fazer deploy de sites estáticos
const fs = require('fs')
const path = require('path')
const mime = require('mime')
function getAllFilesFrom(currentDirPath, callback) {
fs.readdirSync(currentDirPath).forEach(function (name) {
const filePath = path.join(currentDirPath, name)
const stat = fs.statSync(filePath)
if (stat.isFile()) {
fs.readFile(filePath, function (err, data) {
if (err) {
throw err
}
callback(filePath, data)
})
} else if (stat.isDirectory()) {
getAllFilesFrom(filePath, callback)
}
});
}
function getMimeType(filePath) {
return mime.getType(filePath)
}
module.exports = {
getAllFilesFrom,
getMimeType
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment