Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
Add hot reload service chalk
Browse files Browse the repository at this point in the history
  • Loading branch information
Akkadius committed Feb 22, 2020
1 parent 7a8383f commit 1ef4e09
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 45 deletions.
66 changes: 36 additions & 30 deletions app/core/hot-reload-service.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -29,6 +32,10 @@ module.exports = {
return zoneExists;
},

message: function (message) {
console.log(util.format(chalk `{green [{bold HRM}] %s }`, message))
},

/**
* @return {boolean}
*/
Expand All @@ -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())

Expand All @@ -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');
}
});

Expand Down
109 changes: 94 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 25 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}

0 comments on commit 1ef4e09

Please sign in to comment.