Skip to content

Commit 1f30527

Browse files
committed
refactor: streamline service methods and enhance type handling
- Refactored service methods in AnimeService, CharacterService, MediaListService, MediaService, StaffService, and UserService to remove explicit return types, simplifying the code. - Updated methods to use more descriptive parameter types, improving type safety and clarity. - Enhanced the MediaListService to accept a media type parameter, allowing for more flexible media list retrieval. - Removed unused imports and cleaned up code for better maintainability.
1 parent f34aa7f commit 1f30527

File tree

11 files changed

+3624
-8438
lines changed

11 files changed

+3624
-8438
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ permissions:
1515
jobs:
1616
build-and-publish:
1717
runs-on: ubuntu-latest
18+
env:
19+
NODE_ENV: production
1820
steps:
1921
- name: Checkout code
2022
uses: actions/checkout@v4

build.ts

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
import { rmSync } from "node:fs";
2+
import { resolve } from "node:path";
23
import type { BuildConfig } from "bun";
34
import dts from "bun-plugin-dts";
45

5-
const isProduction = process.env.NODE_ENV === "production";
6+
// ─────────────────────────────────────────────────────────────
7+
// Configuration
8+
// ─────────────────────────────────────────────────────────────
69

7-
const outdir = "./dist";
10+
const NODE_ENV = process.env.NODE_ENV ?? "development";
11+
const isProduction = NODE_ENV === "production";
12+
13+
const LOG_LEVEL = process.env.LOG_LEVEL ?? "info"; // "info" | "silent"
14+
const log = (...args: unknown[]) =>
15+
LOG_LEVEL === "info" && console.log(...args);
16+
17+
const outdir = resolve("./dist");
818

919
const defaultBuildConfig: BuildConfig = {
1020
entrypoints: ["./src/index.ts"],
1121
outdir,
1222
minify: isProduction,
1323
sourcemap: isProduction ? undefined : "inline",
24+
target: "bun",
1425
};
1526

16-
type Format = "esm" | "cjs" | "iife";
27+
type Format = "esm" | "cjs";
1728

1829
interface FormatConfig {
1930
format: Format;
@@ -33,36 +44,43 @@ const buildFormats: FormatConfig[] = [
3344
},
3445
];
3546

47+
// ─────────────────────────────────────────────────────────────
48+
// Build Function
49+
// ─────────────────────────────────────────────────────────────
50+
3651
async function buildAll() {
37-
console.log(
38-
`Starting build in ${isProduction ? "production" : "development"} mode...`,
39-
);
52+
log(`\n📦 Starting build in ${NODE_ENV} mode...\n`);
4053

41-
// Remove the dist directory recursively and forcefully before building
54+
// Clean output directory
4255
try {
4356
rmSync(outdir, { recursive: true, force: true });
44-
console.log(`Removed existing '${outdir}' directory.`);
57+
log(`🧹 Removed existing '${outdir}' directory.`);
4558
} catch (err) {
46-
console.warn(`Warning: Could not remove '${outdir}' directory.`, err);
59+
console.warn(`⚠️ Failed to clean '${outdir}':`, err);
4760
}
4861

49-
try {
50-
await Promise.all(
51-
buildFormats.map(({ format, naming, plugins }) => {
52-
console.log(`Building format: ${format}...`);
53-
return Bun.build({
54-
...defaultBuildConfig,
55-
format,
56-
naming,
57-
plugins,
58-
});
59-
}),
60-
);
61-
console.log("Build completed successfully.");
62-
} catch (error) {
63-
console.error("Build failed:", error);
64-
process.exit(1);
62+
// Run builds for each format
63+
for (const { format, naming, plugins } of buildFormats) {
64+
try {
65+
log(`🔧 Building format: ${format}`);
66+
await Bun.build({
67+
...defaultBuildConfig,
68+
format,
69+
naming,
70+
plugins,
71+
});
72+
log(`✅ Built ${format} format successfully.`);
73+
} catch (error) {
74+
console.error(`❌ Build failed for format '${format}':`, error);
75+
process.exit(1);
76+
}
6577
}
78+
79+
log("\n✅ All builds completed successfully.");
6680
}
6781

82+
// ─────────────────────────────────────────────────────────────
83+
// Run Build
84+
// ─────────────────────────────────────────────────────────────
85+
6886
await buildAll();

codegen.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ generates:
88
- typescript-graphql-request
99
config:
1010
rawRequest: false
11+
useTypeImports: true
12+
dedupeOperationSuffix: true
13+
skipTypename: true
14+
avoidOptionals: true
15+
onlyOperationTypes: true

src/@types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import type { getSdk } from "../__generated__/anilist-sdk";
22

33
export type ANILISTSDK = ReturnType<typeof getSdk>;
4+
5+
export type MediaTypeNonEnum = "ANIME" | "MANGA";

0 commit comments

Comments
 (0)