@chrisivey01/builder 1.0.4 → 1.0.6

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.
Files changed (3) hide show
  1. package/index.d.ts +4 -18
  2. package/index.js +32 -1
  3. package/package.json +4 -1
package/index.d.ts CHANGED
@@ -1,21 +1,3 @@
1
- /**
2
- * @typedef {Object} BuildConfig
3
- * @property {'browser' | 'node' | 'neutral'} [platform] - The platform target
4
- * @property {string | string[]} [target] - The target ES version
5
- * @property {'iife' | 'cjs' | 'esm'} [format] - The output format
6
- */
7
- /**
8
- * @typedef {Object} BuilderOptions
9
- * @property {string} [cwd] - Current working directory. Defaults to process.cwd()
10
- * @property {string} [resourceName] - Name of the resource. Defaults to the basename of the cwd
11
- * @property {string[]} [args] - Command line arguments. Defaults to process.argv.slice(2)
12
- * @property {string} [restartEndpoint] - Endpoint for restarting the resource. Defaults to 'http://127.0.0.1:4689/rr'
13
- * @property {number} [restartTimeout] - Timeout for restart requests in milliseconds. Defaults to 2000
14
- * @property {number} [debounceDelay] - Debounce delay for rebuilds in milliseconds. Defaults to 500
15
- * @property {number} [webDevPort] - Port for web dev server. Defaults to 5173
16
- * @property {Record<string, BuildConfig>} [builds] - Build configurations for different targets
17
- * @property {Record<string, string>} [define] - Additional esbuild define values
18
- */
19
1
  /**
20
2
  * Build a FiveM/RedM resource with optional watch mode
21
3
  * @param {BuilderOptions} [options] - Build configuration options
@@ -65,6 +47,10 @@ export type BuilderOptions = {
65
47
  * - Port for web dev server. Defaults to 5173
66
48
  */
67
49
  webDevPort?: number;
50
+ /**
51
+ * - Server IP address for remote access. Checks SERVER_IP or HOST env vars if not provided
52
+ */
53
+ serverIP?: string;
68
54
  /**
69
55
  * - Build configurations for different targets
70
56
  */
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import esbuild from 'esbuild';
2
2
  import { execSync, spawn } from 'node:child_process';
3
3
  import fs from 'node:fs';
4
+ import { networkInterfaces } from 'node:os';
4
5
  import { basename, resolve } from 'path';
5
6
 
6
7
  /**
@@ -19,10 +20,38 @@ import { basename, resolve } from 'path';
19
20
  * @property {number} [restartTimeout] - Timeout for restart requests in milliseconds. Defaults to 2000
20
21
  * @property {number} [debounceDelay] - Debounce delay for rebuilds in milliseconds. Defaults to 500
21
22
  * @property {number} [webDevPort] - Port for web dev server. Defaults to 5173
23
+ * @property {string} [serverIP] - Server IP address for remote access. Checks SERVER_IP or HOST env vars if not provided
22
24
  * @property {Record<string, BuildConfig>} [builds] - Build configurations for different targets
23
25
  * @property {Record<string, string>} [define] - Additional esbuild define values
24
26
  */
25
27
 
28
+ /**
29
+ * Get the network IP address for remote access
30
+ * Checks environment variables first (SERVER_IP or HOST) for remote development
31
+ * @returns {string} The network IP address or fallback to 127.0.0.1
32
+ */
33
+ function getNetworkIP() {
34
+ // Check environment variables first for remote development
35
+ if (process.env.SERVER_IP) {
36
+ return process.env.SERVER_IP;
37
+ }
38
+ if (process.env.HOST) {
39
+ return process.env.HOST;
40
+ }
41
+
42
+ // Try to get from network interfaces
43
+ const nets = networkInterfaces();
44
+ for (const name of Object.keys(nets)) {
45
+ for (const net of nets[name]) {
46
+ // Skip internal (loopback) and non-IPv4 addresses
47
+ if (net.family === 'IPv4' && !net.internal) {
48
+ return net.address;
49
+ }
50
+ }
51
+ }
52
+ return '127.0.0.1'; // Fallback to localhost
53
+ }
54
+
26
55
  /**
27
56
  * Build a FiveM/RedM resource with optional watch mode
28
57
  * @param {BuilderOptions} [options] - Build configuration options
@@ -36,6 +65,8 @@ export async function build(options = {}) {
36
65
  const IS_REDM = args.includes('--redm');
37
66
  const HAS_WEB_DIR = fs.existsSync(resolve(cwd, './web'));
38
67
  const PORT = IS_REDM ? 4700 : 4689;
68
+ const SERVER_IP = options.serverIP || getNetworkIP();
69
+
39
70
  // Configuration defaults
40
71
  const config = {
41
72
  restartEndpoint: options.restartEndpoint || `http://127.0.0.1:${PORT}/rr`,
@@ -77,7 +108,7 @@ export async function build(options = {}) {
77
108
  if (!HAS_WEB_DIR) {
78
109
  updated = updated.replace(/\n?\s*ui_page\s+['"][^'"]*['"]\s*\n?/g, '\n');
79
110
  } else {
80
- const desiredUiPage = IS_WATCH ? `ui_page 'http://127.0.0.1:${config.webDevPort}'` : "ui_page 'html/index.html'";
111
+ const desiredUiPage = IS_WATCH ? `ui_page 'http://${SERVER_IP}:${config.webDevPort}'` : "ui_page 'html/index.html'";
81
112
  updated = updated.match(/ui_page\s+['"][^'"]*['"]/)
82
113
  ? updated.replace(/ui_page\s+['"][^'"]*['"]/, desiredUiPage)
83
114
  : `${updated.trimEnd()}\n\n${desiredUiPage}\n`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrisivey01/builder",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Build tool for FiveM/RedM resources with watch mode and auto-restart",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -22,6 +22,9 @@
22
22
  ],
23
23
  "author": "Chris Ivey",
24
24
  "license": "MIT",
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
25
28
  "dependencies": {
26
29
  "esbuild": "^0.27.2"
27
30
  },