Create file.js

This commit is contained in:
Aleksandr Statciuk 2021-08-01 19:45:26 +03:00
parent 6f21d0d167
commit f7ea225cac

37
scripts/helpers/file.js Normal file
View File

@ -0,0 +1,37 @@
const fs = require('fs')
const path = require('path')
const rootPath = path.resolve(__dirname) + '/../../'
const file = {}
file.getBasename = function (filename) {
return path.basename(filename, path.extname(filename))
}
file.getFilename = function (filename) {
return path.parse(filename).name
}
file.createDir = function (dir) {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir)
}
}
file.read = function (filename) {
return fs.readFileSync(rootPath + filename, { encoding: 'utf8' })
}
file.append = function (filename, data) {
fs.appendFileSync(rootPath + filename, data)
}
file.create = function (filename, data = '') {
fs.writeFileSync(rootPath + filename, data)
}
file.compileMarkdown = function (filepath) {
return markdownInclude.compileFiles(path.resolve(__dirname, filepath))
}
module.exports = file