Compare commits

...

10 commits

Author SHA1 Message Date
Dylan R. E. Moonfire
55d812ea89 build: switching environment to use NixOS flakes 2023-01-25 20:28:19 -06:00
semantic-release-bot
1e01da5f52 chore(release): v0.2.1
## [0.2.1](https://gitlab.com/mfgames-writing/markdowny/compare/v0.2.0...v0.2.1) (2021-02-05)

### Bug Fixes

* correcting some documentation ([a5153e8](a5153e8aa6))
2021-02-05 00:21:05 +00:00
Dylan R. E. Moonfire
a5153e8aa6 fix: correcting some documentation 2021-02-03 23:45:25 -06:00
Dylan R. E. Moonfire
50617fed57 ci: trying to get the repository URL working with token 2021-02-03 23:38:44 -06:00
Dylan R. E. Moonfire
4b76b5f024 ci: setting the repository URL for semantic-release 2021-02-03 23:33:33 -06:00
Dylan R. E. Moonfire
0fa623c2ea build: fixing issues with linting 2021-02-03 23:30:00 -06:00
Dylan R. E. Moonfire
b38e680c9d ci: safer commitlint 2021-02-03 23:25:02 -06:00
Dylan R. E. Moonfire
9b84bcd239 ci: fixing Gitlab build for Yarn 2021-02-03 23:19:34 -06:00
Dylan R. E. Moonfire
6a06145a0a chore: updating links in package.json 2021-02-03 23:15:26 -06:00
Dylan R. E. Moonfire
14df2a0136 chore(deps): updating packages 2021-02-03 23:15:00 -06:00
30 changed files with 6809 additions and 28091 deletions

3
.envrc
View file

@ -1 +1,2 @@
use asdf export PATH=$PWD/scripts:$PATH
use flake || use nix

View file

@ -2,25 +2,20 @@ env:
es6: true es6: true
node: true node: true
extends: 'eslint:recommended' extends: 'eslint:recommended'
parser: typescript-eslint-parser parser: '@typescript-eslint/parser'
parserOptions: parserOptions:
ecmaFeatures: ecmaFeatures:
jsx: true jsx: true
ecmaVersion: 2018 ecmaVersion: 2018
sourceType: module sourceType: module
plugins: plugins:
#- react - '@typescript-eslint/eslint-plugin'
- typescript
rules: rules:
typescript/class-name-casing: '@typescript-eslint/member-ordering':
- error - error
typescript/member-naming: '@typescript-eslint/no-unused-vars':
- error
typescript/member-ordering:
- error
typescript/no-unused-vars:
- off - off
typescript/no-var-requires: '@typescript-eslint/no-var-requires':
- error - error
indent: indent:
- error - error

1
.gitignore vendored
View file

@ -10,3 +10,4 @@ node_modules/
build/ build/
dist/ dist/
lib/ lib/
.direnv/

View file

@ -12,11 +12,11 @@ publish:
- "cat tsconfig.json | jq 'del(.references)' > a && mv a tsconfig.json" - "cat tsconfig.json | jq 'del(.references)' > a && mv a tsconfig.json"
# Make sure the commits are clean # Make sure the commits are clean
- npm ci - yarn install --frozen-lockfile
- npx commitlint --from=master to=CI_BUILD_REF_NAME - if [ $CI_BUILD_BEFORE_SHA == "0000000000000000000000000000000000000000" ]; then npx commitlint --to=HEAD; else npx commitlint --from=$CI_BUILD_BEFORE_SHA; fi
# Build the project # Build the project
- npm run build - yarn run build
# Perform the automatic release process # Perform the automatic release process
- npx semantic-release - npx semantic-release --repository-url=https://oauth2:$GITLAB_TOKEN@gitlab.com/mfgames-writing/markdowny.git

View file

@ -1,3 +0,0 @@
yarn 1.22.10
nodejs 15.7.0
python 2.7.18 3.9.0

View file

