make-mp-data 2.0.15 ā 2.0.17
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 -56
- 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
|
@@ -29,8 +29,6 @@ import { makeMirror } from './lib/generators/mirror.js';
|
|
|
29
29
|
import { makeGroupProfile, makeProfile } from './lib/generators/profiles.js';
|
|
30
30
|
|
|
31
31
|
// Utilities
|
|
32
|
-
import getCliParams from './lib/cli/cli.js';
|
|
33
|
-
import * as u from './lib/utils/utils.js';
|
|
34
32
|
import { generateLineChart } from './lib/utils/chart.js';
|
|
35
33
|
|
|
36
34
|
// External dependencies
|
|
@@ -49,13 +47,6 @@ global.FIXED_NOW = FIXED_NOW;
|
|
|
49
47
|
let FIXED_BEGIN = dayjs.unix(FIXED_NOW).subtract(90, 'd').unix();
|
|
50
48
|
global.FIXED_BEGIN = FIXED_BEGIN;
|
|
51
49
|
|
|
52
|
-
// Package version
|
|
53
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
54
|
-
const packageJsonPath = path.join(__dirname, 'package.json');
|
|
55
|
-
const { version } = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
56
|
-
|
|
57
|
-
// Environment
|
|
58
|
-
const { NODE_ENV = "unknown" } = process.env;
|
|
59
50
|
|
|
60
51
|
/**
|
|
61
52
|
* Main data generation function
|
|
@@ -67,7 +58,7 @@ async function main(config) {
|
|
|
67
58
|
jobTimer.start();
|
|
68
59
|
|
|
69
60
|
//cli mode check for positional dungeon config
|
|
70
|
-
const isCLI =
|
|
61
|
+
const isCLI = config._ && Array.isArray(config._);
|
|
71
62
|
if (isCLI) {
|
|
72
63
|
const firstArg = config._.slice().pop()
|
|
73
64
|
if (firstArg?.endsWith('.js') && existsSync(firstArg)) {
|
|
@@ -86,7 +77,6 @@ async function main(config) {
|
|
|
86
77
|
}
|
|
87
78
|
|
|
88
79
|
let validatedConfig;
|
|
89
|
-
let context;
|
|
90
80
|
try {
|
|
91
81
|
// Step 1: Validate and enrich configuration
|
|
92
82
|
validatedConfig = validateDungeonConfig(config);
|
|
@@ -160,13 +150,9 @@ async function main(config) {
|
|
|
160
150
|
};
|
|
161
151
|
|
|
162
152
|
} catch (error) {
|
|
163
|
-
|
|
164
|
-
// @ts-ignore
|
|
165
|
-
if (context.isCLI() || validatedConfig.verbose) {
|
|
153
|
+
if (validatedConfig?.verbose) {
|
|
166
154
|
console.error(`\nā Error: ${error.message}\n`);
|
|
167
|
-
|
|
168
|
-
console.error(error.stack);
|
|
169
|
-
}
|
|
155
|
+
console.error(error.stack);
|
|
170
156
|
} else {
|
|
171
157
|
sLog("Main execution error", { error: error.message, stack: error.stack }, "ERROR");
|
|
172
158
|
}
|
|
@@ -465,42 +451,3 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
465
451
|
module.exports = main;
|
|
466
452
|
}
|
|
467
453
|
|
|
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
|
-
}
|
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.17",
|
|
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",
|