Skip to content

Commit

Permalink
feat: improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-sa committed Jan 19, 2024
1 parent 8e8fe7a commit ee89f4d
Show file tree
Hide file tree
Showing 24 changed files with 154 additions and 258 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ var/debug
.nx/cache
.angular
.env

apex.config.yaml
apex.config.yml
15 changes: 6 additions & 9 deletions apps/client/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
"tags": ["client"],
"targets": {
"build": {
"executor": "@angular-devkit/build-angular:application",
"executor": "@nx/angular:application",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/client",
"index": "apps/client/src/index.html",
"browser": "apps/client/src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "apps/client/tsconfig.app.json",
"assets": ["apps/client/src/favicon.ico", "apps/client/src/assets"],
"assets": [
"apps/client/src/favicon.ico",
"apps/client/src/assets"
],
"allowedCommonJsDependencies": [
"dot-prop",
"to-fast-properties",
Expand Down Expand Up @@ -52,7 +55,7 @@
"defaultConfiguration": "production"
},
"serve": {
"executor": "@angular-devkit/build-angular:dev-server",
"executor": "@nx/angular:dev-server",
"configurations": {
"production": {
"buildTarget": "client-app:build:production"
Expand All @@ -63,12 +66,6 @@
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"buildTarget": "client-app:build"
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"]
Expand Down
83 changes: 55 additions & 28 deletions apps/client/src/app/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { APP_INITIALIZER, ApplicationConfig } from '@angular/core';
import { provideRouter, Route } from '@angular/router';
import { deserialize } from '@deepkit/type';

import {
ApexClientConfig,
AuthService,
getClientConfig,
importProvidersDynamicallyFrom,
provideRpcClient,
} from '@apex/client';
Expand All @@ -15,29 +14,57 @@ import { MessengerController } from './messenger';
import { RoomController } from './room';
import { IntegrationsModule } from './integrations';

export const clientConfig = getClientConfig();

export const appConfig: ApplicationConfig = {
providers: [
// eslint-disable-next-line functional/prefer-readonly-type
provideRouter(routes as Route[]),
...provideRpcClient('ws://localhost:8082', [
GameController,
RoomController,
MessengerController,
]),
{
provide: ApexClientConfig,
useValue: clientConfig,
},
await importProvidersDynamicallyFrom(
new IntegrationsModule(clientConfig.integrations),
),
{
provide: APP_INITIALIZER,
deps: [AuthService],
useFactory: (auth: AuthService) => async () => auth.initialize(),
multi: true,
},
],
};
export class IntegrationsConfig {
readonly supabase?: unknown;
readonly featurebase?: unknown;
readonly thirdweb?: unknown;
}

export class ApexClientServerConfig {
readonly url: string = 'ws://localhost:8082';
}

export class ApexClientConfig {
readonly integrations: IntegrationsConfig = new IntegrationsConfig();
readonly server: ApexClientServerConfig = new ApexClientServerConfig();
}

export async function getClientConfig(): Promise<ApexClientConfig> {
if (import.meta.env.DEV) {
const result = await fetch('/assets/apex.config.yaml');
const { parse } = await import('yaml');
return deserialize<ApexClientConfig>(parse(await result.text()));
}

const result = await fetch('/config');
return deserialize<ApexClientConfig>(await result.json());
}

export async function getAppConfig(): Promise<ApplicationConfig> {
const clientConfig = await getClientConfig();

return {
providers: [
// eslint-disable-next-line functional/prefer-readonly-type
provideRouter(routes as Route[]),
...provideRpcClient(clientConfig.server.url, [
GameController,
RoomController,
MessengerController,
]),
{
provide: ApexClientConfig,
useValue: clientConfig,
},
await importProvidersDynamicallyFrom(
new IntegrationsModule(clientConfig.integrations),
),
{
provide: APP_INITIALIZER,
deps: [AuthService],
useFactory: (auth: AuthService) => async () => auth.initialize(),
multi: true,
},
],
};
}
4 changes: 3 additions & 1 deletion apps/client/src/app/integrations/integrations.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ClassType } from '@deepkit/core';

import { DynamicNgModule, IntegrationsConfig } from '@apex/client';
import { DynamicNgModule } from '@apex/client';

import { IntegrationsConfig } from '../config';

export class IntegrationsModule extends DynamicNgModule<IntegrationsModule> {
constructor(private readonly config: IntegrationsConfig) {
Expand Down
8 changes: 6 additions & 2 deletions apps/client/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { bootstrapApplication } from '@angular/platform-browser';

import { appConfig } from './app/config';
import { getAppConfig } from './app/config';
import { AppComponent } from './app/app.component';

void bootstrapApplication(AppComponent, appConfig);
void (async () => {
const config = await getAppConfig();
await bootstrapApplication(AppComponent, config);
})();

4 changes: 2 additions & 2 deletions apps/client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "es2022",
"useDefineForClassFields": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
Expand All @@ -11,7 +10,8 @@
"noPropertyAccessFromIndexSignature": true,
// "noImplicitReturns": true,
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"types": ["vite/client"]
},
"files": [],
"include": [],
Expand Down
22 changes: 15 additions & 7 deletions apps/client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import { angular } from '@analogjs/vite-plugin-angular/src/lib/angular-vite-plug

export default defineConfig(({ mode }) => {
const isTestMode = mode === 'test';
const tsConfig = isTestMode ? join(__dirname, 'tsconfig.spec.json') : join(__dirname, 'tsconfig.app.json');
const tsConfig = isTestMode
? join(__dirname, 'tsconfig.spec.json')
: join(__dirname, 'tsconfig.app.json');

return {
optimizeDeps: {
include: [
"dot-prop",
"to-fast-properties",
"buffer",
"ansi-styles",
"format-util"
],
exclude: ['@deepkit/rpc'],
esbuildOptions: {
target: 'esnext',
},
},
build: {
target: 'esnext',
},
plugins: [
nxViteTsPaths(),
Expand All @@ -28,6 +31,11 @@ export default defineConfig(({ mode }) => {
tsConfig,
}),
],
build: {
commonjsOptions: {
esmExternals: true,
},
},
test: {
globals: true,
cache: {
Expand Down
26 changes: 0 additions & 26 deletions apps/node-webpack.config.ts

This file was deleted.

44 changes: 2 additions & 42 deletions apps/server/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"projectType": "application",
"tags": ["server"],
"targets": {
"build-vite": {
"build": {
"executor": "@nx/vite:build",
"outputs": [
"{options.outputPath}"
Expand All @@ -28,7 +28,7 @@
}
}
},
"serve-vite": {
"serve": {
"executor": "nx:run-commands",
"options": {
"command": "vite-node --config=apps/server/vite.config.ts --root apps/server apps/server/src/main.ts"
Expand All @@ -39,46 +39,6 @@
}
}
},
"build": {
"executor": "@nx/webpack:webpack",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"target": "node",
"compiler": "tsc",
"outputPath": "dist/{projectRoot}",
"outputFileName": "main.mjs",
"main": "{projectRoot}/src/main.ts",
"tsConfig": "{projectRoot}/tsconfig.app.json",
"assets": [],
"webpackConfig": "{workspaceRoot}/apps/node-webpack.config.ts",
"buildLibsFromSource": false
},
"configurations": {
"development": {},
"production": {
"optimization": true,
"sourceMap": true,
"namedChunks": true
}
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "server:build"
},
"configurations": {
"development": {
"inspect": false,
"buildTarget": "server-app:build:development"
},
"production": {
"buildTarget": "server-app:build:production"
}
}
},
"seed": {
"executor": "nx:run-commands",
"options": {
Expand Down
10 changes: 0 additions & 10 deletions apps/server/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { integer } from '@deepkit/type';

import { ApexClientConfig } from '@apex/client';

import { IntegrationsConfig } from './integrations';

export class ApexRpcServerConfig {
Expand All @@ -23,11 +21,3 @@ export class ApexServerConfig {
readonly integrations: IntegrationsConfig = new IntegrationsConfig();
readonly database: ApexDatabaseConfig;
}

export class ApexSharedConfig {}

export class ApexConfig {
readonly server: ApexServerConfig = new ApexServerConfig();
readonly client: ApexClientConfig = new ApexClientConfig();
// readonly shared: ApexSharedConfig = new ApexSharedConfig();
}
10 changes: 9 additions & 1 deletion apps/server/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {
Room,
RoomItem,
User,
Point,
Badge,
UserBadge,
UserPoint,
} from '@apex/api/shared';

import { ApexDatabaseConfig } from './config';
Expand Down Expand Up @@ -39,9 +43,13 @@ export class ApexDatabase extends Database {
constructor(config: ApexDatabaseConfig) {
super(ApexDatabase.createAdapter(config), [
BaseItem,
Badge,
Point,
User,
UserBadge,
UserPoint,
Inventory,
InventoryItem,
User,
RoomItem,
Room,
Catalogue,
Expand Down
Loading

0 comments on commit ee89f4d

Please sign in to comment.