From 04a06e85ec36080ededa1c7df0d2d375ce2a65bc Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Wed, 7 Feb 2024 11:38:57 -0800 Subject: [PATCH] IO-2632 Add basic instance manager functions & editor config. --- .editorconfig | 18 ++++++++++++++ client/src/utils/instanceRenderMgr.js | 34 +++++++++++++++++++++++++++ server/utils/instanceMgr.js | 34 +++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 .editorconfig create mode 100644 client/src/utils/instanceRenderMgr.js create mode 100644 server/utils/instanceMgr.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..79368e997 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 4 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.yml] +indent_size = 2 + +[*.json] +indent_size = 2 \ No newline at end of file diff --git a/client/src/utils/instanceRenderMgr.js b/client/src/utils/instanceRenderMgr.js new file mode 100644 index 000000000..ad7892730 --- /dev/null +++ b/client/src/utils/instanceRenderMgr.js @@ -0,0 +1,34 @@ +/** + * FRONT-END Returns the corresponding component/function/object based on the type of instance. + * Based on the node env params, return the correct prop. + * Default is to return the ImEX Prop + * @typedef {Object} InstanceManagerObject + * @property { string | object | function } rome Return this prop if Rome. + * @property { string | object | function } proman Return this prop if Rome. + * @property { string | object | function } imex Return this prop if Rome. + */ + +function InstanceRenderManager({ rome, proman, imex }) { + let propToReturn = null; + + switch (process.env.INSTANCE) { + case "IMEX": + propToReturn = imex; + break; + case "ROME": + propToReturn = rome; + break; + case "PROMANAGER": + propToReturn = proman; + break; + default: + propToReturn = imex; + break; + } + if (!propToReturn) { + throw new Error( + `Prop to return is not valid for this instance (${process.env.INSTANCE}).` + ); + } + return propToReturn; +} diff --git a/server/utils/instanceMgr.js b/server/utils/instanceMgr.js new file mode 100644 index 000000000..581e58c2c --- /dev/null +++ b/server/utils/instanceMgr.js @@ -0,0 +1,34 @@ +/** + * Returns the corresponding component/function/object based on the type of instance. + * Based on the node env params, return the correct prop. + * Default is to return the ImEX Prop + * @typedef {Object} InstanceManagerObject + * @property { string | object | function } rome Return this prop if Rome. + * @property { string | object | function } proman Return this prop if Rome. + * @property { string | object | function } imex Return this prop if Rome. + */ + +function InstanceManager({ rome, proman, imex }) { + let propToReturn = null; + + switch (process.env.INSTANCE) { + case "IMEX": + propToReturn = imex; + break; + case "ROME": + propToReturn = rome; + break; + case "PROMANAGER": + propToReturn = proman; + break; + default: + propToReturn = imex; + break; + } + if (!propToReturn) { + throw new Error( + `Prop to return is not valid for this instance (${process.env.INSTANCE}).` + ); + } + return propToReturn; +}