-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #19 closes #21 closes #22 closes #23 (no longer relevant) closes #24 closes #33 (no longer relevant) closes #34
- Loading branch information
Showing
13 changed files
with
402 additions
and
708 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,32 @@ | ||
#!/usr/bin/env node | ||
|
||
import { Command } from 'commander/esm.mjs'; | ||
import { load as parseYAML } from 'js-yaml'; | ||
import path from 'path'; | ||
import { readFileSync } from 'fs'; | ||
import toolbox2json from '../src/toolbox2json.js'; | ||
|
||
import { fileURLToPath, pathToFileURL } from 'url'; | ||
import { Command } from 'commander/esm.mjs'; | ||
import { fileURLToPath } from 'url'; | ||
import path from 'path'; | ||
import { readFileSync } from 'fs'; | ||
import toolbox2json from '../src/toolbox2json.js'; | ||
|
||
const currentDir = path.dirname(fileURLToPath(import.meta.url)); | ||
|
||
const json = readFileSync(path.join(currentDir, `../package.json`)); | ||
const json = readFileSync(path.join(currentDir, '../package.json')); | ||
const { version } = JSON.parse(json); | ||
|
||
const program = new Command(); | ||
|
||
program.configureHelp({ sortOptions: true }); | ||
|
||
program | ||
.version(version, `-v, --version`, `output the version number`) | ||
.arguments(`<filePath>`) | ||
.description(`parse the Toolbox file`, { | ||
filePath: `path to the Toolbox file`, | ||
.version(version, '-v, --version', 'output the version number') | ||
.arguments('<filePath>') | ||
.description('parse the Toolbox file', { | ||
filePath: 'path to the Toolbox file', | ||
}) | ||
.option(`-m, --mappings <mappingsPath>`, `path to file specifying line marker > property name mappings`) | ||
.option(`-n, --ndjson`, `output newline-delimited JSON`, false) | ||
.option(`-o, --out <outPath>`, `path for the output JSON file`) | ||
.option(`-p, --postprocessor <postprocessorPath>`, `path to the postprocessor file`) | ||
.option(`-s, --silent`, `silences console output`, false) | ||
.option(`-t, --transforms <transformsPath>`, `path to transformations file`) | ||
.option('-n, --ndjson', 'output newline-delimited JSON', false) | ||
.option('-o, --out <outPath>', 'path for the output JSON file') | ||
.option('-s, --silent', 'silences console output', false) | ||
.action(async (filePath, options) => { | ||
|
||
const { | ||
mappings: mappingsPath, | ||
out: outPath, | ||
postprocessor: postprocessorPath, | ||
transforms: transformsPath, | ||
} = options; | ||
|
||
// get mappings from file | ||
|
||
let mappings = {}; | ||
|
||
if (mappingsPath) { | ||
|
||
const mappingsExt = path.extname(mappingsPath); | ||
const mappingsText = readFileSync(mappingsPath, `utf8`); | ||
|
||
if (mappingsExt === `.json`) { | ||
mappings = JSON.parse(mappingsText); | ||
} else { | ||
mappings = parseYAML(mappingsText); | ||
} | ||
|
||
} | ||
|
||
// get postprocessor function from file | ||
|
||
let postprocessor = entry => entry; | ||
|
||
if (postprocessorPath) { | ||
const importPath = pathToFileURL(path.join(process.cwd(), postprocessorPath)); | ||
({ default: postprocessor } = await import(importPath)); | ||
} | ||
|
||
// get transforms from file | ||
|
||
let transforms = {}; | ||
|
||
if (transformsPath) { | ||
const importPath = pathToFileURL(path.join(process.cwd(), transformsPath)); | ||
({ default: transforms } = await import(importPath)); | ||
} | ||
|
||
// run module | ||
|
||
Object.assign(options, { | ||
mappings, | ||
postprocessor, | ||
transforms, | ||
}); | ||
|
||
const readStream = toolbox2json(filePath, options); | ||
|
||
if (!outPath) { | ||
readStream.on(`data`, console.info); | ||
} | ||
|
||
const entries = await toolbox2json(filePath, options); | ||
if (!options.out) console.info(entries); | ||
}); | ||
|
||
program.parseAsync(process.argv); |
Oops, something went wrong.