Skip to content

Commit

Permalink
v2.0
Browse files Browse the repository at this point in the history
closes #19
closes #21
closes #22
closes #23 (no longer relevant)
closes #24
closes #33 (no longer relevant)
closes #34
  • Loading branch information
dwhieb authored Apr 10, 2021
1 parent 4b14e82 commit 5f2f6a8
Show file tree
Hide file tree
Showing 13 changed files with 402 additions and 708 deletions.
7 changes: 4 additions & 3 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ parserOptions:
ecmaFeatures:
impliedStrict: true
sourceType: module
plugins:
- chai-friendly
env:
browser: false
es2021: true
Expand Down Expand Up @@ -377,7 +379,6 @@ rules:
- reject
no-shadow-restricted-names: error
no-sparse-arrays: warn
no-sync: error
no-tabs: warn
no-template-curly-in-string: error
no-ternary: 'off'
Expand All @@ -390,7 +391,6 @@ rules:
- error
- typeof: true
no-undef-init: error
no-undefined: warn
no-underscore-dangle:
- warn
- allow:
Expand All @@ -406,7 +406,8 @@ rules:
no-unreachable-loop: error
no-unsafe-finally: warn
no-unsafe-negation: error
no-unused-expressions: error
# no-unused-expressions: error
chai-friendly/no-unused-expressions: error
no-unused-labels: error
no-unused-vars: error
no-use-before-define:
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ jobs:
- name: install dependencies
run: npm ci

- name: cache dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ hashFiles('**/package-lock.json') }}

- name: run tests
run: npm test

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
key: ${{ hashFiles('**/package-lock.json') }}

- name: install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci

- name: run tests
Expand Down
115 changes: 37 additions & 78 deletions README.md

Large diffs are not rendered by default.

90 changes: 15 additions & 75 deletions bin/toolbox2json.js
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);
Loading

0 comments on commit 5f2f6a8

Please sign in to comment.