Skip to content

Commit

Permalink
Remove unused dep, cleanup some console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dickwolff committed Feb 2, 2024
1 parent 5444ddf commit 1efa91f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18-alpine3.19
FROM node:20-alpine3.19

WORKDIR /app

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -29,6 +34,7 @@ export function createAndRunConverter(converterType: string, inputFilePath: stri
console.log(`[i] Wrote data to '${outputFileName}.json'!`);

completionCallback();

}, (error) => errorCallback(error));
}

Expand Down
15 changes: 10 additions & 5 deletions src/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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);
}
});
Expand Down

0 comments on commit 1efa91f

Please sign in to comment.