Skip to content

Commit

Permalink
Chore: prettier print width to 120 (#606)
Browse files Browse the repository at this point in the history
- **chore is patch**
- **format all**
  • Loading branch information
baruchiro authored Oct 14, 2024
1 parent d37057e commit 3a3bb10
Show file tree
Hide file tree
Showing 65 changed files with 444 additions and 1,265 deletions.
12 changes: 3 additions & 9 deletions .nano-staged.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@ export default {
* @param {string[]} filenames
* @return {string[]}
*/
'{package-lock.json,packages/**/{*.ts,*.tsx,tsconfig.json}}': ({
filenames,
}) => {
'{package-lock.json,packages/**/{*.ts,*.tsx,tsconfig.json}}': ({ filenames }) => {
// if dependencies was changed run type checking for all packages
if (filenames.some((f) => f.endsWith('package-lock.json'))) {
return ['yarn typecheck'];
}

// else run type checking for staged packages
const fileNameToPackageName = (filename) =>
filename
.replace(resolve(process.cwd(), 'packages') + sep, '')
.split(sep)[0];
return [...new Set(filenames.map(fileNameToPackageName))].map(
(p) => `yarn typecheck:${p}`,
);
filename.replace(resolve(process.cwd(), 'packages') + sep, '').split(sep)[0];
return [...new Set(filenames.map(fileNameToPackageName))].map((p) => `yarn typecheck:${p}`);
},
};
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"singleQuote": true
"singleQuote": true,
"printWidth": 120
}
15 changes: 3 additions & 12 deletions packages/main/src/backend/commonTypes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
type CompanyTypes,
type ScraperCredentials,
} from 'israeli-bank-scrapers-core';
import { type CompanyTypes, type ScraperCredentials } from 'israeli-bank-scrapers-core';
import { type Transaction } from 'israeli-bank-scrapers-core/lib/transactions';
import { type Account, type BudgetSummary } from 'ynab';
import { type EventPublisher } from './eventEmitters/EventEmitter';
Expand Down Expand Up @@ -38,14 +35,8 @@ export enum OutputVendorName {
CSV = 'csv',
}

export type OutputVendorConfigs = Exclude<
Config['outputVendors'][OutputVendorName],
undefined
>;
export type OutputVendorConfig<T extends OutputVendorName> = Exclude<
Config['outputVendors'][T],
undefined
>;
export type OutputVendorConfigs = Exclude<Config['outputVendors'][OutputVendorName], undefined>;
export type OutputVendorConfig<T extends OutputVendorName> = Exclude<Config['outputVendors'][T], undefined>;

