Comparing version 1.0.6 to 1.0.7
{ | ||
"name": "monarch", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"author": "James Eggers <james.r.eggers@gmail.com> (http://www.jamesreggers.com/)", | ||
@@ -5,0 +5,0 @@ "description": "A command line utility for generic migrations in Node.js.", |
@@ -99,3 +99,3 @@ <img src="https://github.com/JamesEggers1/node-monarch/raw/master/images/Monarch_butterfly_USGS.png" height="60px" width="64px"> | ||
## License ## | ||
(MIT) | ||
Copyright (c) 2012 James Eggers | ||
@@ -102,0 +102,0 @@ |
@@ -95,2 +95,6 @@ module.exports = (function(){ | ||
if (typeof migration === "number"){ | ||
migration = migration.toString(); | ||
} | ||
console.log(''); | ||
@@ -134,5 +138,13 @@ var migrationsDirectory = _path.resolve(process.cwd() + "/migrations"); | ||
&& script.name.substring(0,14) > migration.substring(0,14)){ | ||
newVersion = script.name; | ||
_clog.log("Reverting: " + newVersion); | ||
script.down(_clog); | ||
try{ | ||
_clog.log("Reverting: " + script.name); | ||
script.down(_clog); | ||
newVersion = script.name; | ||
} catch (e) { | ||
_clog.error("*******************************************************"); | ||
_clog.error("* " + e.name + ": " + e.message); | ||
_clog.error("* Migrations will be halted."); | ||
_clog.error("*******************************************************"); | ||
break; | ||
} | ||
} | ||
@@ -139,0 +151,0 @@ } |
@@ -140,5 +140,13 @@ module.exports = (function(){ | ||
if (script.name.substring(0,14) > currentVersion){ | ||
newVersion = script.name; | ||
_clog.log("Migrating To: " + newVersion); | ||
script.up(_clog); | ||
try{ | ||
_clog.log("Migrating To: " + script.name); | ||
script.up(_clog); | ||
newVersion = script.name; | ||
} catch (e) { | ||
_clog.error("*******************************************************"); | ||
_clog.error("* " + e.name + ": " + e.message); | ||
_clog.error("* Migrations will be halted."); | ||
_clog.error("*******************************************************"); | ||
break; | ||
} | ||
} | ||
@@ -145,0 +153,0 @@ } |
@@ -11,3 +11,3 @@ "use strict"; | ||
describe("Up Command", function(){ | ||
describe("Down Command", function(){ | ||
describe("Error Cases", function(){ | ||
@@ -41,2 +41,18 @@ it("should output an error if the migrations directory does not exist.", function(){ | ||
}); | ||
it("should output an error if an exception is thrown within a migration", function(){ | ||
var count = 1 | ||
, path = "./migrations"; | ||
_helper.errorMigrationSetup(path, count); | ||
_helper.createMigrationTrackerFile(path, "201206301747E0.js"); | ||
var errorWasCalled = false; | ||
_clog.error = function(){ errorWasCalled = true;}; | ||
_down(0); | ||
errorWasCalled.should.be.true; | ||
_helper.deleteRelativeDirectory(path); | ||
}); | ||
}); | ||
@@ -43,0 +59,0 @@ |
@@ -1,103 +0,144 @@ | ||
"use strict"; | ||
module.exports = (function(){ | ||
"use strict"; | ||
var _fs = require("fs") | ||
, _path = require("path") | ||
, _rimraf = require("rimraf") | ||
, _eol = require("../src/utils/eol") | ||
, _template =[ | ||
'' | ||
, 'exports.name = "{{filename}}";' | ||
, '' | ||
, 'exports.up = function(logger){' | ||
, 'logger.test("{{filename}} was migrated up.");' | ||
, '};' | ||
, '' | ||
, 'exports.down = function(logger){' | ||
, 'logger.test("{{filename}} was migrated up.");' | ||
, '};' | ||
].join(_eol); | ||
/** | ||
* Verifies that a directory exists relative to the current working directory. | ||
* @param {string} relativePath The relative path to verify. | ||
* @returns {boolean} Returns true if the directory exists relative to the current working directory. | ||
*/ | ||
module.exports.relativeDirectoryExists = function(relativePath) { | ||
var relativeDirectory = _path.resolve(process.cwd() + "/" + relativePath); | ||
return _path.existsSync(relativeDirectory); | ||
}; | ||
var _fs = require("fs") | ||
, _path = require("path") | ||
, _rimraf = require("rimraf") | ||
, _eol = require("../src/utils/eol") | ||
, _template =[ | ||
'' | ||
, 'exports.name = "{{filename}}";' | ||
, '' | ||
, 'exports.up = function(logger){' | ||
, 'logger.test("{{filename}} was migrated up.");' | ||
, '};' | ||
, '' | ||
, 'exports.down = function(logger){' | ||
, 'logger.test("{{filename}} was migrated up.");' | ||
, '};' | ||
].join(_eol) | ||
, _errorTemplate =[ | ||
'' | ||
, 'exports.name = "{{filename}}";' | ||
, '' | ||
, 'exports.up = function(logger){' | ||
, 'throw new Error("Migration Exception");' | ||
, '};' | ||
, '' | ||
, 'exports.down = function(logger){' | ||
, 'throw new Error("Migration Exception");' | ||
, '};' | ||
].join(_eol); | ||
/** | ||
* Deletes a directory relative to the current working directory and all of its contents. | ||
* @param {string} relativePath The relative path to verify. | ||
*/ | ||
module.exports.deleteRelativeDirectory = function(relativePath) { | ||
var relativeDirectory = _path.resolve(process.cwd() + "/" + relativePath); | ||
_rimraf.sync(relativeDirectory); | ||
}; | ||
/** | ||
* Verifies that a directory exists relative to the current working directory. | ||
* @param {string} relativePath The relative path to verify. | ||
* @returns {boolean} Returns true if the directory exists relative to the current working directory. | ||
*/ | ||
var relativeDirectoryExists = function(relativePath) { | ||
var relativeDirectory = _path.resolve(process.cwd() + "/" + relativePath); | ||
return _path.existsSync(relativeDirectory); | ||
}; | ||
/** | ||
* Verifies that a file exists relative to the current working directory. | ||
* @param {string} relativeFilePath The relative file path to verify. | ||
* @returns {boolean} Returns true if the file exists relative to the current working directory. | ||
*/ | ||
module.exports.relativeFileExists = function(relativeFilePath){ | ||
var relativeFile = _path.resolve(process.cwd() + "/" + relativeFilePath); | ||
return _path.existsSync(relativeFile); | ||
}; | ||
/** | ||
* Deletes a directory relative to the current working directory and all of its contents. | ||
* @param {string} relativePath The relative path to verify. | ||
*/ | ||
var deleteRelativeDirectory = function(relativePath) { | ||
var relativeDirectory = _path.resolve(process.cwd() + "/" + relativePath); | ||
_rimraf.sync(relativeDirectory); | ||
}; | ||
/** | ||
* Creates a directory relative to the current working directory if it does not already exist. | ||
* @param {string} relativeDirectoryPath The relative path to create. | ||
*/ | ||
module.exports.createRelativeDirectory = function (relativeDirectoryPath){ | ||
var relativeDirectory = _path.resolve(process.cwd() + "/" + relativeDirectoryPath); | ||
if(!_path.existsSync(relativeDirectory)){ | ||
_fs.mkdirSync(relativeDirectory); | ||
} | ||
}; | ||
/** | ||
* Verifies that a file exists relative to the current working directory. | ||
* @param {string} relativeFilePath The relative file path to verify. | ||
* @returns {boolean} Returns true if the file exists relative to the current working directory. | ||
*/ | ||
var relativeFileExists = function(relativeFilePath){ | ||
var relativeFile = _path.resolve(process.cwd() + "/" + relativeFilePath); | ||
return _path.existsSync(relativeFile); | ||
}; | ||
module.exports.createMigrationTrackerFile = function(path, content){ | ||
var filename = ".migrationTracker"; | ||
var relativeDirectory = _path.resolve(process.cwd() + "/" + path); | ||
if(!_path.existsSync(relativeDirectory)){ | ||
_fs.mkdirSync(relativeDirectory); | ||
} | ||
_fs.writeFileSync(path + '/' + filename, content); | ||
}; | ||
/** | ||
* Creates a directory relative to the current working directory if it does not already exist. | ||
* @param {string} relativeDirectoryPath The relative path to create. | ||
*/ | ||
var createRelativeDirectory = function (relativeDirectoryPath){ | ||
var relativeDirectory = _path.resolve(process.cwd() + "/" + relativeDirectoryPath); | ||
module.exports.upMigrationSetup = function(path, count){ | ||
var relativeDirectory = _path.resolve(process.cwd() + "/" + path) | ||
, filename | ||
, template; | ||
if(!_path.existsSync(relativeDirectory)){ | ||
_fs.mkdirSync(relativeDirectory); | ||
} | ||
}; | ||
var createMigrationTrackerFile = function(path, content){ | ||
var filename = ".migrationTracker"; | ||
var relativeDirectory = _path.resolve(process.cwd() + "/" + path); | ||
if(!_path.existsSync(relativeDirectory)){ | ||
_fs.mkdirSync(relativeDirectory); | ||
} | ||
_fs.writeFileSync(path + '/' + filename, content); | ||
}; | ||
var upMigrationSetup = function(path, count){ | ||
var relativeDirectory = _path.resolve(process.cwd() + "/" + path) | ||
, filename | ||
, template; | ||
if(!_path.existsSync(relativeDirectory)){ | ||
_fs.mkdirSync(relativeDirectory); | ||
} | ||
for (var i = 0; i < count; i++){ | ||
filename = "2012063017470" + i + ".js"; | ||
template = _template.replace(/\{\{filename\}\}/g, filename); | ||
_fs.writeFileSync(path + '/' + filename, template); | ||
} | ||
}; | ||
var downMigrationSetup = function(path, count){ | ||
var relativeDirectory = _path.resolve(process.cwd() + "/" + path) | ||
, filename | ||
, template; | ||
if(!_path.existsSync(relativeDirectory)){ | ||
_fs.mkdirSync(relativeDirectory); | ||
} | ||
for (var i = 0; i < count; i++){ | ||
filename = "2012063017470" + i + ".js"; | ||
template = _template.replace(/\{\{filename\}\}/g, filename); | ||
_fs.writeFileSync(path + '/' + filename, template); | ||
} | ||
}; | ||
if(!_path.existsSync(relativeDirectory)){ | ||
_fs.mkdirSync(relativeDirectory); | ||
} | ||
for (var i = 0; i < count; i++){ | ||
filename = "2012063017470" + i + ".js"; | ||
template = _template.replace(/\{\{filename\}\}/g, filename); | ||
_fs.writeFileSync(path + '/' + filename, template); | ||
} | ||
}; | ||
var errorMigrationSetup = function(path, count){ | ||
var relativeDirectory = _path.resolve(process.cwd() + "/" + path) | ||
, filename | ||
, template; | ||
if(!_path.existsSync(relativeDirectory)){ | ||
_fs.mkdirSync(relativeDirectory); | ||
} | ||
module.exports.downMigrationSetup = function(path, count){ | ||
var relativeDirectory = _path.resolve(process.cwd() + "/" + path) | ||
, filename | ||
, template; | ||
for (var i = 0; i < count; i++){ | ||
filename = "201206301747E" + i + ".js"; | ||
template = _errorTemplate.replace(/\{\{filename\}\}/g, filename); | ||
_fs.writeFileSync(path + '/' + filename, template); | ||
} | ||
}; | ||
if(!_path.existsSync(relativeDirectory)){ | ||
_fs.mkdirSync(relativeDirectory); | ||
} | ||
for (var i = 0; i < count; i++){ | ||
filename = "2012063017470" + i + ".js"; | ||
template = _template.replace(/\{\{filename\}\}/g, filename); | ||
_fs.writeFileSync(path + '/' + filename, template); | ||
} | ||
}; | ||
return { | ||
relativeDirectoryExists : relativeDirectoryExists | ||
, deleteRelativeDirectory : deleteRelativeDirectory | ||
, relativeFileExists : relativeFileExists | ||
, createRelativeDirectory : createRelativeDirectory | ||
, createMigrationTrackerFile : createMigrationTrackerFile | ||
, upMigrationSetup : upMigrationSetup | ||
, downMigrationSetup : downMigrationSetup | ||
, errorMigrationSetup : errorMigrationSetup | ||
}; | ||
}()); |
@@ -30,2 +30,17 @@ "use strict"; | ||
}); | ||
it("should output an error if an exception is thrown within a migration", function(){ | ||
var count = 1 | ||
, path = "./migrations"; | ||
_helper.errorMigrationSetup(path, count); | ||
var errorWasCalled = false; | ||
_clog.error = function(){ errorWasCalled = true;}; | ||
_up(); | ||
errorWasCalled.should.be.true; | ||
_helper.deleteRelativeDirectory(path); | ||
}); | ||
}); | ||
@@ -32,0 +47,0 @@ |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
38578
21
910
1