Compare commits
No commits in common. "55d812ea8979583c008e72d6a61c01a1b840e56a" and "f8abdefa66555e8f2c499c70520b380e0c096195" have entirely different histories.
55d812ea89
...
f8abdefa66
30 changed files with 28091 additions and 6809 deletions
3
.envrc
3
.envrc
|
@ -1,2 +1 @@
|
|||
export PATH=$PWD/scripts:$PATH
|
||||
use flake || use nix
|
||||
use asdf
|
||||
|
|
|
@ -2,20 +2,25 @@ env:
|
|||
es6: true
|
||||
node: true
|
||||
extends: 'eslint:recommended'
|
||||
parser: '@typescript-eslint/parser'
|
||||
parser: typescript-eslint-parser
|
||||
parserOptions:
|
||||
ecmaFeatures:
|
||||
jsx: true
|
||||
ecmaVersion: 2018
|
||||
sourceType: module
|
||||
plugins:
|
||||
- '@typescript-eslint/eslint-plugin'
|
||||
#- react
|
||||
- typescript
|
||||
rules:
|
||||
'@typescript-eslint/member-ordering':
|
||||
typescript/class-name-casing:
|
||||
- error
|
||||
'@typescript-eslint/no-unused-vars':
|
||||
typescript/member-naming:
|
||||
- error
|
||||
typescript/member-ordering:
|
||||
- error
|
||||
typescript/no-unused-vars:
|
||||
- off
|
||||
'@typescript-eslint/no-var-requires':
|
||||
typescript/no-var-requires:
|
||||
- error
|
||||
indent:
|
||||
- error
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -10,4 +10,3 @@ node_modules/
|
|||
build/
|
||||
dist/
|
||||
lib/
|
||||
.direnv/
|
||||
|
|
|
@ -12,11 +12,11 @@ publish:
|
|||
- "cat tsconfig.json | jq 'del(.references)' > a && mv a tsconfig.json"
|
||||
|
||||
# Make sure the commits are clean
|
||||
- yarn install --frozen-lockfile
|
||||
- if [ $CI_BUILD_BEFORE_SHA == "0000000000000000000000000000000000000000" ]; then npx commitlint --to=HEAD; else npx commitlint --from=$CI_BUILD_BEFORE_SHA; fi
|
||||
- npm ci
|
||||
- npx commitlint --from=master to=CI_BUILD_REF_NAME
|
||||
|
||||
# Build the project
|
||||
- yarn run build
|
||||
- npm run build
|
||||
|
||||
# Perform the automatic release process
|
||||
- npx semantic-release --repository-url=https://oauth2:$GITLAB_TOKEN@gitlab.com/mfgames-writing/markdowny.git
|
||||
- npx semantic-release
|
||||
|
|
3
.tool-versions
Normal file
3
.tool-versions
Normal file
|
@ -0,0 +1,3 @@
|
|||
yarn 1.22.10
|
||||
nodejs 15.7.0
|
||||
python 2.7.18 3.9.0
|
|
@ -1,10 +1,3 @@
|
|||
## [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)
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ Basic usage is:
|
|||
|
||||
```sh
|
||||
markdown verb *.markdown
|
||||
markdowny-wc *.markdown
|
||||
```
|
||||
|
||||
## Verbs
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
module.exports = {
|
||||
extends: ["@commitlint/config-conventional"],
|
||||
rules: {
|
||||
"body-max-line-length": [0],
|
||||
},
|
||||
};
|
42
flake.lock
42
flake.lock
|
@ -1,42 +0,0 @@
|
|||
{
|
||||
"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
24
flake.nix
|
@ -1,24 +0,0 @@
|
|||
{
|
||||
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
Normal file
27846
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
67
package.json
67
package.json
|
@ -1,17 +1,17 @@
|
|||
{
|
||||
"name": "markdowny",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.0",
|
||||
"description": "A set of command-line tools for working with Markdown files with YAML headers.",
|
||||
"keywords": [
|
||||
"markdown"
|
||||
],
|
||||
"homepage": "https://src.mfgames.com/mfgames-writing-js/markdowny#README",
|
||||
"homepage": "https://git.mfgames.com/author-intrusion/markdowny#README",
|
||||
"bugs": {
|
||||
"url": "https://src.mfgames.com/mfgames-writing-js/markdowny/issues"
|
||||
"url": "https://git.mfgames.com/author-intrusion/markdowny/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://src.mfgames.com/mfgames-writing-js/markdowny.git"
|
||||
"url": "https://gitlab.com/mfgames-writing/markdowny.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
|
@ -27,48 +27,77 @@
|
|||
},
|
||||
"scripts": {
|
||||
"barrels": "barrelsby --delete --location all --directory src --exclude '(tests|cli|tools)'",
|
||||
"prebuild": "yarn run barrels && yarn run lint && yarn run format && yarn run clean",
|
||||
"prebuild": "npm run barrels && npm run lint && npm run format && npm run clean",
|
||||
"build": "tsc",
|
||||
"clean": "rimraf lib",
|
||||
"commitmsg": "commitlint -E GIT_PARAMS",
|
||||
"format": "prettier src --write \"**/*.ts\" --loglevel warn",
|
||||
"format": "tsfmt -r && sort-package-json package.json",
|
||||
"lint": "eslint -c .eslintrc.yml src/**/*.ts --fix",
|
||||
"prepack": "yarn run build"
|
||||
"prepack": "npm run build"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
||||
"commitlint": {
|
||||
"extends": [
|
||||
"@commitlint/config-conventional"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"commitizen": {
|
||||
"path": "./node_modules/cz-conventional-changelog"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "^6.0.46",
|
||||
"add-commas": "0.0.4",
|
||||
"dotted": "^0.1.1",
|
||||
"gulp": "^3.9.1",
|
||||
"lodash": "^4.16.5",
|
||||
"markdown-table": "^1.0.0",
|
||||
"read-pkg-up": "^4.0.0",
|
||||
"yaml-front-matter": "^3.4.0",
|
||||
"yargs": "^16.2.0"
|
||||
"yargs": "^12.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^11.0.0",
|
||||
"@commitlint/config-conventional": "^11.0.0",
|
||||
"@semantic-release/changelog": "^5.0.1",
|
||||
"@commitlint/cli": "^7.0.0",
|
||||
"@commitlint/config-conventional": "^7.0.1",
|
||||
"@semantic-release/changelog": "^3.0.0",
|
||||
"@semantic-release/git": "^7.0.1",
|
||||
"@semantic-release/npm": "^5.0.1",
|
||||
"@types/lodash": "^4.14.116",
|
||||
"@types/node": "^6.0.46",
|
||||
"@types/read-pkg-up": "^3.0.1",
|
||||
"@types/yaml": "^1.9.7",
|
||||
"@types/yargs": "^11.1.1",
|
||||
"@typescript-eslint/eslint-plugin": "^4.14.2",
|
||||
"@typescript-eslint/parser": "^4.14.2",
|
||||
"barrelsby": "^1.0.2",
|
||||
"commitizen": "^2.10.1",
|
||||
"cz-conventional-changelog": "^2.1.0",
|
||||
"eslint": "^5.3.0",
|
||||
"eslint-plugin-typescript": "^0.12.0",
|
||||
"husky": "^0.14.3",
|
||||
"prettier": "^2.0.5",
|
||||
"rimraf": "^2.6.2",
|
||||
"semantic-release": "^15.9.8",
|
||||
"sort-package-json": "^1.48.1",
|
||||
"typescript": "^4.1.3"
|
||||
"typescript": "^3.0.1",
|
||||
"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": []
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
module.exports = {
|
||||
endOfLine: "lf",
|
||||
semi: true,
|
||||
singleQuote: false,
|
||||
tabWidth: 4,
|
||||
trailingComma: "es5",
|
||||
};
|
|
@ -1,25 +0,0 @@
|
|||
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",
|
||||
],
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
# !/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
|
|
@ -1,10 +0,0 @@
|
|||
# !/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
|
|
@ -1,14 +0,0 @@
|
|||
# !/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
|
|
@ -1,9 +0,0 @@
|
|||
# !/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
|
|
@ -1,4 +1,8 @@
|
|||
import * as yargs from "yargs";
|
||||
|
||||
yargs.usage("$0 <cmd> [args]").commandDir("tools").demandCommand(1).help("help")
|
||||
yargs
|
||||
.usage("$0 <cmd> [args]")
|
||||
.commandDir("tools")
|
||||
.demandCommand(1)
|
||||
.help("help")
|
||||
.argv;
|
||||
|
|
|
@ -1,5 +1 @@
|
|||
/**
|
||||
* @file Automatically generated by barrelsby.
|
||||
*/
|
||||
|
||||
export * from "./scanner";
|
||||
|
|
|
@ -3,13 +3,15 @@ import * as path from "path";
|
|||
import * as yamlFrontMatter from "yaml-front-matter";
|
||||
|
||||
/**
|
||||
* Parses the input files and returns a list of YAML metadata with special
|
||||
* columns for calculated values.
|
||||
*/
|
||||
export function scanFiles(argv, files: string[]) {
|
||||
* Parses the input files and returns a list of YAML metadata with special
|
||||
* columns for calculated values.
|
||||
*/
|
||||
export function scanFiles(argv, files: string[])
|
||||
{
|
||||
var list: any[] = [];
|
||||
|
||||
for (var file of files) {
|
||||
for (var file of files)
|
||||
{
|
||||
// Load the metadata from the given file.
|
||||
var contents = fs.readFileSync(file, "utf8");
|
||||
var metadata = yamlFrontMatter.loadFront(contents);
|
||||
|
@ -19,7 +21,8 @@ export function scanFiles(argv, files: string[]) {
|
|||
metadata._basename = path.basename(file);
|
||||
metadata._words = metadata.__content
|
||||
.replace("'", "")
|
||||
.split(/\s+/g).length;
|
||||
.split(/\s+/g)
|
||||
.length;
|
||||
|
||||
// Add the metadata to the list.
|
||||
list.push(metadata);
|
||||
|
|
|
@ -6,29 +6,36 @@ import * as yargs from "yargs";
|
|||
export var command = "content";
|
||||
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
|
||||
.help("help")
|
||||
|
||||
.option("output", {
|
||||
.option(
|
||||
"output",
|
||||
{
|
||||
alias: "o",
|
||||
default: "-",
|
||||
describe: "Write output to a file or `-` for standard out",
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
.demand(1);
|
||||
}
|
||||
|
||||
export function handler(argv: any) {
|
||||
export function handler(argv: any)
|
||||
{
|
||||
// Parse through the files and retrieve the metadata.
|
||||
var files = argv._.splice(1);
|
||||
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.
|
||||
if (argv.output === "-") {
|
||||
if (argv.output === "-")
|
||||
{
|
||||
console.log(output);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
fs.writeFileSync(argv.output, Buffer.from(output, "utf-8"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ import * as table from "./table";
|
|||
export var command = "count";
|
||||
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
|
||||
.help("help")
|
||||
|
||||
|
@ -14,8 +15,7 @@ export function builder(yargs: yargs.Arguments) {
|
|||
"fields",
|
||||
"The dotted fields in the metadata to display, or _basename for " +
|
||||
"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-end", "")
|
||||
|
@ -30,8 +30,7 @@ export function builder(yargs: yargs.Arguments) {
|
|||
.describe(
|
||||
"total",
|
||||
"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")
|
||||
.alias("s", "separator")
|
||||
|
@ -47,15 +46,18 @@ export function builder(yargs: yargs.Arguments) {
|
|||
.demand(1);
|
||||
}
|
||||
|
||||
export function handler(argv: any) {
|
||||
export function handler(argv: any)
|
||||
{
|
||||
var files = argv._.splice(1);
|
||||
var data = scanner.scanFiles(argv, files);
|
||||
|
||||
if (argv.total) {
|
||||
if (argv.total)
|
||||
{
|
||||
argv.fields[1] += "t";
|
||||
}
|
||||
|
||||
if (argv.separator) {
|
||||
if (argv.separator)
|
||||
{
|
||||
argv.fields[1] += "s";
|
||||
}
|
||||
|
||||
|
|
|
@ -7,47 +7,63 @@ import * as yargs from "yargs";
|
|||
export var command = "extract";
|
||||
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
|
||||
.help("help")
|
||||
|
||||
.option("list", {
|
||||
.option(
|
||||
"list",
|
||||
{
|
||||
type: "boolean",
|
||||
default: true,
|
||||
describe:
|
||||
"Extract the data as a list of files, otherwise as a single file",
|
||||
})
|
||||
.option("output", {
|
||||
describe: "Extract the data as a list of files, otherwise as a single file",
|
||||
}
|
||||
)
|
||||
.option(
|
||||
"output",
|
||||
{
|
||||
alias: "o",
|
||||
default: "-",
|
||||
describe: "Write output to a file or `-` for standard out",
|
||||
})
|
||||
.option("yaml", {
|
||||
}
|
||||
)
|
||||
.option(
|
||||
"yaml",
|
||||
{
|
||||
alias: "y",
|
||||
type: "boolean",
|
||||
default: false,
|
||||
describe: "Extract the output as YAML instead of JSON",
|
||||
})
|
||||
.option("content", {
|
||||
}
|
||||
)
|
||||
.option(
|
||||
"content",
|
||||
{
|
||||
type: "string",
|
||||
describe: "Include the content as a property in the extracted data",
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
.demand(1);
|
||||
}
|
||||
|
||||
export function handler(argv: any) {
|
||||
export function handler(argv: any)
|
||||
{
|
||||
// Parse through the files and retrieve the metadata.
|
||||
var files = argv._.splice(1);
|
||||
var data: any = scanner.scanFiles(argv, files);
|
||||
|
||||
// Figure out how to handle the content property.
|
||||
if (!argv.content) {
|
||||
if (!argv.content)
|
||||
{
|
||||
// Remove the content from the parsed file.
|
||||
data.forEach((x) => delete x.__content);
|
||||
} else if (argv.content !== "__content") {
|
||||
data.forEach(x => delete x.__content);
|
||||
} else if (argv.content !== "__content")
|
||||
{
|
||||
// Rename the content property.
|
||||
data.forEach((x) => {
|
||||
data.forEach(x =>
|
||||
{
|
||||
x[argv.content] = x.__content;
|
||||
delete x.__content;
|
||||
});
|
||||
|
@ -56,7 +72,9 @@ export function handler(argv: any) {
|
|||
// 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
|
||||
// one item. Otherwise, we write out each one.
|
||||
const items = argv.list ? [data] : data;
|
||||
const items = argv.list
|
||||
? [data]
|
||||
: data;
|
||||
|
||||
// Figure the output of the results (JSON or YAML).
|
||||
const output = argv.yaml
|
||||
|
@ -64,9 +82,11 @@ export function handler(argv: any) {
|
|||
: items.map((x: any) => JSON.stringify(x)).join("\n");
|
||||
|
||||
// Figure out where to write.
|
||||
if (argv.output === "-") {
|
||||
if (argv.output === "-")
|
||||
{
|
||||
console.log(output);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
fs.writeFileSync(argv.output, Buffer.from(output, "utf-8"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ import * as scanner from "../scanner";
|
|||
export var command = "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
|
||||
.help("help")
|
||||
|
||||
|
@ -21,23 +22,30 @@ export function builder(yargs: yargs.Arguments) {
|
|||
.demand(1);
|
||||
}
|
||||
|
||||
export function handler(argv: any) {
|
||||
export function handler(argv: any)
|
||||
{
|
||||
var files = argv._.splice(1);
|
||||
var data = scanner.scanFiles(argv, files);
|
||||
render(argv, data);
|
||||
}
|
||||
|
||||
export function render(argv, data) {
|
||||
for (var key in data) {
|
||||
export function render(argv, data)
|
||||
{
|
||||
for (var key in data)
|
||||
{
|
||||
var number = 1 + parseInt(key.toString());
|
||||
var item = data[key];
|
||||
var title = _.get(item, argv.title);
|
||||
var value = _.get(item, argv.field);
|
||||
|
||||
// Build up the parts so we can do this as a single line.
|
||||
const parts = [`${number}. `, title];
|
||||
const parts = [
|
||||
`${number}. `,
|
||||
title,
|
||||
];
|
||||
|
||||
if (value) {
|
||||
if (value)
|
||||
{
|
||||
parts.push(": " + value.replace(/\n/g, " "));
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@ import * as scanner from "../scanner";
|
|||
export var command = "sections";
|
||||
export var describe = "Extracts a YAML field into sections";
|
||||
|
||||
export function builder(yargs: yargs.Arguments) {
|
||||
export function builder(yargs: yargs.Arguments)
|
||||
{
|
||||
return yargs
|
||||
.help("help")
|
||||
|
||||
|
@ -21,21 +22,25 @@ export function builder(yargs: yargs.Arguments) {
|
|||
.demand(1);
|
||||
}
|
||||
|
||||
export function handler(argv: any) {
|
||||
export function handler(argv: any)
|
||||
{
|
||||
var files = argv._.splice(1);
|
||||
var data = scanner.scanFiles(argv, files);
|
||||
render(argv, data);
|
||||
}
|
||||
|
||||
export function render(argv, data) {
|
||||
for (var item of data) {
|
||||
export function render(argv, data)
|
||||
{
|
||||
for (var item of data)
|
||||
{
|
||||
var title = _.get(item, argv.title);
|
||||
var value = _.get(item, argv.field);
|
||||
|
||||
console.log(`# ${title}`);
|
||||
console.log();
|
||||
|
||||
if (value) {
|
||||
if (value)
|
||||
{
|
||||
console.log(value.replace("\n", "\n\n"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ import * as scanner from "../scanner";
|
|||
export var command = "table";
|
||||
export var describe = "Create a summary table of requested fields";
|
||||
|
||||
export function builder(yargs: yargs.Arguments) {
|
||||
export function builder(yargs: yargs.Arguments)
|
||||
{
|
||||
return yargs
|
||||
.help("help")
|
||||
|
||||
|
@ -36,20 +37,23 @@ export function builder(yargs: yargs.Arguments) {
|
|||
.demand(1);
|
||||
}
|
||||
|
||||
export function handler(argv: any) {
|
||||
export function handler(argv: any)
|
||||
{
|
||||
var files = argv._.splice(1);
|
||||
var data = scanner.scanFiles(argv, files);
|
||||
render(argv, data);
|
||||
}
|
||||
|
||||
export function render(argv, data) {
|
||||
export function render(argv, data)
|
||||
{
|
||||
// Parse out the options and fields from the sources.
|
||||
var columns = parse(argv, argv.titles, argv.fields);
|
||||
|
||||
// Create the header row.
|
||||
var header: any[] = [];
|
||||
|
||||
for (var column1 of columns) {
|
||||
for (var column1 of columns)
|
||||
{
|
||||
header.push(column1.header);
|
||||
}
|
||||
|
||||
|
@ -59,30 +63,35 @@ export function render(argv, data) {
|
|||
// Loop through the results and get the fields we need to display.
|
||||
var totals: any = ["Totals"];
|
||||
|
||||
for (var metadata of data) {
|
||||
for (var metadata of data)
|
||||
{
|
||||
// Add the row to the table.
|
||||
var row: any[] = [];
|
||||
table.push(row);
|
||||
|
||||
// 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.
|
||||
var column = columns[index];
|
||||
var value = _.get(metadata, column.ref);
|
||||
|
||||
// If we have a list, format it with spaces.
|
||||
if (Array.isArray(value)) {
|
||||
if (Array.isArray(value))
|
||||
{
|
||||
value = value.join(argv.listDelimiter);
|
||||
}
|
||||
|
||||
// If we have totals, then add them.
|
||||
if (column.total) {
|
||||
if (column.total)
|
||||
{
|
||||
totals[index] = totals[index] ? parseInt(totals[index]) : 0;
|
||||
totals[index] += parseInt(value);
|
||||
}
|
||||
|
||||
// If we have commas requested, then add those.
|
||||
if (column.comma) {
|
||||
if (column.comma)
|
||||
{
|
||||
value = comma(value);
|
||||
}
|
||||
|
||||
|
@ -92,15 +101,14 @@ export function render(argv, data) {
|
|||
}
|
||||
|
||||
// If we have totals, then add it at the bottom.
|
||||
if (totals.length > 1) {
|
||||
for (
|
||||
var index2 = 0;
|
||||
index2 < columns.length && index2 < totals.length;
|
||||
index2++
|
||||
) {
|
||||
if (totals.length > 1)
|
||||
{
|
||||
for (var index2 = 0; index2 < columns.length && index2 < totals.length; index2++)
|
||||
{
|
||||
var column2 = columns[index2];
|
||||
|
||||
if (column2.comma) {
|
||||
if (column2.comma)
|
||||
{
|
||||
totals[index2] = comma(totals[index2]);
|
||||
}
|
||||
}
|
||||
|
@ -110,45 +118,50 @@ export function render(argv, data) {
|
|||
|
||||
// Format the results in a table.
|
||||
var formattedTable = markdownTable(table, {
|
||||
align: columns.map((c) => c.align),
|
||||
align: columns.map(c => c.align),
|
||||
delimiter: argv.tableDelimiter,
|
||||
start: argv.tableStart,
|
||||
end: argv.tableEnd,
|
||||
rule: argv.tableRule,
|
||||
rule: argv.tableRule
|
||||
});
|
||||
|
||||
// If we don't want the header row, strip off the first line.
|
||||
if (!argv.tableHeader) {
|
||||
formattedTable = formattedTable.substring(
|
||||
formattedTable.indexOf("\n") + 1
|
||||
);
|
||||
if (!argv.tableHeader)
|
||||
{
|
||||
formattedTable = formattedTable.substring(formattedTable.indexOf("\n") + 1);
|
||||
}
|
||||
|
||||
console.log(formattedTable);
|
||||
}
|
||||
|
||||
class Column {
|
||||
class Column
|
||||
{
|
||||
ref: string;
|
||||
header: string;
|
||||
align: string = "l";
|
||||
comma: boolean = false;
|
||||
total: boolean = false;
|
||||
|
||||
public set(field, header) {
|
||||
public set(field, header)
|
||||
{
|
||||
this.ref = this.parseSpecifier(field);
|
||||
this.header = this.parseSpecifier(header ? header : field);
|
||||
}
|
||||
|
||||
private parseSpecifier(spec): string {
|
||||
private parseSpecifier(spec): string
|
||||
{
|
||||
// See if we have options.
|
||||
var m = spec.match(/^(.*?):([lcr.st]+)?$/);
|
||||
|
||||
if (m) {
|
||||
if (m)
|
||||
{
|
||||
// We have a match, so put the first part as the specifier.
|
||||
spec = m[1];
|
||||
|
||||
for (var s of m[2]) {
|
||||
switch (s) {
|
||||
for (var s of m[2])
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case "c":
|
||||
case "l":
|
||||
case "r":
|
||||
|
@ -172,18 +185,19 @@ class Column {
|
|||
}
|
||||
}
|
||||
|
||||
function parse(argv, titles, fields): Column[] {
|
||||
function parse(argv, titles, fields): Column[]
|
||||
{
|
||||
var columns: Column[] = [];
|
||||
|
||||
if (!titles) titles = [];
|
||||
|
||||
for (var index = 0; index < fields.length; index++) {
|
||||
for (var index = 0; index < fields.length; index++)
|
||||
{
|
||||
var column = new Column();
|
||||
|
||||
column.set(
|
||||
fields[index],
|
||||
titles.length >= index ? titles[index] : undefined
|
||||
);
|
||||
titles.length >= index ? titles[index] : undefined);
|
||||
|
||||
columns.push(column);
|
||||
}
|
||||
|
|
|
@ -4,11 +4,15 @@ import * as yargs from "yargs";
|
|||
export var command = "version";
|
||||
export var describe = "Displays version information about the program";
|
||||
|
||||
export function builder(yargs: yargs.Arguments) {
|
||||
return yargs.help("help").demand(0);
|
||||
export function builder(yargs: yargs.Arguments)
|
||||
{
|
||||
return yargs
|
||||
.help("help")
|
||||
.demand(0);
|
||||
}
|
||||
|
||||
export function handler(argv: any) {
|
||||
export function handler(argv: any)
|
||||
{
|
||||
const pkg: any = readPackage.sync();
|
||||
const json = pkg.pkg;
|
||||
|
||||
|
|
9
tsfmt.json
Normal file
9
tsfmt.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"indentSize": 4,
|
||||
"tabSize": 4,
|
||||
"indentStyle": 2,
|
||||
"newLineCharacter": "\n",
|
||||
"convertTabsToSpaces": true,
|
||||
"placeOpenBraceOnNewLineForFunctions": true,
|
||||
"placeOpenBraceOnNewLineForControlBlocks": true
|
||||
}
|
Loading…
Reference in a new issue