data-spring-cli
Version:
Data Spring generates fake datasets geared towards dashboards and data visualizations.
84 lines (83 loc) • 2.58 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var yargonaut = require("yargonaut");
var chalk = yargonaut.chalk();
var yargs_1 = __importDefault(require("yargs"));
var fs_1 = __importDefault(require("fs"));
var data_spring_1 = require("data-spring");
var SampleConfig = [
{ id: "id", type: "id" },
{
id: "date",
type: "date",
interval: {
type: "hour",
},
min: "2016-01-01 00:00:00",
max: "2020-12-31 23:59:00",
},
{
id: "budget",
type: "number",
min: 0,
max: 100,
},
{
id: "department",
type: "string",
values: [
"Environment and Health",
"Housing",
"Transportation",
"Education",
"Agriculture",
"Oil and Gas",
"Parks and Wildlife",
],
min: 0,
max: 100,
},
];
yargonaut.style("cyan").errorsStyle("red");
var cli = yargs_1.default;
cli
.scriptName("data-spring")
.usage("Usage: $0 <command> [options]")
.alias("h", "help")
.alias("v", "version");
cli
.command("create <configFile> <outputFile>", "Generates dataset based on provided config file and outputs to specified output file.", function (yargs) {
yargs
.positional("configFile", {
type: "string",
describe: "Path to the config file.",
})
.positional("outputFile", {
type: "string",
describe: "Path to the output file.",
});
}, function (argv) {
var configFile = argv.configFile, outputFile = argv.outputFile;
var config = fs_1.default.readFileSync(configFile, {
encoding: "utf-8",
});
var parsedConfig = JSON.parse(config);
var data = data_spring_1.DataSpring(parsedConfig);
fs_1.default.writeFileSync(outputFile, JSON.stringify(data));
console.log(chalk.green("Success! Dataset created"));
})
.command("config <outputFile>", "Generates a template config file at the specified location.", function (yargs) {
yargs.positional("outputFile", {
type: "string",
describe: "Path to the outputted config file.",
});
}, function (argv) {
var outputFile = argv.outputFile;
fs_1.default.writeFileSync(outputFile, JSON.stringify(SampleConfig, null, 2));
console.log(chalk.green("Success! Config file created"));
})
.help().argv;
;