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

Commit 17ec8ce7 by Sascha Depold

Move options file to test directory and rename cli-options to options-path

1 parent 121aefa1
...@@ -16,15 +16,16 @@ var configuration = { ...@@ -16,15 +16,16 @@ var configuration = {
migrationsPath: process.cwd() + '/migrations' migrationsPath: process.cwd() + '/migrations'
} }
var loadDefaultOptions = function(path){ var loadDefaultOptions = function(pathToOptionsFile) {
try{ try {
options = require(process.cwd()+'/'+path); var options = require(path.resolve(process.cwd(), '/', pathToOptionsFile))
for (var key in options){
program[key] = options[key]; Object.keys(options).forEach(function(key) {
} program[key] = options[key]
}catch(e){ })
} catch(e) {
console.log(e); console.log(e);
throw new Error('Error reading "' + path + '".') throw new Error('Error reading "' + pathToOptionsFile + '".')
} }
} }
...@@ -94,23 +95,27 @@ var createMigrationsFolder = function(force) { ...@@ -94,23 +95,27 @@ var createMigrationsFolder = function(force) {
} }
try { try {
mkdirp(configuration.migrationsPath); mkdirp(configuration.migrationsPath)
console.log('Successfully created migrations folder at "' + configuration.migrationsPath + '".') console.log('Successfully created migrations folder at "' + configuration.migrationsPath + '".')
} catch(e) { } catch(e) {
} }
} }
var mkdirp = function (path, root) { var mkdirp = function (path, root) {
var dirs = path.split('/')
, dir = dirs.shift()
, root = (root || '') + dir + '/'
var dirs = path.split('/'), dir = dirs.shift(), root = (root||'')+dir+'/'; try {
fs.mkdirSync(root)
try { fs.mkdirSync(root); } } catch (e) {
catch (e) { // dir wasn't made, something went wrong
//dir wasn't made, something went wrong if (!fs.statSync(root).isDirectory()) {
if(!fs.statSync(root).isDirectory()) throw new Error(e); throw new Error(e)
}
} }
return !dirs.length||mkdirp(dirs.join('/'), root); return !dirs.length || mkdirp(dirs.join('/'), root)
} }
...@@ -183,13 +188,13 @@ program ...@@ -183,13 +188,13 @@ program
.option('-c, --create-migration [migration-name]', 'Creates a new migration.') .option('-c, --create-migration [migration-name]', 'Creates a new migration.')
.option('-p, --migrations-path <migration-path>', 'migration directory path.') .option('-p, --migrations-path <migration-path>', 'migration directory path.')
.option('-U, --url <url>', 'Database url. An alternative to a config file') .option('-U, --url <url>', 'Database url. An alternative to a config file')
.option('-o,--cli-options <options_file>', 'Specifies lib options from file.') .option('-o,--options-path <options_file>', 'Specifies lib options from file.')
.option('--config <config_file>', 'Specifies alternate config file.') .option('--config <config_file>', 'Specifies alternate config file.')
.option('--coffee', 'Consider coffee script files as migration source.') .option('--coffee', 'Consider coffee script files as migration source.')
.parse(process.argv) .parse(process.argv)
if(typeof program.cliOptions === 'string') { if(typeof program.optionsPath === 'string') {
loadDefaultOptions(program.cliOptions); loadDefaultOptions(program.optionsPath);
} }
if(typeof program.config === 'string') { if(typeof program.config === 'string') {
...@@ -343,4 +348,3 @@ if (program.migrate || program.undo) { ...@@ -343,4 +348,3 @@ if (program.migrate || program.undo) {
} else { } else {
console.log('No action specified. Try "sequelize --help" for usage information.') console.log('No action specified. Try "sequelize --help" for usage information.')
} }
{
"configFile": "./config/database.json",
"migrationsPath": "./db/migrate"
}
var path = require('path')
module.exports = {
configFile: path.resolve('config', 'database.json'),
migrationsPath: path.resolve('db', 'migrate')
}
...@@ -454,7 +454,9 @@ if (os.type().toLowerCase().indexOf('windows') === -1) { ...@@ -454,7 +454,9 @@ if (os.type().toLowerCase().indexOf('windows') === -1) {
describe(flag, function() { describe(flag, function() {
it("using options file instead of cli switches", function(done) { it("using options file instead of cli switches", function(done) {
exec("rm -rf ./*", { cwd: __dirname + '/tmp' }, function() { exec("rm -rf ./*", { cwd: __dirname + '/tmp' }, function() {
exec( "../../bin/sequelize --init "+flag+" ../../config/options.json" , { cwd: __dirname + '/tmp' }, function() { var _path = path.resolve(__dirname, 'config', 'options.js')
exec("../../bin/sequelize --init " + flag + " " + _path, { cwd: __dirname + '/tmp' }, function(err, stdout) {
exec("ls -ila", { cwd: __dirname + '/tmp' }, function(err, stdout) { exec("ls -ila", { cwd: __dirname + '/tmp' }, function(err, stdout) {
expect(stdout).to.include('db') expect(stdout).to.include('db')
done() done()
...@@ -465,8 +467,6 @@ if (os.type().toLowerCase().indexOf('windows') === -1) { ...@@ -465,8 +467,6 @@ if (os.type().toLowerCase().indexOf('windows') === -1) {
}); });
}) })
})(['--cli-options', '-o']) })(['--options-path', '-o'])
}) })
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!