UNPKG

simple-ascii-chart

Version:
135 lines (134 loc) 4.16 kB
#!/usr/bin/env node "use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var yargs = __importStar(require("yargs")); var index_1 = __importDefault(require("./index")); var argv = yargs .option('input', { alias: 'i', type: 'string', demandOption: true, }) .option('options', { alias: 'o', type: 'string', description: 'plot settings', }) .option('height', { alias: 'h', type: 'number', description: 'plot height', }) .option('hideXAxis', { type: 'boolean', description: 'hide x axis', }) .option('hideYAxis', { type: 'boolean', description: 'hide Y axis', }) .option('fillArea', { type: 'boolean', description: 'fill plot area', }) .option('width', { alias: 'w', type: 'number', description: 'plot width', }) .option('title', { alias: 't', type: 'string', description: 'plot title', }) .option('xLabel', { type: 'string', description: 'x axis label', }) .option('color', { alias: 'c', type: 'array', description: 'plot colors', }) .option('axisCenter', { type: 'array', description: 'plot center coordinates', }) .option('yLabel', { type: 'string', description: 'y axis label', }).argv; var withError = function (cb) { try { cb(); } catch (error) { process.stderr.write('Oops! Something went wrong!\n'); process.exit(1); } }; var execute = function (_a) { var input = _a.input, options = _a.options; withError(function () { var output = (0, index_1.default)(input, options); process.stdout.write(output); process.exit(0); }); }; var prepareParams = function (_a) { var input = _a.input, options = _a.options, width = _a.width, height = _a.height, hideYAxis = _a.hideYAxis, hideXAxis = _a.hideXAxis, fillArea = _a.fillArea, title = _a.title, xLabel = _a.xLabel, yLabel = _a.yLabel, color = _a.color, axisCenter = _a.axisCenter; var currentOptions = options ? JSON.parse(options) : {}; return { input: JSON.parse(input), options: __assign(__assign({}, currentOptions), { width: width, height: height, hideYAxis: hideYAxis, hideXAxis: hideXAxis, title: title, xLabel: xLabel, yLabel: yLabel, fillArea: fillArea, color: color, axisCenter: axisCenter }), }; }; if (argv instanceof Promise) { argv.then(function (parameters) { withError(function () { execute(prepareParams(parameters)); }); }); } else { withError(function () { execute(prepareParams(argv)); }); }