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

Commit 7a3b7196 by Daniel Cohen

sequelize bin support options file + migration path

migrationsPath configured via cli

loading all cli switches via json configuration file , loaded via --options
1 parent 70a0cb3e
Showing with 37 additions and 1 deletions
......@@ -16,6 +16,18 @@ var configuration = {
migrationsPath: process.cwd() + '/migrations'
}
var loadDefaultOptions = function(path){
try{
options = require(path);
for (var key in options){
program[key] = options[key];
}
}catch(e){
console.log(e);
throw new Error('Error reading "' + path + '".')
}
}
var configFileExists = function() {
return fs.existsSync(configuration.configFile)
}
......@@ -82,12 +94,26 @@ var createMigrationsFolder = function(force) {
}
try {
fs.mkdirSync(configuration.migrationsPath)
mkdirp(configuration.migrationsPath);
console.log('Successfully created migrations folder at "' + configuration.migrationsPath + '".')
} catch(e) {
}
}
var mkdirp = function (path, root) {
var dirs = path.split('/'), dir = dirs.shift(), root = (root||'')+dir+'/';
try { fs.mkdirSync(root); }
catch (e) {
//dir wasn't made, something went wrong
if(!fs.statSync(root).isDirectory()) throw new Error(e);
}
return !dirs.length||mkdirp(dirs.join('/'), root);
}
var parseDbUrl = function(urlString) {
var urlParts,
config = {};
......@@ -153,11 +179,17 @@ program
.option('-u, --undo', 'Undo the last migration.')
.option('-f, --force', 'Forces the action to be done.')
.option('-c, --create-migration [migration-name]', 'Creates a new migration.')
.option('-p, --migrations-path', 'migration directory path.')
.option('-U, --url <url>', 'Database url. An alternative to a config file')
.option('--config <config_file>', 'Specifies alternate config file.')
.option('--options <options_file>', 'Specifies lib options from file.')
.option('--coffee', 'Consider coffee script files as migration source.')
.parse(process.argv)
if(typeof program.options === 'string') {
loadDefaultOptions(program.options);
}
if(typeof program.config === 'string') {
if (isRelativePath(program.config)) {
configuration.configFile = path.join(process.cwd(), program.config);
......@@ -166,6 +198,10 @@ if(typeof program.config === 'string') {
}
}
if(typeof program.migrationsPath=== 'string') {
configuration.migrationsPath = program.migrationsPath
}
if(typeof program.env === 'string') {
configuration.environment = program.env
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!