@sgedda/mockifyer-fetch 1.8.85 → 1.8.87
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/metro-atlas-key-handlers.d.ts +8 -6
- package/dist/metro-atlas-key-handlers.js +20 -8
- package/dist/metro-config.d.ts +1 -1
- package/dist/metro-config.js +1 -1
- package/dist/metro-sync-middleware.d.ts +3 -3
- package/dist/metro-sync-middleware.js +23 -23
- package/package.json +1 -1
- package/src/metro-atlas-key-handlers.ts +23 -11
- package/src/metro-config.ts +1 -1
- package/src/metro-sync-middleware.ts +29 -32
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Metro terminal keys for Mockifyer:
|
|
3
|
-
* - `
|
|
3
|
+
* - `t` (default): start/stop Atlas capture (stop generates HTML)
|
|
4
4
|
* - `m` (default): open the Mockifyer dashboard in the browser
|
|
5
5
|
*
|
|
6
6
|
* Opening `mockifyer-atlas` (SSE `/mockifyer-network-events/stream`) auto-starts
|
|
7
|
-
* capture when idle — then press `
|
|
7
|
+
* capture when idle — then press `t` once to stop & generate.
|
|
8
8
|
*
|
|
9
|
+
* `a` is reserved by Metro for Android (`i` iOS, `r` reload, `d` Dev Menu, `j` DevTools).
|
|
9
10
|
* Disable Atlas with `atlasKey: false`, dashboard with `dashboardKey: false`.
|
|
10
11
|
*/
|
|
11
12
|
import * as readline from "readline";
|
|
12
|
-
|
|
13
|
+
/** `t` — `a` launches Android in the Metro / RN CLI. */
|
|
14
|
+
export declare const DEFAULT_METRO_ATLAS_KEY = "t";
|
|
13
15
|
export declare const DEFAULT_METRO_DASHBOARD_KEY = "m";
|
|
14
16
|
export declare const DEFAULT_METRO_DASHBOARD_URL = "http://localhost:3002";
|
|
15
17
|
export type AtlasKeyOption = string | false;
|
|
@@ -17,8 +19,8 @@ export type MetroAtlasSessionPhase = "idle" | "capturing" | "rendering";
|
|
|
17
19
|
export type MetroAtlasSessionStartReason = "key" | "stream";
|
|
18
20
|
export interface AttachMetroAtlasKeyHandlerOptions {
|
|
19
21
|
/**
|
|
20
|
-
* Key that toggles Atlas capture (default `"
|
|
21
|
-
* Pass `false` to disable.
|
|
22
|
+
* Key that toggles Atlas capture (default `"t"`).
|
|
23
|
+
* Pass `false` to disable. `a` is reserved by Metro for Android.
|
|
22
24
|
*/
|
|
23
25
|
atlasKey?: AtlasKeyOption;
|
|
24
26
|
/**
|
|
@@ -57,7 +59,7 @@ export interface AttachedMetroAtlasKeyHandler {
|
|
|
57
59
|
*/
|
|
58
60
|
export declare function resolveKeyOption(value: AtlasKeyOption | undefined, defaultKey: string): string | null;
|
|
59
61
|
/**
|
|
60
|
-
* Normalize `atlasKey` option: default `"
|
|
62
|
+
* Normalize `atlasKey` option: default `"t"`, `false` → disabled, else single char.
|
|
61
63
|
*/
|
|
62
64
|
export declare function resolveAtlasKeyOption(atlasKey?: AtlasKeyOption): string | null;
|
|
63
65
|
/**
|
|
@@ -51,20 +51,31 @@ exports.detachMetroAtlasKeyHandler = detachMetroAtlasKeyHandler;
|
|
|
51
51
|
exports.attachMetroAtlasKeyHandler = attachMetroAtlasKeyHandler;
|
|
52
52
|
/**
|
|
53
53
|
* Metro terminal keys for Mockifyer:
|
|
54
|
-
* - `
|
|
54
|
+
* - `t` (default): start/stop Atlas capture (stop generates HTML)
|
|
55
55
|
* - `m` (default): open the Mockifyer dashboard in the browser
|
|
56
56
|
*
|
|
57
57
|
* Opening `mockifyer-atlas` (SSE `/mockifyer-network-events/stream`) auto-starts
|
|
58
|
-
* capture when idle — then press `
|
|
58
|
+
* capture when idle — then press `t` once to stop & generate.
|
|
59
59
|
*
|
|
60
|
+
* `a` is reserved by Metro for Android (`i` iOS, `r` reload, `d` Dev Menu, `j` DevTools).
|
|
60
61
|
* Disable Atlas with `atlasKey: false`, dashboard with `dashboardKey: false`.
|
|
61
62
|
*/
|
|
62
63
|
const readline = __importStar(require("readline"));
|
|
63
64
|
const child_process_1 = require("child_process");
|
|
64
65
|
const mockifyer_core_1 = require("@sgedda/mockifyer-core");
|
|
65
|
-
/**
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Keys already used by @react-native/community-cli-plugin (avoid stealing).
|
|
68
|
+
* Value is the short reason shown when a binding collides.
|
|
69
|
+
*/
|
|
70
|
+
const RESERVED_METRO_KEYS = new Map([
|
|
71
|
+
["a", "Android"],
|
|
72
|
+
["d", "the Dev Menu"],
|
|
73
|
+
["i", "iOS"],
|
|
74
|
+
["j", "DevTools"],
|
|
75
|
+
["r", "reload"],
|
|
76
|
+
]);
|
|
77
|
+
/** `t` — `a` launches Android in the Metro / RN CLI. */
|
|
78
|
+
exports.DEFAULT_METRO_ATLAS_KEY = "t";
|
|
68
79
|
exports.DEFAULT_METRO_DASHBOARD_KEY = "m";
|
|
69
80
|
exports.DEFAULT_METRO_DASHBOARD_URL = "http://localhost:3002";
|
|
70
81
|
/** Delay so RN/Expo CLI can own raw-mode stdin first. */
|
|
@@ -91,7 +102,7 @@ function resolveKeyOption(value, defaultKey) {
|
|
|
91
102
|
return key || null;
|
|
92
103
|
}
|
|
93
104
|
/**
|
|
94
|
-
* Normalize `atlasKey` option: default `"
|
|
105
|
+
* Normalize `atlasKey` option: default `"t"`, `false` → disabled, else single char.
|
|
95
106
|
*/
|
|
96
107
|
function resolveAtlasKeyOption(atlasKey) {
|
|
97
108
|
return resolveKeyOption(atlasKey, exports.DEFAULT_METRO_ATLAS_KEY);
|
|
@@ -296,8 +307,9 @@ function detachMetroAtlasKeyHandler() {
|
|
|
296
307
|
streamSubscriberCount = 0;
|
|
297
308
|
}
|
|
298
309
|
function warnIfReserved(key, label) {
|
|
299
|
-
|
|
300
|
-
|
|
310
|
+
const reason = RESERVED_METRO_KEYS.get(key);
|
|
311
|
+
if (reason) {
|
|
312
|
+
mockifyer_core_1.logger.warn(`[Mockifyer] ${label} "${key}" is reserved for ${reason} — pick another letter`);
|
|
301
313
|
}
|
|
302
314
|
}
|
|
303
315
|
/**
|
package/dist/metro-config.d.ts
CHANGED
|
@@ -108,7 +108,7 @@ export interface ConfigureMetroOptions {
|
|
|
108
108
|
* syncMiddleware: {
|
|
109
109
|
* projectRoot: __dirname,
|
|
110
110
|
* mockDataPath: './mock-data',
|
|
111
|
-
* // atlasKey: '
|
|
111
|
+
* // atlasKey: 't' (default) — Metro terminal: start/stop Atlas capture (stop → HTML). `a` is Android.
|
|
112
112
|
* // dashboardKey: 'm' (default) — open dashboard in browser
|
|
113
113
|
* // dashboardUrl: 'http://localhost:3002' — or MOCKIFYER_DASHBOARD_URL
|
|
114
114
|
* },
|
package/dist/metro-config.js
CHANGED
|
@@ -127,7 +127,7 @@ function resolveMockifyerCoreReactNativeEntry(moduleName, platform) {
|
|
|
127
127
|
* syncMiddleware: {
|
|
128
128
|
* projectRoot: __dirname,
|
|
129
129
|
* mockDataPath: './mock-data',
|
|
130
|
-
* // atlasKey: '
|
|
130
|
+
* // atlasKey: 't' (default) — Metro terminal: start/stop Atlas capture (stop → HTML). `a` is Android.
|
|
131
131
|
* // dashboardKey: 'm' (default) — open dashboard in browser
|
|
132
132
|
* // dashboardUrl: 'http://localhost:3002' — or MOCKIFYER_DASHBOARD_URL
|
|
133
133
|
* },
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* 15. POST /mockifyer-network-events/snapshot — write hops JSON/NDJSON under atlas-html/
|
|
20
20
|
* 16. POST /mockifyer-network-events/render — render Atlas HTML from buffer hops
|
|
21
21
|
* 17. POST /mockifyer-network-events/clear — clear ring buffer
|
|
22
|
-
* 18. Metro terminal key `
|
|
22
|
+
* 18. Metro terminal key `t` — start/stop Atlas capture (stop generates HTML; stream auto-starts; `atlasKey: false` to disable). `a` is reserved for Android.
|
|
23
23
|
* 19. Metro terminal key `m` — open Mockifyer dashboard in the browser (`dashboardKey: false` to disable)
|
|
24
24
|
*
|
|
25
25
|
* The Hybrid Provider (recommended) uses POST /mockifyer-save for instant file sync.
|
|
@@ -34,9 +34,9 @@ export interface MetroSyncMiddlewareOptions {
|
|
|
34
34
|
/** Path to mock data directory relative to project root (default: 'mock-data') */
|
|
35
35
|
mockDataPath?: string;
|
|
36
36
|
/**
|
|
37
|
-
* Metro terminal key that starts/stops Atlas capture (default `"
|
|
37
|
+
* Metro terminal key that starts/stops Atlas capture (default `"t"`).
|
|
38
38
|
* Start clears the hop buffer; stop generates HTML (same as `POST /mockifyer-network-events/render`).
|
|
39
|
-
* Pass `false` to disable.
|
|
39
|
+
* Pass `false` to disable. `a` is reserved by Metro for Android.
|
|
40
40
|
*/
|
|
41
41
|
atlasKey?: AtlasKeyOption;
|
|
42
42
|
/**
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* 15. POST /mockifyer-network-events/snapshot — write hops JSON/NDJSON under atlas-html/
|
|
21
21
|
* 16. POST /mockifyer-network-events/render — render Atlas HTML from buffer hops
|
|
22
22
|
* 17. POST /mockifyer-network-events/clear — clear ring buffer
|
|
23
|
-
* 18. Metro terminal key `
|
|
23
|
+
* 18. Metro terminal key `t` — start/stop Atlas capture (stop generates HTML; stream auto-starts; `atlasKey: false` to disable). `a` is reserved for Android.
|
|
24
24
|
* 19. Metro terminal key `m` — open Mockifyer dashboard in the browser (`dashboardKey: false` to disable)
|
|
25
25
|
*
|
|
26
26
|
* The Hybrid Provider (recommended) uses POST /mockifyer-save for instant file sync.
|
|
@@ -961,6 +961,8 @@ function createMockSyncMiddleware(options) {
|
|
|
961
961
|
const testConfig = getTestGenerationConfig(options);
|
|
962
962
|
// Log the resolved paths for debugging
|
|
963
963
|
mockifyer_core_1.logger.info(`[MetroSyncMiddleware] Initialized with projectRoot: ${projectRoot}, mockDataPath: ${mockDataPath}`);
|
|
964
|
+
/** Last scenario announced at info. Polls of an unchanged scenario stay quiet. */
|
|
965
|
+
let announcedScenario;
|
|
964
966
|
(0, metro_atlas_key_handlers_1.attachMetroAtlasKeyHandler)({
|
|
965
967
|
atlasKey: options?.atlasKey,
|
|
966
968
|
dashboardKey: options?.dashboardKey,
|
|
@@ -1603,41 +1605,39 @@ function createMockSyncMiddleware(options) {
|
|
|
1603
1605
|
}
|
|
1604
1606
|
// Handle GET endpoint for scenario config
|
|
1605
1607
|
if (url === "/mockifyer-scenario-config" && req.method === "GET") {
|
|
1608
|
+
const writeScenarioResponse = (scenario) => {
|
|
1609
|
+
if (announcedScenario !== scenario) {
|
|
1610
|
+
mockifyer_core_1.logger.info(`[MetroSyncMiddleware] Active scenario: ${scenario}`);
|
|
1611
|
+
announcedScenario = scenario;
|
|
1612
|
+
}
|
|
1613
|
+
res.setHeader("Content-Type", "application/json");
|
|
1614
|
+
res.end(JSON.stringify({
|
|
1615
|
+
success: true,
|
|
1616
|
+
currentScenario: scenario,
|
|
1617
|
+
}));
|
|
1618
|
+
};
|
|
1606
1619
|
try {
|
|
1607
1620
|
// Check environment variable first (highest priority)
|
|
1608
1621
|
if (process.env.MOCKIFYER_SCENARIO) {
|
|
1609
|
-
mockifyer_core_1.logger.
|
|
1610
|
-
|
|
1611
|
-
res.end(JSON.stringify({
|
|
1612
|
-
success: true,
|
|
1613
|
-
currentScenario: process.env.MOCKIFYER_SCENARIO,
|
|
1614
|
-
}));
|
|
1622
|
+
mockifyer_core_1.logger.debug(`[MetroSyncMiddleware] Using scenario from MOCKIFYER_SCENARIO env var: ${process.env.MOCKIFYER_SCENARIO}`);
|
|
1623
|
+
writeScenarioResponse(process.env.MOCKIFYER_SCENARIO);
|
|
1615
1624
|
return;
|
|
1616
1625
|
}
|
|
1617
1626
|
const configPath = path.join(mockDataPath, "scenario-config.json");
|
|
1618
1627
|
const resolvedPath = path.resolve(configPath);
|
|
1619
|
-
mockifyer_core_1.logger.
|
|
1620
|
-
mockifyer_core_1.logger.
|
|
1628
|
+
mockifyer_core_1.logger.debug(`[MetroSyncMiddleware] Reading scenario config from: ${resolvedPath}`);
|
|
1629
|
+
mockifyer_core_1.logger.debug(`[MetroSyncMiddleware] mockDataPath: ${mockDataPath}, projectRoot: ${projectRoot}`);
|
|
1621
1630
|
if (fs.existsSync(configPath)) {
|
|
1622
1631
|
const fileContent = fs.readFileSync(configPath, "utf-8");
|
|
1623
|
-
mockifyer_core_1.logger.
|
|
1632
|
+
mockifyer_core_1.logger.debug(`[MetroSyncMiddleware] File content: ${fileContent}`);
|
|
1624
1633
|
const config = JSON.parse(fileContent);
|
|
1625
1634
|
const scenario = config.currentScenario || DEFAULT_SCENARIO;
|
|
1626
|
-
mockifyer_core_1.logger.
|
|
1627
|
-
|
|
1628
|
-
// Return format expected by ExpoFileSystemProvider: { success: true, currentScenario: ... }
|
|
1629
|
-
res.end(JSON.stringify({
|
|
1630
|
-
success: true,
|
|
1631
|
-
currentScenario: scenario,
|
|
1632
|
-
}));
|
|
1635
|
+
mockifyer_core_1.logger.debug(`[MetroSyncMiddleware] Found scenario in config: ${scenario} (from file: ${JSON.stringify(config)})`);
|
|
1636
|
+
writeScenarioResponse(scenario);
|
|
1633
1637
|
}
|
|
1634
1638
|
else {
|
|
1635
|
-
mockifyer_core_1.logger.
|
|
1636
|
-
|
|
1637
|
-
res.end(JSON.stringify({
|
|
1638
|
-
success: true,
|
|
1639
|
-
currentScenario: DEFAULT_SCENARIO,
|
|
1640
|
-
}));
|
|
1639
|
+
mockifyer_core_1.logger.debug(`[MetroSyncMiddleware] Config file not found at ${resolvedPath}, returning default scenario`);
|
|
1640
|
+
writeScenarioResponse(DEFAULT_SCENARIO);
|
|
1641
1641
|
}
|
|
1642
1642
|
}
|
|
1643
1643
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Metro terminal keys for Mockifyer:
|
|
3
|
-
* - `
|
|
3
|
+
* - `t` (default): start/stop Atlas capture (stop generates HTML)
|
|
4
4
|
* - `m` (default): open the Mockifyer dashboard in the browser
|
|
5
5
|
*
|
|
6
6
|
* Opening `mockifyer-atlas` (SSE `/mockifyer-network-events/stream`) auto-starts
|
|
7
|
-
* capture when idle — then press `
|
|
7
|
+
* capture when idle — then press `t` once to stop & generate.
|
|
8
8
|
*
|
|
9
|
+
* `a` is reserved by Metro for Android (`i` iOS, `r` reload, `d` Dev Menu, `j` DevTools).
|
|
9
10
|
* Disable Atlas with `atlasKey: false`, dashboard with `dashboardKey: false`.
|
|
10
11
|
*/
|
|
11
12
|
import * as readline from "readline";
|
|
12
13
|
import { spawn } from "child_process";
|
|
13
14
|
import { logger } from "@sgedda/mockifyer-core";
|
|
14
15
|
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Keys already used by @react-native/community-cli-plugin (avoid stealing).
|
|
18
|
+
* Value is the short reason shown when a binding collides.
|
|
19
|
+
*/
|
|
20
|
+
const RESERVED_METRO_KEYS: ReadonlyMap<string, string> = new Map([
|
|
21
|
+
["a", "Android"],
|
|
22
|
+
["d", "the Dev Menu"],
|
|
23
|
+
["i", "iOS"],
|
|
24
|
+
["j", "DevTools"],
|
|
25
|
+
["r", "reload"],
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
/** `t` — `a` launches Android in the Metro / RN CLI. */
|
|
29
|
+
export const DEFAULT_METRO_ATLAS_KEY = "t";
|
|
19
30
|
export const DEFAULT_METRO_DASHBOARD_KEY = "m";
|
|
20
31
|
export const DEFAULT_METRO_DASHBOARD_URL = "http://localhost:3002";
|
|
21
32
|
|
|
@@ -30,8 +41,8 @@ export type MetroAtlasSessionStartReason = "key" | "stream";
|
|
|
30
41
|
|
|
31
42
|
export interface AttachMetroAtlasKeyHandlerOptions {
|
|
32
43
|
/**
|
|
33
|
-
* Key that toggles Atlas capture (default `"
|
|
34
|
-
* Pass `false` to disable.
|
|
44
|
+
* Key that toggles Atlas capture (default `"t"`).
|
|
45
|
+
* Pass `false` to disable. `a` is reserved by Metro for Android.
|
|
35
46
|
*/
|
|
36
47
|
atlasKey?: AtlasKeyOption;
|
|
37
48
|
/**
|
|
@@ -102,7 +113,7 @@ export function resolveKeyOption(
|
|
|
102
113
|
}
|
|
103
114
|
|
|
104
115
|
/**
|
|
105
|
-
* Normalize `atlasKey` option: default `"
|
|
116
|
+
* Normalize `atlasKey` option: default `"t"`, `false` → disabled, else single char.
|
|
106
117
|
*/
|
|
107
118
|
export function resolveAtlasKeyOption(
|
|
108
119
|
atlasKey?: AtlasKeyOption,
|
|
@@ -331,9 +342,10 @@ export function detachMetroAtlasKeyHandler(): void {
|
|
|
331
342
|
}
|
|
332
343
|
|
|
333
344
|
function warnIfReserved(key: string, label: string): void {
|
|
334
|
-
|
|
345
|
+
const reason = RESERVED_METRO_KEYS.get(key);
|
|
346
|
+
if (reason) {
|
|
335
347
|
logger.warn(
|
|
336
|
-
`[Mockifyer] ${label} "${key}"
|
|
348
|
+
`[Mockifyer] ${label} "${key}" is reserved for ${reason} — pick another letter`,
|
|
337
349
|
);
|
|
338
350
|
}
|
|
339
351
|
}
|
package/src/metro-config.ts
CHANGED
|
@@ -171,7 +171,7 @@ export interface ConfigureMetroOptions {
|
|
|
171
171
|
* syncMiddleware: {
|
|
172
172
|
* projectRoot: __dirname,
|
|
173
173
|
* mockDataPath: './mock-data',
|
|
174
|
-
* // atlasKey: '
|
|
174
|
+
* // atlasKey: 't' (default) — Metro terminal: start/stop Atlas capture (stop → HTML). `a` is Android.
|
|
175
175
|
* // dashboardKey: 'm' (default) — open dashboard in browser
|
|
176
176
|
* // dashboardUrl: 'http://localhost:3002' — or MOCKIFYER_DASHBOARD_URL
|
|
177
177
|
* },
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* 15. POST /mockifyer-network-events/snapshot — write hops JSON/NDJSON under atlas-html/
|
|
20
20
|
* 16. POST /mockifyer-network-events/render — render Atlas HTML from buffer hops
|
|
21
21
|
* 17. POST /mockifyer-network-events/clear — clear ring buffer
|
|
22
|
-
* 18. Metro terminal key `
|
|
22
|
+
* 18. Metro terminal key `t` — start/stop Atlas capture (stop generates HTML; stream auto-starts; `atlasKey: false` to disable). `a` is reserved for Android.
|
|
23
23
|
* 19. Metro terminal key `m` — open Mockifyer dashboard in the browser (`dashboardKey: false` to disable)
|
|
24
24
|
*
|
|
25
25
|
* The Hybrid Provider (recommended) uses POST /mockifyer-save for instant file sync.
|
|
@@ -77,9 +77,9 @@ export interface MetroSyncMiddlewareOptions {
|
|
|
77
77
|
/** Path to mock data directory relative to project root (default: 'mock-data') */
|
|
78
78
|
mockDataPath?: string;
|
|
79
79
|
/**
|
|
80
|
-
* Metro terminal key that starts/stops Atlas capture (default `"
|
|
80
|
+
* Metro terminal key that starts/stops Atlas capture (default `"t"`).
|
|
81
81
|
* Start clears the hop buffer; stop generates HTML (same as `POST /mockifyer-network-events/render`).
|
|
82
|
-
* Pass `false` to disable.
|
|
82
|
+
* Pass `false` to disable. `a` is reserved by Metro for Android.
|
|
83
83
|
*/
|
|
84
84
|
atlasKey?: AtlasKeyOption;
|
|
85
85
|
/**
|
|
@@ -1274,6 +1274,9 @@ export function createMockSyncMiddleware(options?: MetroSyncMiddlewareOptions) {
|
|
|
1274
1274
|
`[MetroSyncMiddleware] Initialized with projectRoot: ${projectRoot}, mockDataPath: ${mockDataPath}`,
|
|
1275
1275
|
);
|
|
1276
1276
|
|
|
1277
|
+
/** Last scenario announced at info. Polls of an unchanged scenario stay quiet. */
|
|
1278
|
+
let announcedScenario: string | undefined;
|
|
1279
|
+
|
|
1277
1280
|
attachMetroAtlasKeyHandler({
|
|
1278
1281
|
atlasKey: options?.atlasKey,
|
|
1279
1282
|
dashboardKey: options?.dashboardKey,
|
|
@@ -2084,59 +2087,53 @@ export function createMockSyncMiddleware(options?: MetroSyncMiddlewareOptions) {
|
|
|
2084
2087
|
|
|
2085
2088
|
// Handle GET endpoint for scenario config
|
|
2086
2089
|
if (url === "/mockifyer-scenario-config" && req.method === "GET") {
|
|
2090
|
+
const writeScenarioResponse = (scenario: string): void => {
|
|
2091
|
+
if (announcedScenario !== scenario) {
|
|
2092
|
+
logger.info(`[MetroSyncMiddleware] Active scenario: ${scenario}`);
|
|
2093
|
+
announcedScenario = scenario;
|
|
2094
|
+
}
|
|
2095
|
+
res.setHeader("Content-Type", "application/json");
|
|
2096
|
+
res.end(
|
|
2097
|
+
JSON.stringify({
|
|
2098
|
+
success: true,
|
|
2099
|
+
currentScenario: scenario,
|
|
2100
|
+
}),
|
|
2101
|
+
);
|
|
2102
|
+
};
|
|
2103
|
+
|
|
2087
2104
|
try {
|
|
2088
2105
|
// Check environment variable first (highest priority)
|
|
2089
2106
|
if (process.env.MOCKIFYER_SCENARIO) {
|
|
2090
|
-
logger.
|
|
2107
|
+
logger.debug(
|
|
2091
2108
|
`[MetroSyncMiddleware] Using scenario from MOCKIFYER_SCENARIO env var: ${process.env.MOCKIFYER_SCENARIO}`,
|
|
2092
2109
|
);
|
|
2093
|
-
|
|
2094
|
-
res.end(
|
|
2095
|
-
JSON.stringify({
|
|
2096
|
-
success: true,
|
|
2097
|
-
currentScenario: process.env.MOCKIFYER_SCENARIO,
|
|
2098
|
-
}),
|
|
2099
|
-
);
|
|
2110
|
+
writeScenarioResponse(process.env.MOCKIFYER_SCENARIO);
|
|
2100
2111
|
return;
|
|
2101
2112
|
}
|
|
2102
2113
|
|
|
2103
2114
|
const configPath = path.join(mockDataPath, "scenario-config.json");
|
|
2104
2115
|
const resolvedPath = path.resolve(configPath);
|
|
2105
|
-
logger.
|
|
2116
|
+
logger.debug(
|
|
2106
2117
|
`[MetroSyncMiddleware] Reading scenario config from: ${resolvedPath}`,
|
|
2107
2118
|
);
|
|
2108
|
-
logger.
|
|
2119
|
+
logger.debug(
|
|
2109
2120
|
`[MetroSyncMiddleware] mockDataPath: ${mockDataPath}, projectRoot: ${projectRoot}`,
|
|
2110
2121
|
);
|
|
2111
2122
|
|
|
2112
2123
|
if (fs.existsSync(configPath)) {
|
|
2113
2124
|
const fileContent = fs.readFileSync(configPath, "utf-8");
|
|
2114
|
-
logger.
|
|
2125
|
+
logger.debug(`[MetroSyncMiddleware] File content: ${fileContent}`);
|
|
2115
2126
|
const config = JSON.parse(fileContent);
|
|
2116
2127
|
const scenario = config.currentScenario || DEFAULT_SCENARIO;
|
|
2117
|
-
logger.
|
|
2128
|
+
logger.debug(
|
|
2118
2129
|
`[MetroSyncMiddleware] Found scenario in config: ${scenario} (from file: ${JSON.stringify(config)})`,
|
|
2119
2130
|
);
|
|
2120
|
-
|
|
2121
|
-
res.setHeader("Content-Type", "application/json");
|
|
2122
|
-
// Return format expected by ExpoFileSystemProvider: { success: true, currentScenario: ... }
|
|
2123
|
-
res.end(
|
|
2124
|
-
JSON.stringify({
|
|
2125
|
-
success: true,
|
|
2126
|
-
currentScenario: scenario,
|
|
2127
|
-
}),
|
|
2128
|
-
);
|
|
2131
|
+
writeScenarioResponse(scenario);
|
|
2129
2132
|
} else {
|
|
2130
|
-
logger.
|
|
2133
|
+
logger.debug(
|
|
2131
2134
|
`[MetroSyncMiddleware] Config file not found at ${resolvedPath}, returning default scenario`,
|
|
2132
2135
|
);
|
|
2133
|
-
|
|
2134
|
-
res.end(
|
|
2135
|
-
JSON.stringify({
|
|
2136
|
-
success: true,
|
|
2137
|
-
currentScenario: DEFAULT_SCENARIO,
|
|
2138
|
-
}),
|
|
2139
|
-
);
|
|
2136
|
+
writeScenarioResponse(DEFAULT_SCENARIO);
|
|
2140
2137
|
}
|
|
2141
2138
|
} catch (error) {
|
|
2142
2139
|
logger.error(
|