Skip to content

Commit

Permalink
feat: Implement cli helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
fadhlaouir committed Mar 15, 2024
1 parent 8c12026 commit 5f12d5d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions cli/helpers.js
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,
};

0 comments on commit 5f12d5d

Please sign in to comment.