-
Notifications
You must be signed in to change notification settings - Fork 2
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
bebab74
commit 973ba8a
Showing
11 changed files
with
249 additions
and
12 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
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
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,3 @@ | ||
module.exports = { | ||
// Add services here | ||
}; |
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,108 @@ | ||
const { handleError } = require('../../@shared/utils'); | ||
|
||
|
||
/** | ||
* @description To get all {{name}} | ||
* @param {*} req | ||
* @param {*} res | ||
* @param {*} next | ||
* @returns {Array<{{name}}>} {{name}} | ||
*/ | ||
exports.getAll = (req, res, next) => { | ||
try { | ||
return res.status(200).send({ | ||
endpoint: '/v1/{{name}}', | ||
method: req.method, | ||
description: 'Dummy endpoint to get all {{name}}', | ||
{{name}}: [] | ||
}); | ||
} catch (err) { | ||
return handleError(res, err); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @description To get {{name}} by id | ||
* @param {*} req | ||
* @param {*} res | ||
* @param {*} next | ||
* @returns {*} {{name}} | ||
*/ | ||
exports.getById = (req, res, next) => { | ||
try { | ||
const { id } = req.params; | ||
return res.status(200).send({ | ||
endpoint: '/v1/{{name}}/:id', | ||
method: req.method, | ||
description: 'Dummy endpoint to get {{name}} with id', | ||
{{name}}: {id} | ||
}); | ||
} catch (err) { | ||
return handleError(res, err); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @description Adds a {{name}} | ||
* @param {*} req | ||
* @param {*} res | ||
* @param {*} next | ||
* @returns {*} Added {{name}} | ||
*/ | ||
exports.add = (req, res, next) => { | ||
try { | ||
return res.status(201).send({ | ||
endpoint: '/v1/{{name}}', | ||
method: req.method, | ||
description: 'Dummy endpoint to add {{name}}', | ||
{{name}}: req.body | ||
}); | ||
} catch (err) { | ||
return handleError(res, err); | ||
} | ||
} | ||
|
||
/** | ||
* @description Updates a {{name}} | ||
* @param {*} req | ||
* @param {*} res | ||
* @param {*} next | ||
* @returns {*} update {{name}} | ||
*/ | ||
exports.patch = (req, res, next) => { | ||
try { | ||
const { id } = req.params; | ||
return res.status(200).send({ | ||
endpoint: '/v1/{{name}}/:id', | ||
method: req.method, | ||
description: 'Dummy endpoint to update {{name}}', | ||
{{name}}: { id, ...req.body } | ||
}); | ||
} catch (err) { | ||
return handleError(res, err); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @description To delete a record | ||
* @param {*} req | ||
* @param {*} res | ||
* @param {*} next | ||
* @returns {*} http response | ||
*/ | ||
exports.delete = (req, res, next) => { | ||
try { | ||
const { id } = req.params; | ||
return res.status(200).send({ | ||
endpoint: '/v1/{{name}}/:id', | ||
method: req.method, | ||
description: 'Dummy endpoint to update {{name}}', | ||
{{name}}: {id} | ||
}); | ||
} catch (err) { | ||
return handleError(res, err); | ||
} | ||
} |
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,13 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const controller = require('./controller'); | ||
|
||
// Add all routes here | ||
router.get('', controller.getAll); | ||
router.get('/:id', controller.getById); | ||
router.post('', controller.add); | ||
router.patch('/:id', controller.patch); | ||
router.delete('/:id', controller.delete); | ||
|
||
|
||
module.exports = router; |
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,12 @@ | ||
const { handleError } = require('../../@shared/utils'); | ||
|
||
exports.default = (req, res, next) => { | ||
try { | ||
return res.status(200).send({ | ||
endpoint: '/v1/{{name}}', | ||
description: 'auto-generate with @ps-cli@express' | ||
}); | ||
} catch (err) { | ||
return handleError(res, err); | ||
} | ||
} |
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,9 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const controller = require('./controller'); | ||
|
||
// Add all routes here | ||
router.get('', controller.default); | ||
|
||
|
||
module.exports = router; |
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,3 @@ | ||
module.exports = () => { | ||
|
||
} |
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module.exports = { | ||
new: require('./new'), | ||
model: require('./route'), | ||
route: require('./route'), | ||
model: require('./model'), | ||
service: require('./service'), | ||
} |
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 |
---|---|---|
@@ -1,3 +1,55 @@ | ||
module.exports = () => { | ||
const shell = require('shelljs'); | ||
const path = require('path'); | ||
const store = require('../../utils/store'); | ||
const copy = require('copy-template-dir'); | ||
const replace = require('replace-in-file'); | ||
const chalk = require('chalk'); | ||
const ask = require('../../utils/ask'); | ||
|
||
|
||
/** | ||
* @description New Route workflow | ||
*/ | ||
module.exports = async () => { | ||
const vars = store.get('vars'); | ||
let crud = store.get('crud') | ||
|
||
|
||
if (!crud) { | ||
console.log('\n'); | ||
const _crud = await ask({name: 'CRUD', message: 'Do want to generate CRUDs ?', hint: '(yes|no)', initial: 'no', choices: ['yes', 'no'] }); | ||
if (_crud === 'yes') crud = true; | ||
} | ||
|
||
let inDir = path.join(__dirname, `../../template/js/route`); | ||
let outDir = path.join(process.cwd(), './src/@routes/', `${vars.name}`); | ||
|
||
if (crud) { | ||
inDir = path.join(__dirname, `../../template/js/route-crud`); | ||
outDir = path.join(process.cwd(), './src/@routes/', `${vars.name}`); | ||
} | ||
|
||
if (!shell.test('-e', path.join(process.cwd(), './package.json'))) { | ||
shell.echo('The command can only be run in @root folder having package.json'); | ||
process.exit(0); | ||
} | ||
|
||
if (shell.test('-e', outDir)){ | ||
shell.echo('\nThe route already exsists\n'); | ||
process.exit(0); | ||
} | ||
|
||
|
||
copy(inDir, outDir, vars, async (err, createdFiles) => { | ||
if (err) throw err; | ||
createdFiles.forEach((filePath) => console.log(`${chalk.green("[Created]:")} ${filePath.replace(process.cwd(), '')}`)); | ||
}); | ||
|
||
|
||
replace({ | ||
files: path.join(`${outDir}`, '../index.js'), | ||
from: `module.exports = (app) => {`, | ||
to: `module.exports = (app) => { | ||
app.use('/v1/${vars.name}', require('./${vars.name}/routes-config'));` | ||
}) | ||
} |