From 1efa91f8a41bff4a9ca284fadc250937466a2a64 Mon Sep 17 00:00:00 2001 From: Dick Wolff Date: Fri, 2 Feb 2024 10:59:36 +0100 Subject: [PATCH] Remove unused dep, cleanup some console logs --- Dockerfile | 2 +- package.json | 1 - src/converter.ts | 6 ++++++ src/watcher.ts | 15 ++++++++++----- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 36cbff7..5532757 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18-alpine3.19 +FROM node:20-alpine3.19 WORKDIR /app diff --git a/package.json b/package.json index 768c66e..2f2f72e 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "chokidar": "^3.5.3", "cli-progress": "^3.12.0", "closest-match": "^1.3.3", - "cross-fetch": "^4.0.0", "csv-parse": "^5.5.2", "dayjs": "^1.11.10", "dotenv": "^16.3.1", diff --git a/src/converter.ts b/src/converter.ts index 163fb48..a20de21 100644 --- a/src/converter.ts +++ b/src/converter.ts @@ -11,6 +11,11 @@ import { FinpensionConverter } from "./converters/finpensionConverter"; export function createAndRunConverter(converterType: string, inputFilePath: string, outputFilePath: string, completionCallback: CallableFunction, errorCallback: CallableFunction) { + // Verify if Ghostolio account ID is set (because without it there can be no valid output). + if (!process.env.GHOSTFOLIO_ACCOUNT_ID) { + return errorCallback(new Error("Environment variable GHOSTFOLIO_ACCOUNT_ID not set!")); + } + const converterTypeLc = converterType.toLocaleLowerCase(); // Determine convertor type. @@ -29,6 +34,7 @@ export function createAndRunConverter(converterType: string, inputFilePath: stri console.log(`[i] Wrote data to '${outputFileName}.json'!`); completionCallback(); + }, (error) => errorCallback(error)); } diff --git a/src/watcher.ts b/src/watcher.ts index dcea1de..ddc04ae 100644 --- a/src/watcher.ts +++ b/src/watcher.ts @@ -19,7 +19,7 @@ chokidar isProcessing = true; - console.log(`[i] Found ${filePath}!`); + console.log(`[i] Found ${path.basename(filePath)}!`); const fileContents = fs.readFileSync(filePath, "utf-8"); @@ -40,26 +40,31 @@ chokidar () => { // After conversion was succesful, remove input file. - console.log(`[i] Finished converting ${path}, removing file..\n\n`); + console.log(`[i] Finished converting ${path.basename(filePath)}, removing file..`); fs.rmSync(filePath); isProcessing = false; if (!usePolling) { + console.log("[i] Stop container as usePolling is set to false.."); process.exit(0); } }, (err) => { - console.log("[e] An error ocurred while processing. Moving file to output"); + console.log("[e] An error ocurred while processing."); console.log(`[e] Error details: ${err}`); - const errorFilePath = path.join(outputFolder, filePath); - fs.renameSync(filePath, errorFilePath); + // Move file with errors to output folder so it can be fixed manually. + console.log("[e] Moving file to output.."); + const errorFilePath = path.join(outputFolder, path.basename(filePath)); + fs.copyFileSync(filePath, errorFilePath); + fs.rmSync(filePath); isProcessing = false; if (!usePolling) { + console.log("[i] Stop container as usePolling is set to false.."); process.exit(0); } });