Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: organize imports and types with import aliases #96

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
12 changes: 12 additions & 0 deletions electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@ import solid from "vite-plugin-solid";
export default defineConfig({
main: {
plugins: [externalizeDepsPlugin()],
resolve: {
alias: {
"@main": resolve("src/main"),
"@shared": resolve("src/shared"),
},
},
},
preload: {
plugins: [externalizeDepsPlugin()],
resolve: {
alias: {
"@shared": resolve("src/shared"),
},
},
},
renderer: {
resolve: {
alias: {
"@renderer": resolve("src/renderer/src"),
"@shared": resolve("src/shared"),
},
},
plugins: [
Expand Down
20 changes: 0 additions & 20 deletions src/ListenAPI.d.ts

This file was deleted.

8 changes: 4 additions & 4 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Router } from "./lib/route-pass/Router";
import createMenu from "./lib/window/menu";
import trackBounds, { getBounds, wasMaximized } from "./lib/window/resizer";
import { main } from "./main";
import { electronApp, is, optimizer } from "@electron-toolkit/utils";
import { Router } from "@main/lib/route-pass/Router";
import createMenu from "@main/lib/window/menu";
import trackBounds, { getBounds, wasMaximized } from "@main/lib/window/resizer";
import { main } from "@main/main";
import { app, BrowserWindow, dialog } from "electron";
import { join } from "path";

Expand Down
10 changes: 5 additions & 5 deletions src/main/lib/osu-file-parser/OsuFile.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AudioSource, ImageSource, Optional, Result, Song } from "../../../@types";
import { access, readFile, stat } from "../fs-promises";
import { none, some } from "../rust-like-utils-backend/Optional";
import { fail, ok } from "../rust-like-utils-backend/Result";
import { SongBuilder } from "../song/SongBuilder";
import { access, readFile, stat } from "@main/lib/fs-promises";
import { SongBuilder } from "@main/lib/song/SongBuilder";
import { none, some } from "@shared/lib/rust-types/Optional";
import { fail, ok } from "@shared/lib/rust-types/Result";
import { AudioSource, ImageSource, Optional, Result, Song } from "@shared/types/common.types";
import { getAudioDurationInSeconds } from "get-audio-duration";
import fs from "graceful-fs";
import path from "path";
Expand Down
8 changes: 4 additions & 4 deletions src/main/lib/osu-file-parser/OsuParser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AudioSource, ImageSource, ResourceID, Result, Song } from "../../../@types";
import { access } from "../fs-promises";
import { fail, ok } from "../rust-like-utils-backend/Result";
import { assertNever } from "../tungsten/assertNever";
import { OsuFile } from "./OsuFile";
import { access } from "@main/lib/fs-promises";
import { fail, ok } from "@shared/lib/rust-types/Result";
import { assertNever } from "@shared/lib/tungsten/assertNever";
import { AudioSource, ImageSource, ResourceID, Result, Song } from "@shared/types/common.types";
import fs from "graceful-fs";
import os from "os";
import path from "path/posix";
Expand Down
4 changes: 2 additions & 2 deletions src/main/lib/osu-file-parser/WatchFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Result } from "../../../@types";
import { fail, ok } from "../rust-like-utils-backend/Result";
import { fail, ok } from "@shared/lib/rust-types/Result";
import { Result } from "@shared/types/common.types";
import fs from "fs";
import path from "path";

Expand Down
2 changes: 1 addition & 1 deletion src/main/lib/route-pass/Packet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PacketType, Packet } from "../../../@types";
import type { PacketType, Packet } from "@shared/types/common.types";

