Compare commits

..

No commits in common. "59910303f7ba8cc84c8e52638758328891454994" and "39e6455271d3077159a9f6492964efc1d023de40" have entirely different histories.

17 changed files with 93 additions and 249 deletions

View File

@ -11,7 +11,7 @@
"build": "tsup"
},
"dependencies": {
"rage-fw-rpc": "workspace:^"
"ragefw-rpc": "workspace:^"
},
"peerDependencies": {
"@ragempcommunity/types-cef": "^2.1.8",

View File

@ -1,6 +1,6 @@
import { Rpc } from 'rage-fw-rpc'
import rpc from 'rage-rpc'
import type {
import {
_CefEventHasArgs,
_ClientEventHasArgs,
_ServerEventHasArgs,
@ -18,18 +18,11 @@ import type {
class Cef {
private _debugMode: boolean = false
private _rpc: Rpc = new Rpc()
constructor() {}
set debug(debug: boolean) {
this._debugMode = debug
}
get rpc(): Rpc {
return this._rpc
}
public register<EventName extends keyof RageFW_ICustomCefEvent>(
eventName: EventName,
callback: RageFW_CefCallback<EventName>,
@ -39,11 +32,11 @@ class Cef {
}
if ('mp' in window) {
this._rpc.register(eventName, callback)
rpc.register(eventName, callback)
}
}
public async trigger<EventName extends keyof RageFW_ICustomCefEvent>(
public trigger<EventName extends keyof RageFW_ICustomCefEvent>(
eventName: EventName,
...args: _CefEventHasArgs<EventName> extends true
? [RageFW_CefArgs<EventName>]
@ -54,7 +47,7 @@ class Cef {
}
if ('mp' in window) {
return await this._rpc.call(eventName, args)
return rpc.call(eventName, args)
}
return Promise.reject(
@ -62,9 +55,7 @@ class Cef {
)
}
public async triggerServer<
EventName extends keyof RageFW_ICustomServerEvent,
>(
public triggerServer<EventName extends keyof RageFW_ICustomServerEvent>(
eventName: EventName,
...args: _ServerEventHasArgs<EventName> extends true
? [RageFW_ServerArgs<EventName>]
@ -75,7 +66,7 @@ class Cef {
}
if ('mp' in window) {
return await this._rpc.callServer(eventName, args)
return rpc.callServer(eventName, args)
}
return Promise.reject(
@ -83,9 +74,7 @@ class Cef {
)
}
public async triggerClient<
EventName extends keyof RageFW_ICustomClientEvent,
>(
public triggerClient<EventName extends keyof RageFW_ICustomClientEvent>(
eventName: EventName,
...args: _ClientEventHasArgs<EventName> extends true
? [RageFW_ClientArgs<EventName>]
@ -96,7 +85,7 @@ class Cef {
}
if ('mp' in window) {
return await this._rpc.callClient(eventName, args)
return rpc.callClient(eventName, args)
}
return Promise.reject(

View File

@ -16,11 +16,13 @@
],
"dependencies": {
"@inquirer/prompts": "^5.0.5",
"ky": "^1.7.2",
"axios": "^1.7.2",
"chalk": "4.1.2",
"git-clone": "^0.2.0",
"yargs": "^17.7.2"
},
"devDependencies": {
"@types/git-clone": "^0.2.4",
"@types/node": "^20.14.2",
"@types/yargs": "^17.0.32",
"prettier": "^3.3.2",

View File

@ -1,7 +1,7 @@
import c from 'chalk'
import { input, select } from '@inquirer/prompts'
import clone from 'git-clone'
import path from 'node:path'
import { cloneBranch } from '../utils/cloner'
export async function initProject() {
let folder
@ -10,7 +10,7 @@ export async function initProject() {
if (!folder) {
folder = await input({
message: c.gray('Enter project name:'),
default: 'rage-fw-example',
default: 'rage-fw',
})
} else {
console.log(c.gray('Project name:'), folder)
@ -19,14 +19,19 @@ export async function initProject() {
if (!framework) {
framework = await select({
message: c.gray('Select frontend:'),
default: 'react-18',
default: 'react',
loop: true,
choices: [
{
name: 'React + TypeScript (Vite)',
value: 'react-18',
value: 'react',
description: 'React + TypeScript (Vite) as a frontend',
},
// {
// name: 'vue',
// value: 'vue',
// description: 'npm is the most popular package manager',
// },
],
})
} else {
@ -41,20 +46,21 @@ export async function initProject() {
c.gray('as a frontend..'),
)
cloneBranch(
clone(
'https://git.entityseven.com/entityseven/rage-framework-example',
path.join(process.cwd(), folder),
framework,
)
.then(() => {
{},
err => {
if (err) {
console.log(c.red('Error occured: \n', err))
return
}
console.log(c.gray('Scaffolded project into'), folder)
console.log(
c.gray(
`Project was created ar dir: ${path.join(process.cwd(), folder)}`,
),
)
})
.catch(e => {
console.log(c.red('Error occured: \n', e))
})
},
)
}

View File

@ -1,3 +1,4 @@
import axios from 'axios'
import * as fs from 'node:fs'
const latestReleases =
@ -12,33 +13,25 @@ type Asset = {
}
export async function downloadUpdater(): Promise<void> {
const ky = await import('ky').then(ky => ky.default)
const id = await getLatestReleaseID()
const latestAssets = `https://git.entityseven.com/api/v1/repos/entityseven/rage-server-downloader/releases/${id}/assets?page=1&limit=1`
ky.get<Asset[]>(latestAssets)
.then(response => response.json())
.then(async data => {
const downloadURL = data[0].browser_download_url
axios.get<Asset[]>(latestAssets).then(async ({ data }) => {
const downloadURL = data[0].browser_download_url
const file = await ky.get(data[0].browser_download_url)
const fileData = Buffer.from(
file as unknown as WithImplicitCoercion<string>,
'binary',
)
const fileSplit = downloadURL.split('/')
const fileName = fileSplit[fileSplit.length - 1]
fs.writeFileSync(`./${fileName}`, fileData)
const file = await axios.get(data[0].browser_download_url, {
responseType: 'arraybuffer',
})
const fileData = Buffer.from(file.data, 'binary')
const fileSplit = downloadURL.split('/')
const fileName = fileSplit[fileSplit.length - 1]
fs.writeFileSync(`./${fileName}`, fileData)
})
}
async function getLatestReleaseID() {
const ky = await import('ky').then(ky => ky.default)
return ky
.get<Release[]>(latestReleases)
.then(response => response.json())
.then(data => data[0].id)
return axios.get<Release[]>(latestReleases).then(({ data }) => data[0].id)
}

View File

@ -1,67 +0,0 @@
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))
})
}

View File

@ -1,57 +1,40 @@
import c from 'chalk'
import { select } from '@inquirer/prompts'
import { checkForUpdates } from './utils/update'
import { checkForUpdate } from './utils/update'
import { initProject } from './commands/create'
import { downloadUpdater } from './commands/download-updater'
import { testRpc } from './commands/test-rpc'
enum Actions {
INIT_PROJECT = 'INIT_PROJECT',
TEST_RPC = 'TEST_RPC',
UPDATER = 'UPDATER',
}
;(async () => {
await checkForUpdates()
await checkForUpdate()
console.log(c.blueBright('Rage FW CLI | Powered by Entity Seven Group <3'))
console.log(
c.blueBright('Rage FW CLI | Powered by Entity Seven Group <3'),
)
const action = await select({
message: c.gray('Select action:'),
choices: [
{
name: 'Initialize a new project',
name: 'Initialize new project',
value: Actions.INIT_PROJECT,
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',
description: 'Initialize new project and start develop',
},
{
name: 'Install RAGE:MP updater',
value: Actions.UPDATER,
description:
'Use our tool to download or update RAGE:MP server files in two clicks',
'Use our custom updater to download and update RAGE:MP server files.',
},
],
loop: true,
})
switch (action) {
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..'))
}
if (action === Actions.INIT_PROJECT) await initProject()
if (action === Actions.UPDATER) await downloadUpdater()
})()

View File

@ -1,24 +0,0 @@
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,
)
}
})
})
}

View File

@ -1,3 +1,4 @@
import axios from 'axios'
import c from 'chalk'
import yargs from 'yargs'
@ -9,15 +10,12 @@ type Version = {
message: string
}
export async function checkForUpdates(): Promise<void> {
const ky = await import('ky').then(ky => ky.default)
export async function checkForUpdate(): Promise<void> {
return new Promise(res => {
yargs.showVersion(version =>
ky
axios
.get<Version[]>(latestVersionURL)
.then(response => response.json<Version[]>())
.then(data => {
.then(({ data }) => {
const latestVersion = data[0].name
if (latestVersion !== `v${version}`)

View File

@ -11,7 +11,7 @@
"build": "tsup"
},
"dependencies": {
"rage-fw-rpc": "workspace:^"
"ragefw-rpc": "workspace:^"
},
"peerDependencies": {
"@ragempcommunity/types-client": "^2.1.8",

View File

@ -1,33 +1,20 @@
import { Rpc } from 'rage-fw-rpc'
import rpc from 'rage-rpc'
import type {
RageFW_ClientArgs,
RageFW_ClientCallback,
RageFW_ClientEvent,
} from '../types'
import { RageFW_ClientCallback, RageFW_ClientEvent } from '../types'
export class Client {
private _rpc: Rpc = new Rpc()
get rpc(): Rpc {
return this._rpc
}
public register<EventName extends RageFW_ClientEvent>(
eventName: EventName,
callback: RageFW_ClientCallback<EventName>,
): void {
this._rpc.register(
eventName,
async (data: RageFW_ClientArgs<EventName>) => {
return await callback(data)
},
)
rpc.register(eventName, async data => {
return await callback(data)
})
}
public unregister<EventName extends RageFW_ClientEvent>(
eventName: EventName,
): void {
this._rpc.unregister(eventName)
rpc.unregister(eventName)
}
}

View File

@ -1,4 +1,4 @@
import { Rpc } from 'rage-fw-rpc'
import rpc from 'rage-rpc'
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
import {
@ -16,19 +16,15 @@ import {
} from '../types'
export class Player {
private _rpc: Rpc = new Rpc()
public browser: BrowserMp | undefined
get rpc(): Rpc {
return this._rpc
}
public trigger<EventName extends keyof RageFW_ICustomClientEvent>(
eventName: EventName,
...args: _ClientEventHasArgs<EventName> extends true
? [RageFW_ClientArgs<EventName>]
: []
): Promise<RageFW_ClientReturn<EventName>> {
return this._rpc.call(eventName, args)
return rpc.call<RageFW_ClientReturn<EventName>>(eventName, args)
}
public triggerServer<EventName extends RageFW_ClientServerEvent>(
@ -37,7 +33,7 @@ export class Player {
? [RageFW_ClientServerArgs<EventName>]
: []
): Promise<RageFW_ClientServerReturn<EventName>> {
return this._rpc.callServer(eventName, args)
return rpc.callServer(eventName, args)
}
public triggerBrowser<EventName extends RageFW_CefEvent>(
@ -48,6 +44,6 @@ export class Player {
): Promise<RageFW_CefReturn<EventName>> {
if (!this.browser)
throw new Error('You need to initialize browser first')
return this._rpc.callBrowser(this.browser, eventName, args)
return rpc.callBrowser(this.browser, eventName, args)
}
}

32
pnpm-lock.yaml generated
View File

@ -53,27 +53,27 @@ importers:
'@ragempcommunity/types-cef':
specifier: ^2.1.8
version: 2.1.8
rage-fw-rpc:
specifier: workspace:^
version: link:../rpc
rage-fw-shared-types:
specifier: workspace:^
version: link:../shared-types
rage-trpc:
specifier: workspace:^
version: link:../rpc
cli:
dependencies:
'@inquirer/prompts':
specifier: ^5.0.5
version: 5.0.5
axios:
specifier: ^1.7.2
version: 1.7.2
chalk:
specifier: 4.1.2
version: 4.1.2
git-clone:
specifier: ^0.2.0
version: 0.2.0
ky:
specifier: ^1.7.2
version: 1.7.2
yargs:
specifier: ^17.7.2
version: 17.7.2
@ -99,17 +99,17 @@ importers:
'@ragempcommunity/types-client':
specifier: ^2.1.8
version: 2.1.8
rage-fw-rpc:
specifier: workspace:^
version: link:../rpc
rage-fw-shared-types:
specifier: workspace:^
version: link:../shared-types
rage-trpc:
specifier: workspace:^
version: link:../rpc
rpc:
dependencies:
typescript:
specifier: ^5
specifier: ^5.0.0
version: 5.4.5
devDependencies:
'@microsoft/api-extractor':
@ -127,12 +127,12 @@ importers:
'@ragempcommunity/types-server':
specifier: ^2.1.8
version: 2.1.8
rage-fw-rpc:
specifier: workspace:^
version: link:../rpc
rage-fw-shared-types:
specifier: workspace:^
version: link:../shared-types
rage-trpc:
specifier: workspace:^
version: link:../rpc
shared-types: {}
@ -2269,10 +2269,6 @@ packages:
kuler@2.0.0:
resolution: {integrity: sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==}
ky@1.7.2:
resolution: {integrity: sha512-OzIvbHKKDpi60TnF9t7UUVAF1B4mcqc02z5PIvrm08Wyb+yOcz63GRvEuVxNT18a9E1SrNouhB4W2NNLeD7Ykg==}
engines: {node: '>=18'}
lerna@8.1.3:
resolution: {integrity: sha512-Dg/r1dGnRCXKsOUC3lol7o6ggYTA6WWiPQzZJNKqyygn4fzYGuA3Dro2d5677pajaqFnFA72mdCjzSyF16Vi2Q==}
engines: {node: '>=18.0.0'}
@ -5801,8 +5797,6 @@ snapshots:
kuler@2.0.0: {}
ky@1.7.2: {}
lerna@8.1.3(encoding@0.1.13):
dependencies:
'@lerna/create': 8.1.3(encoding@0.1.13)(typescript@5.4.5)

View File

@ -1,5 +1,5 @@
{
"name": "rage-fw-rpc",
"name": "ragefw-rpc",
"description": "RageFW RPC",
"version": "0.2.1",
"scripts": {

View File

@ -11,7 +11,7 @@
"build": "tsup"
},
"dependencies": {
"rage-fw-rpc": "workspace:^"
"ragefw-rpc": "workspace:^"
},
"peerDependencies": {
"@ragempcommunity/types-server": "^2.1.8",

View File

@ -1,6 +1,6 @@
import { Rpc } from 'rage-fw-rpc'
import rpc from 'rage-rpc'
import type {
import {
_CefEventHasArgs,
_ClientEventHasArgs,
RageFW_CefArgs,
@ -12,12 +12,6 @@ import type {
} from '../types'
export class Player {
private _rpc: Rpc = new Rpc()
get rpc(): Rpc {
return this._rpc
}
public triggerClient<EventName extends RageFW_ClientEvent>(
player: PlayerMp,
eventName: EventName,
@ -25,7 +19,7 @@ export class Player {
? [RageFW_ServerClientArgs<EventName>]
: []
): Promise<RageFW_ServerClientReturn<EventName>> {
return this._rpc.callClient(player, eventName, args)
return rpc.callClient(player, eventName, args)
}
public triggerBrowser<EventName extends RageFW_CefEvent>(
@ -35,6 +29,6 @@ export class Player {
? [RageFW_CefArgs<EventName>]
: []
): Promise<RageFW_CefReturn<EventName>> {
return this._rpc.callBrowser(player, eventName, args)
return rpc.callBrowsers(player, eventName, args)
}
}

View File

@ -1,8 +1,8 @@
import { Rpc } from 'rage-fw-rpc'
import rpc from 'rage-rpc'
import { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
import { nativeEvents } from '../native.events'
import type {
import {
_ServerEventHasArgs,
RageFW_ServerArgs,
RageFW_ServerCallback,
@ -13,12 +13,6 @@ import type {
} from '../types'
export class Server {
private _rpc: Rpc = new Rpc()
get rpc(): Rpc {
return this._rpc
}
private isNativeEvent(eventName: string): eventName is keyof IServerEvents {
return nativeEvents.includes(eventName)
}
@ -27,9 +21,8 @@ export class Server {
eventName: EventName,
callback: RageFW_ServerCallbackCustom<EventName>,
): void {
this._rpc.register(
rpc.register(
eventName,
// fixme
async (args: RageFW_ServerArgs<EventName>, info) => {
await callback([info.player as PlayerMp, ...args])
},
@ -87,7 +80,7 @@ export class Server {
private unregisterCustom<EventName extends keyof RageFW_ICustomServerEvent>(
eventName: EventName,
): void {
this._rpc.unregister(eventName)
rpc.unregister(eventName)
}
private unregisterNative<EventName extends keyof IServerEvents>(
@ -112,6 +105,6 @@ export class Server {
? [RageFW_ServerArgs<EventName>]
: []
): Promise<RageFW_ServerReturn<EventName>> {
return this._rpc.call(eventName, args)
return rpc.call<RageFW_ServerReturn<EventName>>(eventName, args)
}
}