Skip to content

Commit

Permalink
Add new params
Browse files Browse the repository at this point in the history
  • Loading branch information
devlato authored Jun 26, 2020
1 parent 086a484 commit 7c320e9
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions bin/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,49 @@ exports.builder = (yargs) => {
requiresArg: true,
demandOption: true
})
.option('template-file', {
alias: 't',
describe: 'template file path',
type: 'string',
requiresArg: true,
demandOption: false
})
.option('extension', {
alias: 'e',
describe: 'migration file extension',
type: 'string',
requiresArg: true,
demandOption: false
})
.positional('name', {
describe: 'descriptive name for the migration file',
type: 'string'
})
}

exports.handler = ({ name, contentType }) => {
exports.handler = ({ name, contentType, templateFile, extension }) => {
const migrationsDirectory = path.join('.', 'migrations', contentType)
const templateFile = path.join(__dirname, '..', '..', 'lib', 'template.js')
templateFile = !!templateFile
? path.isAbsolute(templateFile)
? templateFile
: path.join(process.cwd(), templateFile)
: !!process.env.TEMPLATE_FILE && typeof process.env.TEMPLATE_FILE === 'string'
? path.isAbsolute(process.env.TEMPLATE_FILE)
? process.env.TEMPLATE_FILE
: path.join(__dirname, process.env.TEMPLATE_FILE)
: path.join(__dirname, '..', '..', 'lib', 'template.js')
extension = !!extension
? extension
: !!process.env.MIGRATION_FILE_EXTENSION && typeof process.env.MIGRATION_FILE_EXTENSION === 'string'
? process.env.MIGRATION_FILE_EXTENSION
: '.js'

generator({
name,
templateFile,
migrationsDirectory,
dateFormat: 'UTC:yyyymmddHHMMss',
extension: '.js'
extension: extension
}, (error, filename) => {
if (error) {
log(chalk.bold.red(`🚨 Template generation error ${error.message}`))
Expand Down

0 comments on commit 7c320e9

Please sign in to comment.