diff --git a/bin/bob b/bin/bob index 1832650..854e69a 100644 --- a/bin/bob +++ b/bin/bob @@ -5,4 +5,6 @@ const path = require("node:path"); require(`${path.dirname(__dirname).replace(/\\/g, "/")}/src/bootstrap/app`) - .dispatch(process.argv.slice(2)); + .dispatch(process.argv.slice(2)) + .then((status) => status !== undefined && process.exit(status)) + .catch((err) => process.exit(err.code)); diff --git a/package.json b/package.json index cee9ea6..1a9a2dc 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,7 @@ { "name": "@simplicityjs/simplicity", "version": "1.0.0", - "description": "The Simplest MVC Framework for Node.js ", - "main": "./bin/bob", - "bin": { - "bob": "./bin/bob" - }, + "description": "The Simplest MVC Framework for Node.js", "scripts": { "test": "cross-env NODE_ENV=test LOG_TO_CONSOLE=false mocha tests/\"{,/**/}*.spec.js\"", "test:coverage": "nyc npm test", diff --git a/src/app/http/models/mongoose/index.js b/src/app/http/models/mongoose/index.js index ed2763c..02259b2 100644 --- a/src/app/http/models/mongoose/index.js +++ b/src/app/http/models/mongoose/index.js @@ -4,13 +4,11 @@ const fs = require("node:fs"); const path = require("node:path"); const mongoose = require("mongoose"); const Connections = require("@simplicityjs/framework/connections"); -const config = require("../../../../config"); +const config = require("config"); const db = {}; const basename = path.basename(__filename); -const connectionName = config.get("database.mongoose"); -const connectionConfig = config.get("database.connections")[connectionName]; -const connection = Connections.get(connectionName, connectionConfig); + function createModel(modelName, schema, connection) { if(mongoose.models[modelName]) { @@ -27,9 +25,15 @@ function createModel(modelName, schema, connection) { ); } -fs.readdirSync(__dirname) - .filter(f => f.indexOf(".") !== 0 && f !== basename && f.slice(-3) === ".js") - .forEach(file => { +const modelFiles = fs.readdirSync(__dirname) + .filter(f => f.indexOf(".") !== 0 && f !== basename && f.slice(-3) === ".js"); + +if(modelFiles.length > 0) { + const connectionName = "mongodb"; + const connectionConfig = config.get("database.connections")[connectionName]; + const connection = Connections.get(connectionName, connectionConfig); + + modelFiles.forEach(file => { const modelFile = path.join(__dirname, file); const modelClass = require(modelFile); const modelSchema = require(modelFile).schema; @@ -39,6 +43,7 @@ fs.readdirSync(__dirname) db[modelClass.name] = model; }); -db.connection = connection; + db.connection = connection; +} module.exports = db; diff --git a/src/app/http/models/sequelize/index.js b/src/app/http/models/sequelize/index.js index 0317a5e..f3c8d83 100644 --- a/src/app/http/models/sequelize/index.js +++ b/src/app/http/models/sequelize/index.js @@ -3,7 +3,7 @@ const fs = require("node:fs"); const path = require("node:path"); const Connections = require("@simplicityjs/framework/connections"); -const config = require("../../../../config"); +const config = require("config"); const db = {}; const basename = path.basename(__filename); diff --git a/src/bootstrap/providers.js b/src/bootstrap/providers.js index a5438dd..99ed192 100644 --- a/src/bootstrap/providers.js +++ b/src/bootstrap/providers.js @@ -2,8 +2,8 @@ * Specify your service providers in this file. */ -const AppServiceProvider = require("../service-providers/app-service-provider"); -const CacheServiceProvider = require("../service-providers/cache-service-provider"); +const AppServiceProvider = require("service-providers/app-service-provider"); +const CacheServiceProvider = require("service-providers/cache-service-provider"); /*