Skip to content

Commit

Permalink
feat(cli): 'mslite g model name ..names' now generates model files
Browse files Browse the repository at this point in the history
  • Loading branch information
robophil committed Oct 13, 2017
1 parent 0cee53f commit e534eef
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
10 changes: 10 additions & 0 deletions bin/cmd/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = (cmd, names, options) => {
switch (cmd) {
case 'model':
require('./types/model')(names, options)
break

default:
break
}
}
1 change: 1 addition & 0 deletions bin/cmd/new.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const postfixName = '-service'

module.exports = (name, options) => {
if (name === undefined) throw new Error(`No name passed\nRun 'mslite help'`)
if (options.postfix) {
console.log(`\nNew microservice project created '${name + postfixName}'\n`)
} else {
Expand Down
22 changes: 22 additions & 0 deletions bin/cmd/types/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const fs = require('fs-extra')
const path = require('path')
const cwd = process.cwd()

const dest = `${cwd}/src/models/`
const src = path.resolve(__dirname, '..', '..', '..', 'files/model.js')

module.exports = (names, options) => {
fs.ensureDir(dest).then(() => {
const copyAction = []
names.forEach((name) => {
copyAction.push(fs.copy(src, `${dest}${name}.js`))
})
return copyAction
}).then(copyAction => Promise.all(copyAction).then(() => {

}).catch(err => console.dir(err))
).catch(err => {
if (err instanceof Error) throw err
else throw new Error(err)
})
}
9 changes: 8 additions & 1 deletion bin/mslite.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@ const packageJson = require('../package.json')

//require cmd
const newCmd = require('./cmd/new')
const generateCmd = require('./cmd/generate')

// display the version type
program.version(packageJson.version)

program
.command('new [app-name]')
.command('new <app-name>')
.usage('[app-name]')
.option('-n, --no-postfix', 'no postfix added')
.description('Creates a new micro-service')
.action(newCmd)

program
.command('g <type> [names...]')
.usage('[type]')
.description('generates the file type [model],')
.action(generateCmd)

// parse the arguments
program.parse(process.argv)
11 changes: 11 additions & 0 deletions files/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Define your collection (aka model)
module.exports = (Waterline, config) => Waterline.Collection.extend(Object.assign(config, {

tableName: 'model_name',

identity: 'model_name',

attributes: {

}
}))

0 comments on commit e534eef

Please sign in to comment.