UNPKG

@e-invoice-eu/cli

Version:

Generate e-invoices (E-Rechnung in German) conforming to EN16931 (Factur-X/ZUGFeRD, UBL, CII, XRechnung aka X-Rechnung) from LibreOffice Calc/Excel data or JSON.

111 lines 3.89 kB
"use strict"; 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 () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Transform = void 0; const core_1 = require("@e-invoice-eu/core"); const runtime_1 = require("@esgettext/runtime"); const fs = __importStar(require("fs/promises")); const yaml = __importStar(require("js-yaml")); const optspec_1 = require("../optspec"); const package_1 = require("../package"); const safe_stdout_write_1 = require("../safe-stdout-write"); const gtx = runtime_1.Textdomain.getInstance('e-invoice-eu-cli'); const options = { spreadsheet: { group: gtx._('Input file location'), alias: ['s'], type: 'string', demandOption: true, describe: gtx._('the invoice spreadsheet file'), }, mapping: { group: gtx._('Input file location'), alias: ['m'], type: 'string', demandOption: true, describe: gtx._('the mapping file'), }, output: { group: gtx._('Output file location'), alias: ['o'], type: 'string', demandOption: false, describe: gtx._('the output file; standard output if `-`'), }, }; class Transform { description() { return gtx._('Transform spreadsheet data to JSON.'); } aliases() { return []; } build(argv) { return argv.options(options); } async doRun(configOptions) { const spreadsheet = await fs.readFile(configOptions.spreadsheet); const yamlData = await fs.readFile(configOptions.mapping, 'utf-8'); const mapping = yaml.load(yamlData); const mappingService = new core_1.MappingService(console); const output = JSON.stringify(mappingService.transform(spreadsheet, 'UBL', mapping)); if (typeof configOptions.output === 'undefined' || configOptions.output === '-') { (0, safe_stdout_write_1.safeStdoutWrite)(output); } else { await fs.writeFile(configOptions.output, output, 'utf-8'); } } async run(argv) { const configOptions = argv; if (!(0, optspec_1.coerceOptions)(argv, options)) { return 1; } try { await this.doRun(configOptions); return 0; } catch (e) { console.error(gtx._x('{programName}: {error}', { programName: package_1.Package.getName(), error: e, })); return 1; } } } exports.Transform = Transform; //# sourceMappingURL=transform.js.map