make-mp-data 1.0.5 → 1.0.7

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.
Files changed (2) hide show
  1. package/index.js +79 -67
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -32,44 +32,10 @@ Array.prototype.pickOne = pick;
32
32
  const now = dayjs().unix();
33
33
  const dayInSec = 86400;
34
34
 
35
-
36
-
37
- const args = cliParams();
38
- const {
39
- token,
40
- seed,
41
- format,
42
- numDays,
43
- numUsers,
44
- numEvents,
45
- region
46
- } = args;
47
- const suppliedConfig = args._[0];
48
-
49
- //if the user specifics an separate config file
50
- let config = null;
51
- if (suppliedConfig) {
52
- console.log(`using ${suppliedConfig} for data\n`);
53
- config = require(path.resolve(suppliedConfig));
54
- } else {
55
- console.log(`... using default configuration ...\n`);
56
- config = require("./default.js");
57
- }
58
-
59
- //override config with cli params
60
- if (token) config.token = token;
61
- if (seed) config.seed = seed;
62
- if (format) config.format = format;
63
- if (numDays) config.numDays = numDays;
64
- if (numUsers) config.numUsers = numUsers;
65
- if (numEvents) config.numEvents = numEvents;
66
- if (region) config.region = region;
67
-
68
-
69
35
  //our main program
70
36
  async function main(config) {
71
37
 
72
- const {
38
+ let {
73
39
  seed = "every time a rug is micturated upon in this fair city...",
74
40
  numEvents = 100000,
75
41
  numUsers = 1000,
@@ -87,8 +53,9 @@ async function main(config) {
87
53
  format = "csv",
88
54
  token = null,
89
55
  region = "US",
56
+ writeToDisk = false
90
57
  } = config;
91
-
58
+ if (require.main === module) writeToDisk = true;
92
59
  const uuidChance = new Chance(seed);
93
60
 
94
61
  //the function which generates $distinct_id
@@ -204,6 +171,8 @@ async function main(config) {
204
171
  [lookupFiles, lookupTableData],
205
172
  ];
206
173
  console.log("\n");
174
+
175
+ if (!writeToDisk && !token) return { eventData, userProfilesData, scdTableData, groupProfilesData, lookupTableData };
207
176
  //write the files
208
177
  for (const pair of pairs) {
209
178
  const [paths, data] = pair;
@@ -371,34 +340,77 @@ function buildFileNames(config) {
371
340
  return writePaths;
372
341
  }
373
342
 
374
- //that's all folks :)
375
- main(config)
376
- .then((data) => {
377
- console.log(`------------------SUMMARY------------------`);
378
- const { events, groups, users } = data.import;
379
- const files = data.files;
380
- const folder = files.pop();
381
- const groupBytes = groups.reduce((acc, group) => { return acc + group.bytes; }, 0);
382
- const groupSuccess = groups.reduce((acc, group) => { return acc + group.success; }, 0);
383
- const bytes = events.bytes + groupBytes + users.bytes;
384
- const stats = {
385
- events: comma(events.success || 0),
386
- users: comma(users.success || 0),
387
- groups: comma(groupSuccess || 0),
388
- bytes: bytesHuman(bytes || 0)
389
- };
390
- if (bytes > 0) console.table(stats);
391
- console.log(`\nfiles written to ${folder}...`);
392
- console.log("\t" + files.flat().join('\n\t'));
393
- console.log(`\n------------------SUMMARY------------------\n\n\n`);
394
- })
395
- .catch((e) => {
396
- console.log(`------------------ERROR------------------`);
397
- console.error(e);
398
- console.log(`------------------ERROR------------------`);
399
- debugger;
400
- })
401
- .finally(() => {
402
- console.log('have a wonderful day :)');
403
- openFinder(path.resolve("./data"));
404
- });
343
+ // this is for CLI
344
+ if (require.main === module) {
345
+
346
+ const args = cliParams();
347
+ const {
348
+ token,
349
+ seed,
350
+ format,
351
+ numDays,
352
+ numUsers,
353
+ numEvents,
354
+ region
355
+ } = args;
356
+ const suppliedConfig = args._[0];
357
+
358
+ //if the user specifics an separate config file
359
+ let config = null;
360
+ if (suppliedConfig) {
361
+ console.log(`using ${suppliedConfig} for data\n`);
362
+ config = require(path.resolve(suppliedConfig));
363
+ } else {
364
+ console.log(`... using default configuration ...\n`);
365
+ config = require("./default.js");
366
+ }
367
+
368
+ //override config with cli params
369
+ if (token) config.token = token;
370
+ if (seed) config.seed = seed;
371
+ if (format) config.format = format;
372
+ if (numDays) config.numDays = numDays;
373
+ if (numUsers) config.numUsers = numUsers;
374
+ if (numEvents) config.numEvents = numEvents;
375
+ if (region) config.region = region;
376
+
377
+
378
+ main(config)
379
+ .then((data) => {
380
+ console.log(`------------------SUMMARY------------------`);
381
+ const { events, groups, users } = data.import;
382
+ const files = data.files;
383
+ const folder = files.pop();
384
+ const groupBytes = groups.reduce((acc, group) => { return acc + group.bytes; }, 0);
385
+ const groupSuccess = groups.reduce((acc, group) => { return acc + group.success; }, 0);
386
+ const bytes = events.bytes + groupBytes + users.bytes;
387
+ const stats = {
388
+ events: comma(events.success || 0),
389
+ users: comma(users.success || 0),
390
+ groups: comma(groupSuccess || 0),
391
+ bytes: bytesHuman(bytes || 0)
392
+ };
393
+ if (bytes > 0) console.table(stats);
394
+ console.log(`\nfiles written to ${folder}...`);
395
+ console.log("\t" + files.flat().join('\n\t'));
396
+ console.log(`\n------------------SUMMARY------------------\n\n\n`);
397
+ })
398
+ .catch((e) => {
399
+ console.log(`------------------ERROR------------------`);
400
+ console.error(e);
401
+ console.log(`------------------ERROR------------------`);
402
+ debugger;
403
+ })
404
+ .finally(() => {
405
+ console.log('have a wonderful day :)');
406
+ openFinder(path.resolve("./data"));
407
+ });
408
+
409
+ }
410
+
411
+ else {
412
+ module.exports = main;
413
+ }
414
+
415
+
416
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "make-mp-data",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "builds all mixpanel primitives for a given project",
5
5
  "main": "index.js",
6
6
  "scripts": {