@ -1,3 +1,10 @@
## [0.2.1](https://gitlab.com/mfgames-writing/markdowny/compare/v0.2.0...v0.2.1) (2021-02-05)
### Bug Fixes
* correcting some documentation ([a5153e8](https://gitlab.com/mfgames-writing/markdowny/commit/a5153e8aa615bc9e39a3f1497614b238a73418b2))
## [0.0.3](https://gitlab.com/mfgames-writing/markdowny/compare/v0.0.2...v0.0.3) (2018-08-11) ## [0.0.3](https://gitlab.com/mfgames-writing/markdowny/compare/v0.0.2...v0.0.3) (2018-08-11)

View file

@ -15,6 +15,7 @@ Basic usage is:
```sh ```sh
markdown verb *.markdown markdown verb *.markdown
markdowny-wc *.markdown
``` ```
## Verbs ## Verbs

6
commitlint.config.js Normal file
View file

@ -0,0 +1,6 @@
module.exports = {
extends: ["@commitlint/config-conventional"],
rules: {
"body-max-line-length": [0],
},
};

42
flake.lock Normal file
View file

@ -0,0 +1,42 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1674459583,
"narHash": "sha256-L0UZl/u2H3HGsrhN+by42c5kNYeKtdmJiPzIRvEVeiM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1b1f50645af2a70dc93eae18bfd88d330bfbcf7f",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

24
flake.nix Normal file
View file

@ -0,0 +1,24 @@
{
description =
"A framework for publishing Markdown files in a variety of formats.";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
devShell = pkgs.mkShell {
buildInputs = [
pkgs.nodejs-16_x
pkgs.nixfmt
pkgs.python39Full
pkgs.yarn
pkgs.nodePackages.lerna
];
};
});
}

27846
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,17 +1,17 @@
{ {
"name": "markdowny", "name": "markdowny",
"version": "0.2.0", "version": "0.2.1",
"description": "A set of command-line tools for working with Markdown files with YAML headers.", "description": "A set of command-line tools for working with Markdown files with YAML headers.",
"keywords": [ "keywords": [
"markdown" "markdown"
], ],
"homepage": "https://git.mfgames.com/author-intrusion/markdowny#README", "homepage": "https://src.mfgames.com/mfgames-writing-js/markdowny#README",
"bugs": { "bugs": {
"url": "https://git.mfgames.com/author-intrusion/markdowny/issues" "url": "https://src.mfgames.com/mfgames-writing-js/markdowny/issues"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://gitlab.com/mfgames-writing/markdowny.git" "url": "https://src.mfgames.com/mfgames-writing-js/markdowny.git"
}, },
"license": "MIT", "license": "MIT",
"author": { "author": {
@ -27,77 +27,48 @@
}, },
"scripts": { "scripts": {
"barrels": "barrelsby --delete --location all --directory src --exclude '(tests|cli|tools)'", "barrels": "barrelsby --delete --location all --directory src --exclude '(tests|cli|tools)'",
"prebuild": "npm run barrels && npm run lint && npm run format && npm run clean", "prebuild": "yarn run barrels && yarn run lint && yarn run format && yarn run clean",
"build": "tsc", "build": "tsc",
"clean": "rimraf lib", "clean": "rimraf lib",
"commitmsg": "commitlint -E GIT_PARAMS", "commitmsg": "commitlint -E GIT_PARAMS",
"format": "tsfmt -r && sort-package-json package.json", "format": "prettier src --write \"**/*.ts\" --loglevel warn",
"lint": "eslint -c .eslintrc.yml src/**/*.ts --fix", "lint": "eslint -c .eslintrc.yml src/**/*.ts --fix",
"prepack": "npm run build" "prepack": "yarn run build"
}, },
"commitlint": { "husky": {
"extends": [ "hooks": {
"@commitlint/config-conventional" "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
]
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
} }
}, },
"dependencies": { "dependencies": {
"@types/node": "^6.0.46",
"add-commas": "0.0.4", "add-commas": "0.0.4",
"dotted": "^0.1.1",
"gulp": "^3.9.1",
"lodash": "^4.16.5", "lodash": "^4.16.5",
"markdown-table": "^1.0.0", "markdown-table": "^1.0.0",
"read-pkg-up": "^4.0.0", "read-pkg-up": "^4.0.0",
"yaml-front-matter": "^3.4.0", "yaml-front-matter": "^3.4.0",
"yargs": "^12.0.1" "yargs": "^16.2.0"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^7.0.0", "@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^7.0.1", "@commitlint/config-conventional": "^11.0.0",
"@semantic-release/changelog": "^3.0.0", "@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^7.0.1", "@semantic-release/git": "^7.0.1",
"@semantic-release/npm": "^5.0.1", "@semantic-release/npm": "^5.0.1",
"@types/lodash": "^4.14.116", "@types/lodash": "^4.14.116",
"@types/node": "^6.0.46",
"@types/read-pkg-up": "^3.0.1", "@types/read-pkg-up": "^3.0.1",
"@types/yaml": "^1.9.7", "@types/yaml": "^1.9.7",
"@types/yargs": "^11.1.1", "@types/yargs": "^11.1.1",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"barrelsby": "^1.0.2", "barrelsby": "^1.0.2",
"commitizen": "^2.10.1",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^5.3.0", "eslint": "^5.3.0",
"eslint-plugin-typescript": "^0.12.0", "eslint-plugin-typescript": "^0.12.0",
"husky": "^0.14.3", "husky": "^0.14.3",
"prettier": "^2.0.5",
"rimraf": "^2.6.2", "rimraf": "^2.6.2",
"semantic-release": "^15.9.8", "semantic-release": "^15.9.8",
"sort-package-json": "^1.48.1", "sort-package-json": "^1.48.1",
"typescript": "^3.0.1", "typescript": "^4.1.3"
"typescript-eslint-parser": "^18.0.0",
"typescript-formatter": "^7.2.2"
},
"release": {
"branch": "master",
"message": "chore(release): v${nextRelease.version}\n\n${nextRelease.notes}",
"verifyConditions": [
"@semantic-release/changelog",
"@semantic-release/git"
],
"analyzeCommits": [
"@semantic-release/commit-analyzer"
],
"prepare": [
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git"
],
"publish": [
"@semantic-release/npm"
],
"success": [],
"fail": []
} }
} }

