diff --git a/config.json b/config.json new file mode 100644 index 0000000..a3d6918 --- /dev/null +++ b/config.json @@ -0,0 +1,10 @@ +{ + "storageURL": "http://devweb.local/comunic/current/user_data/", + "storagePath": "/home/pierre/Documents/projets_web/comunic/current/user_data/", + "database": { + "host": "localhost", + "dbName": "comunic", + "user": "pierre", + "password": "pierre" + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 99e85d9..e782288 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,12 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@types/node": { + "version": "12.12.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.8.tgz", + "integrity": "sha512-XLla8N+iyfjvsa0KKV+BP/iGSoTmwxsu5Ci5sM33z9TjohF72DEz95iNvD6pPmemvbQgxAv/909G73gUn8QR7w==", + "dev": true + }, "typescript": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.2.tgz", diff --git a/package.json b/package.json index 5679758..aa806e8 100644 --- a/package.json +++ b/package.json @@ -10,5 +10,8 @@ "license": "MIT", "dependencies": { "typescript": "^3.7.2" + }, + "devDependencies": { + "@types/node": "^12.12.8" } } diff --git a/src/helpers/ConfigHelper.ts b/src/helpers/ConfigHelper.ts new file mode 100644 index 0000000..6593147 --- /dev/null +++ b/src/helpers/ConfigHelper.ts @@ -0,0 +1,47 @@ +import { readFileSync } from "fs"; + + +/** + * Configuration helper + * + * @author Pierre HUBERT + */ + +export interface DatabaseConfiguration { + host : string, + dbName : string, + user : string, + password : string, + dbPrefix : string +} + +export interface Configuration { + storageURL : string, + storagePath : string, + database : DatabaseConfiguration, +} + +export class ConfigurationHelper { + + private static conf : Configuration; + + public static getConf() : Configuration { + return this.conf; + } + + /** + * Load configuration from a specified configuration file + * + * @param fileName Configuration file to load + */ + public static loadConf(fileName : string) { + this.conf = JSON.parse(readFileSync(fileName, {encoding: "utf-8"})); + } +} + +/** + * Get project configuration + */ +export function conf() : Configuration { + return ConfigurationHelper.getConf(); +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index d027236..151ab61 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,12 @@ +import { ConfigurationHelper, conf } from "./helpers/ConfigHelper"; + /** * Main project script * * @author Pierre HUBERT */ -console.log("Comunic API v6\t@author Pierre HUBERT\t2019-" + new Date().getFullYear()); +console.info("Comunic API v6\t@author Pierre HUBERT\t2019-" + new Date().getFullYear()); +console.info("Load configuration..."); +ConfigurationHelper.loadConf("config.json");