make-mp-data 2.0.12 ā 2.0.14
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 +36 -32
- package/lib/cli/cli.js +4 -3
- package/lib/core/context.js +3 -2
- package/package.json +3 -1
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 = import.meta.url === `file://${process.argv[1]}`;
|
|
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
|
-
|
|
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 (
|
|
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 (
|
|
409
|
+
if (config.verbose) {
|
|
407
410
|
console.log('ā
Data flushed to disk successfully');
|
|
408
411
|
}
|
|
409
412
|
}
|
|
@@ -449,17 +452,31 @@ function extractStorageData(storage) {
|
|
|
449
452
|
};
|
|
450
453
|
}
|
|
451
454
|
|
|
452
|
-
//
|
|
453
|
-
|
|
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
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
454
470
|
(async () => {
|
|
455
471
|
const cliConfig = getCliParams();
|
|
456
472
|
|
|
457
|
-
// Load dungeon config
|
|
473
|
+
// Load dungeon config - default to simple mode if no mode specified
|
|
458
474
|
let finalConfig = cliConfig;
|
|
459
475
|
if (cliConfig.complex) {
|
|
460
476
|
const complexConfig = await import('./dungeons/complex.js');
|
|
461
477
|
finalConfig = { ...complexConfig.default, ...cliConfig };
|
|
462
|
-
} else if (cliConfig.simple) {
|
|
478
|
+
} else if (cliConfig.simple || (!cliConfig.complex && !cliConfig.simple)) {
|
|
479
|
+
// Default to simple mode when no flags or when --simple is explicitly set
|
|
463
480
|
const simpleConfig = await import('./dungeons/simple.js');
|
|
464
481
|
finalConfig = { ...simpleConfig.default, ...cliConfig };
|
|
465
482
|
}
|
|
@@ -485,17 +502,4 @@ if (isCLI) {
|
|
|
485
502
|
process.exit(1);
|
|
486
503
|
});
|
|
487
504
|
})();
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
// Cloud Functions setup
|
|
491
|
-
functions.http('entry', async (req, res) => {
|
|
492
|
-
await handleCloudFunctionEntry(req, res, main);
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
// ES Module export
|
|
496
|
-
export default main;
|
|
497
|
-
|
|
498
|
-
// CommonJS compatibility
|
|
499
|
-
if (typeof module !== 'undefined' && module.exports) {
|
|
500
|
-
module.exports = main;
|
|
501
505
|
}
|
package/lib/cli/cli.js
CHANGED
|
@@ -28,9 +28,10 @@ function cliParams() {
|
|
|
28
28
|
.usage(`\nusage:\nnpx $0 [dataModel.js] [options]
|
|
29
29
|
|
|
30
30
|
examples:
|
|
31
|
-
npx $0
|
|
32
|
-
npx $0 --
|
|
33
|
-
npx $0
|
|
31
|
+
npx $0 (uses simple data model by default)
|
|
32
|
+
npx $0 --complex (full enterprise data model)
|
|
33
|
+
npx $0 --token 1234 --u 100 --e 1000 (send data to mixpanel)
|
|
34
|
+
npx $0 myDataConfig.js (use custom config)
|
|
34
35
|
|
|
35
36
|
DOCS: https://github.com/ak--47/make-mp-data
|
|
36
37
|
DATA MODEL: https://github.com/ak--47/make-mp-data/blob/main/default.js
|
package/lib/core/context.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "2.0.14",
|
|
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": {
|