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 ng commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor-Lopes committed Jun 1, 2018
1 parent c8f2b98 commit da74a63
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 37 deletions.
8 changes: 5 additions & 3 deletions commands/ng-controller.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('ng-controller')
.command('ng-controller [cmd]')
.option('-d, --dir <dir>', 'Target Directory')
.option('-f, --filename <filename>', 'filename')
.description('Generate AngularJS Controller')
.action((command) => {
rederer.renderNgController()
.action((cmd, options) => {
rederer.renderNgController(options.dir, options.filename)
})
}
8 changes: 5 additions & 3 deletions commands/ng-directive.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('ng-directive')
.command('ng-directive [cmd]')
.option('-d, --dir <dir>', 'Target Directory')
.option('-f, --filename <filename>', 'filename')
.description('Generate AngularJS Directive')
.action((command) => {
rederer.renderNgDirective()
.action((cmd, options) => {
rederer.renderNgDirective(options.dir, options.filename)
})
}
8 changes: 5 additions & 3 deletions commands/ng-factory.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('ng-factory')
.command('ng-factory [cmd]')
.option('-d, --dir <dir>', 'Target Directory')
.option('-f, --filename <filename>', 'filename')
.description('Generate AngularJS Factory')
.action((command) => {
rederer.renderNgFactory()
.action((cmd, options) => {
rederer.renderNgFactory(options.dir, options.filename)
})
}
10 changes: 6 additions & 4 deletions commands/ng-filter.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('ng-filter')
.command('ng-filter [cmd]')
.option('-d, --dir <dir>', 'Target Directory')
.option('-f, --filename <filename>', 'filename')
.description('Generate AngularJS Filter')
.action((command) => {
rederer.renderNgFilter()
.action((cmd, options) => {
rederer.renderNgFilter(options.dir, options.filename)
})
}
}
10 changes: 6 additions & 4 deletions commands/ng-service.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('ng-service')
.command('ng-service [cmd]')
.option('-d, --dir <dir>', 'Target Directory')
.option('-f, --filename <filename>', 'filename')
.description('Generate AngularJS Service')
.action((command) => {
rederer.renderNgService()
.action((cmd, options) => {
rederer.renderNgService(options.dir, options.filename)
})
}
}
40 changes: 20 additions & 20 deletions libs/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,18 @@ module.exports = {
exit(1)
}
},
renderNgDirective: () => {
renderNgDirective: (_target, _filename) => {
try {
let template = fs.readFileSync('./templates/angularjs/directive.ejs', 'utf-8')
let js = ejs.render(template, {
data: {}
})
let targetDir = 'public/app/directives/name'
let filename = 'name.js'
let targetDir = _target || 'public/app/directives/name'
let filename = _filename || 'name'

dir.mkDirByPathSync(targetDir)

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

log(chalk.green.bold('Angular Directive Generated !'))
} catch (e) {
Expand All @@ -125,18 +125,18 @@ module.exports = {
exit(1)
}
},
renderNgController: () => {
renderNgController: (_target, _filename) => {
try {
let template = fs.readFileSync('./templates/angularjs/controller.ejs', 'utf-8')
let js = ejs.render(template, {
data: {}
})
let targetDir = 'public/app/controllers/name'
let filename = 'NameCtrl.js'
let targetDir = _target || 'public/app/controllers/name'
let filename = _filename || 'NameCtrl'

dir.mkDirByPathSync(targetDir)

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

log(chalk.green.bold('Angular Controller Generated !'))
} catch (e) {
Expand All @@ -145,18 +145,18 @@ module.exports = {
exit(1)
}
},
renderNgFactory: () => {
renderNgFactory: (_target, _filename) => {
try {
let template = fs.readFileSync('./templates/angularjs/factory.ejs', 'utf-8')
let js = ejs.render(template, {
data: {}
})
let targetDir = 'public/app/factories/name'
let filename = 'NameFactory.js'
let targetDir = _target || 'public/app/factories/name'
let filename = _filename || 'NameFactory'

dir.mkDirByPathSync(targetDir)

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

log(chalk.green.bold('Angular Factory Generated !'))
} catch (e) {
Expand All @@ -165,18 +165,18 @@ module.exports = {
exit(1)
}
},
renderNgFilter: () => {
renderNgFilter: (_target, _filename) => {
try {
let template = fs.readFileSync('./templates/angularjs/filter.ejs', 'utf-8')
let js = ejs.render(template, {
data: {}
})
let targetDir = 'public/app/filters/name'
let filename = 'Name.js'
let targetDir = _target || 'public/app/filters/name'
let filename = _filename || 'Name'

dir.mkDirByPathSync(targetDir)

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

log(chalk.green.bold('Angular Filter Generated !'))
} catch (e) {
Expand All @@ -185,18 +185,18 @@ module.exports = {
exit(1)
}
},
renderNgService: () => {
renderNgService: (_target, _filename) => {
try {
let template = fs.readFileSync('./templates/angularjs/service.ejs', 'utf-8')
let js = ejs.render(template, {
data: {}
})
let targetDir = 'public/app/services/name'
let filename = 'NameService.js'
let targetDir = _target || 'public/app/services/name'
let filename = _filename || 'NameService'

dir.mkDirByPathSync(targetDir)

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

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

0 comments on commit da74a63

Please sign in to comment.