From f7ea225cacb1de72c9a781d7cca8c990fd783400 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 1 Aug 2021 19:45:26 +0300 Subject: [PATCH] Create file.js --- scripts/helpers/file.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 scripts/helpers/file.js diff --git a/scripts/helpers/file.js b/scripts/helpers/file.js new file mode 100644 index 000000000..8b1f96c5d --- /dev/null +++ b/scripts/helpers/file.js @@ -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