Last active
September 29, 2022 11:40
-
-
Save Shigetorum635/1d8030d80b33657841e73f8e39955acf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const qoa = require("qoa") | |
const { writeFile, mkdirSync, existsSync } = require("fs") | |
const wizard = [ | |
{ | |
type: "hidden", | |
query: "Host Key of your set?", | |
handle: "HOST_KEY", | |
}, | |
{ | |
type: "input", | |
query: "Port to run Node-Hill on? (default: 42480)", | |
handle: "SERVER_PORT", | |
}, | |
{ | |
type: "input", | |
query: "Map Directory to use? (Leave blank to use default)", | |
handle: "MAP_DIRECTORY", | |
}, | |
{ | |
type: "input", | |
query: "Run server locally? (default: true)", | |
handle: "LOCAL_ONLY", | |
}, | |
{ | |
type: "input", | |
query: "Scripts directory to use? (Leave blank to use default)", | |
handle: "SCRIPTS_DIRECTORY", | |
}, | |
{ | |
type: "input", | |
query: "Map name (without .brk)? (Leave blank to use map.brk)", | |
handle: "MAP_NAME", | |
}, | |
] | |
const sampleScript = ` | |
Game.on('playerJoin', function(player) { | |
console.log('Player %s joined', player.username); | |
}) | |
` | |
qoa.config({ | |
prefix: "Node Hill Setup >", | |
underlineQuery: false, | |
}); | |
const enviromentExists = existsSync(".env") | |
const scriptFolderExists = existsSync("./scripts/") | |
// This is here because the setup is designed to create a .env file. Having another makes no sense! | |
if (enviromentExists) { | |
console.log( | |
"Set up already started the enviorment. Please delete your .env file before starting." | |
); | |
process.exit(1) | |
} | |
(async function start() { | |
console.log( | |
"\nYou can manually edit .env file after the wizard to edit values\n" | |
) | |
const response = await qoa.prompt(wizard); | |
let envfile = "" | |
const defaultSettings = { | |
NH_HOST_KEY: response.HOST_KEY || "", | |
NH_SERVER_PORT: response.SERVER_PORT || 42480, | |
NH_LOCAL_ONLY: response.LOCAL_ONLY || true, | |
NH_SCRIPTS_DIRECTORY: response.SCRIPTS_DIRECTORY || "./scripts/", | |
NH_MAP_NAME: response.MAP_NAME + ".brk" || "map.brk", | |
NH_MODULES: "[]", | |
} | |
if (!defaultSettings.NH_HOST_KEY || defaultSettings.NH_HOST_KEY === "") | |
console.error( | |
"HOST_KEY is a necessary parameter, without it you wont be able of hosting the set publicly!" | |
) | |
const keys = Object.keys(defaultSettings); | |
for (const item of keys) { | |
envfile += `${item}=${defaultSettings[item]}\n` | |
} | |
writeFile("./.env", envfile, (err) => { | |
if (!err) return | |
throw new Error( | |
"There was an error creating the environment file: " + err.message | |
) | |
}) | |
if (!scriptFolderExists) { | |
mkdirSync(defaultSettings.NH_SCRIPTS_DIRECTORY); | |
writeFile( | |
`${defaultSettings.NH_SCRIPTS_DIRECTORY}/main.js`, | |
sampleScript, | |
(err) => { | |
if (!err) return; | |
throw new Error( | |
"There was an error creating the sample script file: " + err.message | |
) | |
} | |
) | |
} | |
console.log("\n=====================================================") | |
console.log("=== Node-Hill Set up Successfully ===") | |
console.log("=====================================================\n") | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Old code, still works