Skip to content

Commit

Permalink
clean up the deps
Browse files Browse the repository at this point in the history
  • Loading branch information
vorant94 committed Apr 19, 2024
1 parent 99c519c commit 3fbeef7
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 553 deletions.
10 changes: 0 additions & 10 deletions .prettierrc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,7 @@ export default {
singleAttributePerLine: true,
plugins: [
'prettier-plugin-tailwindcss',
'prettier-plugin-astro',
'prettier-plugin-organize-imports',
'prettier-plugin-astro-organize-imports',
'prettier-plugin-css-order',
],
overrides: [
{
files: '*.astro',
options: {
parser: 'astro',
},
},
],
};
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
"concurrently": "^8.2.2",
"husky": "^9.0.11",
"prettier": "^3.2.5",
"prettier-plugin-astro": "^0.13.0",
"prettier-plugin-astro-organize-imports": "^0.4.3",
"prettier-plugin-css-order": "^2.0.1",
"prettier-plugin-organize-imports": "^3.2.4",
"prettier-plugin-tailwindcss": "^0.5.12",
Expand Down
12 changes: 5 additions & 7 deletions packages/blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,28 @@
"scripts": {
"watch": "concurrently \"yarn:watch:*\"",
"watch:client": "vite build --watch --mode development",
"watch:server": "yarn clean && tspc --watch",
"watch:server": "tspc --watch",
"watch:test": "vitest watch",
"dev:start": "fastify start dist/app.js --watch --options",
"dev:start": "node --watch --env-file=.env .",
"build": "concurrently \"yarn:build:*\"",
"build:client": "tsc -p tsconfig.client.json && vite build",
"build:server": "yarn clean && tspc && cd dist && yarn fastify eject app.js --esm",
"build:server": "tspc",
"prod:start": "node .",
"test": "vitest run",
"e2e": "playwright test",
"e2e:setup": "playwright install",
"clean": "shx rm -rf dist"
"clean": "shx rm -rf dist && shx rm -rf public/client"
},
"dependencies": {
"@fastify/static": "^7.0.1",
"@fortawesome/fontawesome-free": "^6.5.1",
"@lottiefiles/lottie-player": "^2.0.4",
"@shikijs/rehype": "^1.3.0",
"@vercel/analytics": "^1.2.2",
"alpinejs": "^3.13.7",
"close-with-grace": "^1.3.0",
"clsx": "^2.1.0",
"consola": "^3.2.3",
"date-fns": "^3.6.0",
"dotenv": "^16.4.5",
"fast-glob": "^3.3.2",
"fastify": "^4.26.2",
"fastify-plugin": "^4.5.1",
Expand Down Expand Up @@ -68,7 +67,6 @@
"autoprefixer": "^10.4.19",
"concurrently": "^8.2.2",
"cssnano": "^6.1.2",
"fastify-cli": "^6.1.1",
"postcss": "^8.4.38",
"postcss-load-config": "^5.0.3",
"postcss-nested": "^6.0.1",
Expand Down
14 changes: 7 additions & 7 deletions packages/blog/playwright.config.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { defineConfig, devices } from '@playwright/test';
import { config } from 'dotenv';
import { envSchema, isCiEnv } from './src/config/index.js';
import process from 'node:process';
import { envSchema } from './src/config/index.js';

const env = envSchema.parse(config().parsed ?? {});
const env = envSchema.parse(process.env);

export default defineConfig({
testDir: './e2e',
fullyParallel: true,
forbidOnly: isCiEnv(env),
retries: isCiEnv(env) ? 2 : 0,
workers: isCiEnv(env) ? 1 : undefined,
forbidOnly: env.CI,
retries: env.CI ? 2 : 0,
workers: env.CI ? 1 : undefined,
reporter: 'html',
use: {
baseURL: 'http://localhost:3000',
Expand All @@ -24,6 +24,6 @@ export default defineConfig({
webServer: {
command: 'yarn prod:start',
url: 'http://localhost:3000',
reuseExistingServer: !isCiEnv(env),
reuseExistingServer: !env.CI,
},
});
42 changes: 0 additions & 42 deletions packages/blog/src/app.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions packages/blog/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import '@fortawesome/fontawesome-free/css/brands.css';
import '@fortawesome/fontawesome-free/css/fontawesome.css';
import '@fortawesome/fontawesome-free/css/solid.css';
import '@lottiefiles/lottie-player';
import { inject } from '@vercel/analytics';
import Alpine from 'alpinejs';
import './style.css';

Expand Down Expand Up @@ -70,8 +69,3 @@ window.addEventListener('resize', function () {

window.Alpine = Alpine;
Alpine.start();

// ignore IDEA complaining and rely on tsc only since IDEA doesn't support multiple tsconfig files
if (import.meta.env.MODE === 'production') {
inject();
}
21 changes: 2 additions & 19 deletions packages/blog/src/config/models/env.model.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
import { z } from 'zod';

const base = z.object({
export const envSchema = z.object({
NODE_ENV: z.enum(['development', 'production']).default('development'),
});
const ci = base.extend({
CI: z.coerce.boolean().pipe(z.literal(true)),
});
export type CiEnvModel = z.infer<typeof ci>;

const local = base.extend({
CI: z.void(),
CI: z.coerce.boolean().default(false),
PORT: z.coerce.number().default(3000),
});
export const envSchema = z.union([ci, local]);
export type EnvModel = z.infer<typeof envSchema>;

export function isCiEnv(env: EnvModel): env is CiEnvModel {
return 'CI' in env;
}

export function isDevEnv(env: EnvModel): boolean {
return env.NODE_ENV === 'development';
}
55 changes: 55 additions & 0 deletions packages/blog/src/server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { envSchema } from '@/config/index.js';
import { homeModule } from '@/home/index.js';
import { sendNotFound } from '@/http/index.js';
import { postsModule } from '@/posts/index.js';
import { projectsModule } from '@/projects/index.js';
import { uiModule } from '@/ui/index.js';
import fastifyStatic from '@fastify/static';
import closeWithGrace from 'close-with-grace';
import consola from 'consola';
import Fastify from 'fastify';
import path from 'node:path';
import process from 'node:process';

consola.start('Initializing server...');

const env = envSchema.parse(process.env);

const app = Fastify({
logger: true,
ignoreTrailingSlash: true,
});

await app.register(fastifyStatic, {
root: path.resolve(process.cwd(), 'public'),
});

await app.register(uiModule);
await app.register(homeModule);
await app.register(postsModule);
await app.register(projectsModule);

app.setNotFoundHandler(async (_, reply) => {
return sendNotFound(reply);
});

const closeListeners = closeWithGrace({ delay: 500 }, async function ({ err }) {
if (err) {
app.log.error(err);
}
await app.close();
});

app.addHook('onClose', (_, done) => {
closeListeners.uninstall();
done();
});

app.listen({ port: env.PORT }, (err, address) => {
if (err) {
app.log.error(err);
process.exit(1);
}

consola.success(`Server initialized on ${address}`);
});
2 changes: 1 addition & 1 deletion packages/blog/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
}
},
"include": ["src"],
"exclude": ["src/client.ts"]
"exclude": ["src/client.ts", "src/**/*.spec.ts"]
}
Loading

0 comments on commit 3fbeef7

Please sign in to comment.