make-mp-data 2.0.13 → 2.0.15

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/index.js CHANGED
@@ -56,7 +56,6 @@ const { version } = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
56
56
 
57
57
  // Environment
58
58
  const { NODE_ENV = "unknown" } = process.env;
59
- const isCLI = process.argv[1].endsWith('index.js') || process.argv[1].endsWith('cli.js');
60
59
 
61
60
  /**
62
61
  * Main data generation function
@@ -68,6 +67,7 @@ async function main(config) {
68
67
  jobTimer.start();
69
68
 
70
69
  //cli mode check for positional dungeon config
70
+ const isCLI = process.argv[1] === fileURLToPath(import.meta.url);
71
71
  if (isCLI) {
72
72
  const firstArg = config._.slice().pop()
73
73
  if (firstArg?.endsWith('.js') && existsSync(firstArg)) {
@@ -86,12 +86,13 @@ async function main(config) {
86
86
  }
87
87
 
88
88
  let validatedConfig;
89
+ let context;
89
90
  try {
90
91
  // Step 1: Validate and enrich configuration
91
92
  validatedConfig = validateDungeonConfig(config);
92
93
 
93
94
  // Step 2: Create context with validated config
94
- const context = createContext(validatedConfig);
95
+ const context = createContext(validatedConfig, null, isCLI);
95
96
 
96
97
  // Step 3: Initialize storage containers
97
98
  const storageManager = new StorageManager(context);
@@ -159,7 +160,9 @@ async function main(config) {
159
160
  };
160
161
 
161
162
  } catch (error) {
162
- if (isCLI || validatedConfig.verbose) {
163
+
164
+ // @ts-ignore
165
+ if (context.isCLI() || validatedConfig.verbose) {
163
166
  console.error(`\nāŒ Error: ${error.message}\n`);
164
167
  if (validatedConfig.verbose) {
165
168
  console.error(error.stack);
@@ -199,7 +202,7 @@ async function generateGroupProfiles(context) {
199
202
  const { config, storage } = context;
200
203
  const { groupKeys, groupProps = {} } = config;
201
204
 
202
- if (isCLI || config.verbose) {
205
+ if (context.isCLI() || config.verbose) {
203
206
  console.log('\nšŸ‘„ Generating group profiles...');
204
207
  }
205
208
 
@@ -212,7 +215,7 @@ async function generateGroupProfiles(context) {
212
215
  continue;
213
216
  }
214
217
 
215
- if (isCLI || config.verbose) {
218
+ if (context.isCLI() || config.verbose) {
216
219
  console.log(` Creating ${groupCount.toLocaleString()} ${groupKey} profiles...`);
217
220
  }
218
221
 
@@ -228,7 +231,7 @@ async function generateGroupProfiles(context) {
228
231
  }
229
232
  }
230
233
 
231
- if (isCLI || config.verbose) {
234
+ if (context.isCLI() || config.verbose) {
232
235
  console.log('āœ… Group profiles generated successfully');
233
236
  }
234
237
  }
@@ -241,7 +244,7 @@ async function generateLookupTables(context) {
241
244
  const { config, storage } = context;
242
245
  const { lookupTables } = config;
243
246
 
244
- if (isCLI || config.verbose) {
247
+ if (context.isCLI() || config.verbose) {
245
248
  console.log('\nšŸ” Generating lookup tables...');
246
249
  }
247
250
 
@@ -255,7 +258,7 @@ async function generateLookupTables(context) {
255
258
  continue;
256
259
  }
257
260
 
258
- if (isCLI || config.verbose) {
261
+ if (context.isCLI() || config.verbose) {
259
262
  console.log(` Creating ${entries.toLocaleString()} ${key} lookup entries...`);
260
263
  }
261
264
 
@@ -268,7 +271,7 @@ async function generateLookupTables(context) {
268
271
  }
269
272
  }
270
273
 
271
- if (isCLI || config.verbose) {
274
+ if (context.isCLI() || config.verbose) {
272
275
  console.log('āœ… Lookup tables generated successfully');
273
276
  }
274
277
  }
@@ -281,7 +284,7 @@ async function generateGroupSCDs(context) {
281
284
  const { config, storage } = context;
282
285
  const { scdProps, groupKeys } = config;
283
286
 
284
- if (isCLI || config.verbose) {
287
+ if (context.isCLI() || config.verbose) {
285
288
  console.log('\nšŸ“Š Generating group SCDs...');
286
289
  }
287
290
 
@@ -304,7 +307,7 @@ async function generateGroupSCDs(context) {
304
307
  continue; // No SCDs for this group type
305
308
  }
306
309
 
307
- if (isCLI || config.verbose) {
310
+ if (context.isCLI() || config.verbose) {
308
311
  console.log(` Generating SCDs for ${groupCount.toLocaleString()} ${groupKey} entities...`);
309
312
  }
310
313
 
@@ -346,7 +349,7 @@ async function generateGroupSCDs(context) {
346
349
  }
347
350
  }
348
351
 
349
- if (isCLI || config.verbose) {
352
+ if (context.isCLI() || config.verbose) {
350
353
  console.log('āœ… Group SCDs generated successfully');
351
354
  }
352
355
  }
@@ -365,7 +368,7 @@ async function generateCharts(context) {
365
368
 
366
369
  await generateLineChart(storage.eventData, undefined, chartPath);
367
370
 
368
- if (isCLI || config.verbose) {
371
+ if (context.isCLI() || config.verbose) {
369
372
  console.log(`šŸ“Š Chart generated: ${chartPath}`);
370
373
  } else {
371
374
  sLog("Chart generated", { path: chartPath });
@@ -379,7 +382,7 @@ async function generateCharts(context) {
379
382
  * @param {import('./types').Dungeon} config - Configuration object
380
383
  */
