Compare commits
5
Commits
39e6455271
...
v0.2.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96c92f9d19 | ||
|
|
2b287f06a2 | ||
|
|
2f2b1da99b | ||
|
|
59910303f7 | ||
|
|
828a3deb33 |
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "rage-fw-cef",
|
"name": "@entityseven/rage-fw-cef",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/src/index.d.ts",
|
"types": "dist/src/index.d.ts",
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
"build": "tsup"
|
"build": "tsup"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ragefw-rpc": "workspace:^"
|
"rage-fw-rpc": "workspace:^"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@ragempcommunity/types-cef": "^2.1.8",
|
"@ragempcommunity/types-cef": "^2.1.8",
|
||||||
|
|||||||
+20
-9
@@ -1,6 +1,6 @@
|
|||||||
import rpc from 'rage-rpc'
|
import { Rpc } from 'rage-fw-rpc'
|
||||||
|
|
||||||
import {
|
import type {
|
||||||
_CefEventHasArgs,
|
_CefEventHasArgs,
|
||||||
_ClientEventHasArgs,
|
_ClientEventHasArgs,
|
||||||
_ServerEventHasArgs,
|
_ServerEventHasArgs,
|
||||||
@@ -18,11 +18,18 @@ import {
|
|||||||
|
|
||||||
class Cef {
|
class Cef {
|
||||||
private _debugMode: boolean = false
|
private _debugMode: boolean = false
|
||||||
|
private _rpc: Rpc = new Rpc()
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
set debug(debug: boolean) {
|
set debug(debug: boolean) {
|
||||||
this._debugMode = debug
|
this._debugMode = debug
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get rpc(): Rpc {
|
||||||
|
return this._rpc
|
||||||
|
}
|
||||||
|
|
||||||
public register<EventName extends keyof RageFW_ICustomCefEvent>(
|
public register<EventName extends keyof RageFW_ICustomCefEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: RageFW_CefCallback<EventName>,
|
callback: RageFW_CefCallback<EventName>,
|
||||||
@@ -32,11 +39,11 @@ class Cef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('mp' in window) {
|
if ('mp' in window) {
|
||||||
rpc.register(eventName, callback)
|
this._rpc.register(eventName, callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public trigger<EventName extends keyof RageFW_ICustomCefEvent>(
|
public async trigger<EventName extends keyof RageFW_ICustomCefEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _CefEventHasArgs<EventName> extends true
|
...args: _CefEventHasArgs<EventName> extends true
|
||||||
? [RageFW_CefArgs<EventName>]
|
? [RageFW_CefArgs<EventName>]
|
||||||
@@ -47,7 +54,7 @@ class Cef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('mp' in window) {
|
if ('mp' in window) {
|
||||||
return rpc.call(eventName, args)
|
return await this._rpc.call(eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.reject(
|
return Promise.reject(
|
||||||
@@ -55,7 +62,9 @@ class Cef {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerServer<EventName extends keyof RageFW_ICustomServerEvent>(
|
public async triggerServer<
|
||||||
|
EventName extends keyof RageFW_ICustomServerEvent,
|
||||||
|
>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _ServerEventHasArgs<EventName> extends true
|
...args: _ServerEventHasArgs<EventName> extends true
|
||||||
? [RageFW_ServerArgs<EventName>]
|
? [RageFW_ServerArgs<EventName>]
|
||||||
@@ -66,7 +75,7 @@ class Cef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('mp' in window) {
|
if ('mp' in window) {
|
||||||
return rpc.callServer(eventName, args)
|
return await this._rpc.callServer(eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.reject(
|
return Promise.reject(
|
||||||
@@ -74,7 +83,9 @@ class Cef {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerClient<EventName extends keyof RageFW_ICustomClientEvent>(
|
public async triggerClient<
|
||||||
|
EventName extends keyof RageFW_ICustomClientEvent,
|
||||||
|
>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _ClientEventHasArgs<EventName> extends true
|
...args: _ClientEventHasArgs<EventName> extends true
|
||||||
? [RageFW_ClientArgs<EventName>]
|
? [RageFW_ClientArgs<EventName>]
|
||||||
@@ -85,7 +96,7 @@ class Cef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('mp' in window) {
|
if ('mp' in window) {
|
||||||
return rpc.callClient(eventName, args)
|
return await this._rpc.callClient(eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.reject(
|
return Promise.reject(
|
||||||
|
|||||||
+2
-4
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "create-rage-fw",
|
"name": "@entityseven/create-rage-fw",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
"rage-fw": "dist/index.js"
|
"rage-fw": "dist/index.js"
|
||||||
@@ -16,13 +16,11 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@inquirer/prompts": "^5.0.5",
|
"@inquirer/prompts": "^5.0.5",
|
||||||
"axios": "^1.7.2",
|
"ky": "^1.7.2",
|
||||||
"chalk": "4.1.2",
|
"chalk": "4.1.2",
|
||||||
"git-clone": "^0.2.0",
|
|
||||||
"yargs": "^17.7.2"
|
"yargs": "^17.7.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/git-clone": "^0.2.4",
|
|
||||||
"@types/node": "^20.14.2",
|
"@types/node": "^20.14.2",
|
||||||
"@types/yargs": "^17.0.32",
|
"@types/yargs": "^17.0.32",
|
||||||
"prettier": "^3.3.2",
|
"prettier": "^3.3.2",
|
||||||
|
|||||||
+12
-18
@@ -1,7 +1,7 @@
|
|||||||
import c from 'chalk'
|
import c from 'chalk'
|
||||||
import { input, select } from '@inquirer/prompts'
|
import { input, select } from '@inquirer/prompts'
|
||||||
import clone from 'git-clone'
|
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
|
import { cloneBranch } from '../utils/cloner'
|
||||||
|
|
||||||
export async function initProject() {
|
export async function initProject() {
|
||||||
let folder
|
let folder
|
||||||
@@ -10,7 +10,7 @@ export async function initProject() {
|
|||||||
if (!folder) {
|
if (!folder) {
|
||||||
folder = await input({
|
folder = await input({
|
||||||
message: c.gray('Enter project name:'),
|
message: c.gray('Enter project name:'),
|
||||||
default: 'rage-fw',
|
default: 'rage-fw-example',
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
console.log(c.gray('Project name:'), folder)
|
console.log(c.gray('Project name:'), folder)
|
||||||
@@ -19,19 +19,14 @@ export async function initProject() {
|
|||||||
if (!framework) {
|
if (!framework) {
|
||||||
framework = await select({
|
framework = await select({
|
||||||
message: c.gray('Select frontend:'),
|
message: c.gray('Select frontend:'),
|
||||||
default: 'react',
|
default: 'react-18',
|
||||||
loop: true,
|
loop: true,
|
||||||
choices: [
|
choices: [
|
||||||
{
|
{
|
||||||
name: 'React + TypeScript (Vite)',
|
name: 'React + TypeScript (Vite)',
|
||||||
value: 'react',
|
value: 'react-18',
|
||||||
description: 'React + TypeScript (Vite) as a frontend',
|
description: 'React + TypeScript (Vite) as a frontend',
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// name: 'vue',
|
|
||||||
// value: 'vue',
|
|
||||||
// description: 'npm is the most popular package manager',
|
|
||||||
// },
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@@ -46,21 +41,20 @@ export async function initProject() {
|
|||||||
c.gray('as a frontend..'),
|
c.gray('as a frontend..'),
|
||||||
)
|
)
|
||||||
|
|
||||||
clone(
|
cloneBranch(
|
||||||
'https://git.entityseven.com/entityseven/rage-framework-example',
|
'https://git.entityseven.com/entityseven/rage-framework-example',
|
||||||
path.join(process.cwd(), folder),
|
path.join(process.cwd(), folder),
|
||||||
{},
|
framework,
|
||||||
err => {
|
)
|
||||||
if (err) {
|
.then(() => {
|
||||||
console.log(c.red('Error occured: \n', err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
console.log(c.gray('Scaffolded project into'), folder)
|
console.log(c.gray('Scaffolded project into'), folder)
|
||||||
console.log(
|
console.log(
|
||||||
c.gray(
|
c.gray(
|
||||||
`Project was created ar dir: ${path.join(process.cwd(), folder)}`,
|
`Project was created ar dir: ${path.join(process.cwd(), folder)}`,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
},
|
})
|
||||||
)
|
.catch(e => {
|
||||||
|
console.log(c.red('Error occured: \n', e))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import axios from 'axios'
|
|
||||||
import * as fs from 'node:fs'
|
import * as fs from 'node:fs'
|
||||||
|
|
||||||
const latestReleases =
|
const latestReleases =
|
||||||
@@ -13,17 +12,21 @@ type Asset = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadUpdater(): Promise<void> {
|
export async function downloadUpdater(): Promise<void> {
|
||||||
|
const ky = await import('ky').then(ky => ky.default)
|
||||||
const id = await getLatestReleaseID()
|
const id = await getLatestReleaseID()
|
||||||
|
|
||||||
const latestAssets = `https://git.entityseven.com/api/v1/repos/entityseven/rage-server-downloader/releases/${id}/assets?page=1&limit=1`
|
const latestAssets = `https://git.entityseven.com/api/v1/repos/entityseven/rage-server-downloader/releases/${id}/assets?page=1&limit=1`
|
||||||
|
|
||||||
axios.get<Asset[]>(latestAssets).then(async ({ data }) => {
|
ky.get<Asset[]>(latestAssets)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(async data => {
|
||||||
const downloadURL = data[0].browser_download_url
|
const downloadURL = data[0].browser_download_url
|
||||||
|
|
||||||
const file = await axios.get(data[0].browser_download_url, {
|
const file = await ky.get(data[0].browser_download_url)
|
||||||
responseType: 'arraybuffer',
|
const fileData = Buffer.from(
|
||||||
})
|
file as unknown as WithImplicitCoercion<string>,
|
||||||
const fileData = Buffer.from(file.data, 'binary')
|
'binary',
|
||||||
|
)
|
||||||
|
|
||||||
const fileSplit = downloadURL.split('/')
|
const fileSplit = downloadURL.split('/')
|
||||||
const fileName = fileSplit[fileSplit.length - 1]
|
const fileName = fileSplit[fileSplit.length - 1]
|
||||||
@@ -33,5 +36,9 @@ export async function downloadUpdater(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getLatestReleaseID() {
|
async function getLatestReleaseID() {
|
||||||
return axios.get<Release[]>(latestReleases).then(({ data }) => data[0].id)
|
const ky = await import('ky').then(ky => ky.default)
|
||||||
|
return ky
|
||||||
|
.get<Release[]>(latestReleases)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => data[0].id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import c from 'chalk'
|
||||||
|
import { input, select } from '@inquirer/prompts'
|
||||||
|
import path from 'node:path'
|
||||||
|
import { cloneBranch } from '../utils/cloner'
|
||||||
|
|
||||||
|
const choices = {
|
||||||
|
'rpc-react-18': {
|
||||||
|
name: 'Vite + React 18 + TypeScript',
|
||||||
|
value: 'rpc-react-18',
|
||||||
|
description: 'Vite + React 18 + TypeScript as a frontend',
|
||||||
|
},
|
||||||
|
'rpc-svelte-5': {
|
||||||
|
name: 'Vite + Svelte 5 + TypeScript',
|
||||||
|
value: 'rpc-svelte-5',
|
||||||
|
description: 'Vite + Svelte 5 + TypeScript as a frontend',
|
||||||
|
},
|
||||||
|
} as const
|
||||||
|
|
||||||
|
export async function testRpc() {
|
||||||
|
let folder
|
||||||
|
let framework
|
||||||
|
|
||||||
|
if (!folder) {
|
||||||
|
folder = await input({
|
||||||
|
message: c.gray('Enter project name:'),
|
||||||
|
default: 'rage-fw-rpc-example',
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.log(c.gray('Project name:'), folder)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!framework) {
|
||||||
|
framework = await select({
|
||||||
|
message: c.gray('Select frontend:'),
|
||||||
|
default: 'rpc-react-18',
|
||||||
|
loop: true,
|
||||||
|
choices: Object.values(choices),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.log(c.gray('Frontend:'), framework)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
c.gray('\nScaffolding template project into'),
|
||||||
|
folder,
|
||||||
|
c.gray('with'),
|
||||||
|
choices[framework].name,
|
||||||
|
c.gray('as a frontend..'),
|
||||||
|
)
|
||||||
|
|
||||||
|
cloneBranch(
|
||||||
|
'https://git.entityseven.com/entityseven/rage-framework-example',
|
||||||
|
path.join(process.cwd(), folder),
|
||||||
|
framework,
|
||||||
|
)
|
||||||
|
.then(() => {
|
||||||
|
console.log(c.gray('Scaffolded project into'), folder)
|
||||||
|
console.log(
|
||||||
|
c.gray(
|
||||||
|
`Project was created at dir: ${path.join(process.cwd(), folder)}`,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
console.log(c.red('Error occured: \n', e))
|
||||||
|
})
|
||||||
|
}
|
||||||
+27
-10
@@ -1,40 +1,57 @@
|
|||||||
import c from 'chalk'
|
import c from 'chalk'
|
||||||
import { select } from '@inquirer/prompts'
|
import { select } from '@inquirer/prompts'
|
||||||
|
|
||||||
import { checkForUpdate } from './utils/update'
|
import { checkForUpdates } from './utils/update'
|
||||||
import { initProject } from './commands/create'
|
import { initProject } from './commands/create'
|
||||||
import { downloadUpdater } from './commands/download-updater'
|
import { downloadUpdater } from './commands/download-updater'
|
||||||
|
import { testRpc } from './commands/test-rpc'
|
||||||
|
|
||||||
enum Actions {
|
enum Actions {
|
||||||
INIT_PROJECT = 'INIT_PROJECT',
|
INIT_PROJECT = 'INIT_PROJECT',
|
||||||
|
TEST_RPC = 'TEST_RPC',
|
||||||
UPDATER = 'UPDATER',
|
UPDATER = 'UPDATER',
|
||||||
}
|
}
|
||||||
|
|
||||||
;(async () => {
|
;(async () => {
|
||||||
await checkForUpdate()
|
await checkForUpdates()
|
||||||
|
|
||||||
console.log(
|
console.log(c.blueBright('Rage FW CLI | Powered by Entity Seven Group ️<3'))
|
||||||
c.blueBright('Rage FW CLI | Powered by Entity Seven Group ️ <3'),
|
|
||||||
)
|
|
||||||
|
|
||||||
const action = await select({
|
const action = await select({
|
||||||
message: c.gray('Select action:'),
|
message: c.gray('Select action:'),
|
||||||
choices: [
|
choices: [
|
||||||
{
|
{
|
||||||
name: 'Initialize new project',
|
name: 'Initialize a new project',
|
||||||
value: Actions.INIT_PROJECT,
|
value: Actions.INIT_PROJECT,
|
||||||
description: 'Initialize new project and start develop',
|
description: 'Initialize a new project and start developing',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Test our RPC',
|
||||||
|
value: Actions.TEST_RPC,
|
||||||
|
description:
|
||||||
|
'Initialize a new skeleton project with our RPC set up',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Install RAGE:MP updater',
|
name: 'Install RAGE:MP updater',
|
||||||
value: Actions.UPDATER,
|
value: Actions.UPDATER,
|
||||||
description:
|
description:
|
||||||
'Use our custom updater to download and update RAGE:MP server files.',
|
'Use our tool to download or update RAGE:MP server files in two clicks',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
loop: true,
|
loop: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (action === Actions.INIT_PROJECT) await initProject()
|
switch (action) {
|
||||||
if (action === Actions.UPDATER) await downloadUpdater()
|
case Actions.INIT_PROJECT:
|
||||||
|
await initProject()
|
||||||
|
break
|
||||||
|
case Actions.TEST_RPC:
|
||||||
|
await testRpc()
|
||||||
|
break
|
||||||
|
case Actions.UPDATER:
|
||||||
|
await downloadUpdater()
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
console.log(c.red('Something went wrong..'))
|
||||||
|
}
|
||||||
})()
|
})()
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { exec } from 'child_process'
|
||||||
|
|
||||||
|
export async function cloneBranch(link: string, path: string, branch: string) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const args = ['--single-branch', '-b', branch, '--', link, path]
|
||||||
|
const proc = exec('git clone ' + args.join(' '))
|
||||||
|
|
||||||
|
proc.on('close', (status: number) => {
|
||||||
|
if (status == 0) {
|
||||||
|
resolve(true)
|
||||||
|
} else if (status == 128) {
|
||||||
|
reject(
|
||||||
|
`Folder already exists. 'git clone' from branch ${branch} failed with status ` +
|
||||||
|
status,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
reject(
|
||||||
|
`'git clone' from branch ${branch} failed with status ` +
|
||||||
|
status,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import axios from 'axios'
|
|
||||||
import c from 'chalk'
|
import c from 'chalk'
|
||||||
import yargs from 'yargs'
|
import yargs from 'yargs'
|
||||||
|
|
||||||
@@ -10,12 +9,15 @@ type Version = {
|
|||||||
message: string
|
message: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkForUpdate(): Promise<void> {
|
export async function checkForUpdates(): Promise<void> {
|
||||||
|
const ky = await import('ky').then(ky => ky.default)
|
||||||
|
|
||||||
return new Promise(res => {
|
return new Promise(res => {
|
||||||
yargs.showVersion(version =>
|
yargs.showVersion(version =>
|
||||||
axios
|
ky
|
||||||
.get<Version[]>(latestVersionURL)
|
.get<Version[]>(latestVersionURL)
|
||||||
.then(({ data }) => {
|
.then(response => response.json<Version[]>())
|
||||||
|
.then(data => {
|
||||||
const latestVersion = data[0].name
|
const latestVersion = data[0].name
|
||||||
|
|
||||||
if (latestVersion !== `v${version}`)
|
if (latestVersion !== `v${version}`)
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "rage-fw-client",
|
"name": "@entityseven/rage-fw-client",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/src/index.d.ts",
|
"types": "dist/src/index.d.ts",
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
"build": "tsup"
|
"build": "tsup"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ragefw-rpc": "workspace:^"
|
"rage-fw-rpc": "workspace:^"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@ragempcommunity/types-client": "^2.1.8",
|
"@ragempcommunity/types-client": "^2.1.8",
|
||||||
|
|||||||
@@ -1,20 +1,33 @@
|
|||||||
import rpc from 'rage-rpc'
|
import { Rpc } from 'rage-fw-rpc'
|
||||||
|
|
||||||
import { RageFW_ClientCallback, RageFW_ClientEvent } from '../types'
|
import type {
|
||||||
|
RageFW_ClientArgs,
|
||||||
|
RageFW_ClientCallback,
|
||||||
|
RageFW_ClientEvent,
|
||||||
|
} from '../types'
|
||||||
|
|
||||||
export class Client {
|
export class Client {
|
||||||
|
private _rpc: Rpc = new Rpc()
|
||||||
|
|
||||||
|
get rpc(): Rpc {
|
||||||
|
return this._rpc
|
||||||
|
}
|
||||||
|
|
||||||
public register<EventName extends RageFW_ClientEvent>(
|
public register<EventName extends RageFW_ClientEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: RageFW_ClientCallback<EventName>,
|
callback: RageFW_ClientCallback<EventName>,
|
||||||
): void {
|
): void {
|
||||||
rpc.register(eventName, async data => {
|
this._rpc.register(
|
||||||
|
eventName,
|
||||||
|
async (data: RageFW_ClientArgs<EventName>) => {
|
||||||
return await callback(data)
|
return await callback(data)
|
||||||
})
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public unregister<EventName extends RageFW_ClientEvent>(
|
public unregister<EventName extends RageFW_ClientEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
): void {
|
): void {
|
||||||
rpc.unregister(eventName)
|
this._rpc.unregister(eventName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import rpc from 'rage-rpc'
|
import { Rpc } from 'rage-fw-rpc'
|
||||||
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -16,15 +16,19 @@ import {
|
|||||||
} from '../types'
|
} from '../types'
|
||||||
|
|
||||||
export class Player {
|
export class Player {
|
||||||
|
private _rpc: Rpc = new Rpc()
|
||||||
public browser: BrowserMp | undefined
|
public browser: BrowserMp | undefined
|
||||||
|
|
||||||
|
get rpc(): Rpc {
|
||||||
|
return this._rpc
|
||||||
|
}
|
||||||
public trigger<EventName extends keyof RageFW_ICustomClientEvent>(
|
public trigger<EventName extends keyof RageFW_ICustomClientEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _ClientEventHasArgs<EventName> extends true
|
...args: _ClientEventHasArgs<EventName> extends true
|
||||||
? [RageFW_ClientArgs<EventName>]
|
? [RageFW_ClientArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_ClientReturn<EventName>> {
|
): Promise<RageFW_ClientReturn<EventName>> {
|
||||||
return rpc.call<RageFW_ClientReturn<EventName>>(eventName, args)
|
return this._rpc.call(eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerServer<EventName extends RageFW_ClientServerEvent>(
|
public triggerServer<EventName extends RageFW_ClientServerEvent>(
|
||||||
@@ -33,7 +37,7 @@ export class Player {
|
|||||||
? [RageFW_ClientServerArgs<EventName>]
|
? [RageFW_ClientServerArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_ClientServerReturn<EventName>> {
|
): Promise<RageFW_ClientServerReturn<EventName>> {
|
||||||
return rpc.callServer(eventName, args)
|
return this._rpc.callServer(eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerBrowser<EventName extends RageFW_CefEvent>(
|
public triggerBrowser<EventName extends RageFW_CefEvent>(
|
||||||
@@ -44,6 +48,6 @@ export class Player {
|
|||||||
): Promise<RageFW_CefReturn<EventName>> {
|
): Promise<RageFW_CefReturn<EventName>> {
|
||||||
if (!this.browser)
|
if (!this.browser)
|
||||||
throw new Error('You need to initialize browser first')
|
throw new Error('You need to initialize browser first')
|
||||||
return rpc.callBrowser(this.browser, eventName, args)
|
return this._rpc.callBrowser(this.browser, eventName, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
||||||
"version": "0.1.0",
|
"version": "0.2.1",
|
||||||
"npmClient": "pnpm"
|
"npmClient": "pnpm"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"publish": "pnpm build && lerna publish --force-publish",
|
"publish": "pnpm build && lerna publish --force-publish",
|
||||||
"build": "lerna run build",
|
"build": "lerna run build",
|
||||||
"lint": "eslint --c .eslintrc.yaml --ext .ts client/ server/ shared-types/",
|
"lint": "eslint --c .eslintrc.yaml --ext .ts client/ server/ shared-types/",
|
||||||
|
|
||||||
"rebuild:cef": "cd cef && pnpm build",
|
"rebuild:cef": "cd cef && pnpm build",
|
||||||
"rebuild:client": "cd client && pnpm build",
|
"rebuild:client": "cd client && pnpm build",
|
||||||
"rebuild:server": "cd server && pnpm build",
|
"rebuild:server": "cd server && pnpm build",
|
||||||
|
|||||||
Generated
+3229
-1052
File diff suppressed because it is too large
Load Diff
+8
-2
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "ragefw-rpc",
|
"name": "rage-fw-rpc",
|
||||||
"description": "Rage FW RPC",
|
"description": "Rage FW RPC",
|
||||||
"version": "0.2.1",
|
"version": "0.2.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -17,7 +17,13 @@
|
|||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "^5"
|
"typescript": "^5"
|
||||||
},
|
},
|
||||||
"keywords": ["ragemp", "rage", "rpc", "rage-rpc", "ragerpc"],
|
"keywords": [
|
||||||
|
"ragemp",
|
||||||
|
"rage",
|
||||||
|
"rpc",
|
||||||
|
"rage-rpc",
|
||||||
|
"ragerpc"
|
||||||
|
],
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/src/index.d.ts",
|
"types": "dist/src/index.d.ts",
|
||||||
"author": {
|
"author": {
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "rage-fw-server",
|
"name": "@entityseven/rage-fw-server",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/src/index.d.ts",
|
"types": "dist/src/index.d.ts",
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
"build": "tsup"
|
"build": "tsup"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ragefw-rpc": "workspace:^"
|
"rage-fw-rpc": "workspace:^"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@ragempcommunity/types-server": "^2.1.8",
|
"@ragempcommunity/types-server": "^2.1.8",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import rpc from 'rage-rpc'
|
import { Rpc } from 'rage-fw-rpc'
|
||||||
|
|
||||||
import {
|
import type {
|
||||||
_CefEventHasArgs,
|
_CefEventHasArgs,
|
||||||
_ClientEventHasArgs,
|
_ClientEventHasArgs,
|
||||||
RageFW_CefArgs,
|
RageFW_CefArgs,
|
||||||
@@ -12,6 +12,12 @@ import {
|
|||||||
} from '../types'
|
} from '../types'
|
||||||
|
|
||||||
export class Player {
|
export class Player {
|
||||||
|
private _rpc: Rpc = new Rpc()
|
||||||
|
|
||||||
|
get rpc(): Rpc {
|
||||||
|
return this._rpc
|
||||||
|
}
|
||||||
|
|
||||||
public triggerClient<EventName extends RageFW_ClientEvent>(
|
public triggerClient<EventName extends RageFW_ClientEvent>(
|
||||||
player: PlayerMp,
|
player: PlayerMp,
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
@@ -19,7 +25,7 @@ export class Player {
|
|||||||
? [RageFW_ServerClientArgs<EventName>]
|
? [RageFW_ServerClientArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_ServerClientReturn<EventName>> {
|
): Promise<RageFW_ServerClientReturn<EventName>> {
|
||||||
return rpc.callClient(player, eventName, args)
|
return this._rpc.callClient(player, eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerBrowser<EventName extends RageFW_CefEvent>(
|
public triggerBrowser<EventName extends RageFW_CefEvent>(
|
||||||
@@ -29,6 +35,6 @@ export class Player {
|
|||||||
? [RageFW_CefArgs<EventName>]
|
? [RageFW_CefArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_CefReturn<EventName>> {
|
): Promise<RageFW_CefReturn<EventName>> {
|
||||||
return rpc.callBrowsers(player, eventName, args)
|
return this._rpc.callBrowser(player, eventName, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import rpc from 'rage-rpc'
|
import { Rpc } from 'rage-fw-rpc'
|
||||||
import { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
|
import { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
|
||||||
|
|
||||||
import { nativeEvents } from '../native.events'
|
import { nativeEvents } from '../native.events'
|
||||||
import {
|
import type {
|
||||||
_ServerEventHasArgs,
|
_ServerEventHasArgs,
|
||||||
RageFW_ServerArgs,
|
RageFW_ServerArgs,
|
||||||
RageFW_ServerCallback,
|
RageFW_ServerCallback,
|
||||||
@@ -13,6 +13,12 @@ import {
|
|||||||
} from '../types'
|
} from '../types'
|
||||||
|
|
||||||
export class Server {
|
export class Server {
|
||||||
|
private _rpc: Rpc = new Rpc()
|
||||||
|
|
||||||
|
get rpc(): Rpc {
|
||||||
|
return this._rpc
|
||||||
|
}
|
||||||
|
|
||||||
private isNativeEvent(eventName: string): eventName is keyof IServerEvents {
|
private isNativeEvent(eventName: string): eventName is keyof IServerEvents {
|
||||||
return nativeEvents.includes(eventName)
|
return nativeEvents.includes(eventName)
|
||||||
}
|
}
|
||||||
@@ -21,8 +27,9 @@ export class Server {
|
|||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: RageFW_ServerCallbackCustom<EventName>,
|
callback: RageFW_ServerCallbackCustom<EventName>,
|
||||||
): void {
|
): void {
|
||||||
rpc.register(
|
this._rpc.register(
|
||||||
eventName,
|
eventName,
|
||||||
|
// fixme
|
||||||
async (args: RageFW_ServerArgs<EventName>, info) => {
|
async (args: RageFW_ServerArgs<EventName>, info) => {
|
||||||
await callback([info.player as PlayerMp, ...args])
|
await callback([info.player as PlayerMp, ...args])
|
||||||
},
|
},
|
||||||
@@ -80,7 +87,7 @@ export class Server {
|
|||||||
private unregisterCustom<EventName extends keyof RageFW_ICustomServerEvent>(
|
private unregisterCustom<EventName extends keyof RageFW_ICustomServerEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
): void {
|
): void {
|
||||||
rpc.unregister(eventName)
|
this._rpc.unregister(eventName)
|
||||||
}
|
}
|
||||||
|
|
||||||
private unregisterNative<EventName extends keyof IServerEvents>(
|
private unregisterNative<EventName extends keyof IServerEvents>(
|
||||||
@@ -105,6 +112,6 @@ export class Server {
|
|||||||
? [RageFW_ServerArgs<EventName>]
|
? [RageFW_ServerArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_ServerReturn<EventName>> {
|
): Promise<RageFW_ServerReturn<EventName>> {
|
||||||
return rpc.call<RageFW_ServerReturn<EventName>>(eventName, args)
|
return this._rpc.call(eventName, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user