@modusjs/cli
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -9,6 +9,8 @@ #! /usr/bin/env node | ||
import { csv as moduscsv } from '@modusjs/convert'; | ||
const warn = debug('@modusjs/xsd2json#index:warn'); | ||
const info = debug('@modusjs/xsd2json#index:info'); | ||
const trace = debug('@modusjs/xsd2json#index:trace'); | ||
import { assert as assertModusResult } from '@oada/types/modus/v1/modus-result.js'; | ||
const warn = debug('@modusjs/cli:warn'); | ||
const info = debug('@modusjs/cli:info'); | ||
const trace = debug('@modusjs/cli:trace'); | ||
const { red, cyan } = chalk; | ||
const VERSION = '0.0.7'; | ||
program | ||
@@ -20,3 +22,3 @@ .command('tojson') | ||
//.version(process.env.npm_package_version!) | ||
.version('0.0.6') | ||
.version(VERSION) | ||
.description('Convert one or more Modus XML files, CSV files, or XLSX files to MODUS json. CSV/XLSX files must has supported structures.') | ||
@@ -95,3 +97,27 @@ .action(async (filenames, opts) => { | ||
}); | ||
program | ||
.command('tocsv') | ||
.requiredOption('-o,--output <filename.csv>', 'Name and path of output CSV file)') | ||
.argument('<json files...>') | ||
.version(VERSION) | ||
.description('Condense one or more Modus JSON files into a single flat CSV with standardized headers') | ||
.action(async (filenames, opts) => { | ||
const modusresults = []; | ||
for (const f of filenames) { | ||
try { | ||
const json = JSON.parse((await fs.readFile(f)).toString()); | ||
assertModusResult(json); | ||
modusresults.push(json); | ||
} | ||
catch (e) { | ||
warn(red('ERROR:'), 'Failed to parse file', f, 'as Modus JSON. Error was:', e); | ||
continue; | ||
} | ||
} | ||
info('Parsed', cyan(modusresults.length), ' Modus JSON files for inclusion in CSV output'); | ||
const { str } = moduscsv.toCsv(modusresults); | ||
await fs.writeFile(opts.output, str); | ||
info('Successfully wrote CSV output to', opts.output, 'from', cyan(modusresults.length), 'files'); | ||
}); | ||
program.parse(); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@modusjs/cli", | ||
"packageManager": "yarn@3.2.1", | ||
"version": "0.0.6", | ||
"description": "Conversion utility to generate a JSON schema from the Modus XSD files.", | ||
"version": "0.0.7", | ||
"description": "Conversion utility between various forms of soil test files, including CSV, XLSX, Modus XML, and Modus JSON.", | ||
"type": "module", | ||
@@ -21,2 +21,3 @@ "main": "dist/index.js", | ||
"tojson": "yarn run cli tojson", | ||
"tocsv": "yarn run cli tocsv", | ||
"cli": "node dist/index.js", | ||
@@ -36,3 +37,4 @@ "clean": "rm -rf dist" | ||
"dependencies": { | ||
"@modusjs/convert": "^0.0.3", | ||
"@modusjs/convert": "^0.0.4", | ||
"@oada/types": "^3.1.5", | ||
"chalk": "^4.0.0", | ||
@@ -39,0 +41,0 @@ "commander": "^9.3.0", |
@@ -19,9 +19,10 @@ # Modus xml/json command-line tools | ||
Convert one or more supported files into JSON. Name and path of output file is generally same as input with `.xml` replaced by `.json`. | ||
Except for xlxs files which will use a modified version of the sheetnames for the Modus JSON output files. | ||
Except for xlxs files which group samples by the inferred date, and then creates separate modus files for each group of dates within | ||
each worksheet. | ||
```bash | ||
modus tojson ./path/to/xml/file1 ./path/to/xml/file2 ...etc... | ||
modus tojson -f tomkat ./path/to/tomkat/formatted/xlsx_file | ||
modus tojson -f tomkat ./path/to/tomkat/formatted/xlsx_or_csv_file | ||
``` | ||
Sorry, the diff of this file is not supported yet
12821
121
28
7
+ Added@oada/types@^3.1.5
- Removed@modusjs/convert@0.0.3(transitive)
- Removed@overleaf/o-error@3.4.0(transitive)
- Removedadler-32@1.3.1(transitive)
- Removedboolbase@1.0.0(transitive)
- Removedcfb@1.2.2(transitive)
- Removedcheerio@1.0.0-rc.12(transitive)
- Removedcheerio-select@2.1.0(transitive)
- Removedcodepage@1.15.0(transitive)
- Removedcrc-32@1.2.2(transitive)
- Removedcss-select@5.1.0(transitive)
- Removedcss-what@6.1.0(transitive)
- Removeddayjs@1.11.11(transitive)
- Removeddom-serializer@2.0.0(transitive)
- Removeddomelementtype@2.3.0(transitive)
- Removeddomhandler@5.0.3(transitive)
- Removeddomutils@3.1.0(transitive)
- Removedentities@4.5.0(transitive)
- Removedexcel-date-to-js@1.1.5(transitive)
- Removedfrac@1.1.2(transitive)
- Removedhtmlparser2@8.0.2(transitive)
- Removednth-check@2.1.1(transitive)
- Removedparse5@7.1.2(transitive)
- Removedparse5-htmlparser2-tree-adapter@7.0.0(transitive)
- Removedssf@0.11.2(transitive)
- Removedwmf@1.0.2(transitive)
- Removedword@0.3.0(transitive)
- Removedxlsx@0.18.5(transitive)
Updated@modusjs/convert@^0.0.4