Skip to content

Commit

Permalink
add necessary changes to seeds to operate again
Browse files Browse the repository at this point in the history
Refers to #215
  • Loading branch information
wzrdtales committed Jan 9, 2018
1 parent 5450eb4 commit 6f40d6b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 29 deletions.
65 changes: 36 additions & 29 deletions lib/commands/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ var assert = require('assert');
var path = require('path');
var _assert = require('./helper/assert');

var seedHook = function (internals) {
var Seed = require('../seed.js');
return Seed.registerHook(internals.plugins, internals);
};

function executeSeed (internals, config, callback) {
var index = require('../../connect');
var Seeder = require('../seeder.js');
Expand All @@ -12,36 +17,38 @@ function executeSeed (internals, config, callback) {
internals.argv.destination = internals.argv._.shift().toString();
}

index.connect(
{
config: config.getCurrent().settings,
internals: internals
},
Seeder,
function (err, seeder) {
assert.ifError(err);
var seedDir =
internals.mode !== 'static' ? 'vcseeder-dir' : 'staticseeder-dir';

seeder.seedDir = path.resolve(internals.argv[seedDir]);

if (internals.mode === 'static') {
seeder.seed(
internals.argv,
internals.onComplete.bind(this, seeder, internals, callback)
);
} else {
seeder.createSeedsTable(function (err) {
if (_assert(err, callback)) {
seeder.seed(
internals.argv,
internals.onComplete.bind(this, seeder, internals, callback)
);
}
});
seedHook(internals).then(function () {
index.connect(
{
config: config.getCurrent().settings,
internals: internals
},
Seeder,
function (err, seeder) {
assert.ifError(err);
var seedDir =
internals.mode !== 'static' ? 'vcseeder-dir' : 'staticseeder-dir';

seeder.seedDir = path.resolve(internals.argv[seedDir]);

if (internals.mode === 'static') {
seeder.seed(
internals.argv,
internals.onComplete.bind(this, seeder, internals, callback)
);
} else {
seeder.createSeedsTable(function (err) {
if (_assert(err, callback)) {
seeder.seed(
internals.argv,
internals.onComplete.bind(this, seeder, internals, callback)
);
}
});
}
}
}
);
);
});
}

module.exports = executeSeed;
32 changes: 32 additions & 0 deletions lib/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var path = require('path');
var log = require('db-migrate-shared').log;
var Skeleton = require('./skeleton');

var filesRegEx = /\.js$/;

var Seed = Skeleton.extend({
init: function () {
if (arguments.length >= 3) {
Expand Down Expand Up @@ -95,6 +97,36 @@ var Seed = Skeleton.extend({
}
});

Seed.registerHook = function (Plugin, internals) {
var plugin = Plugin.hook('seeder:Seed:hook:require');
internals.parser = internals.parser || {
filesRegEx: filesRegEx,
extensions: 'js'
};

if (!plugin) {
return Promise.resolve(null);
}

return Promise.resolve(plugin)
.map(function (plugin) {
return plugin['seeder:Seed:hook:require']();
})
.each(function (parser) {
if (parser && parser.extensions) {
internals.parser.extensions =
internals.parser.extensions + '|' + parser.extensions;
}
})
.then(function () {
internals.parser.filesRegEx = new RegExp(
'\\.(' + internals.parser.extensions + ')$'
);

return internals.parser;
});
};

Seed.loadFromFilesystem = function (dir, internals, callback) {
log.verbose('loading seeds from dir', dir);
fs.readdir(dir, function (err, files) {
Expand Down

0 comments on commit 6f40d6b

Please sign in to comment.