UNPKG

@codecovevienna/gittt-cli

Version:

Tracking time with CLI into a git repository

33 lines (32 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExportHelper = void 0; const xlsx_1 = require("xlsx"); const moment = require("moment"); class ExportHelper { static export(path = process.cwd(), name = "gittt-export", type = "ods", projects = []) { const filePath = `${path}/${name}.${type}`; const wb = xlsx_1.utils.book_new(); for (const project of projects) { const sheetData = [ ["Date", "Type", "Amount", "Comment"], ]; for (let i = 1; i <= project.records.length; i++) { const recordData = []; const tmpRecord = project.records[i - 1]; recordData[0] = moment(tmpRecord.end).toDate(); recordData[1] = tmpRecord.type; recordData[2] = tmpRecord.amount; recordData[3] = tmpRecord.message; sheetData[i] = recordData; } const ws = xlsx_1.utils.aoa_to_sheet(sheetData); xlsx_1.utils.book_append_sheet(wb, ws, project.name); } (0, xlsx_1.writeFile)(wb, filePath, { cellDates: true, bookType: type }); } } exports.ExportHelper = ExportHelper;