From b807dcfb1ba750978d266f31a727a6f9c77f6375 Mon Sep 17 00:00:00 2001 From: Nick Cunningham Date: Wed, 26 Jun 2024 16:04:08 -0700 Subject: [PATCH] refactor: use tsconfig.json "paths" property to reduce instances of deep relative path referencing (#35) * refactor: use paths property in tsconfig to reduce deep relative references throughout server files * refactor: use paths property in tsconfig to reduce deep relative references throughout worker files * refactor: use paths property in tsconfig to reduce deep relative references throughout client files * fix: changes to tsconfigs & some packages to correctly resolve aliases --- .../base/inputs/path/path-input.tsx | 8 +- .../components/file-browser-body.tsx | 4 +- .../modules/file-browser/file-browser.tsx | 10 +- .../overlays/create-job/create-job-funcs.ts | 4 +- .../overlays/create-job/create-job.tsx | 24 ++--- .../overlays/upload-preset/upload-preset.tsx | 6 +- .../components/section/section-overlay.tsx | 2 +- client/src/components/section/section.tsx | 2 +- client/src/index.tsx | 12 +-- client/src/pages/primary/primary-context.ts | 6 +- client/src/pages/primary/primary.tsx | 10 +- client/src/sections/dashboard/dashboard.tsx | 4 +- .../sub-sections/dashboard-presets.tsx | 4 +- .../sub-sections/dashboard-queue.tsx | 8 +- .../sub-sections/dashboard-summary.tsx | 4 +- .../sub-sections/dashboard-workers.tsx | 6 +- client/src/sections/error/error.tsx | 2 +- client/src/sections/presets/presets.tsx | 6 +- .../presets/sub-sections/presets-buttons.tsx | 6 +- .../presets/sub-sections/presets-list.tsx | 6 +- .../sections/queue/components/queue-job.tsx | 6 +- client/src/sections/queue/queue.tsx | 7 +- .../queue/sub-sections/queue-jobs.tsx | 6 +- .../queue/sub-sections/queue-status.tsx | 6 +- .../workers/sub-sections/workers-status.tsx | 4 +- .../workers/sub-sections/workers-summary.tsx | 6 +- client/src/sections/workers/workers.tsx | 4 +- client/tsconfig.json | 49 ++++++---- client/vite.config.mts | 3 +- package-lock.json | 95 ++++++++++++++++++- package.json | 8 +- server/scripts/connections.ts | 2 +- server/scripts/database/database-queue.ts | 4 +- server/scripts/database/database-status.ts | 2 +- server/scripts/database/database.ts | 2 - server/scripts/files.ts | 2 +- server/scripts/initialization.ts | 2 +- server/scripts/presets.ts | 7 +- server/scripts/queue.ts | 8 +- server/scripts/worker.ts | 4 +- server/server.ts | 10 +- server/socket/client-socket.ts | 18 ++-- server/socket/worker-socket.ts | 7 +- server/tsconfig.json | 10 +- worker/scripts/transcode.ts | 8 +- worker/socket/server-socket.ts | 4 +- worker/tsconfig.json | 9 +- worker/worker.ts | 4 +- 48 files changed, 272 insertions(+), 159 deletions(-) diff --git a/client/src/components/base/inputs/path/path-input.tsx b/client/src/components/base/inputs/path/path-input.tsx index eb40fca..77731a1 100644 --- a/client/src/components/base/inputs/path/path-input.tsx +++ b/client/src/components/base/inputs/path/path-input.tsx @@ -1,8 +1,8 @@ -import FileBrowser from '../../../modules/file-browser/file-browser'; -import './path-input.scss'; import { useState } from 'react'; -import { FileBrowserMode } from '../../../../../../types/file-browser'; -import { DirectoryItem } from '../../../../../../types/directory'; +import { FileBrowserMode } from 'types/file-browser'; +import { DirectoryItem } from 'types/directory'; +import FileBrowser from 'components/modules/file-browser/file-browser'; +import './path-input.scss'; type Params = { id: string; diff --git a/client/src/components/modules/file-browser/components/file-browser-body.tsx b/client/src/components/modules/file-browser/components/file-browser-body.tsx index 083277c..ff72e69 100644 --- a/client/src/components/modules/file-browser/components/file-browser-body.tsx +++ b/client/src/components/modules/file-browser/components/file-browser-body.tsx @@ -1,6 +1,6 @@ import mime from 'mime'; -import { FileBrowserMode } from '../../../../../../types/file-browser'; -import { Directory, DirectoryItem } from '../../../../../../types/directory'; +import { FileBrowserMode } from 'types/file-browser'; +import { Directory, DirectoryItem } from 'types/directory'; type Params = { mode: FileBrowserMode; diff --git a/client/src/components/modules/file-browser/file-browser.tsx b/client/src/components/modules/file-browser/file-browser.tsx index 3bdc4f0..2f71f5e 100644 --- a/client/src/components/modules/file-browser/file-browser.tsx +++ b/client/src/components/modules/file-browser/file-browser.tsx @@ -1,11 +1,11 @@ /* eslint-disable react-hooks/exhaustive-deps */ import { useEffect, useState } from 'react'; -import { FileBrowserMode } from '../../../../../types/file-browser'; -import { Directory, DirectoryItem, DirectoryRequest } from '../../../../../types/directory'; -import ButtonInput from '../../base/inputs/button/button-input'; -import FileBrowserBody from './components/file-browser-body'; import { useOutletContext } from 'react-router-dom'; -import { PrimaryOutletContextType } from '../../../pages/primary/primary-context'; +import { Directory, DirectoryItem, DirectoryRequest } from 'types/directory'; +import { FileBrowserMode } from 'types/file-browser'; +import ButtonInput from 'components/base/inputs/button/button-input'; +import FileBrowserBody from './components/file-browser-body'; +import { PrimaryOutletContextType } from 'pages/primary/primary-context'; import './file-browser.scss'; type Params = { diff --git a/client/src/components/overlays/create-job/create-job-funcs.ts b/client/src/components/overlays/create-job/create-job-funcs.ts index ead64d0..7d009d7 100644 --- a/client/src/components/overlays/create-job/create-job-funcs.ts +++ b/client/src/components/overlays/create-job/create-job-funcs.ts @@ -1,7 +1,7 @@ import mime from 'mime'; -import { Directory, DirectoryItems, DirectoryRequest } from '../../../../../types/directory'; -import { HandbrakeOutputExtensions } from '../../../../../types/file-extensions'; import { Socket } from 'socket.io-client'; +import { Directory, DirectoryItems, DirectoryRequest } from 'types/directory'; +import { HandbrakeOutputExtensions } from 'types/file-extensions'; export async function RequestDirectory(socket: Socket, path: string, isRecursive: boolean = false) { const request: DirectoryRequest = { diff --git a/client/src/components/overlays/create-job/create-job.tsx b/client/src/components/overlays/create-job/create-job.tsx index 2b26fb2..f7194f8 100644 --- a/client/src/components/overlays/create-job/create-job.tsx +++ b/client/src/components/overlays/create-job/create-job.tsx @@ -2,18 +2,18 @@ import { useState } from 'react'; import { useOutletContext } from 'react-router-dom'; -import { PrimaryOutletContextType } from '../../../pages/primary/primary-context'; -import { QueueRequest } from '../../../../../types/queue'; -import SectionOverlay from '../../section/section-overlay'; -import ButtonGroup from '../../base/inputs/button-group/button-group'; -import { HandbrakeOutputExtensions } from '../../../../../types/file-extensions'; -import ButtonInput from '../../base/inputs/button/button-input'; -import PathInput from '../../base/inputs/path/path-input'; -import { FileBrowserMode } from '../../../../../types/file-browser'; -import SelectInput from '../../base/inputs/select/select-input'; -import TextInput from '../../base/inputs/text/text-input'; -import CheckboxInput from '../../base/inputs/checkbox/checkbox-input'; -import { DirectoryItem, DirectoryItems } from '../../../../../types/directory'; +import { DirectoryItem, DirectoryItems } from 'types/directory'; +import { FileBrowserMode } from 'types/file-browser'; +import { HandbrakeOutputExtensions } from 'types/file-extensions'; +import { QueueRequest } from 'types/queue'; +import { PrimaryOutletContextType } from 'pages/primary/primary-context'; +import ButtonGroup from 'components/base/inputs/button-group/button-group'; +import ButtonInput from 'components/base/inputs/button/button-input'; +import PathInput from 'components/base/inputs/path/path-input'; +import SelectInput from 'components/base/inputs/select/select-input'; +import TextInput from 'components/base/inputs/text/text-input'; +import SectionOverlay from 'components/section/section-overlay'; +import CheckboxInput from 'components/base/inputs/checkbox/checkbox-input'; import { FilterVideoFiles, GetOutputItemsFromInputItems, diff --git a/client/src/components/overlays/upload-preset/upload-preset.tsx b/client/src/components/overlays/upload-preset/upload-preset.tsx index d4e325d..d075a82 100644 --- a/client/src/components/overlays/upload-preset/upload-preset.tsx +++ b/client/src/components/overlays/upload-preset/upload-preset.tsx @@ -1,9 +1,9 @@ import { useState } from 'react'; import { Socket } from 'socket.io-client'; -import { HandbrakePreset } from '../../../../../types/preset'; -import ButtonInput from '../../base/inputs/button/button-input'; +import { HandbrakePreset } from 'types/preset'; +import ButtonInput from 'components/base/inputs/button/button-input'; +import SectionOverlay from 'components/section/section-overlay'; import './upload-preset.scss'; -import SectionOverlay from '../../section/section-overlay'; type Params = { socket: Socket; diff --git a/client/src/components/section/section-overlay.tsx b/client/src/components/section/section-overlay.tsx index 96593b9..22f9e42 100644 --- a/client/src/components/section/section-overlay.tsx +++ b/client/src/components/section/section-overlay.tsx @@ -1,6 +1,6 @@ import { PropsWithChildren, useContext } from 'react'; -import './section-overlay.scss'; import { SectionContext } from './section-context'; +import './section-overlay.scss'; type Params = PropsWithChildren & { id: string; diff --git a/client/src/components/section/section.tsx b/client/src/components/section/section.tsx index 74a99fd..91efec1 100644 --- a/client/src/components/section/section.tsx +++ b/client/src/components/section/section.tsx @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { PropsWithChildren, useRef, useState } from 'react'; -import './section.scss'; import { SectionContext, SectionContextType } from './section-context'; +import './section.scss'; type Params = PropsWithChildren & { title: string; diff --git a/client/src/index.tsx b/client/src/index.tsx index 4725f8d..8f7540e 100644 --- a/client/src/index.tsx +++ b/client/src/index.tsx @@ -5,12 +5,12 @@ import './index.scss'; import '@fontsource/noto-sans'; import '@fontsource/inter'; -import Primary from './pages/primary/primary'; -import Error from './sections/error/error'; -import QueueSection from './sections/queue/queue'; -import WorkersSection from './sections/workers/workers'; -import PresetsSection from './sections/presets/presets'; -import DashboardSection from './sections/dashboard/dashboard'; +import Primary from 'pages/primary/primary'; +import Error from 'sections/error/error'; +import QueueSection from 'sections/queue/queue'; +import WorkersSection from 'sections/workers/workers'; +import PresetsSection from 'sections/presets/presets'; +import DashboardSection from 'sections/dashboard/dashboard'; const routes: RouteObject[] = [ { diff --git a/client/src/pages/primary/primary-context.ts b/client/src/pages/primary/primary-context.ts index 576b933..65881df 100644 --- a/client/src/pages/primary/primary-context.ts +++ b/client/src/pages/primary/primary-context.ts @@ -1,7 +1,7 @@ import { Socket } from 'socket.io-client'; -import { Queue, QueueStatus } from '../../../../types/queue'; -import { ConnectionIDs } from '../../../../types/socket'; -import { HandbrakePresetList } from '../../../../types/preset'; +import { Queue, QueueStatus } from 'types/queue'; +import { ConnectionIDs } from 'types/socket'; +import { HandbrakePresetList } from 'types/preset'; export type PrimaryOutletContextType = { socket: Socket; diff --git a/client/src/pages/primary/primary.tsx b/client/src/pages/primary/primary.tsx index 151408b..4ae3b1b 100644 --- a/client/src/pages/primary/primary.tsx +++ b/client/src/pages/primary/primary.tsx @@ -5,13 +5,13 @@ import { NavLink, Outlet } from 'react-router-dom'; import { io } from 'socket.io-client'; // import 'dotenv/config'; -import { Queue, QueueStatus } from '../../../../types/queue'; -import { ConnectionIDs } from '../../../../types/socket'; -import { HandbrakePresetList } from '../../../../types/preset'; -import { PrimaryOutletContextType } from './primary-context'; +import { Queue, QueueStatus } from 'types/queue'; +import { ConnectionIDs } from 'types/socket'; +import { HandbrakePresetList } from 'types/preset'; -import SideBar from '../../components/modules/side-bar/side-bar'; +import SideBar from 'components/modules/side-bar/side-bar'; +import { PrimaryOutletContextType } from './primary-context'; import './primary.scss'; export default function Primary() { diff --git a/client/src/sections/dashboard/dashboard.tsx b/client/src/sections/dashboard/dashboard.tsx index 98b912b..755b523 100644 --- a/client/src/sections/dashboard/dashboard.tsx +++ b/client/src/sections/dashboard/dashboard.tsx @@ -1,6 +1,6 @@ import { useOutletContext } from 'react-router-dom'; -import { PrimaryOutletContextType } from '../../pages/primary/primary-context'; -import Section from '../../components/section/section'; +import { PrimaryOutletContextType } from 'pages/primary/primary-context'; +import Section from 'components/section/section'; import DashboardSummary from './sub-sections/dashboard-summary'; import DashboardQueue from './sub-sections/dashboard-queue'; import DashboardWorkers from './sub-sections/dashboard-workers'; diff --git a/client/src/sections/dashboard/sub-sections/dashboard-presets.tsx b/client/src/sections/dashboard/sub-sections/dashboard-presets.tsx index f29072b..d29f2a6 100644 --- a/client/src/sections/dashboard/sub-sections/dashboard-presets.tsx +++ b/client/src/sections/dashboard/sub-sections/dashboard-presets.tsx @@ -1,6 +1,6 @@ import { NavLink } from 'react-router-dom'; -import SubSection from '../../../components/section/sub-section'; -import { HandbrakePresetList } from '../../../../../types/preset'; +import { HandbrakePresetList } from 'types/preset'; +import SubSection from 'components/section/sub-section'; import './dashboard-presets.scss'; type Params = { diff --git a/client/src/sections/dashboard/sub-sections/dashboard-queue.tsx b/client/src/sections/dashboard/sub-sections/dashboard-queue.tsx index c207e84..8d1f95b 100644 --- a/client/src/sections/dashboard/sub-sections/dashboard-queue.tsx +++ b/client/src/sections/dashboard/sub-sections/dashboard-queue.tsx @@ -1,9 +1,9 @@ import { NavLink } from 'react-router-dom'; -import { Queue } from '../../../../../types/queue'; -import SubSection from '../../../components/section/sub-section'; +import { Queue } from 'types/queue'; +import { TranscodeStage } from 'types/transcode'; +import ProgressBar from 'components/base/progress/progress-bar'; +import SubSection from 'components/section/sub-section'; import './dashboard-queue.scss'; -import { TranscodeStage } from '../../../../../types/transcode'; -import ProgressBar from '../../../components/base/progress/progress-bar'; type Params = { queue: Queue; diff --git a/client/src/sections/dashboard/sub-sections/dashboard-summary.tsx b/client/src/sections/dashboard/sub-sections/dashboard-summary.tsx index 218d589..f87a6ba 100644 --- a/client/src/sections/dashboard/sub-sections/dashboard-summary.tsx +++ b/client/src/sections/dashboard/sub-sections/dashboard-summary.tsx @@ -1,5 +1,5 @@ -import { QueueStatus } from '../../../../../types/queue'; -import SubSection from '../../../components/section/sub-section'; +import { QueueStatus } from 'types/queue'; +import SubSection from 'components/section/sub-section'; import './dashboard-summary.scss'; type Params = { diff --git a/client/src/sections/dashboard/sub-sections/dashboard-workers.tsx b/client/src/sections/dashboard/sub-sections/dashboard-workers.tsx index 675c7b9..abc3cce 100644 --- a/client/src/sections/dashboard/sub-sections/dashboard-workers.tsx +++ b/client/src/sections/dashboard/sub-sections/dashboard-workers.tsx @@ -1,7 +1,7 @@ import { NavLink } from 'react-router-dom'; -import { Queue } from '../../../../../types/queue'; -import SubSection from '../../../components/section/sub-section'; -import { workerID } from '../../../../../types/socket'; +import { Queue } from 'types/queue'; +import { workerID } from 'types/socket'; +import SubSection from 'components/section/sub-section'; import './dashboard-workers.scss'; type Params = { diff --git a/client/src/sections/error/error.tsx b/client/src/sections/error/error.tsx index 4b59f4e..d2de6cf 100644 --- a/client/src/sections/error/error.tsx +++ b/client/src/sections/error/error.tsx @@ -1,4 +1,4 @@ -import Section from '../../components/section/section'; +import Section from 'components/section/section'; export default function Error() { return ( diff --git a/client/src/sections/presets/presets.tsx b/client/src/sections/presets/presets.tsx index 90453b9..6aef2ce 100644 --- a/client/src/sections/presets/presets.tsx +++ b/client/src/sections/presets/presets.tsx @@ -1,8 +1,8 @@ import { useState } from 'react'; import { useOutletContext } from 'react-router-dom'; -import { PrimaryOutletContextType } from '../../pages/primary/primary-context'; -import Section from '../../components/section/section'; -import UploadPreset from '../../components/overlays/upload-preset/upload-preset'; +import { PrimaryOutletContextType } from 'pages/primary/primary-context'; +import Section from 'components/section/section'; +import UploadPreset from 'components/overlays/upload-preset/upload-preset'; import PresetsButtons from './sub-sections/presets-buttons'; import PresetsList from './sub-sections/presets-list'; import './presets.scss'; diff --git a/client/src/sections/presets/sub-sections/presets-buttons.tsx b/client/src/sections/presets/sub-sections/presets-buttons.tsx index e5dd09f..0441680 100644 --- a/client/src/sections/presets/sub-sections/presets-buttons.tsx +++ b/client/src/sections/presets/sub-sections/presets-buttons.tsx @@ -1,6 +1,6 @@ -import { HandbrakePresetList } from '../../../../../types/preset'; -import ButtonInput from '../../../components/base/inputs/button/button-input'; -import SubSection from '../../../components/section/sub-section'; +import { HandbrakePresetList } from 'types/preset'; +import ButtonInput from 'components/base/inputs/button/button-input'; +import SubSection from 'components/section/sub-section'; import './presets-buttons.scss'; type Params = { diff --git a/client/src/sections/presets/sub-sections/presets-list.tsx b/client/src/sections/presets/sub-sections/presets-list.tsx index 57873b7..e7768a5 100644 --- a/client/src/sections/presets/sub-sections/presets-list.tsx +++ b/client/src/sections/presets/sub-sections/presets-list.tsx @@ -1,6 +1,6 @@ -import { HandbrakePresetList } from '../../../../../types/preset'; -import ButtonInput from '../../../components/base/inputs/button/button-input'; -import SubSection from '../../../components/section/sub-section'; +import { HandbrakePresetList } from 'types/preset'; +import ButtonInput from 'components/base/inputs/button/button-input'; +import SubSection from 'components/section/sub-section'; import './presets-list.scss'; type Params = { diff --git a/client/src/sections/queue/components/queue-job.tsx b/client/src/sections/queue/components/queue-job.tsx index 7ccb23f..943294e 100644 --- a/client/src/sections/queue/components/queue-job.tsx +++ b/client/src/sections/queue/components/queue-job.tsx @@ -1,6 +1,6 @@ -import { Job } from '../../../../../types/queue'; -import { TranscodeStage } from '../../../../../types/transcode'; -import ProgressBar from '../../../components/base/progress/progress-bar'; +import { Job } from 'types/queue'; +import { TranscodeStage } from 'types/transcode'; +import ProgressBar from 'components/base/progress/progress-bar'; import QueueJobSection from './queue-job-section'; import './queue-job.scss'; diff --git a/client/src/sections/queue/queue.tsx b/client/src/sections/queue/queue.tsx index a51e23d..d59a0fc 100644 --- a/client/src/sections/queue/queue.tsx +++ b/client/src/sections/queue/queue.tsx @@ -1,10 +1,10 @@ import { useState } from 'react'; import { useOutletContext } from 'react-router-dom'; -import { PrimaryOutletContextType } from '../../pages/primary/primary-context'; -import Section from '../../components/section/section'; +import { PrimaryOutletContextType } from 'pages/primary/primary-context'; +import Section from 'components/section/section'; +import CreateJob from 'components/overlays/create-job/create-job'; import QueueStatus from './sub-sections/queue-status'; import QueueJobs from './sub-sections/queue-jobs'; -import CreateJob from '../../components/overlays/create-job/create-job'; import './queue.scss'; export default function QueueSection() { @@ -62,7 +62,6 @@ export default function QueueSection() { /> {showCreateJob && ( { setShowCreateJob(false); }} diff --git a/client/src/sections/queue/sub-sections/queue-jobs.tsx b/client/src/sections/queue/sub-sections/queue-jobs.tsx index 751e2dd..c76115f 100644 --- a/client/src/sections/queue/sub-sections/queue-jobs.tsx +++ b/client/src/sections/queue/sub-sections/queue-jobs.tsx @@ -1,7 +1,7 @@ -import { Queue } from '../../../../../types/queue'; -import ButtonInput from '../../../components/base/inputs/button/button-input'; +import { Queue } from 'types/queue'; +import ButtonInput from 'components/base/inputs/button/button-input'; +import SubSection from 'components/section/sub-section'; import QueueJob from '../components/queue-job'; -import SubSection from '../../../components/section/sub-section'; import './queue-jobs.scss'; type Params = { diff --git a/client/src/sections/queue/sub-sections/queue-status.tsx b/client/src/sections/queue/sub-sections/queue-status.tsx index 488cdae..7198c6e 100644 --- a/client/src/sections/queue/sub-sections/queue-status.tsx +++ b/client/src/sections/queue/sub-sections/queue-status.tsx @@ -1,7 +1,7 @@ -import SubSection from '../../../components/section/sub-section'; +import { QueueStatus as QueueStatusType } from 'types/queue'; +import SubSection from 'components/section/sub-section'; +import ButtonInput from 'components/base/inputs/button/button-input'; import './queue-status.scss'; -import ButtonInput from '../../../components/base/inputs/button/button-input'; -import { QueueStatus as QueueStatusType } from '../../../../../types/queue'; type Params = { queueStatus: QueueStatusType; diff --git a/client/src/sections/workers/sub-sections/workers-status.tsx b/client/src/sections/workers/sub-sections/workers-status.tsx index f6fd6b2..69fd777 100644 --- a/client/src/sections/workers/sub-sections/workers-status.tsx +++ b/client/src/sections/workers/sub-sections/workers-status.tsx @@ -1,5 +1,5 @@ -import ProgressBar from '../../../components/base/progress/progress-bar'; -import SubSection from '../../../components/section/sub-section'; +import ProgressBar from 'components/base/progress/progress-bar'; +import SubSection from 'components/section/sub-section'; import { WorkerInfo } from '../workers'; import './workers-status.scss'; diff --git a/client/src/sections/workers/sub-sections/workers-summary.tsx b/client/src/sections/workers/sub-sections/workers-summary.tsx index f2c37d7..7d315bc 100644 --- a/client/src/sections/workers/sub-sections/workers-summary.tsx +++ b/client/src/sections/workers/sub-sections/workers-summary.tsx @@ -1,6 +1,6 @@ -import { Queue } from '../../../../../types/queue'; -import { TranscodeStage } from '../../../../../types/transcode'; -import SubSection from '../../../components/section/sub-section'; +import { Queue } from 'types/queue'; +import { TranscodeStage } from 'types/transcode'; +import SubSection from 'components/section/sub-section'; import { WorkerInfo } from '../workers'; import './workers-summary.scss'; diff --git a/client/src/sections/workers/workers.tsx b/client/src/sections/workers/workers.tsx index a1f1842..19aaefa 100644 --- a/client/src/sections/workers/workers.tsx +++ b/client/src/sections/workers/workers.tsx @@ -1,6 +1,6 @@ import { useOutletContext } from 'react-router-dom'; -import { PrimaryOutletContextType } from '../../pages/primary/primary-context'; -import Section from '../../components/section/section'; +import { PrimaryOutletContextType } from 'pages/primary/primary-context'; +import Section from 'components/section/section'; import WorkersSummary from './sub-sections/workers-summary'; import WorkersStatus from './sub-sections/workers-status'; import './workers.scss'; diff --git a/client/tsconfig.json b/client/tsconfig.json index a7fc6fb..51e87a2 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -1,25 +1,32 @@ { - "compilerOptions": { - "target": "ES2020", - "useDefineForClassFields": true, - "lib": ["ES2020", "DOM", "DOM.Iterable"], - "module": "ESNext", - "skipLibCheck": true, + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "module": "ESNext", + "skipLibCheck": true, - /* Bundler mode */ - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "resolveJsonModule": true, - "isolatedModules": true, - "noEmit": true, - "jsx": "react-jsx", + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", - /* Linting */ - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true - }, - "include": ["src"], - "references": [{ "path": "./tsconfig.node.json" }] + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + + "paths": { + "components/*": ["./src/components/*"], + "pages/*": ["./src/pages/*"], + "sections/*": ["./src/sections/*"], + "types/*": ["../types/*"] + } + }, + "include": ["src"], + "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/client/vite.config.mts b/client/vite.config.mts index 9cb9f95..f0f2e1f 100644 --- a/client/vite.config.mts +++ b/client/vite.config.mts @@ -1,9 +1,10 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; +import tsconfigPaths from 'vite-tsconfig-paths'; // https://vitejs.dev/config/ export default defineConfig({ - plugins: [react()], + plugins: [react(), tsconfigPaths()], server: { host: '127.0.0.1', port: process.env.CLIENT_PORT ? parseInt(process.env.CLIENT_PORT) : 5173, diff --git a/package-lock.json b/package-lock.json index 5248aa9..1b0520f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,8 +42,10 @@ "nodemon": "^3.1.0", "sass": "^1.77.2", "ts-node": "^10.9.2", + "tsconfig-paths": "^4.2.0", "typescript": "^5.4.5", - "vite": "^5.2.11" + "vite": "^5.2.11", + "vite-tsconfig-paths": "^4.3.2" } }, "node_modules/@ampproject/remapping": { @@ -3700,6 +3702,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/globrex": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/globrex/-/globrex-0.1.2.tgz", + "integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==", + "dev": true + }, "node_modules/gopd": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", @@ -5783,6 +5791,15 @@ "node": ">=8" } }, + "node_modules/strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -5993,6 +6010,40 @@ } } }, + "node_modules/tsconfck": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/tsconfck/-/tsconfck-3.1.0.tgz", + "integrity": "sha512-CMjc5zMnyAjcS9sPLytrbFmj89st2g+JYtY/c02ug4Q+CZaAtCgbyviI0n1YvjZE/pzoc6FbNsINS13DOL1B9w==", + "dev": true, + "bin": { + "tsconfck": "bin/tsconfck.js" + }, + "engines": { + "node": "^18 || >=20" + }, + "peerDependencies": { + "typescript": "^5.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/tsconfig-paths": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz", + "integrity": "sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg==", + "dev": true, + "dependencies": { + "json5": "^2.2.2", + "minimist": "^1.2.6", + "strip-bom": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", @@ -6219,6 +6270,48 @@ } } }, + "node_modules/vite-tsconfig-paths": { + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/vite-tsconfig-paths/-/vite-tsconfig-paths-4.3.2.tgz", + "integrity": "sha512-0Vd/a6po6Q+86rPlntHye7F31zA2URZMbH8M3saAZ/xR9QoGN/L21bxEGfXdWmFdNkqPpRdxFT7nmNe12e9/uA==", + "dev": true, + "dependencies": { + "debug": "^4.1.1", + "globrex": "^0.1.2", + "tsconfck": "^3.0.3" + }, + "peerDependencies": { + "vite": "*" + }, + "peerDependenciesMeta": { + "vite": { + "optional": true + } + } + }, + "node_modules/vite-tsconfig-paths/node_modules/debug": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.5.tgz", + "integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==", + "dev": true, + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/vite-tsconfig-paths/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index 9b0ade7..49d8c06 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "description": "HandBrake Web", "scripts": { "client": "vite ./client", - "server": "nodemon ./server/server.ts --watch server", - "worker": "nodemon ./worker/worker.ts --watch worker", + "server": "nodemon ./server/server.ts --watch server --exec ts-node --project ./server/tsconfig.json", + "worker": "nodemon ./worker/worker.ts --watch worker --exec ts-node --project ./worker/tsconfig.json", "build-client": "vite build ./client", "build-server": "tsc --project ./server/tsconfig.json", "build-worker": "tsc --project ./worker/tsconfig.json" @@ -49,7 +49,9 @@ "nodemon": "^3.1.0", "sass": "^1.77.2", "ts-node": "^10.9.2", + "tsconfig-paths": "^4.2.0", "typescript": "^5.4.5", - "vite": "^5.2.11" + "vite": "^5.2.11", + "vite-tsconfig-paths": "^4.3.2" } } diff --git a/server/scripts/connections.ts b/server/scripts/connections.ts index 579fcff..05d574b 100644 --- a/server/scripts/connections.ts +++ b/server/scripts/connections.ts @@ -1,4 +1,4 @@ -import { Client, Connections, Worker } from '../../types/socket'; +import { Client, Connections, Worker } from 'types/socket'; const connections: Connections = { clients: [], diff --git a/server/scripts/database/database-queue.ts b/server/scripts/database/database-queue.ts index c3a8c52..cb7402d 100644 --- a/server/scripts/database/database-queue.ts +++ b/server/scripts/database/database-queue.ts @@ -1,5 +1,5 @@ -import { QueueTable } from '../../../types/database'; -import { Job, Queue, QueueEntry } from '../../../types/queue'; +import { QueueTable } from 'types/database'; +import { Job, Queue, QueueEntry } from 'types/queue'; import { database } from './database'; export function GetQueueFromDatabase() { diff --git a/server/scripts/database/database-status.ts b/server/scripts/database/database-status.ts index ce67966..d988c89 100644 --- a/server/scripts/database/database-status.ts +++ b/server/scripts/database/database-status.ts @@ -1,4 +1,4 @@ -import { StatusTable } from '../../../types/database'; +import { StatusTable } from 'types/database'; import { database } from './database'; // export function InitializeStatus() { diff --git a/server/scripts/database/database.ts b/server/scripts/database/database.ts index cb7ecb3..d5ebb02 100644 --- a/server/scripts/database/database.ts +++ b/server/scripts/database/database.ts @@ -2,8 +2,6 @@ import Database from 'better-sqlite3'; import path from 'path'; import { dataPath } from '../data'; -import { Job, Queue, QueueEntry } from '../../../types/queue'; -import { QueueTable } from '../../../types/database'; const databasePath = path.join(dataPath, 'handbrake.db'); diff --git a/server/scripts/files.ts b/server/scripts/files.ts index 2c44d2b..b4e4bc2 100644 --- a/server/scripts/files.ts +++ b/server/scripts/files.ts @@ -1,7 +1,7 @@ import fs from 'fs/promises'; import path from 'path'; import directoryTree from 'directory-tree'; -import { Directory, DirectoryItem, DirectoryItems } from '../../types/directory'; +import { Directory, DirectoryItem, DirectoryItems } from 'types/directory'; export function GetDirectoryTree(path: string) { const tree = directoryTree(path); diff --git a/server/scripts/initialization.ts b/server/scripts/initialization.ts index 7aa2451..d898673 100644 --- a/server/scripts/initialization.ts +++ b/server/scripts/initialization.ts @@ -1,9 +1,9 @@ // import { Server } from 'socket.io'; +import { Server } from 'http'; import { ReadDataFromFile } from './data'; import { SetPresets, presetsPath } from './presets'; import { InitializeQueue } from './queue'; import { DatabaseConnect } from './database/database'; -import { Server } from 'http'; export default async function Initialization(server: Server) { // JSON ---------------------------------------------------------------------------------------- diff --git a/server/scripts/presets.ts b/server/scripts/presets.ts index 1eab8a2..2399f7c 100644 --- a/server/scripts/presets.ts +++ b/server/scripts/presets.ts @@ -1,8 +1,7 @@ -import fs from 'fs/promises'; -import { HandbrakePreset, HandbrakePresetList } from '../../types/preset'; -import { EmitToAllClients } from './connections'; -import { ReadDataFromFile, WriteDataToFile, dataPath } from './data'; import path from 'path'; +import { HandbrakePreset, HandbrakePresetList } from 'types/preset'; +import { EmitToAllClients } from './connections'; +import { WriteDataToFile, dataPath } from './data'; export const presetsPath = path.join(dataPath, 'presets.json'); console.log(`[server] [presets] Presets path is '${presetsPath}'`); diff --git a/server/scripts/queue.ts b/server/scripts/queue.ts index a8c5a4d..1f60d00 100644 --- a/server/scripts/queue.ts +++ b/server/scripts/queue.ts @@ -1,6 +1,7 @@ -import { Job, QueueEntry, QueueRequest, QueueStatus } from '../../types/queue'; -import { Worker } from '../../types/socket'; -import { TranscodeStage, TranscodeStatusUpdate } from '../../types/transcode'; +import hash from 'object-hash'; +import { Job, QueueEntry, QueueRequest, QueueStatus } from 'types/queue'; +import { Worker } from 'types/socket'; +import { TranscodeStage, TranscodeStatusUpdate } from 'types/transcode'; import { EmitToAllClients, EmitToWorkerWithID, @@ -17,7 +18,6 @@ import { } from './database/database-queue'; import { GetStatusFromDatabase, UpdateStatusInDatabase } from './database/database-status'; import { GetPresets } from './presets'; -import hash from 'object-hash'; // Init -------------------------------------------------------------------------------------------- export function InitializeQueue() { diff --git a/server/scripts/worker.ts b/server/scripts/worker.ts index 7f3115f..8612fa7 100644 --- a/server/scripts/worker.ts +++ b/server/scripts/worker.ts @@ -1,5 +1,5 @@ -import { Job, QueueEntry, QueueStatus } from '../../types/queue'; -import { TranscodeStage } from '../../types/transcode'; +import { Job, QueueEntry, QueueStatus } from 'types/queue'; +import { TranscodeStage } from 'types/transcode'; import { GetWorkerID, GetWorkers } from './connections'; import { GetQueueFromDatabase, UpdateJobInDatabase } from './database/database-queue'; import { GetQueueStatus, SetQueueStatus, StopQueue } from './queue'; diff --git a/server/server.ts b/server/server.ts index 6941620..3fecaaa 100644 --- a/server/server.ts +++ b/server/server.ts @@ -4,11 +4,11 @@ import { Server } from 'socket.io'; import 'dotenv/config'; import cors from 'cors'; -import ClientSocket from './socket/client-socket'; -import WorkerSocket from './socket/worker-socket'; -import Initialization from './scripts/initialization'; -import ClientRoutes from './routes/client'; -import Shutdown from './scripts/shutdown'; +import ClientSocket from 'socket/client-socket'; +import WorkerSocket from 'socket/worker-socket'; +import Initialization from 'scripts/initialization'; +import ClientRoutes from 'routes/client'; +import Shutdown from 'scripts/shutdown'; // Server ------------------------------------------------------------------------------------------ const app = express(); diff --git a/server/socket/client-socket.ts b/server/socket/client-socket.ts index 6a8b8d9..504981b 100644 --- a/server/socket/client-socket.ts +++ b/server/socket/client-socket.ts @@ -1,4 +1,11 @@ import { Server } from 'socket.io'; +import { Directory, DirectoryRequest } from 'types/directory'; +import { HandbrakePreset } from 'types/preset'; +import { QueueRequest } from 'types/queue'; +import { Client } from 'types/socket'; +import { AddClient, RemoveClient } from 'scripts/connections'; +import { GetDirectoryItems, GetDirectoryTree } from 'scripts/files'; +import { AddPreset, GetPresetNames, GetPresets, RemovePreset } from 'scripts/presets'; import { AddJob, ClearQueue, @@ -9,15 +16,8 @@ import { StartQueue, StopJob, StopQueue, -} from '../scripts/queue'; -import { QueueRequest } from '../../types/queue'; -import { AddClient, RemoveClient } from '../scripts/connections'; -import { Client } from '../../types/socket'; -import { GetDirectoryItems, GetDirectoryTree } from '../scripts/files'; -import { HandbrakePreset } from '../../types/preset'; -import { AddPreset, GetPresetNames, GetPresets, RemovePreset } from '../scripts/presets'; -import { videoPath } from '../scripts/video'; -import { Directory, DirectoryRequest } from '../../types/directory'; +} from 'scripts/queue'; +import { videoPath } from 'scripts/video'; const initClient = (socket: Client) => { const queue = GetQueue(); diff --git a/server/socket/worker-socket.ts b/server/socket/worker-socket.ts index 2ef0957..54e0820 100644 --- a/server/socket/worker-socket.ts +++ b/server/socket/worker-socket.ts @@ -1,8 +1,7 @@ import { Server } from 'socket.io'; -import { AddWorker, RemoveWorker } from '../scripts/connections'; -import { TranscodeStage, TranscodeStatusUpdate } from '../../types/transcode'; -import { GetQueue, StopJob, UpdateJob, WorkerForAvailableJobs } from '../scripts/queue'; -import { GetJobFromDatabase, UpdateJobInDatabase } from '../scripts/database/database-queue'; +import { AddWorker, RemoveWorker } from 'scripts/connections'; +import { TranscodeStage, TranscodeStatusUpdate } from 'types/transcode'; +import { GetQueue, StopJob, UpdateJob, WorkerForAvailableJobs } from 'scripts/queue'; export default function WorkerSocket(io: Server) { io.of('/worker').on('connection', (socket) => { diff --git a/server/tsconfig.json b/server/tsconfig.json index c095ae2..585ab51 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -29,7 +29,12 @@ // "rootDir": "./", /* Specify the root folder within your source files. */ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + "paths": { + "routes/*": ["./routes/*"], + "scripts/*": ["./scripts/*"], + "socket/*": ["./socket/*"], + "types/*": ["../types/*"] + } /* Specify a set of entries that re-map imports to additional lookup locations. */, // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ @@ -105,5 +110,8 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ + }, + "ts-node": { + "require": ["tsconfig-paths/register"] } } diff --git a/worker/scripts/transcode.ts b/worker/scripts/transcode.ts index 4d615e1..86def45 100644 --- a/worker/scripts/transcode.ts +++ b/worker/scripts/transcode.ts @@ -1,10 +1,10 @@ import { spawn, ChildProcessWithoutNullStreams as ChildProcess } from 'child_process'; -import { Socket } from 'socket.io-client'; -import { Job, QueueEntry } from '../../types/queue'; import fs from 'fs'; import path from 'path'; -import { TranscodeStage, TranscodeStatus, TranscodeStatusUpdate } from '../../types/transcode'; -import { HandbrakeJSONOutput, Muxing, Scanning, WorkDone, Working } from '../../types/handbrake'; +import { Socket } from 'socket.io-client'; +import { Job, QueueEntry } from 'types/queue'; +import { TranscodeStage, TranscodeStatus, TranscodeStatusUpdate } from 'types/transcode'; +import { HandbrakeJSONOutput, Muxing, Scanning, WorkDone, Working } from 'types/handbrake'; let handbrake: ChildProcess | null = null; export const isTranscoding = () => handbrake != null; diff --git a/worker/socket/server-socket.ts b/worker/socket/server-socket.ts index 157d6d6..53188c5 100644 --- a/worker/socket/server-socket.ts +++ b/worker/socket/server-socket.ts @@ -1,6 +1,6 @@ import { Socket } from 'socket.io-client'; -import { QueueEntry } from '../../types/queue'; -import { StartTranscode, StopTranscode, getJobID } from '../scripts/transcode'; +import { QueueEntry } from 'types/queue'; +import { StartTranscode, StopTranscode, getJobID } from 'scripts/transcode'; import { serverAddress } from '../worker'; const workerID = process.env.WORKER_ID; diff --git a/worker/tsconfig.json b/worker/tsconfig.json index 438b129..bd5c45a 100644 --- a/worker/tsconfig.json +++ b/worker/tsconfig.json @@ -29,7 +29,11 @@ // "rootDir": "./", /* Specify the root folder within your source files. */ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + "paths": { + "scripts/*": ["./scripts/*"], + "socket/*": ["./socket/*"], + "types/*": ["../types/*"] + } /* Specify a set of entries that re-map imports to additional lookup locations. */, // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ @@ -105,5 +109,8 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ + }, + "ts-node": { + "require": ["tsconfig-paths/register"] } } diff --git a/worker/worker.ts b/worker/worker.ts index 3769a14..281149b 100644 --- a/worker/worker.ts +++ b/worker/worker.ts @@ -1,7 +1,7 @@ import 'dotenv/config'; import { io } from 'socket.io-client'; -import ServerSocket from './socket/server-socket'; -import Shutdown from './scripts/shutdown'; +import ServerSocket from 'socket/server-socket'; +import Shutdown from 'scripts/shutdown'; // Setup -------------------------------------------------------------------------------------------