381
384
  async function flushStorageToDisk(storage, config) {
382
- if (isCLI || config.verbose) {
385
+ if (config.verbose) {
383
386
  console.log('\nšŸ’¾ Writing data to disk...');
384
387
  }
385
388
 
@@ -403,7 +406,7 @@ async function flushStorageToDisk(storage, config) {
403
406
 
404
407
  await Promise.all(flushPromises);
405
408
 
406
- if (isCLI || config.verbose) {
409
+ if (config.verbose) {
407
410
  console.log('āœ… Data flushed to disk successfully');
408
411
  }
409
412
  }
@@ -449,8 +452,22 @@ function extractStorageData(storage) {
449
452
  };
450
453
  }
451
454
 
452
- // CLI execution
453
- if (isCLI) {
455
+ // Cloud Functions setup
456
+ functions.http('entry', async (req, res) => {
457
+ await handleCloudFunctionEntry(req, res, main);
458
+ });
459
+
460
+ // ES Module export
461
+ export default main;
462
+
463
+ // CommonJS compatibility
464
+ if (typeof module !== 'undefined' && module.exports) {
465
+ module.exports = main;
466
+ }
467
+
468
+ // CLI execution - check if this file is being run directly
469
+ const __filename = fileURLToPath(import.meta.url);
470
+ if (process.argv[1] === __filename) {
454
471
  (async () => {
455
472
  const cliConfig = getCliParams();
456
473
 
@@ -486,17 +503,4 @@ if (isCLI) {
486
503
  process.exit(1);
487
504
  });
488
505
  })();
489
- }
490
-
491
- // Cloud Functions setup
492
- functions.http('entry', async (req, res) => {
493
- await handleCloudFunctionEntry(req, res, main);
494
- });
495
-
496
- // ES Module export
497
- export default main;
498
-
499
- // CommonJS compatibility
500
- if (typeof module !== 'undefined' && module.exports) {
501
- module.exports = main;
502
506
  }
@@ -61,9 +61,10 @@ function createRuntimeState() {
61
61
  * Context factory that creates a complete context object for data generation
62
62
  * @param {Dungeon} config - Validated configuration object
63
63
  * @param {Storage|null} storage - Storage containers (optional, can be set later)
64
+ * @param {boolean} [isCliMode] - Whether running in CLI mode (optional, will detect if not provided)
64
65
  * @returns {Context} Context object containing all state and dependencies
65
66
  */
66
- export function createContext(config, storage = null) {
67
+ export function createContext(config, storage = null, isCliMode = null) {
67
68
  // Import campaign data (could be made configurable)
68
69
  const campaignData = campaigns;
69
70
 
@@ -76,7 +77,7 @@ export function createContext(config, storage = null) {
76
77
  // Set runtime flags from config
77
78
  runtime.verbose = config.verbose || false;
78
79
  runtime.isBatchMode = config.batchSize && config.batchSize < config.numEvents;
79
- runtime.isCLI = process.argv[1].endsWith('index.js') || process.argv[1].endsWith('cli.js');
80
+ runtime.isCLI = isCliMode !== null ? isCliMode : (process.argv[1].endsWith('index.js') || process.argv[1].endsWith('cli.js'));
80
81
 
81
82
  const context = {
82
83
  config,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "make-mp-data",
3
- "version": "2.0.13",
3
+ "version": "2.0.15",
4
4
  "description": "builds all mixpanel primitives for a given project",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -24,6 +24,7 @@
24
24
  "test:watch": "NODE_ENV=test vitest",
25
25
  "test:ui": "NODE_ENV=test vitest --ui",
26
26
  "coverage": "vitest run --coverage && open ./coverage/index.html",
27
+ "typecheck": "tsc --noEmit",
27
28
  "new:dungeon": "./scripts/new-dungeon.sh",
28
29
  "new:project": "node ./scripts/new-project.mjs",
29
30
  "exp:benchmark": "node --no-warnings --experimental-vm-modules ./tests/benchmark/concurrency.mjs",
@@ -76,6 +77,7 @@
76
77
  "devDependencies": {
77
78
  "@vitest/ui": "^2.1.9",
78
79
  "nodemon": "^3.1.3",
80
+ "typescript": "^5.6.0",
79
81
  "vitest": "^2.1.9"
80
82
  },
81
83
  "nodemonConfig": {