Last active
May 19, 2023 20:10
-
-
Save codebrainz/a79fcd80b82743850712d327d61344fa to your computer and use it in GitHub Desktop.
Function generated by ChatGPT to add file extensions to TS imports (untested/unverified).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fs from "fs"; | |
import * as path from "path"; | |
function updateImportsToUseFileExtension(directoryPath: string): void { | |
const files = fs.readdirSync(directoryPath); | |
files.forEach((file) => { | |
const filePath = path.join(directoryPath, file); | |
// Check if the file is a TypeScript file | |
if (path.extname(file) === ".ts") { | |
const fileContents = fs.readFileSync(filePath, "utf-8"); | |
// Replace named imports without file extensions | |
const updatedNamedImports = fileContents.replace( | |
/import\s+{([^}]+)}\s+from\s+['"]([^'"]+)['"]/g, | |
(match, imports, importPath) => { | |
const updatedPath = | |
importPath.endsWith(".ts") || | |
importPath.endsWith(".js") || | |
importPath.endsWith(".json") || | |
!importPath.includes(".") | |
? importPath | |
: importPath + ".ts"; | |
return `import {${imports}} from '${updatedPath}'`; | |
} | |
); | |
// Replace default imports without file extensions | |
const updatedDefaultImports = updatedNamedImports.replace( | |
/import\s+([^{}\s]+)\s+from\s+['"]([^'"]+)['"]/g, | |
(match, importName, importPath) => { | |
const updatedPath = | |
importPath.endsWith(".ts") || | |
importPath.endsWith(".js") || | |
importPath.endsWith(".json") || | |
!importPath.includes(".") | |
? importPath | |
: importPath + ".ts"; | |
return `import ${importName} from '${updatedPath}'`; | |
} | |
); | |
// Write the updated contents back to the file | |
fs.writeFileSync(filePath, updatedDefaultImports, "utf-8"); | |
} | |
// Recursively process subdirectories | |
if (fs.lstatSync(filePath).isDirectory()) { | |
updateImportsToUseFileExtension(filePath); | |
} | |
}); | |
} | |
// Usage example: | |
const directoryPath = "./listd"; | |
updateImportsToUseFileExtension(directoryPath); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/prisma/seeds/index.ts b/prisma/seeds/index.ts | |
index af53179..081bd3d 100644 | |
--- a/prisma/seeds/index.ts | |
+++ b/prisma/seeds/index.ts | |
@@ -1,7 +1,7 @@ | |
/* eslint-disable no-console */ | |
import { PrismaClient } from '@prisma/client'; | |
-import { seed as localeSeed } from './locales'; | |
-import { seed as testSeed } from './testSeed'; | |
+import { seed as localeSeed } from './locales.ts'; | |
+import { seed as testSeed } from './testSeed.ts'; | |
const prismaClient = new PrismaClient(); | |
diff --git a/src/hooks.server.ts b/src/hooks.server.ts | |
index 2ac6912..331492d 100644 | |
--- a/src/hooks.server.ts | |
+++ b/src/hooks.server.ts | |
@@ -5,8 +5,8 @@ import { detectLocale } from '$lib/i18n/i18n-util.js'; | |
import { SvelteKitAuth } from '@auth/sveltekit'; | |
import Google from '@auth/core/providers/google'; | |
import PrismaAdapter from '$lib/prisma/client'; | |
-import { config } from '$/lib/config.server'; | |
-import prismaClient from '$/lib/db.server'; | |
+import { config } from '$/lib/config.server.ts'; | |
+import prismaClient from '$/lib/db.server.ts'; | |
const handleDetectLocale = (async ({ event, resolve }) => { | |
// TODO: get lang from cookie / user setting | |
diff --git a/src/lib/i18n/ar/index.ts b/src/lib/i18n/ar/index.ts | |
index 693013f..f84ba5b 100644 | |
--- a/src/lib/i18n/ar/index.ts | |
+++ b/src/lib/i18n/ar/index.ts | |
@@ -1,5 +1,5 @@ | |
import type { Translation } from '../i18n-types'; | |
-import en from '../en'; | |
+import en from '../en.ts'; | |
const ar: Translation = { | |
...(en as Translation), | |
diff --git a/src/lib/i18n/de/index.ts b/src/lib/i18n/de/index.ts | |
index 357857e..6d63627 100644 | |
--- a/src/lib/i18n/de/index.ts | |
+++ b/src/lib/i18n/de/index.ts | |
@@ -1,5 +1,5 @@ | |
import type { Translation } from '../i18n-types'; | |
-import en from '../en'; | |
+import en from '../en.ts'; | |
const de: Translation = { | |
...(en as Translation), | |
diff --git a/src/lib/i18n/es/index.ts b/src/lib/i18n/es/index.ts | |
index 16e624e..b79c7a3 100644 | |
--- a/src/lib/i18n/es/index.ts | |
+++ b/src/lib/i18n/es/index.ts | |
@@ -1,5 +1,5 @@ | |
import type { Translation } from '../i18n-types'; | |
-import en from '../en'; | |
+import en from '../en.ts'; | |
const es: Translation = { | |
...(en as Translation), | |
diff --git a/src/lib/i18n/i18n-svelte.ts b/src/lib/i18n/i18n-svelte.ts | |
index 6cdffb3..fa697ad 100644 | |
--- a/src/lib/i18n/i18n-svelte.ts | |
+++ b/src/lib/i18n/i18n-svelte.ts | |
@@ -3,7 +3,7 @@ | |
import { initI18nSvelte } from 'typesafe-i18n/svelte' | |
import type { Formatters, Locales, TranslationFunctions, Translations } from './i18n-types' | |
-import { loadedFormatters, loadedLocales } from './i18n-util' | |
+import { loadedFormatters, loadedLocales } from './i18n-util.ts' | |
const { locale, LL, setLocale } = initI18nSvelte<Locales, Translations, TranslationFunctions, Formatters>(loadedLocales, loadedFormatters) | |
diff --git a/src/lib/i18n/i18n-util.async.ts b/src/lib/i18n/i18n-util.async.ts | |
index 2da5cac..284b81e 100644 | |
--- a/src/lib/i18n/i18n-util.async.ts | |
+++ b/src/lib/i18n/i18n-util.async.ts | |
@@ -1,9 +1,9 @@ | |
// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten. | |
/* eslint-disable */ | |
-import { initFormatters } from './formatters' | |
+import { initFormatters } from './formatters.ts' | |
import type { Locales, Translations } from './i18n-types' | |
-import { loadedFormatters, loadedLocales, locales } from './i18n-util' | |
+import { loadedFormatters, loadedLocales, locales } from './i18n-util.ts' | |
const localeTranslationLoaders = { | |
ar: () => import('./ar'), | |
diff --git a/src/lib/i18n/i18n-util.sync.ts b/src/lib/i18n/i18n-util.sync.ts | |
index b7108f3..ba2a6f8 100644 | |
--- a/src/lib/i18n/i18n-util.sync.ts | |
+++ b/src/lib/i18n/i18n-util.sync.ts | |
@@ -1,17 +1,17 @@ | |
// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten. | |
/* eslint-disable */ | |
-import { initFormatters } from './formatters' | |
+import { initFormatters } from './formatters.ts' | |
import type { Locales, Translations } from './i18n-types' | |
-import { loadedFormatters, loadedLocales, locales } from './i18n-util' | |
+import { loadedFormatters, loadedLocales, locales } from './i18n-util.ts' | |
-import ar from './ar' | |
-import de from './de' | |
-import en from './en' | |
-import es from './es' | |
-import it from './it' | |
-import ru from './ru' | |
-import uk from './uk' | |
+import ar from './ar.ts' | |
+import de from './de.ts' | |
+import en from './en.ts' | |
+import es from './es.ts' | |
+import it from './it.ts' | |
+import ru from './ru.ts' | |
+import uk from './uk.ts' | |
const localeTranslations = { | |
ar, | |
diff --git a/src/lib/i18n/it/index.ts b/src/lib/i18n/it/index.ts | |
index 6f81a57..baf6c48 100644 | |
--- a/src/lib/i18n/it/index.ts | |
+++ b/src/lib/i18n/it/index.ts | |
@@ -1,5 +1,5 @@ | |
import type { Translation } from '../i18n-types'; | |
-import en from '../en'; | |
+import en from '../en.ts'; | |
const it: Translation = { | |
...(en as Translation), | |
diff --git a/src/lib/i18n/ru/index.ts b/src/lib/i18n/ru/index.ts | |
index f464f69..6909357 100644 | |
--- a/src/lib/i18n/ru/index.ts | |
+++ b/src/lib/i18n/ru/index.ts | |
@@ -1,5 +1,5 @@ | |
import type { Translation } from '../i18n-types'; | |
-import en from '../en'; | |
+import en from '../en.ts'; | |
const ru: Translation = { | |
...(en as Translation), | |
diff --git a/src/lib/i18n/uk/index.ts b/src/lib/i18n/uk/index.ts | |
index de90565..4709823 100644 | |
--- a/src/lib/i18n/uk/index.ts | |
+++ b/src/lib/i18n/uk/index.ts | |
@@ -1,5 +1,5 @@ | |
import type { Translation } from '../i18n-types'; | |
-import en from '../en'; | |
+import en from '../en.ts'; | |
const uk: Translation = { | |
...(en as Translation), | |
diff --git a/src/lib/server/YouTubeAPI.ts b/src/lib/server/YouTubeAPI.ts | |
index f16914c..cbf2644 100644 | |
--- a/src/lib/server/YouTubeAPI.ts | |
+++ b/src/lib/server/YouTubeAPI.ts | |
@@ -1,7 +1,7 @@ | |
import { youtube, type youtube_v3 } from '@googleapis/youtube'; | |
-import { config } from '$/lib/config.server'; | |
+import { config } from '$/lib/config.server.ts'; | |
import type { YouTubeMeta } from '@prisma/client'; | |
-import redisClient from './redis'; | |
+import redisClient from './redis.ts'; | |
const ytClient = youtube({ | |
version: 'v3', | |
diff --git a/src/lib/server/queries.ts b/src/lib/server/queries.ts | |
index d1d2fc4..df15459 100644 | |
--- a/src/lib/server/queries.ts | |
+++ b/src/lib/server/queries.ts | |
@@ -1,4 +1,4 @@ | |
-import prismaClient from '$lib/db.server'; | |
+import prismaClient from '$lib/db.server.ts'; | |
import { z } from 'zod'; | |
export async function getList(id: string, userId: string | undefined = undefined) { | |
diff --git a/src/lib/server/redis.ts b/src/lib/server/redis.ts | |
index 4672920..82bfd9f 100644 | |
--- a/src/lib/server/redis.ts | |
+++ b/src/lib/server/redis.ts | |
@@ -1,5 +1,5 @@ | |
import { createClient } from 'redis'; | |
-import { config } from '../config.server'; | |
+import { config } from '../config.server.ts'; | |
const client = createClient({ | |
url: config.REDIS_URL, | |
diff --git a/src/routes/(protected)/create/+page.server.ts b/src/routes/(protected)/create/+page.server.ts | |
index 7144fc4..5e4e465 100644 | |
--- a/src/routes/(protected)/create/+page.server.ts | |
+++ b/src/routes/(protected)/create/+page.server.ts | |
@@ -4,7 +4,7 @@ import { LL, setLocale } from '$lib/i18n/i18n-svelte'; | |
import { get } from 'svelte/store'; | |
import { z, ZodError } from 'zod'; | |
import * as YouTubeAPI from '$lib/server/YouTubeAPI'; | |
-import prismaClient from '$lib/db.server'; | |
+import prismaClient from '$lib/db.server.ts'; | |
export async function load() { | |
return { | |
diff --git a/src/routes/(protected)/edit/[id]/+page.server.ts b/src/routes/(protected)/edit/[id]/+page.server.ts | |
index ee5d8bf..e6d22c3 100644 | |
--- a/src/routes/(protected)/edit/[id]/+page.server.ts | |
+++ b/src/routes/(protected)/edit/[id]/+page.server.ts | |
@@ -4,7 +4,7 @@ import { LL, setLocale } from '$lib/i18n/i18n-svelte'; | |
import { get } from 'svelte/store'; | |
import { z, ZodError } from 'zod'; | |
import * as YouTubeAPI from '$lib/server/YouTubeAPI'; | |
-import prismaClient from '$lib/db.server'; | |
+import prismaClient from '$lib/db.server.ts'; | |
import { getList } from '$/lib/server/queries'; | |
export async function load({ params, locals }) { | |
diff --git a/src/routes/(protected)/onboarding/+page.server.ts b/src/routes/(protected)/onboarding/+page.server.ts | |
index d0f5e65..fd4e24f 100644 | |
--- a/src/routes/(protected)/onboarding/+page.server.ts | |
+++ b/src/routes/(protected)/onboarding/+page.server.ts | |
@@ -1,5 +1,5 @@ | |
import { redirect } from '@sveltejs/kit'; | |
-import prismaClient from '../../../lib/db.server'; | |
+import prismaClient from '../../../lib/db.server.ts'; | |
export const actions = { | |
default: async (event) => { | |
diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts | |
index 141433a..8459834 100644 | |
--- a/src/routes/+layout.ts | |
+++ b/src/routes/+layout.ts | |
@@ -1,4 +1,4 @@ | |
-import { loadLocaleAsync } from '$lib/i18n/i18n-util.async'; | |
+import { loadLocaleAsync } from '$lib/i18n/i18n-util.async.ts'; | |
export const load = async (event) => { | |
const { locale } = event.data; | |
diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts | |
index c892641..d13a0eb 100644 | |
--- a/src/routes/+page.server.ts | |
+++ b/src/routes/+page.server.ts | |
@@ -1,4 +1,4 @@ | |
-import prismaClient from '$lib/db.server'; | |
+import prismaClient from '$lib/db.server.ts'; | |
import type { List } from '@prisma/client'; | |
export async function load({ locals }) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment