Skip to content

Commit

Permalink
feat: move files after importing using config value
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Dec 15, 2023
1 parent 5733bda commit f46f91f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ This tool can be configured using a `.budget-cli.json` file in the root of this
"carryover": 125
}
}
},
"moveFilesAfterImport": {
"AccountTranslatorName1": "/path/to/destination/directory/for/TranslatorName1",
"AccountTranslatorName2": "/path/to/destination/directory/for/TranslatorName2",
}
}
```
Expand All @@ -89,6 +93,7 @@ All keys are optional and will provide defaults.
- `subCategories`: This can be set to an object with `income` and `expense` as keys. Each of those keys must be set to an array of strings indicating the sub-categories to use for each. When importing transactions, the tool will prompt you to select one.
- `expenseTypeMapping`: The keys in the object are expense categories and the values are an expense type of "need" or "want" to automatically map expense categories to types.
- `expenseAllowance`: This can be set to an object with keys indicating a specific year. Each year should be set to an object with expense sub-categories as keys. Each sub-category should be set to an object with the keys `allowance`, indicating how much is allowed per month, and `carryover`, indicating any rollover from the previous year (or `0` if none).
- `moveFilesAfterImport`: This can be set to an object with keys indicating an account name and values indicating an absolute path to a local directory. If a destination path is set for a specific account, the CSV file will be moved there after successful import.

## Usage

Expand Down
6 changes: 6 additions & 0 deletions src/scripts/import.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "path";
import { renameSync } from "fs";

import { getTranslator } from "../translators/index.js";
import { DB } from "../utils/storage.js";
Expand Down Expand Up @@ -183,5 +184,10 @@ export const run = async (
splitRemaining = roundCurrency(splitRemaining - splitAmount);
}
}

const destination = config.moveFilesAfterImport[importAccountName];
if (destination) {
renameSync(currentFile, path.join(destination, csvFile));
}
}
};
2 changes: 2 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const configPath = path.join(process.cwd(), ".budget-cli.json");
const defaultConfig = {
outputFile: "./output/data.csv",
expenseTypeMapping: {},
moveFilesAfterImport: {},
subCategories: {
income: ["salary", "reimbursable", "other"],
expense: [
Expand Down Expand Up @@ -50,6 +51,7 @@ export interface Configuration {
subCategories: SubCategories;
getOutputFile: (args?: CommandArgs) => string;
expenseTypeMapping: { [key: string]: "need" | "want" };
moveFilesAfterImport: { [key: string]: string };
expenseAllowance?: {
[key: string]: Allowance;
};
Expand Down

0 comments on commit f46f91f

Please sign in to comment.