7
prettier.config.js Normal file
View file

@ -0,0 +1,7 @@
module.exports = {
endOfLine: "lf",
semi: true,
singleQuote: false,
tabWidth: 4,
trailingComma: "es5",
};

25
release.config.js Normal file
View file

@ -0,0 +1,25 @@
module.exports = {
branches: ["main"],
extends: ["@commitlint/config-conventional"],
message:
"chore(release): v${nextRelease.version} [CI SKIP]\n\n${nextRelease.notes}",
plugins: [
[
"@semantic-release/commit-analyzer",
{
preset: "conventionalcommits",
},
],
"@semantic-release/npm",
[
"@semantic-release/exec",
{
prepareCmd: "npm run build",
},
],
"@semantic-release/changelog",
"@semantic-release/git",
],
};

9
scripts/build.sh Executable file
View file

@ -0,0 +1,9 @@
# !/usr/bin/env bash
#mfgames-project:setup@v0.0.0
log() { echo "🚧 $(basename $0): $@"; }
cd $(dirname $(dirname $0))
#mfgames-project:setup
./scripts/setup.sh || exit 1
yarn run build

10
scripts/release.sh Executable file
View file

@ -0,0 +1,10 @@
# !/usr/bin/env bash
#mfgames-project:setup@v0.0.0
log() { echo "🚢 $(basename $0): $@"; }
cd $(dirname $(dirname $0))
#mfgames-project:setup
./scripts/setup.sh || exit 1
yarn run build
semantic-release --repository-url=https://oauth2:$GITLAB_TOKEN@gitlab.com/mfgames-writing/markdowny.git

14
scripts/setup.sh Executable file
View file

@ -0,0 +1,14 @@
# !/usr/bin/env bash
#mfgames-project:setup@v0.0.0
log() { echo "🌱 $(basename $0): $@"; }
cd $(dirname $(dirname $0))
#mfgames-project:setup
if [ -d node_modules ]
then
log "node_modules exists, not installing Yarn packages"
else
log "installing Yarn packages"
yarn install --frozen-lockfile
fi

9
scripts/test.sh Executable file
View file

@ -0,0 +1,9 @@
# !/usr/bin/env bash
#mfgames-project:setup@v0.0.0
log() { echo "🧪 $(basename $0): $@"; }
cd $(dirname $(dirname $0))
#mfgames-project:setup
./scripts/setup.sh || exit 1
npx commitlint --from=$CI_BUILD_BEFORE_SHA

View file

@ -1,8 +1,4 @@
import * as yargs from "yargs"; import * as yargs from "yargs";
yargs yargs.usage("$0 <cmd> [args]").commandDir("tools").demandCommand(1).help("help")
.usage("$0 <cmd> [args]")
.commandDir("tools")
.demandCommand(1)
.help("help")
.argv; .argv;

View file

@ -1 +1,5 @@
/**
* @file Automatically generated by barrelsby.
*/
export * from "./scanner"; export * from "./scanner";

View file

