Created
April 11, 2019 19:22
-
-
Save andreybleme/6e25ad8c2b10595022f7492ba6999771 to your computer and use it in GitHub Desktop.
andreybleme.com | Criando uma CLI para fazer deploy de sites estáticos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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