diff --git a/build/business/alias/index.js b/build/business/alias/index.js deleted file mode 100644 index 7424a83..0000000 --- a/build/business/alias/index.js +++ /dev/null @@ -1,92 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.removeAllAliases = exports.removeAlias = exports.getAliasOrCreate = exports.addAlias = void 0; -const harvest_1 = require("../../service/api/harvest"); -const error_1 = require("../error"); -const alias_1 = require("../../service/filesystem/alias"); -const alias_2 = require("../../cli/user-input/alias"); -const cli_output_1 = require("../../cli/cli-output"); -class AliasNotFoundError extends error_1.HarveyError { -} -async function addAlias(aliasKey, searchString) { - return new Promise((resolve) => { - const aliasSearchTerm = searchString ?? aliasKey; - (0, harvest_1.getMyProjectTaskAssignments)().then((projectTaskAssignments) => { - const filteredProjectTaskAssignments = projectTaskAssignments.filter((projectTaskAssignment) => { - return projectTaskAssignment.task.name.includes(aliasSearchTerm); - }); - if (filteredProjectTaskAssignments.length === 0) { - throw new Error(`Task "${aliasSearchTerm}" was not found.`); - } - if (filteredProjectTaskAssignments.length > 10) { - throw new Error(`Too many tasks for "${aliasSearchTerm}" were found. Please use a more specific alias.`); - } - findSingleProjectTaskAssignment(aliasKey, filteredProjectTaskAssignments).then((projectTaskAssignment) => { - const alias = mapProjectTaskAssignmentToAlias(aliasKey, projectTaskAssignment); - storeAlias(alias); - resolve(alias); - }); - }); - }); -} -exports.addAlias = addAlias; -async function getAliasOrCreate(aliasKey) { - return new Promise((resolve) => { - try { - const alias = getAlias(aliasKey); - resolve(alias); - } - catch (error) { - if (!(error instanceof AliasNotFoundError)) { - throw error; - } - addAlias(aliasKey).then(resolve); - } - }); -} -exports.getAliasOrCreate = getAliasOrCreate; -function getAlias(aliasKey) { - const alias = (0, alias_1.readAliasFile)().get(aliasKey); - if (!alias) { - throw new AliasNotFoundError(); - } - return alias; -} -function removeAlias(aliasKey) { - const aliases = (0, alias_1.readAliasFile)(); - if (!aliases.has(aliasKey)) { - throw new Error(`"${aliasKey}" was not found. Nothing to remove.`); - } - aliases.delete(aliasKey); - (0, alias_1.writeAliasFile)(aliases); -} -exports.removeAlias = removeAlias; -function removeAllAliases() { - (0, alias_1.writeAliasFile)(new Map()); -} -exports.removeAllAliases = removeAllAliases; -async function findSingleProjectTaskAssignment(aliasKey, projectTaskAssignments) { - return new Promise((resolve) => { - if (projectTaskAssignments.length == 1) { - resolve(projectTaskAssignments[0]); - return; - } - (0, cli_output_1.printMessage)(`Multiple tasks for "${aliasKey}" were found:`); - projectTaskAssignments.forEach((projectTaskAssignment, index) => { - (0, cli_output_1.printMessage)(`${index} - ${projectTaskAssignment.task.name} (${projectTaskAssignment.project.name})`); - }); - (0, alias_2.askToChooseTaskProjectAssignmentForAliasing)(projectTaskAssignments).then(resolve); - }); -} -function mapProjectTaskAssignmentToAlias(aliasKey, projectTaskAssignment) { - return { - alias: aliasKey, - idProject: projectTaskAssignment.project.id, - idTask: projectTaskAssignment.task.id, - }; -} -function storeAlias(alias) { - const aliases = (0, alias_1.readAliasFile)(); - aliases.set(alias.alias, alias); - (0, alias_1.writeAliasFile)(aliases); -} diff --git a/build/business/config/index.js b/build/business/config/index.js deleted file mode 100644 index 11c1a4c..0000000 --- a/build/business/config/index.js +++ /dev/null @@ -1,65 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.initializeConfig = exports.defaultConfig = exports.HarveyConfig = void 0; -const cli_output_1 = require("../../cli/cli-output"); -const config_1 = require("../../cli/user-input/config"); -const harvest_1 = require("../../service/api/harvest"); -const config_2 = require("../../service/filesystem/config"); -class HarveyConfig { - constructor() { - throw new Error("Don't use the constructor of this class. Only use it's static methods."); - } - static getConfig() { - if (!this.config) { - throw new Error('Global config was never initialised.'); - } - return this.config; - } - static loadConfig(configFilePath) { - this.config = (0, config_2.readConfigFile)(configFilePath); - return this.config; - } - static setConfig(config) { - this.config = config; - } - static resetConfig() { - this.config = undefined; - } -} -exports.HarveyConfig = HarveyConfig; -exports.defaultConfig = { - accountId: '', - accessToken: '', - aliasFilePath: '~/.config/harvey/aliases.json', - pausedTimerFilePath: '~/.config/harvey/paused_timer.json', - defaultRoundingInterval: 15, - fileParser: { - type: 'xlsx', - worksheet: 'Timebooking', - aliasColumn: 'Link', - minutesColumn: 'Minutes', - }, -}; -async function initializeConfig(filePath) { - return new Promise((resolve) => { - const newConfig = exports.defaultConfig; - (0, config_1.askForHarvestAccountId)().then((accountId) => { - newConfig.accountId = accountId; - (0, config_1.askForPersonalAccessToken)().then((token) => { - newConfig.accessToken = token; - (0, harvest_1.isAccountIdAndTokenValid)(newConfig.accountId, newConfig.accessToken).then((credentialsAreValid) => { - if (credentialsAreValid) { - (0, config_2.writeConfigFile)(newConfig, filePath); - (0, cli_output_1.printMessage)(`Sucessfully generated config "${filePath}".`); - resolve(); - } - else { - (0, cli_output_1.printMessage)('Could not authenticate, please try again.'); - initializeConfig(filePath).then(resolve); - } - }); - }); - }); - }); -} -exports.initializeConfig = initializeConfig; diff --git a/build/business/day/index.js b/build/business/day/index.js deleted file mode 100644 index bca41da..0000000 --- a/build/business/day/index.js +++ /dev/null @@ -1,91 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.TimeEntryModifyAction = exports.modifyDay = exports.roundDay = exports.printDay = void 0; -const harvest_1 = require("../../service/api/harvest"); -const day_1 = require("../../cli/user-input/day"); -const day_2 = require("../../cli/cli-output/day"); -const round_1 = require("../round"); -async function printDay(date) { - return new Promise((resolve) => { - (0, harvest_1.getMyTimeEntriesPerDate)(date).then((timeEntries) => { - (0, day_2.printTimeEntryTable)(timeEntries); - resolve(); - }); - }); -} -exports.printDay = printDay; -async function roundDay(date, roundingInterval) { - return new Promise((resolve) => { - (0, harvest_1.getMyTimeEntriesPerDate)(date).then((timeEntries) => { - const updatePromises = []; - timeEntries.forEach((timeEntry) => { - timeEntry = (0, round_1.roundTimeEntry)(timeEntry, roundingInterval); - updatePromises.push((0, harvest_1.saveTimeEntry)(timeEntry)); - }); - Promise.all(updatePromises).then(() => resolve()); - }); - }); -} -exports.roundDay = roundDay; -async function modifyDay(date, roundingInterval) { - return new Promise((resolve) => { - (0, harvest_1.getMyTimeEntriesPerDate)(date).then((timeEntries) => { - (0, day_2.printTimeEntryTable)(timeEntries); - (0, day_1.askToChooseTimeEntryToModify)(timeEntries).then((timeEntry) => { - modifyTimeEntry(timeEntry, roundingInterval).then(resolve); - }); - }); - }); -} -exports.modifyDay = modifyDay; -var TimeEntryModifyAction; -(function (TimeEntryModifyAction) { - TimeEntryModifyAction[TimeEntryModifyAction["time"] = 0] = "time"; - TimeEntryModifyAction[TimeEntryModifyAction["notes"] = 1] = "notes"; - TimeEntryModifyAction[TimeEntryModifyAction["round"] = 2] = "round"; - TimeEntryModifyAction[TimeEntryModifyAction["delete"] = 3] = "delete"; -})(TimeEntryModifyAction = exports.TimeEntryModifyAction || (exports.TimeEntryModifyAction = {})); -async function modifyTimeEntry(timeEntry, roundingInterval) { - return new Promise((resolve) => { - (0, day_1.askForTimeEntryModifyAction)().then((modifyAction) => { - switch (modifyAction) { - case TimeEntryModifyAction.time: - setNewTimeEntryTime(timeEntry).then(resolve); - break; - case TimeEntryModifyAction.notes: - setNewTimeEntryNote(timeEntry).then(resolve); - break; - case TimeEntryModifyAction.round: - roundAndSaveTimeEntry(timeEntry, roundingInterval).then(resolve); - break; - case TimeEntryModifyAction.delete: - (0, harvest_1.deleteTimeEntry)(timeEntry).then(resolve); - break; - } - }); - }); -} -async function roundAndSaveTimeEntry(timeEntry, roundingInterval) { - return new Promise((resolve) => { - timeEntry = (0, round_1.roundTimeEntry)(timeEntry, roundingInterval); - (0, harvest_1.saveTimeEntry)(timeEntry).then(() => resolve()); - }); -} -async function setNewTimeEntryTime(timeEntry) { - return new Promise((resolve) => { - (0, day_1.askForNewHours)().then((hours) => { - timeEntry.hours = hours; - (0, harvest_1.saveTimeEntry)(timeEntry).then(() => resolve()); - }); - }); -} -async function setNewTimeEntryNote(timeEntry) { - return new Promise((resolve) => { - (0, day_1.askForNewNote)().then((newNote) => { - timeEntry.notes = newNote; - (0, harvest_1.saveTimeEntry)(timeEntry).then(() => { - resolve(); - }); - }); - }); -} diff --git a/build/business/error/index.js b/build/business/error/index.js deleted file mode 100644 index 5fe1eed..0000000 --- a/build/business/error/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleError = exports.HarveyFileNotFoundError = exports.HarveyError = void 0; -const cli_output_1 = require("../../cli/cli-output"); -class HarveyError extends Error { -} -exports.HarveyError = HarveyError; -class HarveyFileNotFoundError extends HarveyError { -} -exports.HarveyFileNotFoundError = HarveyFileNotFoundError; -function handleError(error) { - if (error instanceof HarveyError) { - (0, cli_output_1.printMessage)(`${error.message}`); - } - else { - throw error; - } -} -exports.handleError = handleError; diff --git a/build/business/harvest/index.js b/build/business/harvest/index.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/business/harvest/index.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/business/parser/file-parser/csv-file-parser.js b/build/business/parser/file-parser/csv-file-parser.js deleted file mode 100644 index ef5fa34..0000000 --- a/build/business/parser/file-parser/csv-file-parser.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.CsvFileParser = void 0; -const error_1 = require("../../error"); -class CsvFileParser { - constructor() { - this.parserKey = 'csv'; - } - async parseFile(filePath) { - throw new error_1.HarveyError(`Cannot parse ${filePath} yet. CSV file parser is not yet implemented.`); - } -} -exports.CsvFileParser = CsvFileParser; diff --git a/build/business/parser/file-parser/xlsx-file-parser.js b/build/business/parser/file-parser/xlsx-file-parser.js deleted file mode 100644 index 26d2141..0000000 --- a/build/business/parser/file-parser/xlsx-file-parser.js +++ /dev/null @@ -1,61 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.XlsxFileParser = void 0; -const exceljs_1 = require("exceljs"); -const user_input_1 = require("../../../cli/user-input"); -const config_1 = require("../../config"); -const error_1 = require("../../error"); -class XlsxFileParser { - constructor() { - this.parserKey = 'xlsx'; - } - async parseFile(filePath) { - return new Promise((resolve) => { - const config = config_1.HarveyConfig.getConfig(); - this.readFile(filePath).then((workbook) => { - var _a, _b, _c; - const worksheet = this.findWorksheetByName(((_a = config.fileParser).worksheet ?? (_a.worksheet = 'Timebooking')), workbook); - const aliasHeadingCell = this.findCellByValue(((_b = config.fileParser).aliasColumn ?? (_b.aliasColumn = 'Link')), worksheet); - const minutesHeadingCell = this.findCellByValue(((_c = config.fileParser).minutesColumn ?? (_c.minutesColumn = 'Minutes')), worksheet); - let aliasCell = worksheet.getCell(aliasHeadingCell.row + 1, aliasHeadingCell.col); - let minutesCell = worksheet.getCell(minutesHeadingCell.row + 1, minutesHeadingCell.col); - const entries = []; - while (aliasCell.text) { - entries.push({ - alias: aliasCell.text, - hours: (0, user_input_1.parseUserTimeInput)(minutesCell.text), - }); - aliasCell = worksheet.getCell(aliasCell.row + 1, aliasCell.col); - minutesCell = worksheet.getCell(minutesCell.row + 1, minutesCell.col); - } - resolve(entries); - }); - }); - } - async readFile(filePath) { - const workbook = new exceljs_1.Workbook(); - return workbook.xlsx.readFile(filePath); - } - findWorksheetByName(name, workbook) { - const foundWorksheet = workbook.worksheets.find((worksheet) => { - return worksheet.name.toLowerCase().includes(name.toLowerCase()); - }); - if (foundWorksheet) { - return foundWorksheet; - } - throw new error_1.HarveyError(`Could not find worksheet "${name}".`); - } - findCellByValue(value, worksheet) { - let match; - worksheet.eachRow((row) => row.eachCell((cell) => { - if (cell.text && cell.text.toLowerCase().includes(value.toLowerCase())) { - match = cell; - } - })); - if (match) { - return match; - } - throw new error_1.HarveyError(`Could not find cell with value "${value}".`); - } -} -exports.XlsxFileParser = XlsxFileParser; diff --git a/build/business/parser/index.js b/build/business/parser/index.js deleted file mode 100644 index d67fb56..0000000 --- a/build/business/parser/index.js +++ /dev/null @@ -1,74 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.parseFileAndBookEntries = void 0; -const alias_1 = require("../alias"); -const config_1 = require("../config"); -const error_1 = require("../error"); -const harvest_1 = require("../../service/api/harvest"); -const csv_file_parser_1 = require("./file-parser/csv-file-parser"); -const xlsx_file_parser_1 = require("./file-parser/xlsx-file-parser"); -function getFileParsers() { - return [new csv_file_parser_1.CsvFileParser(), new xlsx_file_parser_1.XlsxFileParser()]; -} -function getFileParserByKey(fileParserKey) { - const fileParsers = getFileParsers(); - const foundFileParser = fileParsers.find((fileParser) => { - return fileParser.parserKey == fileParserKey; - }); - if (!foundFileParser) { - throw new error_1.HarveyError(`No file parser implemented for type "${fileParserKey}".`); - } - return foundFileParser; -} -async function parseFileAndBookEntries(filePath, date, note) { - return new Promise((resolve) => { - const config = config_1.HarveyConfig.getConfig(); - const fileParser = getFileParserByKey(config.fileParser.type); - fileParser.parseFile(filePath).then((entries) => { - bookEntries(entries, date, note).then(() => resolve()); - }); - }); -} -exports.parseFileAndBookEntries = parseFileAndBookEntries; -async function bookEntries(entries, date, note) { - return new Promise((resolve) => { - findAliases(entries).then((aliases) => { - const timeEntries = mapAliasesAndEntriesToHarvestTimeEntry(aliases, entries, date, note); - const timeEntryCreationPromises = []; - for (const timeEntry of timeEntries) { - timeEntryCreationPromises.push((0, harvest_1.saveTimeEntry)(timeEntry)); - } - Promise.all(timeEntryCreationPromises).then(() => { - resolve(); - }); - }); - }); -} -async function findAliases(entries) { - const aliases = []; - for (const entry of entries) { - aliases.push(await (0, alias_1.getAliasOrCreate)(entry.alias)); - } - return new Promise((resolve) => { - resolve(aliases); - }); -} -function mapAliasesAndEntriesToHarvestTimeEntry(aliases, entries, date, note) { - const harvestTimeEntries = []; - for (const entry of entries) { - const alias = aliases.find((alias) => { - return alias.alias == entry.alias; - }); - if (!alias) { - throw new error_1.HarveyError(`Alias "${entry.alias}" not found.`); - } - harvestTimeEntries.push({ - task_id: alias.idTask, - project_id: alias.idProject, - hours: entry.hours, - notes: note, - spent_date: date, - }); - } - return harvestTimeEntries; -} diff --git a/build/business/round/index.js b/build/business/round/index.js deleted file mode 100644 index d209c08..0000000 --- a/build/business/round/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.roundTimeEntry = void 0; -function roundTimeEntry(timeEntry, roundingInterval) { - const minutes = timeEntry.hours * 60; - timeEntry.hours = (Math.ceil(minutes / roundingInterval) * roundingInterval) / 60; - return timeEntry; -} -exports.roundTimeEntry = roundTimeEntry; diff --git a/build/business/timer/index.js b/build/business/timer/index.js deleted file mode 100644 index 449b387..0000000 --- a/build/business/timer/index.js +++ /dev/null @@ -1,204 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.stopRunningTimer = exports.updateTimer = exports.startTimer = exports.resumePausedTimer = exports.pauseActiveTimer = exports.showTimer = exports.HarveyTimerStatus = void 0; -const alias_1 = require("../alias"); -const error_1 = require("../error"); -const harvest_1 = require("../../service/api/harvest"); -const timer_1 = require("../../cli/cli-output/timer"); -const round_1 = require("../round"); -const timer_2 = require("../../service/filesystem/timer"); -var HarveyTimerStatus; -(function (HarveyTimerStatus) { - HarveyTimerStatus[HarveyTimerStatus["stopped"] = 0] = "stopped"; - HarveyTimerStatus[HarveyTimerStatus["running"] = 1] = "running"; - HarveyTimerStatus[HarveyTimerStatus["paused"] = 2] = "paused"; -})(HarveyTimerStatus = exports.HarveyTimerStatus || (exports.HarveyTimerStatus = {})); -async function showTimer() { - return new Promise((resolve) => { - const pausedTimer = getPausedTimer(); - (0, harvest_1.getRunningTimeEntry)().then((activeTimer) => { - if (!pausedTimer && !activeTimer) { - (0, timer_1.printTimer)({ status: HarveyTimerStatus.stopped }); - } - else if (activeTimer) { - (0, timer_1.printTimer)({ status: HarveyTimerStatus.running, timeEntry: activeTimer }); - } - else if (pausedTimer) { - (0, timer_1.printTimer)({ status: HarveyTimerStatus.paused, timeEntry: pausedTimer }); - } - resolve(); - }); - }); -} -exports.showTimer = showTimer; -async function pauseActiveTimer() { - return new Promise((resolve) => { - (0, harvest_1.getRunningTimeEntry)().then((activeTimer) => { - if (!activeTimer) { - throw new error_1.HarveyError('No active timer to pause.'); - } - (0, harvest_1.stopTimeEntry)(activeTimer).then((stoppedTimer) => { - (0, timer_2.storePausedTimer)(stoppedTimer); - resolve(); - }); - }); - }); -} -exports.pauseActiveTimer = pauseActiveTimer; -function resumePausedTimer() { - return new Promise((resolve) => { - (0, harvest_1.getRunningTimeEntry)().then((activeTimer) => { - const pausedTimer = (0, timer_2.readPausedTimer)(); - if (!activeTimer && !pausedTimer) { - throw new error_1.HarveyError('No paused timer to resume available.'); - } - if (activeTimer) { - (0, timer_2.deletePausedTimer)(); - resolve(); - } - if (pausedTimer) { - (0, harvest_1.restartTimeEntry)(pausedTimer).then(() => { - (0, timer_2.deletePausedTimer)(); - resolve(); - }); - } - }); - }); -} -exports.resumePausedTimer = resumePausedTimer; -function startTimer(alias, date, note) { - return new Promise((resolve) => { - (0, timer_2.deletePausedTimer)(); - (0, harvest_1.getRunningTimeEntry)().then((activeTimer) => { - if (activeTimer) { - throw new error_1.HarveyError('Timer already running. Please stop it, before starting a new one.'); - } - (0, alias_1.getAliasOrCreate)(alias).then((aliasEntry) => { - (0, harvest_1.saveTimeEntry)({ - project_id: aliasEntry.idProject, - task_id: aliasEntry.idTask, - hours: 0, - notes: note, - spent_date: date, - is_running: true, - }).then(() => { - resolve(); - }); - }); - }); - }); -} -exports.startTimer = startTimer; -function updateTimer(date, note, addHours, subtractHours, round, roundingInterval) { - return new Promise((resolve, reject) => { - const hourDiff = getHourTimeDiff(addHours ?? 0, subtractHours ?? 0); - if (hourDiff !== 0 && round) { - reject(new error_1.HarveyError('Rounding and adding/subtracting are exclusive timer actions. Please only use one.')); - return; - } - const promises = [ - updateRunningTimer(date, note, hourDiff, round ?? false, roundingInterval), - updatePausedTimer(date, note, hourDiff, round ?? false, roundingInterval), - ]; - Promise.all(promises) - .then(() => { - resolve(); - }) - .catch((error) => { - reject(error); - }); - }); -} -exports.updateTimer = updateTimer; -function getHourTimeDiff(addHours, subtractHours) { - return addHours - subtractHours; -} -function setHourTimeDiffOnTimeEntry(timeEntry, hourDiff) { - const newHours = timeEntry.hours + hourDiff; - if (newHours < 0) { - throw new error_1.HarveyError('Cannot set time entries new to time to a value below 0.'); - } - if (newHours > 24) { - throw new error_1.HarveyError('Cannot set time entries new to time to a value above 24h.'); - } - timeEntry.hours = newHours; - return timeEntry; -} -async function updateRunningTimer(date, note, hourDiff, round, roundingInterval) { - return new Promise((resolve, reject) => { - (0, harvest_1.getRunningTimeEntry)().then((activeTimer) => { - if (activeTimer) { - try { - activeTimer = setUpdatesOnTimeEntry(activeTimer, date, note, hourDiff, round, roundingInterval); - } - catch (error) { - reject(error); - return; - } - (0, harvest_1.saveTimeEntry)(activeTimer) - .then(() => resolve()) - .catch(reject); - } - else { - resolve(); - } - }); - }); -} -async function updatePausedTimer(date, note, hourDiff, round, roundingInterval) { - return new Promise((resolve, reject) => { - let pausedTimer = (0, timer_2.readPausedTimer)(); - if (pausedTimer) { - try { - pausedTimer = setUpdatesOnTimeEntry(pausedTimer, date, note, hourDiff, round, roundingInterval); - } - catch (error) { - reject(error); - return; - } - (0, harvest_1.saveTimeEntry)(pausedTimer) - .then((updatedTimer) => { - (0, timer_2.storePausedTimer)(updatedTimer); - resolve(); - }) - .catch(reject); - } - else { - resolve(); - } - }); -} -function setUpdatesOnTimeEntry(timeEntry, date, note, hourDiff, round, roundingInterval) { - if (date) - timeEntry.spent_date = date; - if (note) - timeEntry.notes = note; - if (round) { - timeEntry = (0, round_1.roundTimeEntry)(timeEntry, roundingInterval); - } - timeEntry = setHourTimeDiffOnTimeEntry(timeEntry, hourDiff); - return timeEntry; -} -function stopRunningTimer(round, roundingInterval) { - return new Promise((resolve) => { - (0, harvest_1.getRunningTimeEntry)().then((activeTimer) => { - (0, timer_2.deletePausedTimer)(); - if (activeTimer) { - (0, harvest_1.stopTimeEntry)(activeTimer).then((stoppedTimer) => { - if (round) { - stoppedTimer = (0, round_1.roundTimeEntry)(stoppedTimer, roundingInterval); - (0, harvest_1.saveTimeEntry)(stoppedTimer).then(() => resolve()); - } - resolve(); - }); - } - else { - resolve(); - } - }); - }); -} -exports.stopRunningTimer = stopRunningTimer; -function getPausedTimer() { - return (0, timer_2.readPausedTimer)(); -} diff --git a/build/cli/cli-output/day.js b/build/cli/cli-output/day.js deleted file mode 100644 index a7c82d9..0000000 --- a/build/cli/cli-output/day.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.printTimeEntryTable = void 0; -const cli_table_1 = __importDefault(require("cli-table")); -const _1 = require("."); -function printTimeEntryTable(timeEntries) { - let totalTime = 0; - const table = new cli_table_1.default({ - head: ['ID', 'Task', 'Notes', 'Time'], - colWidths: [4, 49, 20, 7], - }); - timeEntries.forEach((timeEntry, index) => { - totalTime += timeEntry.hours; - table.push([index, timeEntry.task?.name ?? '', timeEntry.notes ?? '', (0, _1.formatHours)(timeEntry.hours)]); - }); - process.stdout.write(table.toString() + '\n'); - process.stdout.write(' Sum: ' + (0, _1.formatHours)(totalTime) + '\n\n'); -} -exports.printTimeEntryTable = printTimeEntryTable; diff --git a/build/cli/cli-output/index.js b/build/cli/cli-output/index.js deleted file mode 100644 index 31ede24..0000000 --- a/build/cli/cli-output/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.formatHours = exports.printMessage = void 0; -function printMessage(message) { - process.stdout.write(message + '\n'); -} -exports.printMessage = printMessage; -function formatHours(hours) { - const fullHours = Math.floor(hours); - const minutes = (hours - fullHours) * 60; - return `${fullHours}:${String(Math.floor(minutes)).padStart(2, '0')}`; -} -exports.formatHours = formatHours; diff --git a/build/cli/cli-output/timer.js b/build/cli/cli-output/timer.js deleted file mode 100644 index 77f4dd8..0000000 --- a/build/cli/cli-output/timer.js +++ /dev/null @@ -1,39 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.printTimer = void 0; -const cli_table_1 = __importDefault(require("cli-table")); -const _1 = require("."); -const timer_1 = require("../../business/timer"); -function printTimer(timer) { - const timeEntry = timer.timeEntry; - let tableHead = ['Status']; - let colWidth = [9]; - let tableRow = [getStatusString(timer.status)]; - if (timeEntry && timeEntry.task) { - tableHead = tableHead.concat(['Task', 'Notes', 'Timer']); - colWidth = colWidth.concat([44, 20, 7]); - tableRow = tableRow.concat([timeEntry.task.name, (timeEntry.notes ?? (timeEntry.notes = '')), (0, _1.formatHours)(timeEntry.hours)]); - } - const table = new cli_table_1.default({ - head: tableHead, - colWidths: colWidth, - }); - table.push(tableRow); - process.stdout.write(table.toString() + '\n'); -} -exports.printTimer = printTimer; -function getStatusString(status) { - switch (status) { - case timer_1.HarveyTimerStatus.stopped: - return 'STOPPED'; - case timer_1.HarveyTimerStatus.running: - return 'RUNNING'; - case timer_1.HarveyTimerStatus.paused: - return 'PAUSED'; - default: - throw new Error('Cannot format status.'); - } -} diff --git a/build/cli/command/alias.js b/build/cli/command/alias.js deleted file mode 100644 index 93b16c3..0000000 --- a/build/cli/command/alias.js +++ /dev/null @@ -1,49 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.handler = exports.builder = exports.desc = exports.command = void 0; -const alias_1 = require("../../business/alias"); -const config_1 = require("../../business/config"); -const error_1 = require("../../business/error"); -exports.command = 'alias []'; -exports.desc = 'Manages Harvey aliases.'; -const builder = (yargs) => yargs - .options({ - search: { type: 'string', alias: 's' }, - config: { type: 'string', alias: 'c', default: '~/.config/harvey/config.json' }, -}) - .positional('alias', { type: 'string', demandOption: false }) - .positional('action', { - type: 'string', - demandOption: true, - choices: ['add', 'remove', 'remove-all'], -}); -exports.builder = builder; -const handler = async (argv) => { - const { config, alias, action, search } = argv; - try { - config_1.HarveyConfig.loadConfig(config); - switch (action) { - case 'add': - if (!alias) { - throw new error_1.HarveyError(' is required to add an alias.'); - } - await (0, alias_1.addAlias)(alias, search); - break; - case 'remove': - if (!alias) { - throw new error_1.HarveyError(' is required to remove an alias.'); - } - await (0, alias_1.removeAlias)(alias); - break; - case 'remove-all': - await (0, alias_1.removeAllAliases)(); - break; - } - } - catch (error) { - (0, error_1.handleError)(error); - process.exit(1); - } - process.exit(0); -}; -exports.handler = handler; diff --git a/build/cli/command/book.js b/build/cli/command/book.js deleted file mode 100644 index dc7b73f..0000000 --- a/build/cli/command/book.js +++ /dev/null @@ -1,40 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.handler = exports.builder = exports.desc = exports.command = void 0; -const alias_1 = require("../../business/alias"); -const config_1 = require("../../business/config"); -const error_1 = require("../../business/error"); -const harvest_1 = require("../../service/api/harvest"); -const user_input_1 = require("../user-input"); -exports.command = 'book