make-mp-data 2.0.14 ā 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 +45 -0
- package/index.js +3 -45
- package/lib/core/context.js +1 -1
- package/package.json +3 -2
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 =
|
|
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
|
-
|
|
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,41 +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
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
470
|
-
(async () => {
|
|
471
|
-
const cliConfig = getCliParams();
|
|
472
|
-
|
|
473
|
-
// Load dungeon config - default to simple mode if no mode specified
|
|
474
|
-
let finalConfig = cliConfig;
|
|
475
|
-
if (cliConfig.complex) {
|
|
476
|
-
const complexConfig = await import('./dungeons/complex.js');
|
|
477
|
-
finalConfig = { ...complexConfig.default, ...cliConfig };
|
|
478
|
-
} else if (cliConfig.simple || (!cliConfig.complex && !cliConfig.simple)) {
|
|
479
|
-
// Default to simple mode when no flags or when --simple is explicitly set
|
|
480
|
-
const simpleConfig = await import('./dungeons/simple.js');
|
|
481
|
-
finalConfig = { ...simpleConfig.default, ...cliConfig };
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
main(finalConfig)
|
|
485
|
-
.then(result => {
|
|
486
|
-
console.log(`š Generated ${(result.eventCount || 0).toLocaleString()} events for ${(result.userCount || 0).toLocaleString()} users`);
|
|
487
|
-
console.log(`ā±ļø Total time: ${result.time?.human || 'unknown'}`);
|
|
488
|
-
if (result.files?.length) {
|
|
489
|
-
console.log(`š Files written: ${result.files.length}`);
|
|
490
|
-
if (cliConfig.verbose) {
|
|
491
|
-
result.files.forEach(file => console.log(` ${file}`));
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
console.log(`\nā
Job completed successfully!`);
|
|
495
|
-
process.exit(0);
|
|
496
|
-
})
|
|
497
|
-
.catch(error => {
|
|
498
|
-
console.error(`\nā Job failed: ${error.message}`);
|
|
499
|
-
if (cliConfig.verbose) {
|
|
500
|
-
console.error(error.stack);
|
|
501
|
-
}
|
|
502
|
-
process.exit(1);
|
|
503
|
-
});
|
|
504
|
-
})();
|
|
505
|
-
}
|
package/lib/core/context.js
CHANGED
|
@@ -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]
|
|
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.
|
|
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": "./
|
|
41
|
+
"make-mp-data": "./cli.js"
|
|
41
42
|
},
|
|
42
43
|
"keywords": [
|
|
43
44
|
"mixpanel",
|