Начата работа над логикой сервера

This commit is contained in:
Book Pauk
2018-12-26 21:06:45 +07:00
parent 9b925dbf1b
commit 3c5d32cd72
4 changed files with 395 additions and 0 deletions

29
server/core/utils.js Normal file
View File

@@ -0,0 +1,29 @@
const Promise = require('bluebird');
const fs = require('fs');
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function statPathSync(path) {
try {
return fs.statSync(path);
} catch (ex) {}
return false;
}
function mkDirIfNotExistsSync(path) {
console.log(path);
let exists = statPathSync(path);
if (!exists) {
fs.mkdirSync(path, {recursive: true, mode: 0o755});
} else if (!exists.isDirectory()) {
throw new Error(`Not a directory: ${path}`);
}
}
module.exports = {
sleep,
statPathSync,
mkDirIfNotExistsSync,
};