forked from deadvey/blogger-nodejs
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
import { createRequire } from 'module';
|
|
const require = createRequire(import.meta.url)
|
|
// 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
|
|
export function initialise() {
|
|
const fs = require("fs");
|
|
try {
|
|
const users = require("../data/users.json");
|
|
}
|
|
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("../config.json");
|
|
}
|
|
catch (error) {
|
|
console.log("Copying the example config to config.js")
|
|
console.log("!!! PLEASE MODIFY config.json TO YOUR NEEDS !!!")
|
|
fs.copyFile('../example-config.json', '../config.json', (err) => {
|
|
console.log("Error copying file")
|
|
})
|
|
}
|
|
console.log("Successfully initialised")
|
|
process.exit(0)
|
|
}
|