@jpp-toolkit/plugin-build-fivem 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +0 -1
- package/dist/index.mjs +8 -19
- package/dist/index.mjs.map +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +4 -4
- package/src/fivem-build-command.ts +5 -21
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { Command } from "@jpp-toolkit/core";
|
|
3
|
+
import { FivemRcon } from "@jpp-toolkit/rcon";
|
|
3
4
|
import { createFivemRspackConfig } from "@jpp-toolkit/rspack-config";
|
|
4
5
|
import { getErrMsg } from "@jpp-toolkit/utils";
|
|
5
6
|
import { Flags } from "@oclif/core";
|
|
6
7
|
import { rspack } from "@rspack/core";
|
|
7
|
-
import Rcon from "rcon";
|
|
8
8
|
|
|
9
9
|
//#region src/fivem-build-command.ts
|
|
10
10
|
var FivemBuildCommand = class FivemBuildCommand extends Command {
|
|
@@ -106,32 +106,21 @@ var FivemBuildCommand = class FivemBuildCommand extends Command {
|
|
|
106
106
|
}
|
|
107
107
|
if (stats) this.logger.log(stats.toString(), "\n");
|
|
108
108
|
}
|
|
109
|
-
async _connectRcon(host, port, password) {
|
|
110
|
-
return new Promise((resolve, reject) => {
|
|
111
|
-
const rcon = new Rcon(host, port, password, {
|
|
112
|
-
tcp: false,
|
|
113
|
-
challenge: false
|
|
114
|
-
});
|
|
115
|
-
rcon.on("auth", () => resolve(rcon));
|
|
116
|
-
rcon.on("error", reject);
|
|
117
|
-
rcon.on("end", () => reject(/* @__PURE__ */ new Error("RCON connection ended unexpectedly.")));
|
|
118
|
-
rcon.connect();
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
109
|
async _enableAutoReload(compiler, resourceName, host, port, password) {
|
|
122
|
-
const rcon =
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
110
|
+
const rcon = new FivemRcon({
|
|
111
|
+
host,
|
|
112
|
+
port,
|
|
113
|
+
password
|
|
126
114
|
});
|
|
127
|
-
|
|
115
|
+
await rcon.connect();
|
|
116
|
+
compiler.hooks.done.tapPromise("FivemAutoReloadPlugin", async (stats) => {
|
|
128
117
|
if (stats.hasErrors()) {
|
|
129
118
|
this.logger.warning("Build failed. Skipping FiveM resource reload.\n");
|
|
130
119
|
return;
|
|
131
120
|
}
|
|
132
121
|
this.logger.info(`Reloading FiveM resource "${resourceName}"...`);
|
|
133
122
|
try {
|
|
134
|
-
rcon.
|
|
123
|
+
await rcon.refreshAndEnsureResource(resourceName);
|
|
135
124
|
this.logger.success(`FiveM resource reloaded successfully.\n`);
|
|
136
125
|
} catch (error) {
|
|
137
126
|
this.logger.error(`Failed to reload FiveM resource: ${getErrMsg(error)}\n`);
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/fivem-build-command.ts","../src/index.ts"],"sourcesContent":["import path from 'node:path';\n\nimport { Command } from '@jpp-toolkit/core';\nimport { createFivemRspackConfig } from '@jpp-toolkit/rspack-config';\nimport { getErrMsg } from '@jpp-toolkit/utils';\nimport { Flags } from '@oclif/core';\nimport type { Compiler, Stats } from '@rspack/core';\nimport { rspack } from '@rspack/core';\
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/fivem-build-command.ts","../src/index.ts"],"sourcesContent":["import path from 'node:path';\n\nimport { Command } from '@jpp-toolkit/core';\nimport { FivemRcon } from '@jpp-toolkit/rcon';\nimport { createFivemRspackConfig } from '@jpp-toolkit/rspack-config';\nimport { getErrMsg } from '@jpp-toolkit/utils';\nimport { Flags } from '@oclif/core';\nimport type { Compiler, Stats } from '@rspack/core';\nimport { rspack } from '@rspack/core';\n\ntype Mode = 'development' | 'production';\ntype ServerAddress = { readonly host: string; readonly port: number };\n\nexport class FivemBuildCommand extends Command {\n static override summary = 'Build the FiveM resource using predefined config.';\n\n static override flags = {\n watch: Flags.boolean({\n char: 'w',\n description: 'Watch files for changes and rebuild automatically.',\n default: false,\n }),\n mode: Flags.string({\n char: 'm',\n description: 'Set the build mode (development or production).',\n options: ['development', 'production'],\n required: false,\n }),\n autoReload: Flags.boolean({\n char: 'r',\n description: 'Automatically reload FiveM resource after build.',\n default: false,\n }),\n server: Flags.string({\n char: 's',\n description: 'Server \"ip:port\" to connect for reloading FiveM resource after build.',\n default: '127.0.0.1:30120',\n required: false,\n }),\n password: Flags.string({\n char: 'p',\n description: 'RCON password for the FiveM server to reload resource after build.',\n required: false,\n }),\n resourceName: Flags.string({\n char: 'n',\n description:\n 'Name of the FiveM resource to reload. If not provided, the name of the folder containing the resource will be used.',\n required: false,\n }),\n };\n\n static override examples = [\n {\n description: 'Build the FiveM resource.',\n command: '<%= config.bin %> <%= command.id %>',\n },\n {\n description: 'Build the FiveM resource in watch mode.',\n command: '<%= config.bin %> <%= command.id %> --watch',\n },\n {\n description: 'Build the FiveM resource in production mode.',\n command: '<%= config.bin %> <%= command.id %> --mode=production',\n },\n {\n description:\n 'Build the FiveM resource and automatically reload it on the server after build.',\n command:\n '<%= config.bin %> <%= command.id %> --auto-reload --password your_rcon_password',\n },\n {\n description:\n 'Build the FiveM resource in watch mode and automatically reload it on the server after each build.',\n command:\n '<%= config.bin %> <%= command.id %> --watch --auto-reload --password your_rcon_password',\n },\n {\n description:\n 'Build the FiveM resource and connect to a specific server for auto-reload.',\n command:\n '<%= config.bin %> <%= command.id %> --auto-reload --server=127.0.0.1:30120 --password your_rcon_password',\n },\n ];\n\n public async run(): Promise<void> {\n const { flags } = await this.parse(FivemBuildCommand);\n\n const { watch, autoReload, password } = flags;\n const mode = (flags.mode ?? (watch ? 'development' : 'production')) as Mode;\n const { host, port } = this._parseServerAddress(flags.server);\n const resourceName = flags.resourceName ?? path.basename(process.cwd());\n\n const config = createFivemRspackConfig({ mode });\n const compiler = rspack(config);\n\n if (autoReload) {\n if (!password) {\n this.fatalError(\n 'RCON password is required for auto-reload. Please provide it using the --password flag.',\n );\n }\n\n await this._enableAutoReload(compiler, resourceName, host, port, password);\n }\n\n if (flags.watch) {\n this.logger.info(`Building FiveM resource in watch mode...\\n`);\n compiler.watch({}, this._compilerCallback.bind(this));\n } else {\n this.logger.info(`Building FiveM resource...\\n`);\n compiler.run(this._compilerCallback.bind(this));\n this.exit(0);\n }\n }\n\n private _parseServerAddress(address: string): ServerAddress {\n const match = /^(?<host>[^:]+):(?<port>\\d+)$/u.exec(address);\n const { host, port } = match?.groups ?? {};\n\n if (!host || !port) {\n throw new Error(\n `Invalid server address format: ${address}. Expected format is \"ip:port\".`,\n );\n }\n\n return { host, port: parseInt(port) };\n }\n\n private _compilerCallback(err: Error | null, stats: Stats | undefined): void {\n if (err) {\n this.logger.error(getErrMsg(err));\n if ('details' in err) this.logger.error(err.details as string);\n if ('stack' in err) this.logger.error(err.stack);\n return;\n }\n\n if (stats) this.logger.log(stats.toString(), '\\n');\n }\n\n private async _enableAutoReload(\n compiler: Compiler,\n resourceName: string,\n host: string,\n port: number,\n password: string,\n ): Promise<void> {\n const rcon = new FivemRcon({ host, port, password });\n await rcon.connect();\n\n compiler.hooks.done.tapPromise('FivemAutoReloadPlugin', async (stats) => {\n if (stats.hasErrors()) {\n this.logger.warning('Build failed. Skipping FiveM resource reload.\\n');\n return;\n }\n\n this.logger.info(`Reloading FiveM resource \"${resourceName}\"...`);\n try {\n await rcon.refreshAndEnsureResource(resourceName);\n this.logger.success(`FiveM resource reloaded successfully.\\n`);\n } catch (error) {\n this.logger.error(`Failed to reload FiveM resource: ${getErrMsg(error)}\\n`);\n }\n });\n }\n}\n","import { FivemBuildCommand } from './fivem-build-command';\n\nexport const commands = {\n 'build:fivem': FivemBuildCommand,\n};\n"],"mappings":";;;;;;;;;AAaA,IAAa,oBAAb,MAAa,0BAA0B,QAAQ;CAC3C,OAAgB,UAAU;CAE1B,OAAgB,QAAQ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-build-fivem",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Plugin that add the fivem build command to the jpp cli.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jpp",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@oclif/core": "4.8.0",
|
|
38
38
|
"@rspack/core": "1.6.7",
|
|
39
|
-
"rcon": "1.1.0",
|
|
40
39
|
"@jpp-toolkit/core": "0.0.15",
|
|
41
|
-
"@jpp-toolkit/
|
|
40
|
+
"@jpp-toolkit/rcon": "0.0.2",
|
|
41
|
+
"@jpp-toolkit/rspack-config": "0.0.3",
|
|
42
42
|
"@jpp-toolkit/utils": "0.0.14"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"oclif": "4.22.
|
|
45
|
+
"oclif": "4.22.55"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": "24",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
|
|
3
3
|
import { Command } from '@jpp-toolkit/core';
|
|
4
|
+
import { FivemRcon } from '@jpp-toolkit/rcon';
|
|
4
5
|
import { createFivemRspackConfig } from '@jpp-toolkit/rspack-config';
|
|
5
6
|
import { getErrMsg } from '@jpp-toolkit/utils';
|
|
6
7
|
import { Flags } from '@oclif/core';
|
|
7
8
|
import type { Compiler, Stats } from '@rspack/core';
|
|
8
9
|
import { rspack } from '@rspack/core';
|
|
9
|
-
import Rcon from 'rcon';
|
|
10
10
|
|
|
11
11
|
type Mode = 'development' | 'production';
|
|
12
12
|
type ServerAddress = { readonly host: string; readonly port: number };
|
|
@@ -138,18 +138,6 @@ export class FivemBuildCommand extends Command {
|
|
|
138
138
|
if (stats) this.logger.log(stats.toString(), '\n');
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
private async _connectRcon(host: string, port: number, password: string): Promise<Rcon> {
|
|
142
|
-
return new Promise((resolve, reject) => {
|
|
143
|
-
const rcon = new Rcon(host, port, password, { tcp: false, challenge: false });
|
|
144
|
-
|
|
145
|
-
rcon.on('auth', () => resolve(rcon));
|
|
146
|
-
rcon.on('error', reject);
|
|
147
|
-
rcon.on('end', () => reject(new Error('RCON connection ended unexpectedly.')));
|
|
148
|
-
|
|
149
|
-
rcon.connect();
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
141
|
private async _enableAutoReload(
|
|
154
142
|
compiler: Compiler,
|
|
155
143
|
resourceName: string,
|
|
@@ -157,14 +145,10 @@ export class FivemBuildCommand extends Command {
|
|
|
157
145
|
port: number,
|
|
158
146
|
password: string,
|
|
159
147
|
): Promise<void> {
|
|
160
|
-
const rcon =
|
|
161
|
-
|
|
162
|
-
rcon.on('response', (res: string) => {
|
|
163
|
-
if (res.includes("Couldn't find resource")) this.fatalError("Couldn't find resource");
|
|
164
|
-
if (res === 'rint Invalid password') this.fatalError('Invalid password');
|
|
165
|
-
});
|
|
148
|
+
const rcon = new FivemRcon({ host, port, password });
|
|
149
|
+
await rcon.connect();
|
|
166
150
|
|
|
167
|
-
compiler.hooks.done.
|
|
151
|
+
compiler.hooks.done.tapPromise('FivemAutoReloadPlugin', async (stats) => {
|
|
168
152
|
if (stats.hasErrors()) {
|
|
169
153
|
this.logger.warning('Build failed. Skipping FiveM resource reload.\n');
|
|
170
154
|
return;
|
|
@@ -172,7 +156,7 @@ export class FivemBuildCommand extends Command {
|
|
|
172
156
|
|
|
173
157
|
this.logger.info(`Reloading FiveM resource "${resourceName}"...`);
|
|
174
158
|
try {
|
|
175
|
-
rcon.
|
|
159
|
+
await rcon.refreshAndEnsureResource(resourceName);
|
|
176
160
|
this.logger.success(`FiveM resource reloaded successfully.\n`);
|
|
177
161
|
} catch (error) {
|
|
178
162
|
this.logger.error(`Failed to reload FiveM resource: ${getErrMsg(error)}\n`);
|