-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c12026
commit 5f12d5d
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* -------------------------------------------------------------------------- */ | ||
/* DEPENDENCIES */ | ||
/* -------------------------------------------------------------------------- */ | ||
// packages | ||
const path = require('path'); | ||
const fs = require('fs').promises; | ||
|
||
/* -------------------------------------------------------------------------- */ | ||
/* Helper functions */ | ||
/* -------------------------------------------------------------------------- */ | ||
|
||
/** | ||
* Capitalizes the first character of the entity name. | ||
* @param {string} entity - The entity name | ||
* @returns {string} - The capitalized entity name | ||
*/ | ||
function capitalizeEntity(entity) { | ||
return entity.charAt(0).toUpperCase() + entity.slice(1); | ||
} | ||
|
||
/** | ||
* Checks if the entity already exists in the project. | ||
* If the entity already exists, it logs a message and exits the process. | ||
* @param {string} entity - The entity name | ||
* @returns {boolean} - Returns true if the entity exists, false otherwise | ||
*/ | ||
async function isEntityExists(entity) { | ||
// Capitalize the entity name | ||
const ENTITY = capitalizeEntity(entity); | ||
|
||
// Construct the file path for the model file | ||
const modelFilePath = path.join('src', 'models', `${ENTITY}.model.js`); | ||
|
||
try { | ||
// Check if the model file exists | ||
await fs.access(modelFilePath); | ||
return true; // Model file exists | ||
} catch (error) { | ||
return false; // Model file does not exist | ||
} | ||
} | ||
|
||
module.exports = { | ||
capitalizeEntity, | ||
isEntityExists, | ||
}; |