iptv/scripts/helpers/file.js

39 lines
864 B
JavaScript
Raw Normal View History

2021-08-01 19:42:04 +02:00
const markdownInclude = require('markdown-include')
2021-08-01 18:45:26 +02:00
const path = require('path')
2021-08-01 19:42:04 +02:00
const fs = require('fs')
2021-08-01 18:45:26 +02:00
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)
}
2021-08-01 19:42:04 +02:00
file.compileMarkdown = function (filename) {
markdownInclude.compileFiles(rootPath + filename)
2021-08-01 18:45:26 +02:00
}
module.exports = file