1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 03:29:37 +02:00

Merge branch 'feature' into v1.7.0

This commit is contained in:
Paweł Malak 2021-10-11 14:31:59 +02:00
commit 55f192f664
53 changed files with 1172 additions and 385 deletions

View file

@ -3,7 +3,7 @@ const fs = require('fs');
class File {
constructor(path) {
this.path = path;
this.content = '';
this.content = null;
}
read() {
@ -16,10 +16,13 @@ class File {
}
}
write(data) {
write(data, isJSON) {
this.content = data;
fs.writeFileSync(this.path, this.content);
fs.writeFileSync(
this.path,
isJSON ? JSON.stringify(this.content) : this.content
);
}
}
module.exports = File;
module.exports = File;

View file

@ -1,22 +0,0 @@
const fs = require('fs');
const { join } = require('path');
const Logger = require('./Logger');
const logger = new Logger();
// Check if flame.css exists in mounted docker volume. Create new file if not
const findCss = () => {
const srcPath = join(__dirname, '../data/flame.css');
const destPath = join(__dirname, '../public/flame.css');
if (fs.existsSync(srcPath)) {
fs.copyFileSync(srcPath, destPath);
logger.log('Custom CSS file found');
return;
}
logger.log('Creating empty CSS file');
fs.writeFileSync(destPath, '');
}
module.exports = findCss;

32
utils/init/createFile.js Normal file
View file

@ -0,0 +1,32 @@
const fs = require('fs');
const { join } = require('path');
const Logger = require('../Logger');
const logger = new Logger();
const createFile = async (file) => {
const { name, msg, template, isJSON, paths } = file;
const srcPath = join(__dirname, paths.src, name);
const destPath = join(__dirname, paths.dest, name);
// Check if file exists
if (fs.existsSync(srcPath)) {
fs.copyFileSync(srcPath, destPath);
if (process.env.NODE_ENV == 'development') {
logger.log(msg.found);
}
return;
}
// Create file if not
fs.writeFileSync(destPath, isJSON ? JSON.stringify(template) : template);
if (process.env.NODE_ENV == 'development') {
logger.log(msg.created);
}
};
module.exports = createFile;

9
utils/init/index.js Normal file
View file

@ -0,0 +1,9 @@
const initConfig = require('./initConfig');
const initFiles = require('./initFiles');
const initApp = async () => {
await initConfig();
await initFiles();
};
module.exports = initApp;

View file

@ -1,7 +1,8 @@
const { Op } = require('sequelize');
const Config = require('../models/Config');
const Config = require('../../models/Config');
const { config } = require('./initialConfig.json');
const Logger = require('./Logger');
const Logger = require('../Logger');
const logger = new Logger();
const initConfig = async () => {
@ -28,7 +29,10 @@ const initConfig = async () => {
}
});
logger.log('Initial config created');
if (process.env.NODE_ENV == 'development') {
logger.log('Initial config created');
}
return;
};

8
utils/init/initFiles.js Normal file
View file

@ -0,0 +1,8 @@
const createFile = require('./createFile');
const { files } = require('./initialFiles.json');
const initFiles = async () => {
files.forEach(async (file) => await createFile(file));
};
module.exports = initFiles;

View file

@ -0,0 +1,32 @@
{
"files": [
{
"name": "flame.css",
"msg": {
"created": "Created empty CSS file",
"found": "Custom CSS file found"
},
"paths": {
"src": "../../data",
"dest": "../../public"
},
"template": "",
"isJSON": false
},
{
"name": "customQueries.json",
"msg": {
"created": "Created empty queries file",
"found": "Custom queries file found"
},
"paths": {
"src": "../../data",
"dest": "../../data"
},
"template": {
"queries": []
},
"isJSON": true
}
]
}