nmig/src/ReportGenerator.ts
2018-09-29 20:58:32 +03:00

50 lines
2 KiB
TypeScript

/*
* This file is a part of "NMIG" - the database migration tool.
*
* Copyright (C) 2016 - present, Anatoly Khaytovich <anatolyuss@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (please see the "LICENSE.md" file).
* If not, see <http://www.gnu.org/licenses/gpl.txt>.
*
* @author Anatoly Khaytovich <anatolyuss@gmail.com>
*/
import { log } from './FsOps';
import Conversion from './Conversion';
import { EventEmitter } from 'events';
/**
* Generates a summary report.
*/
export default (conversion: Conversion, endMsg: string): void => {
let differenceSec: number = ((new Date()).getTime() - conversion._timeBegin.getTime()) / 1000;
const seconds: number = Math.floor(differenceSec % 60);
differenceSec = differenceSec / 60;
const minutes: number = Math.floor(differenceSec % 60);
const hours: number = Math.floor(differenceSec / 60);
const formattedHours: string = hours < 10 ? `0${ hours }` : `${ hours }`;
const formattedMinutes: string = minutes < 10 ? `0${ minutes }` : `${ minutes }`;
const formattedSeconds: string = seconds < 10 ? `0${ seconds }` : `${ seconds }`;
const output: string = `\t--[generateReport] ${ endMsg }
\n\t--[generateReport] Total time: ${ formattedHours }:${ formattedMinutes }:${ formattedSeconds }
\n\t--[generateReport] (hours:minutes:seconds)`;
log(conversion, output);
if (conversion._runsInTestMode) {
(<EventEmitter>conversion._eventEmitter).emit(conversion._migrationCompletedEvent);
return;
}
process.exit();
}