export function cratePacket<T>(
channel: string,
Expand Down
9 changes: 4 additions & 5 deletions src/main/lib/route-pass/Router.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { APIFunction, Packet } from "../../../@types";
import { ListenAPI } from "../../../ListenAPI";
import { RequestAPI } from "../../../RequestAPI";
import { assertNever } from "../tungsten/assertNever";
import { TokenNamespace } from "../tungsten/token";
import { cratePacket } from "./Packet";
import { assertNever } from "@shared/lib/tungsten/assertNever";
import { TokenNamespace } from "@shared/lib/tungsten/token";
import type { APIFunction, Packet } from "@shared/types/common.types";
import { ListenAPI, RequestAPI } from "@shared/types/router.types";
import { BrowserWindow, ipcMain } from "electron";

type Pending = {
Expand Down
22 changes: 0 additions & 22 deletions src/main/lib/rust-like-utils-backend/Optional.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/lib/search-parser/SearchParser.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { closestLevenDist } from "./levenshteinDistance";
import {
SearchPropertyValidation,
SearchConfig,
SearchProperty,
SearchQuery,
ValidationSuggestion,
SearchQuerySuggestion,
} from "./@search-types";
import { closestLevenDist } from "./levenshteinDistance";
} from "@shared/types/search-parser.types";

type ComparisonExtractionTrue = {
isPresent: true;
Expand Down
5 changes: 4 additions & 1 deletion src/main/lib/search-parser/validators.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { SearchPropertyValidation, SearchPropertyValidator } from "./@search-types";
import { closestLevenDist } from "./levenshteinDistance";
import {
SearchPropertyValidation,
SearchPropertyValidator,
} from "@shared/types/search-parser.types";

export const equalsSymbols = ["=", "==", "!="];
export const greaterThanSymbols = [">", ">="];
Expand Down
2 changes: 1 addition & 1 deletion src/main/lib/song/SongBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Song } from "../../../@types";
import { Song } from "@shared/types/common.types";

export class SongBuilder {
private song: any = {};
Expand Down
9 changes: 7 additions & 2 deletions src/main/lib/song/filter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { OsuSearchAbleProperties, SongIndex, SongsQueryPayload, Tag } from "../../../@types";
import { assertNever } from "../tungsten/assertNever";
import { assertNever } from "@shared/lib/tungsten/assertNever";
import {
OsuSearchAbleProperties,
SongIndex,
SongsQueryPayload,
Tag,
} from "@shared/types/common.types";

export function filter(indexes: SongIndex[], query: SongsQueryPayload): SongIndex[] {
if (query.searchQuery === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/lib/song/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Song, SongIndex } from "../../../@types";
import { averageBPM, msToBPM } from "./average-bpm";
import { Song, SongIndex } from "@shared/types/common.types";

function createSongIndex(id: string, song: Song): SongIndex {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/main/lib/song/indexMapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Song, SongIndex } from "../../../@types";
import { Storage } from "../storage/Storage";
import { Storage } from "@main/lib/storage/Storage";
import { Song, SongIndex } from "@shared/types/common.types";

export function* indexMapper(indexes: SongIndex[]): Generator<Song> {
for (let i = 0; i < indexes.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/lib/song/order.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Order, Result, Song } from "../../../@types";
import { ok } from "../rust-like-utils-backend/Result";
import { averageBPM, msToBPM } from "./average-bpm";
import { ok } from "@shared/lib/rust-types/Result";
import { Order, Result, Song } from "@shared/types/common.types";

export default function order(ordering: Order): Result<(a: Song, b: Song) => number, string> {
const { option, direction } = ordering;
Expand Down
2 changes: 1 addition & 1 deletion src/main/lib/storage/Storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BlobMap, TableMap } from "../../../@types";
import { Table } from "./Table";
import { BlobMap, TableMap } from "@shared/types/common.types";
import { app } from "electron";
import fs from "fs";
import path from "path";
Expand Down
4 changes: 2 additions & 2 deletions src/main/lib/storage/Table.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Optional } from "../../../@types";
import { none, some } from "../rust-like-utils-backend/Optional";
import { none, some } from "@shared/lib/rust-types/Optional";
import { Optional } from "@shared/types/common.types";
import fs from "fs";

export class Table<S> {
Expand Down
26 changes: 2 additions & 24 deletions src/main/lib/template-parser/parser/TemplateParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,10 @@
// String is converted to tokens and parser validates grammar of token sequence. From this sequence a
// "list of instructions" is created. Using the "list of instructions" together with data source will produce a dynamic
// string templating. Similar architecture is used to interpret search queries
import { TemplateTokenizer, Tokens } from "../tokenizer/TemplateTokenizer";
import { TemplateTokenizer, Tokens } from "@main/lib/template-parser/tokenizer/TemplateTokenizer";
import { ConfigError, ConfigSuccess, ConfigItem } from "@shared/types/template-parser.types";
import { closest } from "fastest-levenshtein";

export type ConfigItem = {
type: "TEXT" | "IDENT";
literal: string;
};

export type ConfigError = {
type: "error";
error: {
message: string;
suggestion?: {
start: number;
end: number;
replacement: string;
description: string;
};
};
};

export type ConfigSuccess = {
type: "success";
config: ConfigItem[];
};

export class TemplateParser {
private readonly identifiers: string[];
private readonly tokenizer = new TemplateTokenizer();
Expand Down
2 changes: 1 addition & 1 deletion src/main/lib/template-parser/template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConfigItem } from "./parser/TemplateParser";
import { ConfigItem } from "@shared/types/template-parser.types";

export type IdentAccessor = (ident: string) => string;

Expand Down
52 changes: 0 additions & 52 deletions src/main/lib/tungsten/math.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/lib/window/resizer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { orDefault } from "../rust-like-utils-backend/Optional";
import { Storage } from "../storage/Storage";
import { Storage } from "@main/lib/storage/Storage";
import { orDefault } from "@shared/lib/rust-types/Optional";
import { BrowserWindow } from "electron";

/**
Expand Down
18 changes: 9 additions & 9 deletions src/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DirParseResult, OsuParser } from "./lib/osu-file-parser/OsuParser";
import { Router } from "./lib/route-pass/Router";
import { orDefault } from "./lib/rust-like-utils-backend/Optional";
import { collectTagsAndIndexSongs } from "./lib/song";
import { Storage } from "./lib/storage/Storage";
import { throttle } from "./lib/throttle";
import { dirSubmit } from "./router/dir-router";
import { showError } from "./router/error-router";
import "./router/import";
import { DirParseResult, OsuParser } from "@main/lib/osu-file-parser/OsuParser";
import { Router } from "@main/lib/route-pass/Router";
import { collectTagsAndIndexSongs } from "@main/lib/song";
import { Storage } from "@main/lib/storage/Storage";
import { throttle } from "@main/lib/throttle";
import { dirSubmit } from "@main/router/dir-router";
import { showError } from "@main/router/error-router";
import "@main/router/import";
import { orDefault } from "@shared/lib/rust-types/Optional";
import { BrowserWindow } from "electron";

export let mainWindow: BrowserWindow;
Expand Down
2 changes: 1 addition & 1 deletion src/main/router/dev-router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Router } from "../lib/route-pass/Router";
import { Router } from "@main/lib/route-pass/Router";
import { app } from "electron";
import path from "path";

Expand Down
4 changes: 2 additions & 2 deletions src/main/router/dir-router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Router } from "../lib/route-pass/Router";
import { none, some } from "../lib/rust-like-utils-backend/Optional";
import { Router } from "@main/lib/route-pass/Router";
import { none, some } from "@shared/lib/rust-types/Optional";
import { dialog } from "electron";
import path from "path";

Expand Down
2 changes: 1 addition & 1 deletion src/main/router/discord-router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Router } from "../lib/route-pass/Router";
import { Router } from "@main/lib/route-pass/Router";
import { Client, SetActivity } from "@xhayper/discord-rpc";

const client = new Client({ clientId: "1292942523425099826" });
Expand Down
2 changes: 1 addition & 1 deletion src/main/router/error-router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Router } from "../lib/route-pass/Router";
import { Router } from "@main/lib/route-pass/Router";
import { BrowserWindow } from "electron";

let pending: (() => void)[] = [];
Expand Down
1 change: 0 additions & 1 deletion src/main/router/index.d.ts

This file was deleted.

8 changes: 4 additions & 4 deletions src/main/router/local-volume-router.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AudioSource, ResourceID } from "../../@types";
import { delay } from "../lib/delay-backend";
import { Router } from "../lib/route-pass/Router";
import { Storage } from "../lib/storage/Storage";
import { delay } from "@main/lib/delay-backend";
import { Router } from "@main/lib/route-pass/Router";
import { Storage } from "@main/lib/storage/Storage";
import { AudioSource, ResourceID } from "@shared/types/common.types";

const [writeAudioSource] = delay((audioID: ResourceID, audioSource: AudioSource) => {
Storage.getTable("audio").write(audioID, audioSource);
Expand Down
10 changes: 5 additions & 5 deletions src/main/router/parser-router.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Router } from "../lib/route-pass/Router";
import { SearchParser } from "../lib/search-parser/SearchParser";
import { defaultRelationSymbols, num, set, text, time } from "../lib/search-parser/validators";
import { TemplateParser } from "../lib/template-parser/parser/TemplateParser";
import templateIdentifiers from "../lib/template-parser/template-identifiers";
import { Router } from "@main/lib/route-pass/Router";
import { SearchParser } from "@main/lib/search-parser/SearchParser";
import { defaultRelationSymbols, num, set, text, time } from "@main/lib/search-parser/validators";
import { TemplateParser } from "@main/lib/template-parser/parser/TemplateParser";
import templateIdentifiers from "@main/lib/template-parser/template-identifiers";

/**
* Examples of valid search queries:
Expand Down
Loading