-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up the settings implementation & renamed base_dir project-wid…
…e to git_dir
- Loading branch information
Showing
31 changed files
with
115 additions
and
125 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
.DS_Store | ||
node_modules | ||
dist | ||
settings.yml | ||
settings.json | ||
/coverage | ||
/docs | ||
|
||
|
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
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
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
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,41 @@ | ||
import { readFileSync, readdirSync } from "fs"; | ||
import { join } from "path"; | ||
import { load } from "js-yaml"; | ||
import { exit } from "process"; | ||
import { Settings } from "./types"; | ||
import buildApp from "./app"; | ||
|
||
const settings = load(readFileSync(join(__dirname, "/../../../settings.yml"), "utf8")) as Settings; | ||
const settings = JSON.parse(readFileSync(join(__dirname, "/../../../settings.json"), "utf-8")) as Settings; | ||
|
||
const settings_keys = Object.keys(settings); | ||
|
||
const mandatory_settings = [ "host", "port", "dev_port", "title", "about", "base_dir", "production" ]; | ||
const mandatory_settings = [ "host", "port", "title", "about", "git_dir" ]; | ||
|
||
// Make sure that all the required settings are present | ||
// Get missing mandatory settings | ||
const settings_not_included = mandatory_settings.filter(x => !settings_keys.includes(x)); | ||
|
||
// Error out and exit if there's any missing settings | ||
if(settings_not_included.length !== 0) { | ||
console.log(`Error: settings.yml is missing ${(settings_not_included.length > 1) ? "keys" : "key"}:`); | ||
console.log(`Error: settings file is missing ${(settings_not_included.length > 1) ? "keys" : "key"}:`); | ||
console.log(settings_not_included.join(", ")); | ||
exit(1); | ||
} | ||
|
||
// Make sure that there's not an excessive amount of settings | ||
const mandatory_not_included = settings_keys.filter(x => !mandatory_settings.includes(x)); | ||
if(mandatory_not_included.length !== 0) { | ||
console.log(`Error: settings.yml includes ${(mandatory_not_included.length > 1) ? "pointless keys" : "a pointless key"}:`); | ||
console.log(mandatory_not_included.join(", ")); | ||
exit(1); | ||
} | ||
|
||
// Make sure that the base directory specified in the settings actually exists | ||
// Make sure that the git directory specified in the settings actually exists | ||
try { | ||
readdirSync(settings.base_dir); | ||
readdirSync(settings.git_dir); | ||
} | ||
catch { | ||
console.error(`Error: Tried opening the base directory. No such directory: ${settings.base_dir}`); | ||
console.error(`Error: Git directory ${settings.git_dir} doesn't exist!`); | ||
exit(1); | ||
} | ||
|
||
const dist_dir = join(__dirname, "/../../client/dist"); | ||
|
||
if(settings.production) { | ||
try { | ||
readdirSync(dist_dir); | ||
} | ||
catch { | ||
console.error("Error: Tried opening the dist directory but it doesn't exist.\nDid you accidentally turn on the production setting?"); | ||
exit(1); | ||
} | ||
} | ||
|
||
const app = buildApp(settings, dist_dir); | ||
const app = buildApp(settings); | ||
|
||
app.listen(settings.port, settings.host, (err: Error, addr: string) => { | ||
if(err) { | ||
console.error(err); | ||
exit(1); | ||
} | ||
|
||
console.log(`App is running on ${addr}`); | ||
console.log(`Githermit is running on ${addr}`); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
export type Settings = { | ||
host: string, | ||
port: number, | ||
dev_port: number, | ||
title: string, | ||
about: string, | ||
base_dir: string, | ||
production: boolean | ||
git_dir: string, | ||
dev: { | ||
port: number | ||
} | ||
} |
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
Oops, something went wrong.