@ -3,15 +3,13 @@ import * as path from "path";
import * as yamlFrontMatter from "yaml-front-matter"; import * as yamlFrontMatter from "yaml-front-matter";
/** /**
* Parses the input files and returns a list of YAML metadata with special * Parses the input files and returns a list of YAML metadata with special
* columns for calculated values. * columns for calculated values.
*/ */
export function scanFiles(argv, files: string[]) export function scanFiles(argv, files: string[]) {
{
var list: any[] = []; var list: any[] = [];
for (var file of files) for (var file of files) {
{
// Load the metadata from the given file. // Load the metadata from the given file.
var contents = fs.readFileSync(file, "utf8"); var contents = fs.readFileSync(file, "utf8");
var metadata = yamlFrontMatter.loadFront(contents); var metadata = yamlFrontMatter.loadFront(contents);
@ -21,8 +19,7 @@ export function scanFiles(argv, files: string[])
metadata._basename = path.basename(file); metadata._basename = path.basename(file);
metadata._words = metadata.__content metadata._words = metadata.__content
.replace("'", "") .replace("'", "")
.split(/\s+/g) .split(/\s+/g).length;
.length;
// Add the metadata to the list. // Add the metadata to the list.
list.push(metadata); list.push(metadata);

View file

@ -6,36 +6,29 @@ import * as yargs from "yargs";
export var command = "content"; export var command = "content";
export var describe = "Extracts the content of the file without metadata"; export var describe = "Extracts the content of the file without metadata";
export function builder(yargs: yargs.Arguments) export function builder(yargs: yargs.Arguments) {
{
return yargs return yargs
.help("help") .help("help")
.option( .option("output", {
"output", alias: "o",
{ default: "-",
alias: "o", describe: "Write output to a file or `-` for standard out",
default: "-", })
describe: "Write output to a file or `-` for standard out",
}
)
.demand(1); .demand(1);
} }
export function handler(argv: any) export function handler(argv: any) {
{
// Parse through the files and retrieve the metadata. // Parse through the files and retrieve the metadata.
var files = argv._.splice(1); var files = argv._.splice(1);
var data: any = scanner.scanFiles(argv, files); var data: any = scanner.scanFiles(argv, files);
var output = data.map(x => x.__content).join("\n"); var output = data.map((x) => x.__content).join("\n");
// Figure out where to write. // Figure out where to write.
if (argv.output === "-") if (argv.output === "-") {
{
console.log(output); console.log(output);
} else } else {
{
fs.writeFileSync(argv.output, Buffer.from(output, "utf-8")); fs.writeFileSync(argv.output, Buffer.from(output, "utf-8"));
} }
} }

View file

@ -5,8 +5,7 @@ import * as table from "./table";
export var command = "count"; export var command = "count";
export var describe = "Counts the number of words in the given input"; export var describe = "Counts the number of words in the given input";
export function builder(yargs: yargs.Arguments) export function builder(yargs: yargs.Arguments) {
{
return yargs return yargs
.help("help") .help("help")
@ -14,8 +13,9 @@ export function builder(yargs: yargs.Arguments)
.describe( .describe(
"fields", "fields",
"The dotted fields in the metadata to display, or _basename for " + "The dotted fields in the metadata to display, or _basename for " +
"the name of the file, or _words to count the number of words. " + "the name of the file, or _words to count the number of words. " +
"Appending a `:r` at the end right-aligns the output.") "Appending a `:r` at the end right-aligns the output."
)
.default("table-start", "") .default("table-start", "")
.default("table-end", "") .default("table-end", "")
@ -30,14 +30,15 @@ export function builder(yargs: yargs.Arguments)
.describe( .describe(
"total", "total",
"If provided, adds a special entry with a _basename of Totals " + "If provided, adds a special entry with a _basename of Totals " +
"that adds up all the words.") "that adds up all the words."
)
.boolean("separator") .boolean("separator")
.alias("s", "separator") .alias("s", "separator")
.describe( .describe(
"separator", "separator",
"If provided, then the word counts will have comma separators " + "If provided, then the word counts will have comma separators " +
"for thousands." "for thousands."
) )
.alias("o", "output") .alias("o", "output")
@ -46,18 +47,15 @@ export function builder(yargs: yargs.Arguments)
.demand(1); .demand(1);
} }
export function handler(argv: any) export function handler(argv: any) {
{
var files = argv._.splice(1); var files = argv._.splice(1);
var data = scanner.scanFiles(argv, files); var data = scanner.scanFiles(argv, files);
if (argv.total) if (argv.total) {
{
argv.fields[1] += "t"; argv.fields[1] += "t";
} }
if (argv.separator) if (argv.separator) {
{
argv.fields[1] += "s"; argv.fields[1] += "s";
} }

View file

@ -7,63 +7,47 @@ import * as yargs from "yargs";
export var command = "extract"; export var command = "extract";
export var describe = "Extracts a YAML from a list of files"; export var describe = "Extracts a YAML from a list of files";
export function builder(yargs: yargs.Arguments) export function builder(yargs: yargs.Arguments) {
{
return yargs return yargs
.help("help") .help("help")
.option( .option("list", {
"list", type: "boolean",
{ default: true,
type: "boolean", describe:
default: true, "Extract the data as a list of files, otherwise as a single file",
describe: "Extract the data as a list of files, otherwise as a single file", })
} .option("output", {
) alias: "o",
.option( default: "-",
"output", describe: "Write output to a file or `-` for standard out",
{ })
alias: "o", .option("yaml", {
default: "-", alias: "y",
describe: "Write output to a file or `-` for standard out", type: "boolean",
} default: false,
) describe: "Extract the output as YAML instead of JSON",
.option( })
"yaml", .option("content", {
{ type: "string",
alias: "y", describe: "Include the content as a property in the extracted data",
type: "boolean", })
default: false,
describe: "Extract the output as YAML instead of JSON",
}
)
.option(
"content",
{
type: "string",
describe: "Include the content as a property in the extracted data",
}
)
.demand(1); .demand(1);
} }
export function handler(argv: any) export function handler(argv: any) {
{
// Parse through the files and retrieve the metadata. // Parse through the files and retrieve the metadata.
var files = argv._.splice(1); var files = argv._.splice(1);
var data: any = scanner.scanFiles(argv, files); var data: any = scanner.scanFiles(argv, files);
// Figure out how to handle the content property. // Figure out how to handle the content property.
if (!argv.content) if (!argv.content) {
{
// Remove the content from the parsed file. // Remove the content from the parsed file.
data.forEach(x => delete x.__content); data.forEach((x) => delete x.__content);
} else if (argv.content !== "__content") } else if (argv.content !== "__content") {
{
// Rename the content property. // Rename the content property.
data.forEach(x => data.forEach((x) => {
{
x[argv.content] = x.__content; x[argv.content] = x.__content;
delete x.__content; delete x.__content;
}); });
@ -72,9 +56,7 @@ export function handler(argv: any)
// Determine if we are displaying a list of items. If we want a list, then // Determine if we are displaying a list of items. If we want a list, then
// we wrap the data in another list (list of a list) so it writes out only // we wrap the data in another list (list of a list) so it writes out only
// one item. Otherwise, we write out each one. // one item. Otherwise, we write out each one.
const items = argv.list const items = argv.list ? [data] : data;
? [data]
: data;
// Figure the output of the results (JSON or YAML). // Figure the output of the results (JSON or YAML).
const output = argv.yaml const output = argv.yaml
@ -82,11 +64,9 @@ export function handler(argv: any)
: items.map((x: any) => JSON.stringify(x)).join("\n"); : items.map((x: any) => JSON.stringify(x)).join("\n");
// Figure out where to write. // Figure out where to write.
if (argv.output === "-") if (argv.output === "-") {
{
console.log(output); console.log(output);
} else } else {
{
fs.writeFileSync(argv.output, Buffer.from(output, "utf-8")); fs.writeFileSync(argv.output, Buffer.from(output, "utf-8"));
} }
} }

View file

@ -5,8 +5,7 @@ import * as scanner from "../scanner";
export var command = "list"; export var command = "list";
export var describe = "Extracts a YAML field into an order list"; export var describe = "Extracts a YAML field into an order list";
export function builder(yargs: yargs.Arguments) export function builder(yargs: yargs.Arguments) {
{
return yargs return yargs
.help("help") .help("help")
@ -22,30 +21,23 @@ export function builder(yargs: yargs.Arguments)
.demand(1); .demand(1);
} }
export function handler(argv: any) export function handler(argv: any) {
{
var files = argv._.splice(1); var files = argv._.splice(1);
var data = scanner.scanFiles(argv, files); var data = scanner.scanFiles(argv, files);
render(argv, data); render(argv, data);
} }
export function render(argv, data) export function render(argv, data) {
{ for (var key in data) {
for (var key in data)
{
var number = 1 + parseInt(key.toString()); var number = 1 + parseInt(key.toString());
var item = data[key]; var item = data[key];
var title = _.get(item, argv.title); var title = _.get(item, argv.title);
var value = _.get(item, argv.field); var value = _.get(item, argv.field);
// Build up the parts so we can do this as a single line. // Build up the parts so we can do this as a single line.
const parts = [ const parts = [`${number}. `, title];
`${number}. `,
title,
];
if (value) if (value) {
{
parts.push(": " + value.replace(/\n/g, " ")); parts.push(": " + value.replace(/\n/g, " "));
} }

View file

@ -5,8 +5,7 @@ import * as scanner from "../scanner";
export var command = "sections"; export var command = "sections";
export var describe = "Extracts a YAML field into sections"; export var describe = "Extracts a YAML field into sections";
export function builder(yargs: yargs.Arguments) export function builder(yargs: yargs.Arguments) {
{
return yargs return yargs
.help("help") .help("help")
@ -22,25 +21,21 @@ export function builder(yargs: yargs.Arguments)
.demand(1); .demand(1);
} }
export function handler(argv: any) export function handler(argv: any) {
{
var files = argv._.splice(1); var files = argv._.splice(1);
var data = scanner.scanFiles(argv, files); var data = scanner.scanFiles(argv, files);
render(argv, data); render(argv, data);
} }
export function render(argv, data) export function render(argv, data) {
{ for (var item of data) {
for (var item of data)
{
var title = _.get(item, argv.title); var title = _.get(item, argv.title);
var value = _.get(item, argv.field); var value = _.get(item, argv.field);
console.log(`# ${title}`); console.log(`# ${title}`);
console.log(); console.log();
if (value) if (value) {
{
console.log(value.replace("\n", "\n\n")); console.log(value.replace("\n", "\n\n"));
} }
} }

View file

@ -7,8 +7,7 @@ import * as scanner from "../scanner";
export var command = "table"; export var command = "table";
export var describe = "Create a summary table of requested fields"; export var describe = "Create a summary table of requested fields";
export function builder(yargs: yargs.Arguments) export function builder(yargs: yargs.Arguments) {
{
return yargs return yargs
.help("help") .help("help")
@ -37,23 +36,20 @@ export function builder(yargs: yargs.Arguments)
.demand(1); .demand(1);
} }
export function handler(argv: any) export function handler(argv: any) {
{
var files = argv._.splice(1); var files = argv._.splice(1);
var data = scanner.scanFiles(argv, files); var data = scanner.scanFiles(argv, files);
render(argv, data); render(argv, data);
} }
export function render(argv, data) export function render(argv, data) {
{
// Parse out the options and fields from the sources. // Parse out the options and fields from the sources.
var columns = parse(argv, argv.titles, argv.fields); var columns = parse(argv, argv.titles, argv.fields);
// Create the header row. // Create the header row.
var header: any[] = []; var header: any[] = [];
for (var column1 of columns) for (var column1 of columns) {
{
header.push(column1.header); header.push(column1.header);
} }
@ -63,35 +59,30 @@ export function render(argv, data)
// Loop through the results and get the fields we need to display. // Loop through the results and get the fields we need to display.
var totals: any = ["Totals"]; var totals: any = ["Totals"];
for (var metadata of data) for (var metadata of data) {
{
// Add the row to the table. // Add the row to the table.
var row: any[] = []; var row: any[] = [];
table.push(row); table.push(row);
// Loop through our fields and retrieve each one. // Loop through our fields and retrieve each one.
for (var index = 0; index < columns.length; index++) for (var index = 0; index < columns.length; index++) {
{
// Grab the value, even if nested. // Grab the value, even if nested.
var column = columns[index]; var column = columns[index];
var value = _.get(metadata, column.ref); var value = _.get(metadata, column.ref);
// If we have a list, format it with spaces. // If we have a list, format it with spaces.
if (Array.isArray(value)) if (Array.isArray(value)) {
{
value = value.join(argv.listDelimiter); value = value.join(argv.listDelimiter);
} }
// If we have totals, then add them. // If we have totals, then add them.
if (column.total) if (column.total) {
{
totals[index] = totals[index] ? parseInt(totals[index]) : 0; totals[index] = totals[index] ? parseInt(totals[index]) : 0;
totals[index] += parseInt(value); totals[index] += parseInt(value);
} }
// If we have commas requested, then add those. // If we have commas requested, then add those.
if (column.comma) if (column.comma) {
{
value = comma(value); value = comma(value);
} }
@ -101,14 +92,15 @@ export function render(argv, data)
} }
// If we have totals, then add it at the bottom. // If we have totals, then add it at the bottom.
if (totals.length > 1) if (totals.length > 1) {
{ for (
for (var index2 = 0; index2 < columns.length && index2 < totals.length; index2++) var index2 = 0;
{ index2 < columns.length && index2 < totals.length;
index2++
) {
var column2 = columns[index2]; var column2 = columns[index2];
if (column2.comma) if (column2.comma) {
{
totals[index2] = comma(totals[index2]); totals[index2] = comma(totals[index2]);
} }
} }
@ -118,50 +110,45 @@ export function render(argv, data)
// Format the results in a table. // Format the results in a table.
var formattedTable = markdownTable(table, { var formattedTable = markdownTable(table, {
align: columns.map(c => c.align), align: columns.map((c) => c.align),
delimiter: argv.tableDelimiter, delimiter: argv.tableDelimiter,
start: argv.tableStart, start: argv.tableStart,
end: argv.tableEnd, end: argv.tableEnd,
rule: argv.tableRule rule: argv.tableRule,
}); });
// If we don't want the header row, strip off the first line. // If we don't want the header row, strip off the first line.
if (!argv.tableHeader) if (!argv.tableHeader) {
{ formattedTable = formattedTable.substring(
formattedTable = formattedTable.substring(formattedTable.indexOf("\n") + 1); formattedTable.indexOf("\n") + 1
);
} }
console.log(formattedTable); console.log(formattedTable);
} }
class Column class Column {
{
ref: string; ref: string;
header: string; header: string;
align: string = "l"; align: string = "l";
comma: boolean = false; comma: boolean = false;
total: boolean = false; total: boolean = false;
public set(field, header) public set(field, header) {
{
this.ref = this.parseSpecifier(field); this.ref = this.parseSpecifier(field);
this.header = this.parseSpecifier(header ? header : field); this.header = this.parseSpecifier(header ? header : field);
} }
private parseSpecifier(spec): string private parseSpecifier(spec): string {
{
// See if we have options. // See if we have options.
var m = spec.match(/^(.*?):([lcr.st]+)?$/); var m = spec.match(/^(.*?):([lcr.st]+)?$/);
if (m) if (m) {
{
// We have a match, so put the first part as the specifier. // We have a match, so put the first part as the specifier.
spec = m[1]; spec = m[1];
for (var s of m[2]) for (var s of m[2]) {
{ switch (s) {
switch (s)
{
case "c": case "c":
case "l": case "l":
case "r": case "r":
@ -185,19 +172,18 @@ class Column
} }
} }
function parse(argv, titles, fields): Column[] function parse(argv, titles, fields): Column[] {
{
var columns: Column[] = []; var columns: Column[] = [];
if (!titles) titles = []; if (!titles) titles = [];
for (var index = 0; index < fields.length; index++) for (var index = 0; index < fields.length; index++) {
{
var column = new Column(); var column = new Column();
column.set( column.set(
fields[index], fields[index],
titles.length >= index ? titles[index] : undefined); titles.length >= index ? titles[index] : undefined
);
columns.push(column); columns.push(column);
} }

View file

@ -4,15 +4,11 @@ import * as yargs from "yargs";
export var command = "version"; export var command = "version";
export var describe = "Displays version information about the program"; export var describe = "Displays version information about the program";
export function builder(yargs: yargs.Arguments) export function builder(yargs: yargs.Arguments) {
{ return yargs.help("help").demand(0);
return yargs
.help("help")
.demand(0);
} }
export function handler(argv: any) export function handler(argv: any) {
{
const pkg: any = readPackage.sync(); const pkg: any = readPackage.sync();
const json = pkg.pkg; const json = pkg.pkg;

View file

@ -1,9 +0,0 @@
{
"indentSize": 4,
"tabSize": 4,
"indentStyle": 2,
"newLineCharacter": "\n",
"convertTabsToSpaces": true,
"placeOpenBraceOnNewLineForFunctions": true,
"placeOpenBraceOnNewLineForControlBlocks": true
}

6517
yarn.lock Normal file

File diff suppressed because it is too large Load diff