Skip to content

Commit

Permalink
Extended config for hotReload
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0a0d committed Jul 1, 2020
1 parent 715e891 commit c231942
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
8 changes: 6 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ declare namespace Moleculer {
| ActionParamSchema;
type ActionParams = { [key: string]: ActionParamTypes };

interface HotReloadOptions {
enabled?: boolean;
modules?: Array<string>;
}

interface TracerExporterOptions {
type: string;
options?: GenericObject;
Expand Down Expand Up @@ -787,8 +792,7 @@ declare namespace Moleculer {
};
internalMiddlewares?: boolean;

hotReload?: boolean;
hotReloadModules?: Array<string>;
hotReload?: boolean | HotReloadOptions;

middlewares?: Array<Middleware | string>;

Expand Down
21 changes: 13 additions & 8 deletions src/middlewares/hot-reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,22 @@ module.exports = function HotReloadMiddleware(broker) {

// After broker started
started(broker) {
if (broker.options.hotReload) {
broker.logger.info("Hot-reload is ACTIVE.");

if (Array.isArray(broker.options.hotReloadModules)) {
hotReloadModules = broker.options.hotReloadModules.map(moduleName => `/node_modules/${moduleName}/`);
if (broker.options.hotReload == null) {
return;
} else if (typeof broker.options.hotReload === 'object') {
if (broker.options.hotReload.enabled !== true) {
return;
}
if (Array.isArray(broker.options.hotReload.modules)) {
hotReloadModules = broker.options.hotReload.modules.map(moduleName => `/node_modules/${moduleName}/`);
}
} else if (broker.options.hotReload !== true) {
return;
}

watchProjectFiles();
watchProjectFiles();

watchProjectFolders();
}
watchProjectFolders();
},

serviceStarted() {
Expand Down

0 comments on commit c231942

Please sign in to comment.