make-mp-data 2.0.15 → 2.0.16

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/cli.js ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CLI entry point for make-mp-data
5
+ * This file is only used when running via CLI/npx
6
+ */
7
+
8
+ import main from './index.js';
9
+ import getCliParams from './lib/cli/cli.js';
10
+
11
+ (async () => {
12
+ try {
13
+ const cliConfig = getCliParams();
14
+
15
+ // Load dungeon config - default to simple mode if no mode specified
16
+ let finalConfig = cliConfig;
17
+ if (cliConfig.complex) {
18
+ const complexConfig = await import('./dungeons/complex.js');
19
+ finalConfig = { ...complexConfig.default, ...cliConfig };
20
+ } else if (cliConfig.simple || (!cliConfig.complex && !cliConfig.simple)) {
21
+ // Default to simple mode when no flags or when --simple is explicitly set
22
+ const simpleConfig = await import('./dungeons/simple.js');
23
+ finalConfig = { ...simpleConfig.default, ...cliConfig };
24
+ }
25
+
26
+ const result = await main(finalConfig);
27
+
28
+ console.log(`šŸ“Š Generated ${(result.eventCount || 0).toLocaleString()} events for ${(result.userCount || 0).toLocaleString()} users`);
29
+ console.log(`ā±ļø Total time: ${result.time?.human || 'unknown'}`);
30
+ if (result.files?.length) {
31
+ console.log(`šŸ“ Files written: ${result.files.length}`);
32
+ if (cliConfig.verbose) {
33
+ result.files.forEach(file => console.log(` ${file}`));
34
+ }
35
+ }
36
+ console.log(`\nāœ… Job completed successfully!`);
37
+ process.exit(0);
38
+ } catch (error) {
39
+ console.error(`\nāŒ Job failed: ${error.message}`);
40
+ if (process.env.NODE_ENV === 'development') {
41
+ console.error(error.stack);
42
+ }
43
+ process.exit(1);
44
+ }
45
+ })();
package/index.js CHANGED
@@ -67,7 +67,7 @@ async function main(config) {
67
67
  jobTimer.start();
68
68
 
69
69
  //cli mode check for positional dungeon config
70
- const isCLI = process.argv[1] === fileURLToPath(import.meta.url);
70
+ const isCLI = config._ && Array.isArray(config._);
71
71
  if (isCLI) {
72
72
  const firstArg = config._.slice().pop()
73
73
  if (firstArg?.endsWith('.js') && existsSync(firstArg)) {
@@ -160,13 +160,9 @@ async function main(config) {
160
160
  };
161
161
 
162
162
  } catch (error) {
163
-
164
- // @ts-ignore
165
- if (context.isCLI() || validatedConfig.verbose) {
163
+ if (validatedConfig?.verbose) {
166
164
  console.error(`\nāŒ Error: ${error.message}\n`);
167
- if (validatedConfig.verbose) {
168
- console.error(error.stack);
169
- }
165
+ console.error(error.stack);
170
166
  } else {
171
167
  sLog("Main execution error", { error: error.message, stack: error.stack }, "ERROR");
172
168
  }
@@ -465,42 +461,3 @@ if (typeof module !== 'undefined' && module.exports) {
465
461
  module.exports = main;
466
462
  }
467
463
 
468
- // CLI execution - check if this file is being run directly
469
- const __filename = fileURLToPath(import.meta.url);
470
- if (process.argv[1] === __filename) {
471
- (async () => {
472
- const cliConfig = getCliParams();
473
-
474
- // Load dungeon config - default to simple mode if no mode specified
475
- let finalConfig = cliConfig;
476
- if (cliConfig.complex) {
477
- const complexConfig = await import('./dungeons/complex.js');
478
- finalConfig = { ...complexConfig.default, ...cliConfig };
479
- } else if (cliConfig.simple || (!cliConfig.complex && !cliConfig.simple)) {
480
- // Default to simple mode when no flags or when --simple is explicitly set
481
- const simpleConfig = await import('./dungeons/simple.js');
482
- finalConfig = { ...simpleConfig.default, ...cliConfig };
483
- }
484
-
485
- main(finalConfig)
486
- .then(result => {
487
- console.log(`šŸ“Š Generated ${(result.eventCount || 0).toLocaleString()} events for ${(result.userCount || 0).toLocaleString()} users`);
488
- console.log(`ā±ļø Total time: ${result.time?.human || 'unknown'}`);
489
- if (result.files?.length) {
490
- console.log(`šŸ“ Files written: ${result.files.length}`);
491
- if (cliConfig.verbose) {
492
- result.files.forEach(file => console.log(` ${file}`));
493
- }
494
- }
495
- console.log(`\nāœ… Job completed successfully!`);
496
- process.exit(0);
497
- })
498
- .catch(error => {
499
- console.error(`\nāŒ Job failed: ${error.message}`);
500
- if (cliConfig.verbose) {
501
- console.error(error.stack);
502
- }
503
- process.exit(1);
504
- });
505
- })();
506
- }
@@ -77,7 +77,7 @@ export function createContext(config, storage = null, isCliMode = null) {
77
77
  // Set runtime flags from config
78
78
  runtime.verbose = config.verbose || false;
79
79
  runtime.isBatchMode = config.batchSize && config.batchSize < config.numEvents;
80
- runtime.isCLI = isCliMode !== null ? isCliMode : (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') || false);
81
81
 
82
82
  const context = {
83
83
  config,
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "make-mp-data",
3
- "version": "2.0.15",
3
+ "version": "2.0.16",
4
4
  "description": "builds all mixpanel primitives for a given project",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "types": "types.d.ts",
8
8
  "files": [
9
9
  "index.js",
10
+ "cli.js",
10
11
  "types.d.ts",
11
12
  "lib/",
12
13
  "dungeons/",
@@ -37,7 +38,7 @@
37
38
  "url": "git+https://github.com/ak--47/make-mp-data.git"
38
39
  },
39
40
  "bin": {
40
- "make-mp-data": "./index.js"
41
+ "make-mp-data": "./cli.js"
41
42
  },
42
43
  "keywords": [
43
44
  "mixpanel",