Skip to content

Commit

Permalink
refactor: 🔨 general refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
simplymichael committed Aug 30, 2024
1 parent 16676c5 commit 4700533
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
4 changes: 3 additions & 1 deletion bin/bob
Original file line number Diff line number Diff line change
Expand Up @@ -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));
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
21 changes: 13 additions & 8 deletions src/app/http/models/mongoose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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;
Expand All @@ -39,6 +43,7 @@ fs.readdirSync(__dirname)
db[modelClass.name] = model;
});

db.connection = connection;
db.connection = connection;
}

module.exports = db;
2 changes: 1 addition & 1 deletion src/app/http/models/sequelize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");


/*
Expand Down

0 comments on commit 4700533

Please sign in to comment.