@jpp-toolkit/plugin-build-fivem 0.0.9 → 0.0.11
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.mjs +5 -3
- package/dist/index.mjs.map +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +4 -4
- package/src/fivem-build-command.ts +10 -3
package/dist/index.mjs
CHANGED
|
@@ -82,10 +82,10 @@ var FivemBuildCommand = class FivemBuildCommand extends Command {
|
|
|
82
82
|
}
|
|
83
83
|
if (flags.watch) {
|
|
84
84
|
this.logger.info(`Building FiveM resource in watch mode...\n`);
|
|
85
|
-
compiler.watch({}, this._compilerCallback
|
|
85
|
+
compiler.watch({}, (err, stats) => this._compilerCallback(err, stats, true));
|
|
86
86
|
} else {
|
|
87
87
|
this.logger.info(`Building FiveM resource...\n`);
|
|
88
|
-
compiler.run(this._compilerCallback
|
|
88
|
+
compiler.run((err, stats) => this._compilerCallback(err, stats));
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
_parseServerAddress(address) {
|
|
@@ -96,14 +96,16 @@ var FivemBuildCommand = class FivemBuildCommand extends Command {
|
|
|
96
96
|
port: parseInt(port)
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
|
-
_compilerCallback(err, stats) {
|
|
99
|
+
_compilerCallback(err, stats, isWatchMode = false) {
|
|
100
100
|
if (err) {
|
|
101
101
|
this.logger.error(getErrMsg(err));
|
|
102
102
|
if ("details" in err) this.logger.error(err.details);
|
|
103
103
|
if ("stack" in err) this.logger.error(err.stack);
|
|
104
|
+
if (!isWatchMode) this.exit(1);
|
|
104
105
|
return;
|
|
105
106
|
}
|
|
106
107
|
if (stats) this.logger.log(stats.toString(), "\n");
|
|
108
|
+
if (!isWatchMode) this.exit(0);
|
|
107
109
|
}
|
|
108
110
|
async _enableAutoReload(compiler, resourceName, host, port, password) {
|
|
109
111
|
const rcon = new FivemRcon({
|
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 { 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
|
|
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({}, (err, stats) => this._compilerCallback(err, stats, true));\n } else {\n this.logger.info(`Building FiveM resource...\\n`);\n compiler.run((err, stats) => this._compilerCallback(err, stats));\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(\n err: Error | null,\n stats: Stats | undefined,\n isWatchMode = false,\n ): 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 if (!isWatchMode) this.exit(1);\n return;\n }\n\n if (stats) this.logger.log(stats.toString(), '\\n');\n\n if (!isWatchMode) this.exit(0);\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;EACpB,OAAO,MAAM,QAAQ;GACjB,MAAM;GACN,aAAa;GACb,SAAS;GACZ,CAAC;EACF,MAAM,MAAM,OAAO;GACf,MAAM;GACN,aAAa;GACb,SAAS,CAAC,eAAe,aAAa;GACtC,UAAU;GACb,CAAC;EACF,YAAY,MAAM,QAAQ;GACtB,MAAM;GACN,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C9B,UAAU,EAAE;AAE1C,MAAI,CAAC,QAAQ,CAAC,KACV,OAAM,IAAI,MACN,kCAAkC,QAAQ,iCAC7C;AAGL,SAAO;GAAE;GAAM,MAAM,SAAS,KAAK;GAAE;;CAGzC,AAAQ,kBACJ,KACA,OACA,cAAc,OACV;AACJ,MAAI,KAAK;AACL,QAAK,OAAO,MAAM,UAAU,IAAI,CAAC;AACjC,OAAI,aAAa,IAAK,MAAK,OAAO,MAAM,IAAI,QAAkB;AAC9D,OAAI,WAAW,IAAK,MAAK,OAAO,MAAM,IAAI,MAAM;AAChD,OAAI,CAAC,YAAa,MAAK,KAAK,EAAE;AAC9B;;AAGJ,MAAI,MAAO,MAAK,OAAO,IAAI,MAAM,UAAU,EAAE,KAAK;AAElD,MAAI,CAAC,YAAa,MAAK,KAAK,EAAE;;CAGlC,MAAc,kBACV,UACA,cACA,MACA,MACA,UACa;EACb,MAAM,OAAO,IAAI,UAAU;GAAE;GAAM;GAAM;GAAU,CAAC;AACpD,QAAM,KAAK,SAAS;AAEpB,WAAS,MAAM,KAAK,WAAW,yBAAyB,OAAO,UAAU;AACrE,OAAI,MAAM,WAAW,EAAE;AACnB,SAAK,OAAO,QAAQ,kDAAkD;AACtE;;AAGJ,QAAK,OAAO,KAAK,6BAA6B,aAAa,MAAM;AACjE,OAAI;AACA,UAAM,KAAK,yBAAyB,aAAa;AACjD,SAAK,OAAO,QAAQ,0CAA0C;YACzD,OAAO;AACZ,SAAK,OAAO,MAAM,oCAAoC,UAAU,MAAM,CAAC,IAAI;;IAEjF;;;;;;ACvKV,MAAa,WAAW,EACpB,eAAe,mBAClB"}
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jpp-toolkit/plugin-build-fivem",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Plugin that add the fivem build command to the jpp cli.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jpp",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@oclif/core": "4.8.0",
|
|
38
38
|
"@rspack/core": "1.6.7",
|
|
39
|
-
"@jpp-toolkit/rcon": "0.0.3",
|
|
40
39
|
"@jpp-toolkit/core": "0.0.15",
|
|
41
|
-
"@jpp-toolkit/
|
|
42
|
-
"@jpp-toolkit/utils": "0.0.14"
|
|
40
|
+
"@jpp-toolkit/rcon": "0.0.3",
|
|
41
|
+
"@jpp-toolkit/utils": "0.0.14",
|
|
42
|
+
"@jpp-toolkit/rspack-config": "0.0.3"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"oclif": "4.22.55"
|
|
@@ -106,10 +106,10 @@ export class FivemBuildCommand extends Command {
|
|
|
106
106
|
|
|
107
107
|
if (flags.watch) {
|
|
108
108
|
this.logger.info(`Building FiveM resource in watch mode...\n`);
|
|
109
|
-
compiler.watch({}, this._compilerCallback
|
|
109
|
+
compiler.watch({}, (err, stats) => this._compilerCallback(err, stats, true));
|
|
110
110
|
} else {
|
|
111
111
|
this.logger.info(`Building FiveM resource...\n`);
|
|
112
|
-
compiler.run(this._compilerCallback
|
|
112
|
+
compiler.run((err, stats) => this._compilerCallback(err, stats));
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -126,15 +126,22 @@ export class FivemBuildCommand extends Command {
|
|
|
126
126
|
return { host, port: parseInt(port) };
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
private _compilerCallback(
|
|
129
|
+
private _compilerCallback(
|
|
130
|
+
err: Error | null,
|
|
131
|
+
stats: Stats | undefined,
|
|
132
|
+
isWatchMode = false,
|
|
133
|
+
): void {
|
|
130
134
|
if (err) {
|
|
131
135
|
this.logger.error(getErrMsg(err));
|
|
132
136
|
if ('details' in err) this.logger.error(err.details as string);
|
|
133
137
|
if ('stack' in err) this.logger.error(err.stack);
|
|
138
|
+
if (!isWatchMode) this.exit(1);
|
|
134
139
|
return;
|
|
135
140
|
}
|
|
136
141
|
|
|
137
142
|
if (stats) this.logger.log(stats.toString(), '\n');
|
|
143
|
+
|
|
144
|
+
if (!isWatchMode) this.exit(0);
|
|
138
145
|
}
|
|
139
146
|
|
|
140
147
|
private async _enableAutoReload(
|