2017-02-22 13:20:47 -05:00
|
|
|
/* jslint node: true */
|
|
|
|
|
'use strict';
|
2013-11-13 12:46:55 -05:00
|
|
|
|
2016-12-23 15:49:28 +03:00
|
|
|
var async = require('async');
|
2017-02-22 13:20:47 -05:00
|
|
|
var path = require('path');
|
2013-12-31 13:02:49 -05:00
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
var utils = require('../public/src/utils');
|
2013-11-13 12:46:55 -05:00
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
var Upgrade = {};
|
2013-11-13 12:46:55 -05:00
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
Upgrade.run = function (callback) {
|
|
|
|
|
process.stdout.write('\nParsing upgrade scripts... ');
|
2013-11-13 12:46:55 -05:00
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
utils.walk(path.join(__dirname, './upgrades'), function (err, files) {
|
2015-04-27 20:26:02 -04:00
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
Upgrade.process(files, callback);
|
2013-11-13 12:46:55 -05:00
|
|
|
});
|
|
|
|
|
};
|
2013-10-03 22:36:00 -04:00
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
Upgrade.runSingle = function (query, callback) {
|
|
|
|
|
process.stdout.write('\nParsing upgrade scripts... ');
|
2016-12-09 14:33:59 -05:00
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
async.waterfall([
|
|
|
|
|
async.apply(utils.walk, path.join(__dirname, './upgrades')),
|
|
|
|
|
function (files, next) {
|
|
|
|
|
next(null, files.filter(function (file) {
|
|
|
|
|
return file.search(new RegExp(query)) !== -1;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
], function (err, files) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
2016-12-09 14:33:59 -05:00
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
Upgrade.process(files, callback);
|
|
|
|
|
});
|
|
|
|
|
};
|
2016-12-09 14:33:59 -05:00
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
Upgrade.process = function (files, callback) {
|
|
|
|
|
process.stdout.write('OK'.green + String(' ' + files.length).cyan + ' script(s) found\n'.cyan);
|
2017-01-11 09:43:22 -05:00
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
// Do I need to sort the files here? we'll see.
|
|
|
|
|
// sort();
|
2016-12-09 14:33:59 -05:00
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
async.eachSeries(files, function (file, next) {
|
|
|
|
|
var scriptExport = require(file);
|
|
|
|
|
var date = new Date(scriptExport.timestamp);
|
2016-12-09 14:33:59 -05:00
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
process.stdout.write(' → '.white + String('[' + [date.getFullYear(), date.getMonth() + 1, date.getDate() + 1].join('/') + '] ').gray + String(scriptExport.name).reset + '... ');
|
2016-12-09 14:33:59 -05:00
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
// Do the upgrade...
|
|
|
|
|
scriptExport.method(function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
process.stdout.write('error\n'.red);
|
|
|
|
|
return next(err);
|
2014-03-18 11:44:22 -04:00
|
|
|
}
|
|
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
process.stdout.write('OK\n'.green);
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
}, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
2013-12-06 14:22:31 -05:00
|
|
|
}
|
2015-04-22 10:27:54 -04:00
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
process.stdout.write('Upgrade complete!\n\n'.green);
|
|
|
|
|
callback();
|
2013-12-06 14:22:31 -05:00
|
|
|
});
|
2013-12-31 13:02:49 -05:00
|
|
|
};
|
2013-12-06 14:22:31 -05:00
|
|
|
|
2017-02-22 13:20:47 -05:00
|
|
|
module.exports = Upgrade;
|