Permalink
Browse files

Updated initializers to include opts

  • Loading branch information...
DamonOehlman committed Oct 23, 2012
1 parent 6c489e0 commit 293bd254634781e36e86e78a7463db9b34dbbb26
Showing with 12 additions and 11 deletions.
  1. +9 −8 index.js
  2. +3 −3 test/initialization.js
View
@@ -70,7 +70,7 @@ function Scaffolder(opts) {
// bind each of the initializers to the scaffolder instance
initializers = initializers.map(function(initializer) {
- return initializer.bind(scaffolder);
+ return initializer.bind(scaffolder, opts);
});
// if we encountered an error, then emit an error event and abort processing
@@ -114,7 +114,7 @@ Scaffolder.prototype.getPath = function(callback) {
}
};
-Scaffolder.prototype.loadActions = function(callback) {
+Scaffolder.prototype.loadActions = function(opts, callback) {
// determine the action path
var commandPath = path.resolve(this.srcPath, this.commandPath),
scaffolder = this;
@@ -152,19 +152,20 @@ Scaffolder.prototype.loadActions = function(callback) {
});
};
-Scaffolder.prototype.loadPackage = function(targetPath, callback) {
+Scaffolder.prototype.loadPackage = function(targetPath, opts, callback) {
var scaffolder = this,
updatePackageData = false,
packageData;
- // if the targetPath is a function, then default to the source path
- if (typeof targetPath == 'function') {
- callback = targetPath;
+ // if the target path is not a string, then bump parameters
+ if (typeof targetPath != 'string' && (! (targetPath instanceof String))) {
+ callback = typeof targetPath == 'function' ? targetPath : opts;
+ opts = typeof targetPath == 'function' ? {} : targetPath;
targetPath = this.srcPath;
+
updatePackageData = true;
}
-
-
+
// load the package.json file from the specified directory
fs.readFile(path.join(targetPath, 'package.json'), 'utf8', function(err, data) {
// if we read the file successfully, then parse it
View
@@ -39,7 +39,7 @@ describe('scaffolder initialization tests', function() {
it('should be able to include an initialization function that will be called before ready', function(done) {
var initialized = false,
s = scaffolder(_.extend({
- init: function(callback) {
+ init: function(opts, callback) {
initialized = true;
callback();
}
@@ -56,12 +56,12 @@ describe('scaffolder initialization tests', function() {
initB = false,
s = scaffolder(_.extend({
init: [
- function(callback) {
+ function(opts, callback) {
initA = true;
callback();
},
- function(callback) {
+ function(opts, callback) {
initB = true;
callback();
}

0 comments on commit 293bd25

Please sign in to comment.