updated logic to make it a bit simpler to implement per upgrade script

This commit is contained in:
Julian Lam
2017-04-16 13:25:01 -04:00
parent 1cd50a8c30
commit 33082d90cc
4 changed files with 56 additions and 51 deletions

View File

@@ -7,7 +7,7 @@ var path = require('path');
var semver = require('semver');
var db = require('./database');
var utils = require('../public/src/utils');
var file = require('../src/file');
/*
* Need to write an upgrade script for NodeBB? Cool.
@@ -58,7 +58,7 @@ var Upgrade = {
Upgrade.getAll = function (callback) {
async.waterfall([
async.apply(utils.walk, path.join(__dirname, './upgrades')),
async.apply(file.walk, path.join(__dirname, './upgrades')),
function (files, next) {
// Sort the upgrade scripts based on version
var versionA;
@@ -128,7 +128,7 @@ Upgrade.runSingle = function (query, callback) {
process.stdout.write('\nParsing upgrade scripts... ');
async.waterfall([
async.apply(utils.walk, path.join(__dirname, './upgrades')),
async.apply(file.walk, path.join(__dirname, './upgrades')),
function (files, next) {
next(null, files.filter(function (file) {
return path.basename(file, '.js') === query;
@@ -207,14 +207,19 @@ Upgrade.incrementProgress = function () {
this.current += 1;
// Redraw the progress bar
var percentage = Math.floor((this.current / this.total) * 100) + '%';
var filled = Math.floor((this.current / this.total) * 15);
var unfilled = 15 - filled;
var percentage = 0;
var filled = 0;
var unfilled = 15;
if (this.total) {
percentage = Math.floor((this.current / this.total) * 100) + '%';
filled = Math.floor((this.current / this.total) * 15);
unfilled = 15 - filled;
}
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(' → '.white + String('[' + [this.date.getUTCFullYear(), this.date.getUTCMonth() + 1, this.date.getUTCDate()].join('/') + '] ').gray + String(this.script.name).reset + '... ');
process.stdout.write('[' + (filled ? new Array(filled).join('#') : '') + new Array(unfilled).join(' ') + '] (' + this.current + '/' + this.total + ') ' + percentage);
process.stdout.write('[' + (filled ? new Array(filled).join('#') : '') + new Array(unfilled).join(' ') + '] (' + this.current + '/' + (this.total || '??') + ') ' + percentage);
};
module.exports = Upgrade;