From b683d054ed6bacf1f66ce742a83969a879b10040 Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Wed, 16 Apr 2025 14:55:11 -0400 Subject: [PATCH] feature/IO-3066-1-scaffolding: Minor cleanup --- eslint.config.mjs | 50 +++++++++++++--------- package-lock.json | 23 +++++++--- package.json | 3 +- src/main/http-server/http-server.ts | 4 +- src/main/index.ts | 12 +++++- src/main/ipc/ipcMainHandler.settings.ts | 5 +-- src/main/ipc/ipcMainHandler.user.ts | 4 +- src/main/util/createDirectoryIfNotExist.ts | 4 +- src/main/util/toRenderer.ts | 5 +-- src/main/util/uppercaseObjectKeys.ts | 5 +-- 10 files changed, 69 insertions(+), 46 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index f4490e8..47f4e17 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -5,27 +5,35 @@ import eslintPluginReactHooks from "eslint-plugin-react-hooks"; import eslintPluginReactRefresh from "eslint-plugin-react-refresh"; export default tseslint.config( - { ignores: ["**/node_modules", "**/dist", "**/out"] }, - tseslint.configs.recommended, - eslintPluginReact.configs.flat.recommended, - eslintPluginReact.configs.flat["jsx-runtime"], - { - settings: { - react: { - version: "detect", - }, + {ignores: ["**/node_modules", "**/dist", "**/out"]}, + tseslint.configs.recommended, + eslintPluginReact.configs.flat.recommended, + eslintPluginReact.configs.flat["jsx-runtime"], + { + settings: { + react: { + version: "detect", + }, + }, }, - }, - { - files: ["**/*.{ts,tsx}"], - plugins: { - "react-hooks": eslintPluginReactHooks, - "react-refresh": eslintPluginReactRefresh, + { + files: ["**/*.{ts,tsx}"], + plugins: { + "react-hooks": eslintPluginReactHooks, + "react-refresh": eslintPluginReactRefresh, + }, + rules: { + ...eslintPluginReactHooks.configs.recommended.rules, + ...eslintPluginReactRefresh.configs.vite.rules, + }, + }, - rules: { - ...eslintPluginReactHooks.configs.recommended.rules, - ...eslintPluginReactRefresh.configs.vite.rules, + { + files: ["**/*.{js,mjs,ts,tsx,jsx,tsx}"], + rules: { + "prettier/prettier": ["error", {"endOfLine": "off"}] + } }, - }, - eslintConfigPrettier, -); + eslintConfigPrettier, +) + diff --git a/package-lock.json b/package-lock.json index f45d6e6..66e4524 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bodyshop-desktop", - "version": "0.0.1-alpha.2", + "version": "0.0.1-alpha.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "bodyshop-desktop", - "version": "0.0.1-alpha.2", + "version": "0.0.1-alpha.5", "hasInstallScript": true, "dependencies": { "@apollo/client": "^3.13.6", @@ -27,6 +27,7 @@ "@electron-toolkit/tsconfig": "^1.0.1", "@playwright/test": "^1.51.1", "@reduxjs/toolkit": "^2.6.1", + "@types/cors": "^2.8.17", "@types/express": "^5.0.1", "@types/lodash": "^4.17.16", "@types/node": "^22.14.0", @@ -61,7 +62,7 @@ "react-router": "^7.5.0", "redux-logger": "^3.0.6", "typescript": "^5.8.3", - "vite": "^6.2.5" + "vite": "6.2.6" } }, "node_modules/@ampproject/remapping": { @@ -4328,6 +4329,16 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/cors": { + "version": "2.8.17", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz", + "integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/debug": { "version": "4.1.12", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz", @@ -14789,9 +14800,9 @@ } }, "node_modules/vite": { - "version": "6.2.5", - "resolved": "https://registry.npmjs.org/vite/-/vite-6.2.5.tgz", - "integrity": "sha512-j023J/hCAa4pRIUH6J9HemwYfjB5llR2Ps0CWeikOtdR8+pAURAk0DoJC5/mm9kd+UgdnIy7d6HE4EAvlYhPhA==", + "version": "6.2.6", + "resolved": "https://registry.npmjs.org/vite/-/vite-6.2.6.tgz", + "integrity": "sha512-9xpjNl3kR4rVDZgPNdTL0/c6ao4km69a/2ihNQbcANz8RuCOK3hQBmLSJf3bRKVQjVMda+YvizNE8AwvogcPbw==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 57b752f..9364148 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@electron-toolkit/tsconfig": "^1.0.1", "@playwright/test": "^1.51.1", "@reduxjs/toolkit": "^2.6.1", + "@types/cors": "^2.8.17", "@types/express": "^5.0.1", "@types/lodash": "^4.17.16", "@types/node": "^22.14.0", @@ -76,6 +77,6 @@ "react-router": "^7.5.0", "redux-logger": "^3.0.6", "typescript": "^5.8.3", - "vite": "^6.2.5" + "vite": "6.2.6" } } diff --git a/src/main/http-server/http-server.ts b/src/main/http-server/http-server.ts index c57dac7..98dbeed 100644 --- a/src/main/http-server/http-server.ts +++ b/src/main/http-server/http-server.ts @@ -12,7 +12,7 @@ import { handlePartsPriceChangeRequest } from "../ppc/ppc-handler"; import { handleQuickBookRequest } from "../quickbooks-desktop/quickbooks-desktop"; export default class LocalServer { - private app: express.Application; + private readonly app: express.Application; private server: http.Server | null; private PORT = 1337; @@ -149,7 +149,7 @@ export default class LocalServer { ); this.app.post( "/refresh", - async (req: express.Request, res: express.Response) => { + async (_req: express.Request, res: express.Response) => { log.debug("[HTTP Server] Refresh request received"); try { await handleShopMetaDataFetch(true); diff --git a/src/main/index.ts b/src/main/index.ts index 6185f7b..c571d0c 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -67,6 +67,7 @@ function createWindow(): void { const template: Electron.MenuItemConstructorOptions[] = [ // { role: 'appMenu' } + // @ts-ignore ...(isMac ? [ { @@ -89,7 +90,9 @@ function createWindow(): void { { label: "File", submenu: [ + // @ts-ignore ...(!isMac ? [{ role: "about" }] : []), + // @ts-ignore isMac ? { role: "close" } : { role: "quit" }, ], }, @@ -103,6 +106,7 @@ function createWindow(): void { { role: "cut" }, { role: "copy" }, { role: "paste" }, + // @ts-ignore ...(isMac ? [ { role: "pasteAndMatchStyle" }, @@ -120,6 +124,7 @@ function createWindow(): void { // { role: 'viewMenu' } { label: "View", + // @ts-ignore submenu: [ { role: "reload" }, { role: "forceReload" }, @@ -134,6 +139,7 @@ function createWindow(): void { }, { label: "Application", + // @ts-ignore submenu: [ { label: "Open on Startup", @@ -235,6 +241,7 @@ function createWindow(): void { submenu: [ { role: "minimize" }, { role: "zoom" }, + // @ts-ignore ...(isMac ? [ { type: "separator" }, @@ -257,6 +264,7 @@ function createWindow(): void { // Update the menu to make the hidden item visible // Find the menu item dynamically by its id const fileMenu = template.find((item) => item.label === "Application"); + // @ts-ignore const hiddenItem = fileMenu?.submenu?.find( (item) => item.id === "development", ); @@ -375,7 +383,7 @@ app.whenReady().then(async () => { // module.someFunction() log.debug("Successfully loaded ipcMainConfig", module); } catch (error) { - log.error("Failed to load ipcMainconfig", { + log.error("Failed to load ipcMainConfig", { ...ErrorTypeCheck(error), }); } @@ -409,7 +417,7 @@ app.whenReady().then(async () => { // if (import.meta.env.DEV) { // // Useful for some dev/debugging tasks, but download can - // // not be validated becuase dev app is not signed + // // not be validated because dev app is not signed // autoUpdater.channel = "alpha"; // autoUpdater.updateConfigPath = path.join( // __dirname, diff --git a/src/main/ipc/ipcMainHandler.settings.ts b/src/main/ipc/ipcMainHandler.settings.ts index 93f0d5d..a066d79 100644 --- a/src/main/ipc/ipcMainHandler.settings.ts +++ b/src/main/ipc/ipcMainHandler.settings.ts @@ -38,8 +38,7 @@ const SettingsWatchedFilePathsRemove = async ( }; const SettingsWatchedFilePathsGet = async (): Promise => { - const filepaths: string[] = Store.get("settings.filepaths") || []; - return filepaths; + return Store.get("settings.filepaths") || []; }; const SettingsWatcherPollingGet = async (): Promise<{ @@ -66,7 +65,7 @@ const SettingsWatcherPollingSet = async ( //Restart the watcher with these new settings. await StopWatcher(); - StartWatcher(); + await StartWatcher(); return { enabled, interval }; }; diff --git a/src/main/ipc/ipcMainHandler.user.ts b/src/main/ipc/ipcMainHandler.user.ts index 46ef6df..7be54a5 100644 --- a/src/main/ipc/ipcMainHandler.user.ts +++ b/src/main/ipc/ipcMainHandler.user.ts @@ -36,7 +36,7 @@ const ipcMainHandleAuthStateChanged = async ( } } catch (error) { log.error( - "Error while querying active bodyshop or masterdata", + "Error while querying active bodyshop or master data", errorTypeCheck(error), ); sendIpcToRenderer( @@ -48,7 +48,7 @@ const ipcMainHandleAuthStateChanged = async ( }; const handleShopMetaDataFetch = async ( - reloadWindow: boolean, + reloadWindow?: boolean, ): Promise => { try { log.debug("Requery shop information & master data."); diff --git a/src/main/util/createDirectoryIfNotExist.ts b/src/main/util/createDirectoryIfNotExist.ts index 07e4626..3b049a4 100644 --- a/src/main/util/createDirectoryIfNotExist.ts +++ b/src/main/util/createDirectoryIfNotExist.ts @@ -3,9 +3,9 @@ import fs from "fs"; import path from "path"; import errorTypeCheck from "../../util/errorTypeCheck"; -const createdDirectoryIfNotExist = async (dirpath: string) => { +const createdDirectoryIfNotExist = async (dirPath: string) => { try { - const directoryPath = path.dirname(dirpath); + const directoryPath = path.dirname(dirPath); if (!fs.existsSync(directoryPath)) { log.info(`Directory does not exist. Creating: ${directoryPath}`); fs.mkdirSync(directoryPath, { recursive: true }); diff --git a/src/main/util/toRenderer.ts b/src/main/util/toRenderer.ts index 9c5754b..39b23f2 100644 --- a/src/main/util/toRenderer.ts +++ b/src/main/util/toRenderer.ts @@ -1,9 +1,8 @@ -import { BrowserWindow } from "electron"; +import {BrowserWindow} from "electron"; import log from "electron-log/main"; const getMainWindow = (): Electron.BrowserWindow => { - const mainWindow = BrowserWindow.getAllWindows()[0]; - return mainWindow; + return BrowserWindow.getAllWindows()[0]; }; const sendIpcToRenderer = (ipcMessage: string, ...args: any[]): void => { diff --git a/src/main/util/uppercaseObjectKeys.ts b/src/main/util/uppercaseObjectKeys.ts index 3571e8b..44b9ec3 100644 --- a/src/main/util/uppercaseObjectKeys.ts +++ b/src/main/util/uppercaseObjectKeys.ts @@ -13,12 +13,9 @@ function uppercaseObjectKeys>( return Object.entries(obj).reduce( (result, [key, value]) => { const uppercaseKey = key.toUpperCase(); - const newValue = - typeof value === "object" && value !== null + result[uppercaseKey] = typeof value === "object" && value !== null ? uppercaseObjectKeys(value) : value; - - result[uppercaseKey] = newValue; return result; }, {} as Record,