Skip to content

Commit

Permalink
Move checker logic into separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
sdepold committed Feb 7, 2014
1 parent ae40ce9 commit 809ad7c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions bin/sequelize
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ if(typeof program.env === 'string') {
configuration.environment = program.env
}

var supportCoffeeScript = function() {
try {
config = readConfig()
} catch(e) {
console.log(e.message)
process.exit(1)
}

return program.coffee || config.coffee
}

if (program.migrate || program.undo) {
if (configFileExists() || program.url) {
var config
Expand Down Expand Up @@ -209,7 +220,7 @@ if (program.migrate || program.undo) {
var sequelize = new Sequelize(config.database, config.username, config.password, options)
, migratorOptions = { path: configuration.migrationsPath }

if (program.coffee || config.coffee) {
if (supportCoffeeScript()) {
migratorOptions = _.merge(migratorOptions, { filesFilter: /\.js$|\.coffee$/ })
}

Expand Down Expand Up @@ -252,21 +263,14 @@ if (program.migrate || program.undo) {
} else if(program.createMigration) {
createMigrationsFolder()

try {
var config = readConfig()
} catch(e) {
console.log(e.message)
process.exit(1)
}

var mirationContent = ""
, migrationExtension = (program.coffee || config.coffee) ? '.coffee' : '.js'
, migrationExtension = (supportCoffeeScript()) ? '.coffee' : '.js'
, migrationName = [
moment().format('YYYYMMDDHHmmss'),
(typeof program.createMigration === 'string') ? program.createMigration : 'unnamed-migration'
].join('-') + migrationExtension

if (program.coffee || config.coffee) {
if (supportCoffeeScript()) {
migrationContent = [
"module.exports = ",
" up: (migration, DataTypes, done) ->",
Expand Down

0 comments on commit 809ad7c

Please sign in to comment.