From 45d2b149301d609471424fcce7471c0fea5955b5 Mon Sep 17 00:00:00 2001 From: fadhlaouir Date: Fri, 15 Mar 2024 14:45:16 +0100 Subject: [PATCH] feat: After creating the entity import it in server.js :tada: --- cli/generateCrud.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cli/generateCrud.js b/cli/generateCrud.js index 1ce0dc8..2491df1 100644 --- a/cli/generateCrud.js +++ b/cli/generateCrud.js @@ -66,6 +66,18 @@ async function generateEmptyCrud(entity) { controllerTemplate, ); await fs.writeFile(`src/routes/${entity}.route.js`, routeTemplate); + + // Line to add in server.js + const lineToAdd = `const ${entity}Routes = require('./src/routes/${entity}/${entity}.route');\napp.use('/v1/api', ${entity}Routes);\n`; + + try { + // Append the line to server.js + const serverFilePath = path.join(__dirname, 'server.js'); + await fs.appendFile(serverFilePath, lineToAdd); + console.log(`Added routes for ${entity} in server.js`); + } catch (error) { + console.error('Error appending route to server.js:', error); + } } /** @@ -210,6 +222,18 @@ async function generateMinimalCrud(entity) { controllerTemplate, ); await fs.writeFile(`src/routes/${entity}.route.js`, routeTemplate); + + // Line to add in server.js + const lineToAdd = `const ${entity}Routes = require('./src/routes/${entity}/${entity}.route');\napp.use('/v1/api', ${entity}Routes);\n`; + + try { + // Append the line to server.js + const serverFilePath = path.join(__dirname, 'server.js'); + await fs.appendFile(serverFilePath, lineToAdd); + console.log(`Added routes for ${entity} in server.js`); + } catch (error) { + console.error('Error appending route to server.js:', error); + } } module.exports = {