From 5b9e3ec9766d6d5e120021a706443d1a6751262f Mon Sep 17 00:00:00 2001 From: Ariel Gordon Date: Wed, 19 Aug 2020 07:48:58 +0300 Subject: [PATCH 01/26] Add Json Exporter --- src/components/App/Exporters.vue | 12 +++++++++--- .../Exporters/{Exporter.vue => JsonExporter.vue} | 4 +++- src/modules/transactions.js | 3 +++ .../configManager/configManager.ts | 8 ++++++++ .../configManager/defaultConfig.ts | 9 ++++++++- src/originalBudgetTrackingApp/index.ts | 8 ++++++++ .../outputVendors/index.js | 7 ++++++- .../outputVendors/json/index.js | 15 +++++++++++++++ 8 files changed, 60 insertions(+), 6 deletions(-) rename src/components/App/Exporters/{Exporter.vue => JsonExporter.vue} (90%) diff --git a/src/components/App/Exporters.vue b/src/components/App/Exporters.vue index a28e7e4a..7ed05118 100644 --- a/src/components/App/Exporters.vue +++ b/src/components/App/Exporters.vue @@ -5,20 +5,26 @@ Exporters - + diff --git a/src/modules/transactions.js b/src/modules/transactions.js index 29a527cf..ef2f22ba 100644 --- a/src/modules/transactions.js +++ b/src/modules/transactions.js @@ -98,6 +98,9 @@ export function getHash(transaction) { const hashProps = properties.filter((p) => p.hash); const key = hashProps.reduce((prev, prop) => { const value = transaction[prop.name]; + if (!value) { + return ''; + } if (typeof prop.hash === 'function') { return prev + prop.hash(value).toString(); } diff --git a/src/originalBudgetTrackingApp/configManager/configManager.ts b/src/originalBudgetTrackingApp/configManager/configManager.ts index a202ef53..16cff532 100644 --- a/src/originalBudgetTrackingApp/configManager/configManager.ts +++ b/src/originalBudgetTrackingApp/configManager/configManager.ts @@ -15,6 +15,7 @@ export interface Config { outputVendors: { googleSheets?: GoogleSheetsConfig; ynab?: YnabConfig; + json?: JsonConfig; }; scraping: { 'numDaysBack': number; @@ -30,6 +31,13 @@ export interface Config { }; } +export interface JsonConfig { + active: boolean; + options: { + fileName: string; + path:string; + } +} export interface GoogleSheetsConfig { active: boolean; options: { diff --git a/src/originalBudgetTrackingApp/configManager/defaultConfig.ts b/src/originalBudgetTrackingApp/configManager/defaultConfig.ts index 8347a64c..fcdf604a 100644 --- a/src/originalBudgetTrackingApp/configManager/defaultConfig.ts +++ b/src/originalBudgetTrackingApp/configManager/defaultConfig.ts @@ -3,11 +3,18 @@ import { Config } from './configManager'; const DEFAULT_CONFIG: Config = { scraping: { numDaysBack: 40, - showBrowser: false, + showBrowser: true, accountsToScrape: [ ] }, outputVendors: { + json: { + active: true, + options: { + path: '', + fileName: '../transaction.json' + } + }, ynab: { active: false, options: { diff --git a/src/originalBudgetTrackingApp/index.ts b/src/originalBudgetTrackingApp/index.ts index 99fb4618..15d87cf4 100644 --- a/src/originalBudgetTrackingApp/index.ts +++ b/src/originalBudgetTrackingApp/index.ts @@ -3,6 +3,7 @@ import moment from 'moment'; import * as bankScraper from './bankScraper'; import { ScaperScrapingResult, Transaction } from './bankScraper'; import * as ynab from './outputVendors/ynab/ynab'; +import * as json from './outputVendors/json/index'; import { EnrichedTransaction } from './commonTypes'; import * as googleSheets from './outputVendors/googleSheets/googleSheets'; import * as categoryCalculation from './categoryCalculationScript'; @@ -106,6 +107,13 @@ export function calculateTransactionHash({ async function createTransactionsInExternalVendors(config: Config, companyIdToTransactions: Record, startDate: Date) { await ynab.init(config); const activeVendors: any = []; + if (config.outputVendors.json?.active) { + activeVendors.push({ + name: 'json', + createTransactionFunction: json.createTransactions, + options: config.outputVendors.json.options, + }); + } if (config.outputVendors.ynab?.active) { activeVendors.push({ name: 'ynab', diff --git a/src/originalBudgetTrackingApp/outputVendors/index.js b/src/originalBudgetTrackingApp/outputVendors/index.js index ca812f98..bfd95dd6 100644 --- a/src/originalBudgetTrackingApp/outputVendors/index.js +++ b/src/originalBudgetTrackingApp/outputVendors/index.js @@ -8,6 +8,11 @@ // acc[name] = { name, ...vendor }; // return acc; // }, {}); -export default { +import * as json from './json/index'; +export default { + json: { + name: 'json', + ...json + }, }; diff --git a/src/originalBudgetTrackingApp/outputVendors/json/index.js b/src/originalBudgetTrackingApp/outputVendors/json/index.js index 9c621d9c..e15e2ede 100644 --- a/src/originalBudgetTrackingApp/outputVendors/json/index.js +++ b/src/originalBudgetTrackingApp/outputVendors/json/index.js @@ -1,3 +1,6 @@ +import { readFileToObject, writeFile } from '@/modules/filesystem'; +import { transactionArrayToObject } from '@/modules/transactions'; + export const displayName = 'Json'; export const description = 'Create a new Json file with the transactions, or merge them into existing file'; @@ -15,3 +18,15 @@ export const fields = { export const output = async (transactions, config) => { console.log(transactions, config); }; + +export const createTransactions = async (transactionsToCreate, options) => { + const filePath = `${options.fileName}`; + const savedObject = transactionArrayToObject( + readFileToObject(filePath, []), + ); + const combineObject = { ...savedObject, transactionsToCreate }; + writeFile( + filePath, + JSON.stringify(Object.values(combineObject), null, 4), + ); +}; From 1ceb9e78a8b94bc69af416e4425087ce3d65b85c Mon Sep 17 00:00:00 2001 From: Baruch Odem Date: Wed, 26 Aug 2020 21:35:21 +0300 Subject: [PATCH 02/26] fix merge lint --- src/originalBudgetTrackingApp/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/originalBudgetTrackingApp/index.ts b/src/originalBudgetTrackingApp/index.ts index 84685bee..1ccffdec 100644 --- a/src/originalBudgetTrackingApp/index.ts +++ b/src/originalBudgetTrackingApp/index.ts @@ -3,7 +3,6 @@ import moment from 'moment'; import * as bankScraper from './bankScraper'; import { ScaperScrapingResult, Transaction } from './bankScraper'; import * as ynab from './outputVendors/ynab/ynab'; -import * as json from './outputVendors/json/index'; import { EnrichedTransaction } from './commonTypes'; import * as categoryCalculation from './categoryCalculationScript'; import * as configManager from './configManager/configManager'; From e32f357dfb30900e6da34f9ac4378f79b50764a0 Mon Sep 17 00:00:00 2001 From: Baruch Odem Date: Mon, 31 Aug 2020 21:14:59 +0300 Subject: [PATCH 03/26] main.ts remove @ts-nocheck use composition --- .eslintrc.js | 2 +- package.json | 1 + src/main.ts | 29 ++++++++++++----------------- src/store/plugins/vuex-persist.d.ts | 8 ++++++++ yarn.lock | 12 ++++++++++++ 5 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 src/store/plugins/vuex-persist.d.ts diff --git a/.eslintrc.js b/.eslintrc.js index 87f4bb56..9fb7e0c9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -48,7 +48,7 @@ module.exports = { // 'no-param-reassign': ['error', { ignorePropertyModificationsFor: ['state'] }], 'no-param-reassign': 'off', 'no-shadow': ['error', { allow: ['state'] }], - 'import/extensions': ['error', { js: 'never', vue: 'never', json: 'always' }], + 'import/extensions': ['off'], 'no-plusplus': ['error', { allowForLoopAfterthoughts: true }], // allow debugger during development 'no-debugger': productionError, diff --git a/package.json b/package.json index fac4d44b..2438ca1b 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@brafdlog/israeli-bank-scrapers-core": "^0.9.2", "@getstation/electron-google-oauth2": "2.1.0", "@sentry/electron": "^1.3.0", + "@vue/composition-api": "^1.0.0-beta.11", "core-js": "^3.4.4", "download-chromium": "^2.2.0", "electron-log": "^4.1.1", diff --git a/src/main.ts b/src/main.ts index c1ff8f49..7aecffd3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,10 +1,9 @@ -// @ts-nocheck -// eslint-disable-next-line import/no-extraneous-dependencies +import VueCompositionAPI, { h, ref } from '@vue/composition-api'; import electron from 'electron'; import Vue from 'vue'; -import App from './components/App'; +import App from './components/App.vue'; import FormField from './components/shared/FormField'; -import SplashScreen from './components/SplashScreen'; +import SplashScreen from './components/SplashScreen.vue'; import { initializeReporter } from './modules/reporting'; import LoggerPlugin from './plugins/logger'; import vuetify from './plugins/vuetify'; @@ -22,6 +21,8 @@ const logger = electron.remote.getGlobal('logger'); logger.info('The renderer process got the logger'); Vue.use(LoggerPlugin, { logger }); +Vue.use(VueCompositionAPI); + Vue.config.productionTip = process.env.NODE_ENV !== 'production'; Vue.component('form-field', FormField); @@ -33,18 +34,12 @@ new Vue({ name: 'IsraeliBankScrapersDesktop', - data() { - return { - loaded: false, - }; - }, - created() { - logger.info('Vue registered'); - this.$store.restored.then(() => { - this.loaded = true; + setup(_, { root }) { + const loaded = ref(false); + root.$store.restored.then(() => { + loaded.value = true; }); - }, - render(h) { - return this.loaded ? h(App) : h(SplashScreen); - }, + + return () => (loaded.value ? h(App) : h(SplashScreen)); + } }).$mount('#app'); diff --git a/src/store/plugins/vuex-persist.d.ts b/src/store/plugins/vuex-persist.d.ts new file mode 100644 index 00000000..ae9567f0 --- /dev/null +++ b/src/store/plugins/vuex-persist.d.ts @@ -0,0 +1,8 @@ +import Vue, { VNode } from 'vue' +import { Store } from 'vuex' + +declare module 'vuex' { + export interface Store { + restored: Promise + } +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 0fc84ad5..a022c1a1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1994,6 +1994,13 @@ optionalDependencies: prettier "^1.18.2" +"@vue/composition-api@^1.0.0-beta.11": + version "1.0.0-beta.11" + resolved "https://registry.yarnpkg.com/@vue/composition-api/-/composition-api-1.0.0-beta.11.tgz#260e9d23d59078d7a6358fec53c77a9adc0cd5b5" + integrity sha512-WHwX8e1V2NxQtFn7DsgET3QKAfA8kIm13hT4lCdGMAtxbM1dZ/lczF4wdhmkKtKrZiv657aanXV+cgGFF71krg== + dependencies: + tslib "^2.0.1" + "@vue/eslint-config-prettier@^6.0.0": version "6.0.0" resolved "https://registry.yarnpkg.com/@vue/eslint-config-prettier/-/eslint-config-prettier-6.0.0.tgz#ad5912b308f4ae468458e02a2b05db0b9d246700" @@ -13005,6 +13012,11 @@ tslib@^1.9.0: resolved "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz#eb15d128827fbee2841549e171f45ed338ac7e35" integrity sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA== +tslib@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.0.1.tgz#410eb0d113e5b6356490eec749603725b021b43e" + integrity sha512-SgIkNheinmEBgx1IUNirK0TUD4X9yjjBRTqqjggWCU3pUEqIk3/Uwl3yRixYKT6WjQuGiwDv4NomL3wqRCj+CQ== + tslint@^5.20.1: version "5.20.1" resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.20.1.tgz#e401e8aeda0152bc44dd07e614034f3f80c67b7d" From 508914c00bdf87762e2ec5a5569d5b77d37b8ca0 Mon Sep 17 00:00:00 2001 From: Baruch Odem Date: Tue, 1 Sep 2020 08:16:06 +0300 Subject: [PATCH 04/26] Wrap exporters with ExpansionPanel --- src/components/App/Exporters.vue | 40 +++------ .../App/Exporters/ExpansionPanel.vue | 29 ++++++ src/components/App/Exporters/JsonExporter.vue | 89 +++++-------------- 3 files changed, 62 insertions(+), 96 deletions(-) create mode 100644 src/components/App/Exporters/ExpansionPanel.vue diff --git a/src/components/App/Exporters.vue b/src/components/App/Exporters.vue index 7ed05118..53f4eea1 100644 --- a/src/components/App/Exporters.vue +++ b/src/components/App/Exporters.vue @@ -1,40 +1,22 @@ - diff --git a/src/components/App/Exporters/JsonExporter.vue b/src/components/App/Exporters/JsonExporter.vue index 36699a99..ab1dc6bd 100644 --- a/src/components/App/Exporters/JsonExporter.vue +++ b/src/components/App/Exporters/JsonExporter.vue @@ -1,76 +1,31 @@ - From a11dce9e40e39b1ac5fbb16554ad0c17928160a9 Mon Sep 17 00:00:00 2001 From: Baruch Odem Date: Wed, 16 Sep 2020 17:17:29 +0300 Subject: [PATCH 08/26] Initialize YnabExporter with almost nothing differ from JsonExporter --- src/components/app/Exporters.vue | 6 +- src/components/app/exporters/JsonExporter.vue | 4 +- src/components/app/exporters/YnabExporter.vue | 64 +++++++++++++++++++ .../configManager/configManager.ts | 2 +- 4 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/components/app/exporters/YnabExporter.vue diff --git a/src/components/app/Exporters.vue b/src/components/app/Exporters.vue index 4253779c..a144badc 100644 --- a/src/components/app/Exporters.vue +++ b/src/components/app/Exporters.vue @@ -6,16 +6,20 @@ + + + diff --git a/src/components/app/exporters/JsonExporter.vue b/src/components/app/exporters/JsonExporter.vue index 17d52768..87250ba3 100644 --- a/src/components/app/exporters/JsonExporter.vue +++ b/src/components/app/exporters/JsonExporter.vue @@ -6,12 +6,12 @@ + + + + + Save + + + + + + + diff --git a/src/originalBudgetTrackingApp/configManager/configManager.ts b/src/originalBudgetTrackingApp/configManager/configManager.ts index 566d08d2..04a873b6 100644 --- a/src/originalBudgetTrackingApp/configManager/configManager.ts +++ b/src/originalBudgetTrackingApp/configManager/configManager.ts @@ -33,7 +33,7 @@ export interface Config { export type OutputVendorsNames = keyof Config['outputVendors'] export type OutputVendorsConfigs = Exclude -export type OutputVendorsConfig = Config['outputVendors'][T] +export type OutputVendorsConfig = Exclude interface OutputVendorConfigBase { active: boolean; From 36d393d4f18862dce293e4f16a98b128222a0c26 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 16 Sep 2020 18:16:09 +0300 Subject: [PATCH 09/26] Extract common exporter form logic to a common function --- src/components/app/Exporters.vue | 4 ++- .../app/exporters/GoogleSheetsExporter.vue | 24 +++--------------- src/components/app/exporters/JsonExporter.vue | 22 +++------------- src/components/app/exporters/YnabExporter.vue | 24 +++--------------- .../app/exporters/exportersCommon.ts | 25 +++++++++++++++++++ src/originalBudgetTrackingApp/commonTypes.ts | 3 ++- src/store/modules/config.ts | 2 +- 7 files changed, 41 insertions(+), 63 deletions(-) create mode 100644 src/components/app/exporters/exportersCommon.ts diff --git a/src/components/app/Exporters.vue b/src/components/app/Exporters.vue index 3cb415eb..0eeed593 100644 --- a/src/components/app/Exporters.vue +++ b/src/components/app/Exporters.vue @@ -23,7 +23,9 @@ import YnabExporter from './exporters/YnabExporter.vue'; import ExpansionPanel from './exporters/ExpansionPanel.vue'; export default Vue.extend({ - components: { ExpansionPanel, JsonExporter, GoogleSheetsExporter, YnabExporter }, + components: { + ExpansionPanel, JsonExporter, GoogleSheetsExporter, YnabExporter + }, }); diff --git a/src/components/app/exporters/GoogleSheetsExporter.vue b/src/components/app/exporters/GoogleSheetsExporter.vue index 33fd9bfb..af389a67 100644 --- a/src/components/app/exporters/GoogleSheetsExporter.vue +++ b/src/components/app/exporters/GoogleSheetsExporter.vue @@ -39,35 +39,19 @@ diff --git a/src/components/app/exporters/YnabExporter.vue b/src/components/app/exporters/YnabExporter.vue index d5ea9d79..b64d1878 100644 --- a/src/components/app/exporters/YnabExporter.vue +++ b/src/components/app/exporters/YnabExporter.vue @@ -22,51 +22,12 @@ outlined @change="changed = true" /> - - - + @@ -98,30 +59,29 @@