diff --git a/.gitignore b/.gitignore index b03a1ad5..1118f206 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ pids # Editor files .vscode +.idea # Directory for instrumented libs generated by jscoverage/JSCover lib-cov diff --git a/src/commands/model_generate.js b/src/commands/model_generate.js index 1ab3ae5c..75d97637 100644 --- a/src/commands/model_generate.js +++ b/src/commands/model_generate.js @@ -16,6 +16,12 @@ exports.builder = (yargs) => type: 'string', demandOption: true, }) + .option('file-name', { + describe: + 'Specify custom file name for the model created. Default name is model name in lowercase', + type: 'string', + demandOption: false, + }) .option('force', { describe: 'Forcefully re-creates model with the same name', type: 'string', @@ -37,7 +43,7 @@ exports.handler = function (args) { helpers.migration.generateTableCreationFile(args); helpers.view.log( 'New model was created at', - clc.blueBright(helpers.path.getModelPath(args.name)), + clc.blueBright(helpers.path.getModelPath(args.name, args['file-name'])), '.' ); helpers.view.log( @@ -78,7 +84,7 @@ function ensureMigrationsFolder() { } function checkModelFileExistence(args) { - const modelPath = helpers.path.getModelPath(args.name); + const modelPath = helpers.path.getModelPath(args.name, args['file-name']); if (args.force === undefined && helpers.model.modelFileExists(modelPath)) { helpers.view.notifyAboutExistingFile(modelPath); diff --git a/src/commands/seed.js b/src/commands/seed.js index 1a7c25d1..a16db9fb 100644 --- a/src/commands/seed.js +++ b/src/commands/seed.js @@ -44,9 +44,10 @@ function seedAll(args) { function seedUndoAll(args) { return getMigrator('seeder', args) .then((migrator) => { - return (helpers.umzug.getStorage('seeder') === 'none' - ? migrator.pending() - : migrator.executed() + return ( + helpers.umzug.getStorage('seeder') === 'none' + ? migrator.pending() + : migrator.executed() ).then((seeders) => { if (seeders.length === 0) { helpers.view.log('No seeders found.'); diff --git a/src/core/migrator.js b/src/core/migrator.js index 4e89afd8..592678ad 100644 --- a/src/core/migrator.js +++ b/src/core/migrator.js @@ -66,7 +66,8 @@ export async function getMigrator(type, args) { } export function ensureCurrentMetaSchema(migrator) { - const queryInterface = migrator.options.storageOptions.sequelize.getQueryInterface(); + const queryInterface = + migrator.options.storageOptions.sequelize.getQueryInterface(); const tableName = migrator.options.storageOptions.tableName; const columnName = migrator.options.storageOptions.columnName; diff --git a/src/helpers/model-helper.js b/src/helpers/model-helper.js index 2fb43c9f..ce66795e 100644 --- a/src/helpers/model-helper.js +++ b/src/helpers/model-helper.js @@ -116,7 +116,7 @@ module.exports = { }, generateFile(args) { - const modelPath = helpers.path.getModelPath(args.name); + const modelPath = helpers.path.getModelPath(args.name, args['file-name']); helpers.asset.write(modelPath, this.generateFileContent(args)); }, diff --git a/src/helpers/path-helper.js b/src/helpers/path-helper.js index 8249903e..d4b2cd53 100644 --- a/src/helpers/path-helper.js +++ b/src/helpers/path-helper.js @@ -69,10 +69,10 @@ module.exports = { return args.modelsPath || path.resolve(process.cwd(), 'models'); }, - getModelPath(modelName) { + getModelPath(modelName, fileName) { return path.resolve( this.getModelsPath(), - this.addFileExtension(modelName.toLowerCase()) + this.addFileExtension(fileName ? fileName : modelName.toLowerCase()) ); }, diff --git a/test/support/helpers.js b/test/support/helpers.js index 8861507f..853a4d55 100644 --- a/test/support/helpers.js +++ b/test/support/helpers.js @@ -27,11 +27,13 @@ module.exports = { clearDirectory: function () { return through.obj(function (file, encoding, callback) { - exec('rm -rf * & rm -rf .sequelizerc', { cwd: file.path }, function ( - err - ) { - callback(err, file); - }); + exec( + 'rm -rf * & rm -rf .sequelizerc', + { cwd: file.path }, + function (err) { + callback(err, file); + } + ); }); }, @@ -53,41 +55,41 @@ module.exports = { logToFile(command); - exec(command, { cwd: file.path, env: env }, function ( - err, - stdout, - stderr - ) { - var result = file; + exec( + command, + { cwd: file.path, env: env }, + function (err, stdout, stderr) { + var result = file; - logToFile({ err: err, stdout: stdout, stderr: stderr }); + logToFile({ err: err, stdout: stdout, stderr: stderr }); - if (stdout) { - expect(stdout).to.not.contain('EventEmitter'); - } + if (stdout) { + expect(stdout).to.not.contain('EventEmitter'); + } - if (options.pipeStdout) { - result = stdout; - } else if (options.pipeStderr) { - result = stderr; - } + if (options.pipeStdout) { + result = stdout; + } else if (options.pipeStderr) { + result = stderr; + } - if (options.exitCode) { - try { - expect(err).to.be.ok(); - expect(err.code).to.equal(1); - callback(null, result); - } catch (e) { - callback( - new Error('Expected cli to exit with a non-zero code'), - null - ); + if (options.exitCode) { + try { + expect(err).to.be.ok(); + expect(err.code).to.equal(1); + callback(null, result); + } catch (e) { + callback( + new Error('Expected cli to exit with a non-zero code'), + null + ); + } + } else { + err = options.pipeStderr ? null : err; + callback(err, result); } - } else { - err = options.pipeStderr ? null : err; - callback(err, result); } - }); + ); }); },