不要怂,就是干,撸起袖子干!

Commit abb43452 by Mick Hansen

Merge pull request #1444 from fundon/fix-readconfig-twice

fix read config twice
2 parents 8684ab96 cd9798eb
Showing with 14 additions and 19 deletions
...@@ -7,7 +7,7 @@ var path = require("path") ...@@ -7,7 +7,7 @@ var path = require("path")
, moment = require("moment") , moment = require("moment")
, _ = Sequelize.Utils._ , _ = Sequelize.Utils._
, url = require("url") , url = require("url")
, supportCS = undefined , supportsCoffee
var configuration = { var configuration = {
configFile: process.cwd() + '/config/config.json', configFile: process.cwd() + '/config/config.json',
...@@ -142,6 +142,8 @@ var readConfig = function() { ...@@ -142,6 +142,8 @@ var readConfig = function() {
config = config[configuration.environment] config = config[configuration.environment]
} }
supportsCoffee = program.coffee || config.coffee
return config return config
} }
...@@ -170,21 +172,6 @@ if(typeof program.env === 'string') { ...@@ -170,21 +172,6 @@ if(typeof program.env === 'string') {
configuration.environment = program.env configuration.environment = program.env
} }
var supportCoffeeScript = function() {
if (supportCS === undefined) {
try {
config = readConfig()
} catch(e) {
console.log(e.message)
process.exit(1)
}
supportCS = program.coffee || config.coffee
}
return supportCS
}
if (program.migrate || program.undo) { if (program.migrate || program.undo) {
if (configFileExists() || program.url) { if (configFileExists() || program.url) {
var config var config
...@@ -225,7 +212,7 @@ if (program.migrate || program.undo) { ...@@ -225,7 +212,7 @@ if (program.migrate || program.undo) {
var sequelize = new Sequelize(config.database, config.username, config.password, options) var sequelize = new Sequelize(config.database, config.username, config.password, options)
, migratorOptions = { path: configuration.migrationsPath } , migratorOptions = { path: configuration.migrationsPath }
if (supportCoffeeScript()) { if (supportsCoffee) {
migratorOptions = _.merge(migratorOptions, { filesFilter: /\.js$|\.coffee$/ }) migratorOptions = _.merge(migratorOptions, { filesFilter: /\.js$|\.coffee$/ })
} }
...@@ -272,14 +259,22 @@ if (program.migrate || program.undo) { ...@@ -272,14 +259,22 @@ if (program.migrate || program.undo) {
} else if(program.createMigration) { } else if(program.createMigration) {
createMigrationsFolder() createMigrationsFolder()
var config;
try {
config = readConfig()
} catch(e) {
console.log(e.message)
process.exit(1)
}
var mirationContent = "" var mirationContent = ""
, migrationExtension = (supportCoffeeScript()) ? '.coffee' : '.js' , migrationExtension = supportsCoffee ? '.coffee' : '.js'
, migrationName = [ , migrationName = [
moment().format('YYYYMMDDHHmmss'), moment().format('YYYYMMDDHHmmss'),
(typeof program.createMigration === 'string') ? program.createMigration : 'unnamed-migration' (typeof program.createMigration === 'string') ? program.createMigration : 'unnamed-migration'
].join('-') + migrationExtension ].join('-') + migrationExtension
if (supportCoffeeScript()) { if (supportsCoffee) {
migrationContent = [ migrationContent = [
"module.exports = ", "module.exports = ",
" up: (migration, DataTypes, done) ->", " up: (migration, DataTypes, done) ->",
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!