interface OutputVendorConfigBase {
active: boolean;
Expand Down
9 changes: 2 additions & 7 deletions packages/main/src/backend/configManager/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { existsSync, promises as fs } from 'fs';
import configExample from './defaultConfig';
import logger from '/@/logging/logger';

export async function getConfig(
configPath: string = configFilePath,
): Promise<Config> {
export async function getConfig(configPath: string = configFilePath): Promise<Config> {
const configFromFile = await getConfigFromFile(configPath);
if (configFromFile) {
const decrypted = (await decrypt(configFromFile)) as string;
Expand All @@ -31,10 +29,7 @@ export async function getConfig(
return configExample;
}

export async function updateConfig(
configPath: string,
configToUpdate: Config,
): Promise<void> {
export async function updateConfig(configPath: string, configToUpdate: Config): Promise<void> {
const stringifiedConfig = JSON.stringify(configToUpdate, null, 2);
const encryptedConfigStr = await encrypt(stringifiedConfig);
await fs.writeFile(configPath, encryptedConfigStr);
Expand Down
3 changes: 1 addition & 2 deletions packages/main/src/backend/configManager/encryption/salt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ export default async function SALT(defaultValue?: string): Promise<string> {
const existedSALT = await loadSALT();
if (existedSALT) return existedSALT;

if (!defaultValue)
throw Error('SALT not existed and no default value provided');
if (!defaultValue) throw Error('SALT not existed and no default value provided');

await saveSALT(defaultValue);
return defaultValue;
Expand Down
18 changes: 3 additions & 15 deletions packages/main/src/backend/eventEmitters/EventEmitter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// eslint-disable-next-line max-classes-per-file
import {
type EnrichedTransaction,
type OutputVendorName,
} from '@/backend/commonTypes';
import { type EnrichedTransaction, type OutputVendorName } from '@/backend/commonTypes';
import Emittery from 'emittery';
import { type CompanyTypes } from 'israeli-bank-scrapers-core';

Expand Down Expand Up @@ -93,13 +90,7 @@ export interface ExporterEventParams {
export class ExporterEvent extends BudgetTrackingEvent {
allTransactions: EnrichedTransaction[];

constructor({
message,
allTransactions,
status,
error,
exporterName,
}: ExporterEventParams) {
constructor({ message, allTransactions, status, error, exporterName }: ExporterEventParams) {
super({
message,
accountType: AccountType.EXPORTER,
Expand Down Expand Up @@ -155,7 +146,4 @@ export class BudgetTrackingEventEmitter extends Emittery<EventDataMap> {}

export type EventPublisher = Pick<BudgetTrackingEventEmitter, 'emit'>;

export type EventSubscriber = Pick<
BudgetTrackingEventEmitter,
'on' | 'once' | 'off' | 'onAny' | 'anyEvent' | 'offAny'
>;
export type EventSubscriber = Pick<BudgetTrackingEventEmitter, 'on' | 'once' | 'off' | 'onAny' | 'anyEvent' | 'offAny'>;
5 changes: 1 addition & 4 deletions packages/main/src/backend/eventEmitters/loggerEmitter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
BudgetTrackingEventEmitter,
type EventPublisher,
} from '@/backend/eventEmitters/EventEmitter';
import { BudgetTrackingEventEmitter, type EventPublisher } from '@/backend/eventEmitters/EventEmitter';

interface Logger {
info: (...params: unknown[]) => void;
Expand Down
16 changes: 4 additions & 12 deletions packages/main/src/backend/export/exportTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import outputVendors from '@/backend/export/outputVendors';
import _ from 'lodash';
import logger from '/@/logging/logger';

type ExecutionResult = Partial<
Record<OutputVendorName, ExportTransactionsResult>
>;
type ExecutionResult = Partial<Record<OutputVendorName, ExportTransactionsResult>>;

export async function createTransactionsInExternalVendors(
outputVendorsConfig: Config['outputVendors'],
Expand All @@ -38,10 +36,7 @@ export async function createTransactionsInExternalVendors(
};

await outputVendor.init?.(outputVendorsConfig);
await eventPublisher.emit(
EventNames.EXPORTER_START,
new ExporterEvent({ message: 'Starting', ...baseEvent }),
);
await eventPublisher.emit(EventNames.EXPORTER_START, new ExporterEvent({ message: 'Starting', ...baseEvent }));
try {
const exportTransactionsResult = await outputVendor.exportTransactions(
{
Expand All @@ -57,8 +52,7 @@ export async function createTransactionsInExternalVendors(
message: 'Finished',
...baseEvent,
status: AccountStatus.DONE,
exportedTransactionsNum:
exportTransactionsResult.exportedTransactionsNum,
exportedTransactionsNum: exportTransactionsResult.exportedTransactionsNum,
}),
);
executionResult[outputVendor.name] = exportTransactionsResult;
Expand All @@ -78,9 +72,7 @@ export async function createTransactionsInExternalVendors(

await Promise.all(exportPromises);
if (!Object.keys(executionResult).length) {
const error = new Error(
'You need to set at least one output vendor to be active',
);
const error = new Error('You need to set at least one output vendor to be active');
throw error;
}

Expand Down
18 changes: 4 additions & 14 deletions packages/main/src/backend/export/outputVendors/csv/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import {
type ExportTransactionsFunction,
type OutputVendor,
} from '@/backend/commonTypes';
import {
mergeTransactions,
sortByDate,
} from '@/backend/transactions/transactions';
import { mergeTransactions, sortByDate } from '@/backend/transactions/transactions';
import { parse } from 'csv-parse/sync';
import { stringify } from 'csv-stringify/sync';
import { promises as fs } from 'fs';
Expand Down Expand Up @@ -86,21 +83,14 @@ export const serializeTransactions = (transactions: EnrichedTransaction[]) => {
});
};

const exportTransactions: ExportTransactionsFunction = async ({
transactionsToCreate,
outputVendorsConfig,
}) => {
const exportTransactions: ExportTransactionsFunction = async ({ transactionsToCreate, outputVendorsConfig }) => {
const { filePath } = outputVendorsConfig.csv!.options;
const savedTransactions = await parseTransactionsFile(filePath);
const mergedTransactions = mergeTransactions(
savedTransactions,
transactionsToCreate,
);
const mergedTransactions = mergeTransactions(savedTransactions, transactionsToCreate);
const sorted = sortByDate(mergedTransactions);
await writeCsvFile(filePath, serializeTransactions(sorted));
return {
exportedTransactionsNum:
mergedTransactions.length - savedTransactions.length,
exportedTransactionsNum: mergedTransactions.length - savedTransactions.length,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@ import ElectronGoogleOAuth2 from 'electron-google-oauth2';
import { clientId, clientSecret, redirectUri, scopes } from './googleAuth';

export default () => {
if (!clientId || !clientSecret)
throw Error("No 'clientId' or 'clientSecret' for google login");
if (!clientId || !clientSecret) throw Error("No 'clientId' or 'clientSecret' for google login");

// @ts-expect-error - The package 'electron-google-oauth2' is my own package, I don't know why it's not recognized
const electronGoogleOAuth2 = new ElectronGoogleOAuth2.default(
clientId,
clientSecret,
scopes,
{
successRedirectURL: redirectUri,
},
);
const electronGoogleOAuth2 = new ElectronGoogleOAuth2.default(clientId, clientSecret, scopes, {
successRedirectURL: redirectUri,
});

return electronGoogleOAuth2.openAuthWindowAndGetTokens();
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import {
type ExportTransactionsFunction,
type OutputVendor,
} from '@/backend/commonTypes';
import {
EventNames,
ExporterEvent,
type EventPublisher,
} from '@/backend/eventEmitters/EventEmitter';
import { EventNames, ExporterEvent, type EventPublisher } from '@/backend/eventEmitters/EventEmitter';
import { filterExistedHashes } from '@/backend/transactions/transactions';
import { type Auth } from 'googleapis';
import moment from 'moment/moment';
Expand Down Expand Up @@ -37,39 +33,24 @@ const createTransactionsInGoogleSheets: ExportTransactionsFunction = async (
{ transactionsToCreate: transactions, outputVendorsConfig },
eventPublisher,
) => {
const { spreadsheetId, credentials } =
outputVendorsConfig.googleSheets!.options;
const { spreadsheetId, credentials } = outputVendorsConfig.googleSheets!.options;
if (!credentials) throw new Error("You must set the 'credentials'");
const oAuthClient = createClient(credentials);

const sheet = await googleSheets.getSheet(
spreadsheetId,
DEFAULT_SHEET_NAME,
oAuthClient,
);
const sheet = await googleSheets.getSheet(spreadsheetId, DEFAULT_SHEET_NAME, oAuthClient);
if (!sheet) {
throw new Error(
`There is no sheet called ${DEFAULT_SHEET_NAME} in the spreadsheet`,
);
throw new Error(`There is no sheet called ${DEFAULT_SHEET_NAME} in the spreadsheet`);
}

const hashesAlreadyExistingInGoogleSheets =
await googleSheets.getExistingHashes(
spreadsheetId,
DEFAULT_SHEET_NAME,
oAuthClient,
);
const transactionsToCreate = filterExistedHashes(
transactions,
hashesAlreadyExistingInGoogleSheets,
const hashesAlreadyExistingInGoogleSheets = await googleSheets.getExistingHashes(
spreadsheetId,
DEFAULT_SHEET_NAME,
oAuthClient,
);
const transactionsToCreate = filterExistedHashes(transactions, hashesAlreadyExistingInGoogleSheets);

if (transactionsToCreate.length === 0) {
await emitProgressEvent(
eventPublisher,
transactions,
'All transactions already exist in google sheets',
);
await emitProgressEvent(eventPublisher, transactions, 'All transactions already exist in google sheets');
return {
exportedTransactionsNum: 0,
};
Expand Down Expand Up @@ -123,23 +104,11 @@ async function emitProgressEvent(
);
}

export async function createSpreadsheet(
spreadsheetTitle: string,
credentials: Auth.Credentials,
): Promise<string> {
export async function createSpreadsheet(spreadsheetTitle: string, credentials: Auth.Credentials): Promise<string> {
const auth = createClient(credentials);
const spreadsheetId = await googleSheets.createSpreadsheet(
spreadsheetTitle,
DEFAULT_SHEET_NAME,
auth,
);
const spreadsheetId = await googleSheets.createSpreadsheet(spreadsheetTitle, DEFAULT_SHEET_NAME, auth);

await googleSheets.appendToSpreadsheet(
spreadsheetId,
`${DEFAULT_SHEET_NAME}!A:A`,
[COLUMN_HEADERS],
auth,
);
await googleSheets.appendToSpreadsheet(spreadsheetId, `${DEFAULT_SHEET_NAME}!A:A`, [COLUMN_HEADERS], auth);

return spreadsheetId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,12 @@ export const getAllSpreadsheets = async (auth: OAuth2Client) => {
return response.data.files as Spreadsheet[];
};

export async function getSheet(
spreadsheetId: string,
sheetName: string,
auth: OAuth2Client,
) {
export async function getSheet(spreadsheetId: string, sheetName: string, auth: OAuth2Client) {
const spreadsheetResponse = await sheets.spreadsheets.get({
auth,
spreadsheetId,
});
const sheet = spreadsheetResponse.data.sheets?.find(
({ properties }) => properties?.title === sheetName,
);
const sheet = spreadsheetResponse.data.sheets?.find(({ properties }) => properties?.title === sheetName);

return sheet;
}
Expand Down
18 changes: 4 additions & 14 deletions packages/main/src/backend/export/outputVendors/json/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import {
type ExportTransactionsFunction,
type OutputVendor,
} from '@/backend/commonTypes';
import {
mergeTransactions,
sortByDate,
} from '@/backend/transactions/transactions';
import { mergeTransactions, sortByDate } from '@/backend/transactions/transactions';
import { promises as fs } from 'fs';
import logger from '/@/logging/logger';

Expand All @@ -24,21 +21,14 @@ const parseTransactionsFile = async (filename: string) => {
}
};

const exportTransactions: ExportTransactionsFunction = async ({
transactionsToCreate,
outputVendorsConfig,
}) => {
const exportTransactions: ExportTransactionsFunction = async ({ transactionsToCreate, outputVendorsConfig }) => {
const { filePath } = outputVendorsConfig.json!.options;
const savedTransactions = await parseTransactionsFile(filePath);
const mergedTransactions = mergeTransactions(
savedTransactions,
transactionsToCreate,
);
const mergedTransactions = mergeTransactions(savedTransactions, transactionsToCreate);
const sorted = sortByDate(mergedTransactions);
await fs.writeFile(filePath, JSON.stringify(sorted, null, 4));
return {
exportedTransactionsNum:
mergedTransactions.length - savedTransactions.length,
exportedTransactionsNum: mergedTransactions.length - savedTransactions.length,
};
};

Expand Down
Loading

0 comments on commit 3a3bb10

Please sign in to comment.