@demoscript/cli 1.1.8 → 1.1.9

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 (2) hide show
  1. package/dist/bundle.cjs +43 -5
  2. package/package.json +3 -3
package/dist/bundle.cjs CHANGED
@@ -74201,17 +74201,48 @@ var source_default = chalk;
74201
74201
 
74202
74202
  // src/commands/serve.ts
74203
74203
  var __dirname3 = (0, import_path3.dirname)((0, import_url2.fileURLToPath)(importMetaUrl));
74204
- function getNetworkUrl(port) {
74204
+ function getHostIp() {
74205
74205
  const nets = (0, import_os.networkInterfaces)();
74206
74206
  for (const name of Object.keys(nets)) {
74207
74207
  for (const net of nets[name] || []) {
74208
74208
  if (net.family === "IPv4" && !net.internal) {
74209
- return `http://${net.address}:${port}`;
74209
+ return net.address;
74210
74210
  }
74211
74211
  }
74212
74212
  }
74213
74213
  return null;
74214
74214
  }
74215
+ function getNetworkUrl(port) {
74216
+ const hostIp = getHostIp();
74217
+ return hostIp ? `http://${hostIp}:${port}` : null;
74218
+ }
74219
+ function replaceLocalhostWithIp(url, hostIp) {
74220
+ return url.replace(/localhost/gi, hostIp).replace(/127\.0\.0\.1/g, hostIp);
74221
+ }
74222
+ function processConfigForNetwork(config, hostIp, autoReplace) {
74223
+ if (!hostIp) return config;
74224
+ const processValue = (value) => {
74225
+ if (typeof value === "string") {
74226
+ let result = value.replace(/\$\{host_ip\}/gi, hostIp);
74227
+ if (autoReplace) {
74228
+ result = replaceLocalhostWithIp(result, hostIp);
74229
+ }
74230
+ return result;
74231
+ }
74232
+ if (Array.isArray(value)) {
74233
+ return value.map(processValue);
74234
+ }
74235
+ if (value && typeof value === "object") {
74236
+ const processed = {};
74237
+ for (const [k, v] of Object.entries(value)) {
74238
+ processed[k] = processValue(v);
74239
+ }
74240
+ return processed;
74241
+ }
74242
+ return value;
74243
+ };
74244
+ return processValue(config);
74245
+ }
74215
74246
  async function serve(demoPath, options) {
74216
74247
  const { port, host, open: open3, watch: watch2 } = options;
74217
74248
  const resolvedPath = (0, import_path3.resolve)(process.cwd(), demoPath);
@@ -74222,10 +74253,16 @@ async function serve(demoPath, options) {
74222
74253
  let { config, recordings, openapiSpec } = await loadDemo(demoFile);
74223
74254
  console.log(source_default.green(` Loaded: ${config.title}`));
74224
74255
  console.log(source_default.gray(` Steps: ${config.steps.length}`));
74256
+ const hostIp = getHostIp();
74257
+ const autoReplaceLocalhost = host === "0.0.0.0";
74258
+ if (hostIp && autoReplaceLocalhost) {
74259
+ console.log(source_default.gray(` Host IP: ${hostIp} (auto-replacing localhost)`));
74260
+ }
74225
74261
  const app = (0, import_express.default)();
74226
74262
  app.use(import_express.default.json());
74227
74263
  app.get("/api/demo", (_req, res) => {
74228
- res.json({ config, recordings, openapiSpec });
74264
+ const processedConfig = processConfigForNetwork(config, hostIp, autoReplaceLocalhost);
74265
+ res.json({ config: processedConfig, recordings, openapiSpec });
74229
74266
  });
74230
74267
  const wsClients = /* @__PURE__ */ new Set();
74231
74268
  app.post("/api/execute", createRestProxy());
@@ -74249,7 +74286,7 @@ async function serve(demoPath, options) {
74249
74286
  }
74250
74287
  }
74251
74288
  app.all("/sandbox", sandboxHandler);
74252
- app.all("/sandbox/*", sandboxHandler);
74289
+ app.all("/sandbox/*path", sandboxHandler);
74253
74290
  app.post("/api/open-browser", async (req, res) => {
74254
74291
  try {
74255
74292
  const { url } = req.body;
@@ -74362,7 +74399,8 @@ async function serve(demoPath, options) {
74362
74399
  recordings = reloaded.recordings;
74363
74400
  openapiSpec = reloaded.openapiSpec;
74364
74401
  console.log(source_default.green(` Reloaded: ${config.title}`));
74365
- const message = JSON.stringify({ type: "reload", config, recordings, openapiSpec });
74402
+ const processedConfig = processConfigForNetwork(config, hostIp, autoReplaceLocalhost);
74403
+ const message = JSON.stringify({ type: "reload", config: processedConfig, recordings, openapiSpec });
74366
74404
  for (const client of wsClients) {
74367
74405
  if (client.readyState === import_websocket.default.OPEN) {
74368
74406
  client.send(message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@demoscript/cli",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "CLI tool for DemoScript - create and present scripted product demonstrations",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,9 +20,9 @@
20
20
  "documentation"
21
21
  ],
22
22
  "scripts": {
23
- "build": "tsc && npm run bundle-ui",
24
- "bundle": "node esbuild.config.js && npm run bundle-ui",
23
+ "build": "node esbuild.config.js && npm run bundle-ui",
25
24
  "bundle-ui": "cp -r ../ui/dist ./dist/ui-dist && rm -f ./dist/ui-dist/assets/*.map",
25
+ "typecheck": "tsc --noEmit",
26
26
  "dev": "tsc --watch",
27
27
  "lint": "eslint src --ext .ts",
28
28
  "test": "vitest run",