minimonolith 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import url from 'url';
|
|
3
|
+
|
|
4
|
+
// Function to find the project root from any nested directory inside node_modules/
|
|
5
|
+
const getProjectRoot = (currentFileUrl, MODULE_FOLDER) => {
|
|
6
|
+
const currentPath = path.dirname(url.fileURLToPath(currentFileUrl));
|
|
7
|
+
const nodeModulesIndex = currentPath.indexOf(MODULE_FOLDER);
|
|
8
|
+
if (nodeModulesIndex === -1) {
|
|
9
|
+
throw new Error(MODULE_FOLDER+' not found in the path '+currentPath);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const nodeModulesPath = currentPath.substring(0, nodeModulesIndex);
|
|
13
|
+
return url.pathToFileURL(nodeModulesPath);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { getProjectRoot };
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import url from 'url'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { getProjectRoot } from '../pathHandler/index.js';
|
|
4
|
+
import { registerModel } from '../databaseHandler/index.js';
|
|
4
5
|
import { methodHandler } from './methodHandler.js';
|
|
5
6
|
import { registerMethods } from './registerMethods.js';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
const serviceHandler = async (API, SERVICE_NAME, SRC_FOLDER='') => {
|
|
8
|
+
const serviceHandler = async (API, SERVICE_NAME, SRC_FOLDER='', MODULE_FOLDER='node_modules/') => {
|
|
9
9
|
try {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const PROJECT_ROOT_PATH = getProjectRoot(import.meta.url, MODULE_FOLDER)+'/';
|
|
11
|
+
const PROJECT_RELATIVE_SERVICE_PATH = './' + SRC_FOLDER + `${SERVICE_NAME}/`;
|
|
12
|
+
//const SERVICE_URL = new URL(RELATIVE_SERVICE_PATH, url.pathToFileURL(process.cwd()+'/'));
|
|
13
|
+
const SERVICE_URL = new URL(PROJECT_RELATIVE_SERVICE_PATH, PROJECT_ROOT_PATH);
|
|
12
14
|
const SERVICE_MODULE = await import(`${SERVICE_URL}index.js`);
|
|
13
15
|
|
|
14
16
|
if (SERVICE_MODULE.modelSchema) registerModel(SERVICE_NAME, SERVICE_MODULE.modelSchema);
|