lots of fixes and more EJS
This commit is contained in:
39
src/initialise.js
Normal file
39
src/initialise.js
Normal file
@@ -0,0 +1,39 @@
|
||||
// Initialise the program by creating users.js, comments.js, posts.js and config.js
|
||||
// All require default content in them to start off with
|
||||
// Then exit successfully
|
||||
// returns nothing
|
||||
function initialise() {
|
||||
try {
|
||||
const users = require("../data/users.js");
|
||||
}
|
||||
catch (error) {
|
||||
console.log("Creating users file")
|
||||
fs.writeFileSync(`../data/users.json`, `{\n"users": []\n}`)
|
||||
}
|
||||
try {
|
||||
const posts = require("../data/posts.json");
|
||||
}
|
||||
catch (error) {
|
||||
console.log("Creating posts file")
|
||||
fs.writeFileSync(`../data/posts.json`, `{\n"posts": []\n}`)
|
||||
}
|
||||
try {
|
||||
const comments = require("../data/comments.json");
|
||||
}
|
||||
catch (error) {
|
||||
console.log("Creating comments file")
|
||||
fs.writeFileSync(`../data/comments.json`, `{\n"comments": [],\n"counter": 0}`)
|
||||
}
|
||||
try {
|
||||
const config = require("../data/config.js");
|
||||
}
|
||||
catch (error) {
|
||||
console.log("Copying the example config to config.js")
|
||||
console.log("!!! PLEASE MODIFY config.js TO YOUR NEEDS !!!")
|
||||
fs.copyFile('example-config.js', 'config.js', (err) => {
|
||||
console.log("Error copying file")
|
||||
})
|
||||
}
|
||||
console.log("Successfully initialised")
|
||||
process.exit(0)
|
||||
}
|
Reference in New Issue
Block a user