-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathutils.js
47 lines (43 loc) · 1.03 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { presetSchemas } from "@tinybirdco/mockingbird/server";
import fs from "fs";
export const presetSchemaNames = Object.keys(presetSchemas);
const commonOptions = {
template: {
describe: "Template to use for populating",
default: presetSchemaNames[0],
choices: presetSchemaNames,
},
schema: {
describe: "Path to schema file",
},
eps: {
describe: "Events per second",
default: 1,
},
limit: {
describe: "Max number of rows to send (-1 for unlimited)",
default: -1,
},
logs: {
describe: "Enable logs",
default: true,
},
};
export const createCommand = ({
name,
options,
generator,
middlewares = [],
}) => [
name,
true,
(yargs) => yargs.options({ ...commonOptions, ...options }),
(config) =>
new generator(config).generate(name === "base" ? console.log : undefined),
[parseSchemaMiddleware, ...middlewares],
];
const parseSchemaMiddleware = (argv) => ({
schema: argv.schema
? JSON.parse(fs.readFileSync(argv.schema, "utf8"))
: presetSchemas[argv.template],
});