From 7c320e9069e25d4ee468501ae62cc294272ba0c3 Mon Sep 17 00:00:00 2001 From: Denis Tokarev Date: Fri, 26 Jun 2020 22:43:54 +1000 Subject: [PATCH] Add new params --- bin/commands/create.js | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/bin/commands/create.js b/bin/commands/create.js index 596e52d..bc0fb05 100755 --- a/bin/commands/create.js +++ b/bin/commands/create.js @@ -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}`))