Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

Commit

Permalink
Add options to all express commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor-Lopes committed Jun 1, 2018
1 parent aa51c0c commit c8f2b98
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion commands/express-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ module.exports = function initCommand(program) {
.option('-f, --filename <filename>', 'filename')
.description('Generate Express Lib')
.action((cmd, options) => {
rederer.renderExpressController(options.dir, options.filename)
rederer.renderExpressLib(options.dir, options.filename)
})
}
12 changes: 7 additions & 5 deletions commands/express-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ const rederer = require('../libs/renderer.js')

module.exports = function initCommand(program) {
program
.command('express-model')
.description('Generate express model')
.action((command) => {
rederer.renderExpressModel()
.command('express-model [cmd]')
.option('-d, --dir <dir>', 'Target Directory')
.option('-f, --filename <filename>', 'filename')
.description('Generate Express Model')
.action((cmd, options) => {
rederer.renderExpressModel(options.dir, options.filename)
})
}
}
12 changes: 7 additions & 5 deletions commands/express-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ const rederer = require('../libs/renderer.js')

module.exports = function initCommand(program) {
program
.command('express-route')
.description('Generate express route')
.action((command) => {
rederer.renderExpressRoute()
.command('express-route [cmd]')
.option('-d, --dir <dir>', 'Target Directory')
.option('-f, --filename <filename>', 'filename')
.description('Generate Express Route')
.action((cmd, options) => {
rederer.renderExpressRoute(options.dir, options.filename)
})
}
}
12 changes: 7 additions & 5 deletions commands/express-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ const rederer = require('../libs/renderer.js')

module.exports = function initCommand(program) {
program
.command('express-spec')
.description('Generate Express spec')
.action((command) => {
rederer.renderExpressSpec()
.command('express-spec [cmd]')
.option('-d, --dir <dir>', 'Target Directory')
.option('-f, --filename <filename>', 'filename')
.description('Generate Express Spec')
.action((cmd, options) => {
rederer.renderExpressSpec(options.dir, options.filename)
})
}
}
28 changes: 14 additions & 14 deletions libs/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ module.exports = {
exit(1)
}
},
renderExpressRoute: () => {
renderExpressRoute: (_target, _filename) => {
try {
let template = fs.readFileSync('./templates/express/route.ejs', 'utf-8')
let js = ejs.render(template, {
data: {}
})
let targetDir = 'app/routes/hello'
let filename = 'index.js'
let targetDir = _target || 'app/routes/hello'
let filename = _filename || 'index'

dir.mkDirByPathSync(targetDir)

fs.writeFileSync('./' + targetDir + '/' + filename, js, 'utf8')
fs.writeFileSync('./' + targetDir + '/' + filename + '.js', js, 'utf8')

log(chalk.green.bold('Express Route Generated !'))
} catch (e) {
Expand All @@ -52,11 +52,11 @@ module.exports = {
data: {}
})
let targetDir = _target || 'app/libs/hello'
let filename = _filename || 'index.js'
let filename = _filename || 'index'

dir.mkDirByPathSync(targetDir)

fs.writeFileSync('./' + targetDir + '/' + filename, js, 'utf8')
fs.writeFileSync('./' + targetDir + '/' + filename + '.js', js, 'utf8')

log(chalk.green.bold('Express Lib Generated !'))
} catch (e) {
Expand All @@ -65,18 +65,18 @@ module.exports = {
exit(1)
}
},
renderExpressModel: () => {
renderExpressModel: (_target, _filename) => {
try {
let template = fs.readFileSync('./templates/express/model.ejs', 'utf-8')
let js = ejs.render(template, {
data: {}
})
let targetDir = 'app/models'
let filename = 'User.js'
let targetDir = _target || 'app/models'
let filename = _filename || 'User'

dir.mkDirByPathSync(targetDir)

fs.writeFileSync('./' + targetDir + '/' + filename, js, 'utf8')
fs.writeFileSync('./' + targetDir + '/' + filename + '.js', js, 'utf8')

log(chalk.green.bold('Express Model Generated !'))
} catch (e) {
Expand All @@ -85,18 +85,18 @@ module.exports = {
exit(1)
}
},
renderExpressSpec: () => {
renderExpressSpec: (_target, _filename) => {
try {
let template = fs.readFileSync('./templates/express/spec.ejs', 'utf-8')
let js = ejs.render(template, {
data: {}
})
let targetDir = 'specs/resources/hello'
let filename = 'index.spec.js'
let targetDir = _target || 'specs/resources/hello'
let filename = _filename || 'index.spec'

dir.mkDirByPathSync(targetDir)

fs.writeFileSync('./' + targetDir + '/' + filename, js, 'utf8')
fs.writeFileSync('./' + targetDir + '/' + filename + '.spec.js', js, 'utf8')

log(chalk.green.bold('Mocha Spec Generated !'))
} catch (e) {
Expand Down

0 comments on commit c8f2b98

Please sign in to comment.