mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Classes to seperate module, eslint formatting
This commit is contained in:
parent
b2b0e862dd
commit
f30f4d4fc5
8 changed files with 468 additions and 413 deletions
|
@ -6,8 +6,7 @@ module.exports = {
|
|||
Beep: Beep,
|
||||
WriteBackup: WriteBackup,
|
||||
FileExists: FileExists,
|
||||
CreatePath: CreatePath,
|
||||
GetAllFilesFromFolder: GetAllFilesFromFolder
|
||||
CreatePath: CreatePath
|
||||
}
|
||||
|
||||
var fs = require('fs')
|
||||
|
@ -17,7 +16,7 @@ var logger = require('../utils/logger.js')
|
|||
const dataFile = './public/data.json'
|
||||
|
||||
function ReadFile (name) {
|
||||
if (!FileExists(name)) { throw 'No such file: ' + name }
|
||||
if (!FileExists(name)) { throw new Error('No such file: ' + name) }
|
||||
return fs.readFileSync(name, 'utf8')
|
||||
}
|
||||
|
||||
|
@ -31,14 +30,14 @@ function CreatePath (path, onlyPath) {
|
|||
var p = path.split('/')
|
||||
var currDir = p[0]
|
||||
for (var i = 1; i < p.length; i++) {
|
||||
if (currDir != '' && !fs.existsSync(currDir)) {
|
||||
if (currDir !== '' && !fs.existsSync(currDir)) {
|
||||
try {
|
||||
fs.mkdirSync(currDir)
|
||||
} catch (e) { console.log('Failed to make ' + currDir + ' directory... ') }
|
||||
}
|
||||
currDir += '/' + p[i]
|
||||
}
|
||||
if (onlyPath == undefined || onlyPath == false) { fs.writeFileSync(path, '') } else { fs.mkdirSync(path) }
|
||||
if (onlyPath === undefined || onlyPath === false) { fs.writeFileSync(path, '') } else { fs.mkdirSync(path) }
|
||||
}
|
||||
|
||||
function WriteFile (content, path) {
|
||||
|
@ -78,18 +77,3 @@ function WriteBackup () {
|
|||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
function GetAllFilesFromFolder (dir) {
|
||||
var results = []
|
||||
|
||||
fs.readdirSync(dir).forEach(function (file) {
|
||||
file = dir + '/' + file
|
||||
var stat = fs.statSync(file)
|
||||
|
||||
if (stat && stat.isDirectory()) {
|
||||
results = results.concat(_getAllFilesFromFolder(file))
|
||||
} else results.push(file)
|
||||
})
|
||||
|
||||
return results
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue