There is now a Makefile because I learnt make syntax
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
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`, `[]`)
|
||||
}
|
||||
try {
|
||||
const posts = require("../data/posts.json");
|
||||
}
|
||||
catch (error) {
|
||||
console.log("Creating posts file")
|
||||
fs.writeFileSync(`../data/posts.json`, `[]`)
|
||||
}
|
||||
try {
|
||||
const comments = require("../data/comments.json");
|
||||
}
|
||||
catch (error) {
|
||||
console.log("Creating comments file")
|
||||
fs.writeFileSync(`../data/comments.json`, `[]`)
|
||||
}
|
||||
try {
|
||||
const comments = require("../data/data.json");
|
||||
}
|
||||
catch (error) {
|
||||
console.log("Creating generic data file")
|
||||
fs.writeFileSync(`../data/data.json`, `{"hitcount": 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)
|
||||
}
|
||||
@@ -10,15 +10,8 @@ const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date util
|
||||
const ejs = require("ejs")
|
||||
const func = require("./functions.js")
|
||||
const data = require("./data.js")
|
||||
const init = require("./initialise.js")
|
||||
|
||||
|
||||
// There's only one possible argument, so we can just check if the user passed that one
|
||||
// TODO I plan on adding more such as --help and --post so I should make this more robust at some point
|
||||
if (process.argv[2] == "--first-time") {
|
||||
init.initialise() // Creates any files such users.js, posts.js, comments.js or config.js if they are not present
|
||||
}
|
||||
|
||||
// Define the modules now so they are global
|
||||
let users // contains a list of users, each user is an object containing username,prettyname,hash and description
|
||||
let posts // contains a list of posts,
|
||||
@@ -37,7 +30,7 @@ if (config["data_storage"] == "json") {
|
||||
// if they don't all import then
|
||||
// inform the user to pass --first-time and exit with an error code
|
||||
console.log("A file is missing!")
|
||||
console.log("Run with --first-time to initialise the program")
|
||||
console.log("Run 'make' to initialise the data files")
|
||||
console.log(error)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user