From e580fbc6236368da9e0cc4a6c980fb290d5aa635 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Fri, 24 Nov 2023 14:40:17 -0600 Subject: [PATCH] add yaml output option --- package-lock.json | 4 ++-- packages/cli/index.js | 6 ++++-- packages/cli/package.json | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index e790dee..8e2b46a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5952,7 +5952,6 @@ "version": "2.3.4", "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.4.tgz", "integrity": "sha512-8aAvwVUSHpfEqTQ4w/KMlf3HcRdt50E5ODIQJBw1fQ5RL34xabzxtUlzTXVqc4rkZsPbvrXKWnABCD7kWSmocA==", - "dev": true, "engines": { "node": ">= 14" } @@ -6005,7 +6004,8 @@ "commander": "^11.1.0", "fast-xml-parser": "^4.3.2", "serialport": "^12.0.0", - "ws": "^8.14.2" + "ws": "^8.14.2", + "yaml": "^2.3.4" }, "bin": { "aas-cli": "index.js" diff --git a/packages/cli/index.js b/packages/cli/index.js index 8d80590..fa99960 100755 --- a/packages/cli/index.js +++ b/packages/cli/index.js @@ -6,7 +6,7 @@ const { writeFileSync } = require('fs'); const { program, Option } = require('commander'); const { WebSocketServer } = require('ws'); const { XMLBuilder } = require('fast-xml-parser'); - +const { stringify: yamlify } = require('yaml'); const packageInfo = require('./package.json'); program.name(packageInfo.name); @@ -14,7 +14,7 @@ program.version(packageInfo.version); program.description('Simple protocol router /s'); program.option('-d, --device ', 'serialport path'); program.option('-o, --output ', 'file to write console info to'); -program.addOption(new Option('-f, --format ').choices(['json', 'xml']).default('json')); +program.addOption(new Option('-f, --format ').choices(['json', 'xml', 'yaml']).default('json')); program.option('--websocket ', 'enable websocket server for updates', undefined); program.parse(process.argv); @@ -84,6 +84,8 @@ port.on('data', (data) => { xmlBuilder = new XMLBuilder(); } outputString = xmlBuilder.build({ console: aasConsole.toJSON() }); + } else if (options.format === 'yaml') { + outputString = yamlify(aasConsole.toJSON()); } if (outputString) { writeFileSync(options.output, outputString); diff --git a/packages/cli/package.json b/packages/cli/package.json index 0c038a8..09ced12 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -17,7 +17,8 @@ "commander": "^11.1.0", "fast-xml-parser": "^4.3.2", "serialport": "^12.0.0", - "ws": "^8.14.2" + "ws": "^8.14.2", + "yaml": "^2.3.4" }, "devDependencies": { "pkg": "^5.8.1",