Skip to content

Commit

Permalink
Use tsx instead of ts-node
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsilvestre committed Nov 24, 2024
1 parent 491e138 commit 6f9b774
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions app/lib/files.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import path from "path";

import { kanjivgExtractedComponents } from "./dic/kanjivgExtractedComponents";

const libDirectory = (function () {
try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return __dirname;
} catch (e) {
return import.meta.url.replace("file:/", "");
}
})();

export const files = {
kanjidicInput1: vendor("kanjidic/kanji_bank_1.json"),
kanjidicInput2: vendor("kanjidic/kanji_bank_2.json"),
Expand Down Expand Up @@ -32,17 +42,13 @@ export const files = {

function vendor<S extends string>(string: S) {
return path.resolve(
import.meta.url,
libDirectory,
"vendor",
string,
) as `${string}/vendor/${S}`;
}
function dic<S extends string>(string: S) {
return path.resolve(
import.meta.url,
"dic",
string,
) as `${string}/vendor/${S}`;
return path.resolve(libDirectory, "dic", string) as `${string}/vendor/${S}`;
}

function readTextFileSync<T>(filepath: string) {
Expand All @@ -59,14 +65,14 @@ export function getKvgFilePath(character: string) {
.codePointAt(0)
?.toString(16)
.padStart(5, "0")}.svg`;
return path.resolve(import.meta.url, "vendor", "kanjivg", "svgs", filename);
return path.resolve(libDirectory, "vendor", "kanjivg", "svgs", filename);
}

export function getGlyphwikiSvgFilePath(figureKey: string) {
const filename = `${
[...figureKey].length === 1 ? getGlyphWikiCode(figureKey) : figureKey
}.svg`;
return path.resolve(import.meta.url, "vendor", "glyphwiki", "svgs", filename);
return path.resolve(libDirectory, "vendor", "glyphwiki", "svgs", filename);
}

export function getGlyphWikiCode(key: string) {
Expand All @@ -84,7 +90,7 @@ export function getGlyphWikiCode(key: string) {

export function getShuowenFilePath(filenameCharacters: string) {
return path.resolve(
import.meta.url,
libDirectory,
"dic",
"shuowenSvgs",
Array.from(filenameCharacters, (char) =>
Expand All @@ -95,7 +101,7 @@ export function getShuowenFilePath(filenameCharacters: string) {

export function getGlyphsFilePath(char: string) {
return path.resolve(
import.meta.url,
libDirectory,
"dic",
"glyphs",
char.codePointAt(0)!.toString(16) + ".json",
Expand Down

0 comments on commit 6f9b774

Please sign in to comment.