refactor
This commit is contained in:
parent
835c84261c
commit
8a42309956
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
|||||||
.idea
|
.idea
|
||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
|
dist
|
9
client/build.js
Normal file
9
client/build.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { build } from 'esbuild'
|
||||||
|
|
||||||
|
build({
|
||||||
|
entryPoints: ['./src/index.ts'],
|
||||||
|
format: 'esm',
|
||||||
|
platform: 'node',
|
||||||
|
target: 'node10.4',
|
||||||
|
outdir: './dist',
|
||||||
|
}).then(r => console.log('Successfully build.'))
|
15
client/dts.config.json
Normal file
15
client/dts.config.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"compilationOptions": {
|
||||||
|
"followSymlinks": true,
|
||||||
|
"preferredConfigPath": "../tsconfig.json"
|
||||||
|
},
|
||||||
|
"entries": [
|
||||||
|
{
|
||||||
|
"filePath": "./src/index.ts",
|
||||||
|
"outFile": "./dist/index.d.ts",
|
||||||
|
"libraries": {
|
||||||
|
"inlinedLibraries": ["@ragempcommunity/types-client"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -5,7 +5,11 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"files": ["dist/**/*"],
|
"files": ["dist/**/*"],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsup"
|
"build": "node --es-module-specifier-resolution=node build.js",
|
||||||
|
"types": "dts-bundle-generator --config dts.config.json"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"rage-fw-shared-types": "workspace:shared-types:*"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "SashaGoncharov19",
|
"author": "SashaGoncharov19",
|
||||||
|
@ -1,23 +1,19 @@
|
|||||||
/// <reference types="../../shared/client/index.d.ts" />
|
|
||||||
import rpc from 'rage-rpc'
|
import rpc from 'rage-rpc'
|
||||||
|
import {
|
||||||
|
RageFW_ClientEventReturn,
|
||||||
|
RageFW_ClientEvent,
|
||||||
|
RageFW_ClientEventArguments,
|
||||||
|
} from './types'
|
||||||
|
|
||||||
class Player implements RageFW_Player {
|
class Player {
|
||||||
public triggerClient<EventName extends RageFW_ClientEvent>(
|
public triggerServer<EventName extends RageFW_ClientEvent>(
|
||||||
player: PlayerMp,
|
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: RageFW_ClientEventArguments<EventName>
|
...args: RageFW_ClientEventArguments<EventName>
|
||||||
): Promise<RageFW_ClientEventReturn<EventName>> {
|
): Promise<RageFW_ClientEventReturn<EventName>> {
|
||||||
return rpc.callClient(player, eventName, ...args)
|
return rpc.callServer(eventName, ...args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const rage = {
|
export const rage = {
|
||||||
player: new Player(),
|
player: new Player(),
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool = rage.player.triggerClient(
|
|
||||||
{} as PlayerMp,
|
|
||||||
'customClientEvent',
|
|
||||||
'arg1',
|
|
||||||
2,
|
|
||||||
)
|
|
||||||
|
17
client/src/types.ts
Normal file
17
client/src/types.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/// <reference types="@ragempcommunity/types-client" />
|
||||||
|
|
||||||
|
import { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
||||||
|
|
||||||
|
export type RageFW_ClientEvent =
|
||||||
|
| keyof RageFW_ICustomClientEvent
|
||||||
|
| keyof IClientEvents
|
||||||
|
|
||||||
|
export type RageFW_ClientEventArguments<K extends RageFW_ClientEvent> =
|
||||||
|
K extends keyof RageFW_ICustomClientEvent
|
||||||
|
? Parameters<RageFW_ICustomClientEvent[K]>
|
||||||
|
: (K extends keyof IClientEvents ? IClientEvents[K] : never)[]
|
||||||
|
|
||||||
|
export type RageFW_ClientEventReturn<K extends RageFW_ClientEvent> =
|
||||||
|
K extends keyof RageFW_ICustomClientEvent
|
||||||
|
? ReturnType<RageFW_ICustomClientEvent[K]>
|
||||||
|
: never
|
@ -1,13 +1,9 @@
|
|||||||
{
|
{
|
||||||
|
"extends": "../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ESNext",
|
"typeRoots": [
|
||||||
"lib": ["ESNext", "ES5"],
|
"@ragempcommunity/types-client"
|
||||||
"module": "ESNext",
|
],
|
||||||
"moduleResolution": "NodeNext",
|
"baseUrl": "./src"
|
||||||
"esModuleInterop": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"types": ["../node_modules/@ragempcommunity/types-server", "../../shared/client"]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
lerna.json
Normal file
5
lerna.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"npmClient": "pnpm"
|
||||||
|
}
|
13
package.json
13
package.json
@ -1,16 +1,15 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"workspaces": [
|
|
||||||
"server"
|
|
||||||
],
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@ragempcommunity/types-cef": "^2.1.8",
|
||||||
"@ragempcommunity/types-client": "^2.1.8",
|
"@ragempcommunity/types-client": "^2.1.8",
|
||||||
"@ragempcommunity/types-server": "^2.1.8",
|
"@ragempcommunity/types-server": "^2.1.8",
|
||||||
"@ragempcommunity/types-cef": "^2.1.8",
|
"dts-bundle-generator": "^9.5.1",
|
||||||
"rage-rpc": "^0.4.0",
|
"esbuild": "^0.21.5",
|
||||||
"tsup": "^8.1.0",
|
|
||||||
"prettier": "^3.3.1",
|
"prettier": "^3.3.1",
|
||||||
"typescript": "^5.4.5"
|
"rage-rpc": "^0.4.0",
|
||||||
|
"typescript": "^5.4.5",
|
||||||
|
"lerna": "^8.1.3"
|
||||||
},
|
},
|
||||||
"type": "module"
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
4557
pnpm-lock.yaml
generated
4557
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
5
pnpm-workspace.yaml
Normal file
5
pnpm-workspace.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
packages:
|
||||||
|
- "server/*"
|
||||||
|
- "client/*"
|
||||||
|
- "shared/*"
|
||||||
|
- "shared-types/*"
|
9
server/build.js
Normal file
9
server/build.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { build } from 'esbuild'
|
||||||
|
|
||||||
|
build({
|
||||||
|
entryPoints: ['./src/index.ts'],
|
||||||
|
format: 'esm',
|
||||||
|
platform: 'node',
|
||||||
|
target: 'node10.4',
|
||||||
|
outdir: './dist',
|
||||||
|
}).then(r => console.log('Successfully build.'))
|
15
server/dts.config.json
Normal file
15
server/dts.config.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"compilationOptions": {
|
||||||
|
"followSymlinks": true,
|
||||||
|
"preferredConfigPath": "../tsconfig.json"
|
||||||
|
},
|
||||||
|
"entries": [
|
||||||
|
{
|
||||||
|
"filePath": "./src/index.ts",
|
||||||
|
"outFile": "./dist/index.d.ts",
|
||||||
|
"libraries": {
|
||||||
|
"inlinedLibraries": ["@ragempcommunity/types-server"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -2,10 +2,15 @@
|
|||||||
"name": "rage-fw-server",
|
"name": "rage-fw-server",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"types": "dist/index.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"files": ["dist/**/*"],
|
"files": ["dist/**/*"],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsup"
|
"build": "node --es-module-specifier-resolution=node build.js",
|
||||||
|
"types": "dts-bundle-generator --config dts.config.json"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"rage-fw-shared-types": "workspace:shared-types:*"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "SashaGoncharov19",
|
"author": "SashaGoncharov19",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/// <reference types="../../shared/server/index.d.ts" />
|
|
||||||
import rpc from 'rage-rpc'
|
import rpc from 'rage-rpc'
|
||||||
|
import { RageFW_ServerEvent, RageFW_ServerEventCallback } from './types.js'
|
||||||
|
|
||||||
class Server implements RageFW_Server {
|
class Server {
|
||||||
public register<EventName extends RageFW_ServerEvent>(
|
public register<EventName extends RageFW_ServerEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: RageFW_ServerEventCallback<EventName>,
|
callback: RageFW_ServerEventCallback<EventName>,
|
||||||
@ -19,34 +19,9 @@ class Server implements RageFW_Server {
|
|||||||
: (callback as (arg: typeof args) => void)(args)
|
: (callback as (arg: typeof args) => void)(args)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
// Object.keys(events).forEach(eventName =>
|
|
||||||
// // unknown[] ?
|
|
||||||
// // rpc.register(eventName, (args: unknown[]) =>
|
|
||||||
// // Array.isArray(args) ? events[eventName as keyof typeof events](...args) : callback(args),
|
|
||||||
// // ),
|
|
||||||
// rpc.register(eventName, (...args: unknown[]) =>
|
|
||||||
// events[eventName as EventName](args),
|
|
||||||
// ),
|
|
||||||
// )
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const rage = {
|
export const rage = {
|
||||||
event: new Server(),
|
event: new Server(),
|
||||||
}
|
}
|
||||||
|
|
||||||
rage.event.register('customServerEvent', (player, arg1, arg2) => {
|
|
||||||
console.log(player, arg1, arg2)
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
|
|
||||||
rage.event.registerMany({
|
|
||||||
customServerEvent: (player, arg1, arg2) => {
|
|
||||||
console.log(player, arg1, arg2)
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
playerDeath: (player, reason, killer) => {
|
|
||||||
console.log(player, reason, killer)
|
|
||||||
return undefined
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
18
server/src/types.ts
Normal file
18
server/src/types.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/// <reference types="@ragempcommunity/types-server" />
|
||||||
|
|
||||||
|
import { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
|
||||||
|
|
||||||
|
export type RageFW_ServerEvent =
|
||||||
|
| keyof RageFW_ICustomServerEvent
|
||||||
|
| keyof IServerEvents
|
||||||
|
|
||||||
|
export type RageFW_ServerEventCallback<
|
||||||
|
K extends keyof RageFW_ICustomServerEvent | keyof IServerEvents,
|
||||||
|
> = K extends keyof RageFW_ICustomServerEvent
|
||||||
|
? (
|
||||||
|
player: PlayerMp,
|
||||||
|
...args: Parameters<RageFW_ICustomServerEvent[K]>
|
||||||
|
) => ReturnType<RageFW_ICustomServerEvent[K]>
|
||||||
|
: K extends keyof IServerEvents
|
||||||
|
? ThisifyServerEvents[K]
|
||||||
|
: never
|
@ -1,17 +1,9 @@
|
|||||||
{
|
{
|
||||||
|
"extends": "../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ESNext",
|
"typeRoots": [
|
||||||
"lib": [
|
"@ragempcommunity/types-server"
|
||||||
"ESNext",
|
|
||||||
"ES5",
|
|
||||||
"dom"
|
|
||||||
],
|
],
|
||||||
"module": "ESNext",
|
"baseUrl": "./src"
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"types": ["../node_modules/@ragempcommunity/types-server", "../../shared/server"]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
shared-types/package.json
Normal file
11
shared-types/package.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "rage-fw-shared-types",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"types": "types/types/index.d.ts",
|
||||||
|
"files": [
|
||||||
|
"types/**/*"
|
||||||
|
],
|
||||||
|
"author": "SashaGoncharov19",
|
||||||
|
"license": "MIT",
|
||||||
|
"type": "module"
|
||||||
|
}
|
5
shared-types/types/types/index.d.ts
vendored
Normal file
5
shared-types/types/types/index.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
declare module 'rage-fw-shared-types' {
|
||||||
|
export interface RageFW_ICustomServerEvent {}
|
||||||
|
|
||||||
|
export interface RageFW_ICustomClientEvent {}
|
||||||
|
}
|
25
shared/client/index.d.ts
vendored
25
shared/client/index.d.ts
vendored
@ -1,25 +0,0 @@
|
|||||||
/// <reference types="@ragempcommunity/types-client" />
|
|
||||||
|
|
||||||
interface RageFW_ICustomClientEvent {
|
|
||||||
customClientEvent(arg1: string, arg2: number): boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent | keyof IClientEvents
|
|
||||||
|
|
||||||
type RageFW_ClientEventArguments<K extends RageFW_ClientEvent> =
|
|
||||||
K extends keyof RageFW_ICustomClientEvent
|
|
||||||
? Parameters<RageFW_ICustomClientEvent[K]>
|
|
||||||
: (K extends keyof IClientEvents ? ThisifyClientEvents[K] : never)[]
|
|
||||||
|
|
||||||
type RageFW_ClientEventReturn<K extends RageFW_ClientEvent> =
|
|
||||||
K extends keyof RageFW_ICustomClientEvent
|
|
||||||
? ReturnType<RageFW_ICustomClientEvent[K]>
|
|
||||||
: never
|
|
||||||
|
|
||||||
declare class RageFW_Player {
|
|
||||||
declare triggerClient<EventName extends RageFW_ClientEvent>(
|
|
||||||
player: PlayerMp,
|
|
||||||
eventName: EventName,
|
|
||||||
...args: RageFW_ClientEventArguments<EventName>
|
|
||||||
): Promise<RageFW_ClientEventReturn<EventName>>
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "es2016",
|
|
||||||
"module": "commonjs",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "rage-fw-shared-client",
|
"name": "rage-fw-shared",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "index.d.ts",
|
"main": "index.d.ts",
|
30
shared/server/index.d.ts
vendored
30
shared/server/index.d.ts
vendored
@ -1,30 +0,0 @@
|
|||||||
/// <reference types="@ragempcommunity/types-server" />
|
|
||||||
declare interface RageFW_ICustomServerEvent {
|
|
||||||
customServerEvent(arg1: string, arg2: number): boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
type RageFW_ServerEvent =
|
|
||||||
| keyof RageFW_ICustomServerEvent
|
|
||||||
| keyof IServerEvents
|
|
||||||
|
|
||||||
type RageFW_ServerEventCallback<
|
|
||||||
K extends keyof RageFW_ICustomServerEvent | keyof IServerEvents,
|
|
||||||
> = K extends keyof RageFW_ICustomServerEvent
|
|
||||||
? (
|
|
||||||
player: PlayerMp,
|
|
||||||
...args: Parameters<RageFW_ICustomServerEvent[K]>
|
|
||||||
) => ReturnType<RageFW_ICustomServerEvent[K]>
|
|
||||||
: K extends keyof IServerEvents
|
|
||||||
? ThisifyServerEvents[K]
|
|
||||||
: never
|
|
||||||
|
|
||||||
declare class RageFW_Server {
|
|
||||||
declare register<EventName extends RageFW_ServerEvent>(
|
|
||||||
eventName: EventName,
|
|
||||||
callback: RageFW_ServerEventCallback<EventName>,
|
|
||||||
): void
|
|
||||||
|
|
||||||
declare registerMany<EventName extends RageFW_ServerEvent>(events: {
|
|
||||||
[key: EventName]: RageFW_ServerEventCallback<EventName>
|
|
||||||
}): void
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "rage-fw-shared-server",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"type": "module",
|
|
||||||
"main": "index.d.ts",
|
|
||||||
"files": [
|
|
||||||
"index.d.ts"
|
|
||||||
],
|
|
||||||
"scripts": {
|
|
||||||
"test": "tsup"
|
|
||||||
},
|
|
||||||
"keywords": [],
|
|
||||||
"author": "SashaGoncharov19",
|
|
||||||
"license": "MIT",
|
|
||||||
"description": "Shared server types for rage-fw"
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "es2016",
|
|
||||||
"module": "commonjs",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,20 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es2016",
|
"target": "ESNext",
|
||||||
"module": "commonjs",
|
"module": "ESNext",
|
||||||
"esModuleInterop": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"skipLibCheck": true
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"declaration": true,
|
||||||
|
"useUnknownInCatchVariables": false,
|
||||||
|
"exactOptionalPropertyTypes": true,
|
||||||
|
"typeRoots": [
|
||||||
|
"./shared-types/types"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user