diff --git a/app/core/hot-reload-service.js b/app/core/hot-reload-service.js index df81080..f948c93 100644 --- a/app/core/hot-reload-service.js +++ b/app/core/hot-reload-service.js @@ -1,13 +1,16 @@ /** - * hot-reload-service.js + * HRM.js * @type {{exec: module.exports.exec}} */ const serverDataService = require('./eqemu-data-service-client') const pathManager = require('./path-manager') -const debug = require('debug')('eqemu-admin:hot-reload-service') +const debug = require('debug')('eqemu-admin:HRM') const watch = require('node-watch'); const database = require('./database') const eqemuConfigService = require('./eqemu-config-service') +const chalk = require('chalk'); +const util = require('util'); +const path = require('path'); module.exports = { zones: null, @@ -29,6 +32,10 @@ module.exports = { return zoneExists; }, + message: function (message) { + console.log(util.format(chalk `{green [{bold HRM}] %s }`, message)) + }, + /** * @return {boolean} */ @@ -38,7 +45,10 @@ module.exports = { await database.init(); await this.loadZones(); - console.log('[hot-reload-service] Starting hot-reload service listener...') + this.message('Starting HRM listener (Hot-Reload Module) v1.0') + this.message(util.format(chalk `Watching scripts [{bold %s}]`, pathManager.getEmuQuestsPath())) + this.message(util.format(chalk `Watching scripts [{bold %s}]`, pathManager.getEmuLuaModulesPath())) + this.message(util.format(chalk `Watching scripts [{bold %s}]`, pathManager.getEmuPluginsPath())) debug('Starting listener for [%s]', pathManager.getEmuQuestsPath()) @@ -48,59 +58,55 @@ module.exports = { * Lua Modules */ watch(pathManager.getEmuLuaModulesPath(), { recursive: true }, function (evt, file) { - console.log( - '[hot-reload-service] [lua_modules] [%s] changed type [%s]', - file, - evt - ); + const changedFile = path.dirname(file).split(path.sep).pop() + '/' + path.basename(file); - console.log('[hot-reload-service] [global] Reloading all zones globally'); - serverDataService.hotReloadZoneQuests("all"); + self.message(util.format( + chalk`[{bold lua_modules}] Reloading [{bold All Zones}] File [{bold %s}]`, + changedFile + )); + serverDataService.hotReloadZoneQuests('all'); }); /** * Plugins */ watch(pathManager.getEmuPluginsPath(), { recursive: true }, function (evt, file) { - console.log( - '[hot-reload-service] [plugins] [%s] changed type [%s]', - file, - evt - ); + const changedFile = path.dirname(file).split(path.sep).pop() + '/' + path.basename(file); + + self.message(util.format( + chalk`[{bold plugins}] Reloading [{bold All Zones}] File [{bold %s}]`, + changedFile + )); - console.log('[hot-reload-service] [global] Reloading all zones globally'); - serverDataService.hotReloadZoneQuests("all"); + serverDataService.hotReloadZoneQuests('all'); }); /** * Quests */ watch(pathManager.getEmuQuestsPath(), { recursive: true }, function (evt, file) { - const changedFile = file.replace(pathManager.getEmuQuestsPath() + '/', ''); - const changedZone = changedFile.split('/')[0].trim() - - console.log( - '[hot-reload-service] [%s] changed type [%s] zone [%s] zone_exists [%s]', - changedFile, - evt, - changedZone, - self.doesZoneExist(changedZone) + const changedFile = path.dirname(file).split(path.sep).pop() + '/' + path.basename(file); + const changedZone = path.dirname(file).split(path.sep).pop(); + + const changedData = util.format( + chalk`File [{bold %s}]`, + changedFile ); /** * Zone */ if (self.doesZoneExist(changedZone)) { - console.log('[hot-reload-service] [zone] Reloading zone [%s]', changedZone); + self.message(util.format(chalk `[{bold zone}] Reloading [{bold %s}] %s`, changedZone, changedData)); serverDataService.hotReloadZoneQuests(changedZone); } /** * Global */ - if (changedZone === "global") { - console.log('[hot-reload-service] [global] Reloading all zones globally'); - serverDataService.hotReloadZoneQuests("all"); + if (changedZone === 'global') { + self.message(util.format(chalk `[{bold global}] Reloading [{bold %s}] %s`, 'All Zones', changedData)); + serverDataService.hotReloadZoneQuests('all'); } }); diff --git a/package-lock.json b/package-lock.json index 42627b8..cfc0ce3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,9 +1,14 @@ { "name": "eqemu-admin", - "version": "1.0.7", + "version": "1.0.8", "lockfileVersion": 1, "requires": true, "dependencies": { + "@types/color-name": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", + "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==" + }, "@types/geojson": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-1.0.6.tgz", @@ -112,9 +117,28 @@ "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" }, "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "requires": { + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" + }, + "dependencies": { + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + } + } }, "application-config": { "version": "1.0.1", @@ -189,6 +213,30 @@ "chalk": "^1.1.3", "esutils": "^2.0.2", "js-tokens": "^3.0.2" + }, + "dependencies": { + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "requires": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + } + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" + } } }, "balanced-match": { @@ -404,15 +452,12 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", "requires": { - "ansi-styles": "^2.2.1", - "escape-string-regexp": "^1.0.2", - "has-ansi": "^2.0.0", - "strip-ansi": "^3.0.0", - "supports-color": "^2.0.0" + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" } }, "changelog-parser": { @@ -1372,6 +1417,30 @@ "shelljs": "^0.3.0", "update-notifier": "^2.2.0", "yargs": "^2.1.1" + }, + "dependencies": { + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "requires": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + } + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" + } } }, "gh-release-assets": { @@ -3539,9 +3608,19 @@ "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" }, "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", + "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", + "requires": { + "has-flag": "^4.0.0" + }, + "dependencies": { + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + } + } }, "systeminformation": { "version": "4.17.2", diff --git a/package.json b/package.json index b5acca2..db6d935 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "url": "https://github.com/Akkadius/eqemu-web-admin.git" }, "dependencies": { + "chalk": "^3.0.0", "child_process": "^1.0.2", "commander": "^2.20.0", "cookie-parser": "~1.4.3", diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..22bc042 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "lib": [ + "es5", + "es6" + ], + "target": "es6", + "module": "commonjs", + "moduleResolution": "node", + "outDir": "./build", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "sourceMap": true, + "esModuleInterop": true, + "allowJs": true, + "noImplicitAny": false, + "baseUrl": ".", + "paths": { + "*": ["node_modules/*", "src/types/*"] + }, + "declaration": true, + "forceConsistentCasingInFileNames": true + }, + "exclude": ["node_modules"] +}