From dce80229c9925a86c331d99c79b76b4b535e33a3 Mon Sep 17 00:00:00 2001 From: "D. Moonfire" Date: Thu, 19 Oct 2017 18:39:45 -0500 Subject: [PATCH] Refactoring layout to fit with a different standard. - Same directory for the source and library files. - Switched from dotted to lodash directly. - tscconfig.json moved up a level. - Updated TypeScript packages. - Updated various files that were now throwing errors. --- bin/markdowny | 2 +- bin/markdowny-wc | 2 +- gulpfile.js | 0 package.json | 7 +++-- src/scanner.ts | 2 +- src/sections.ts | 8 ++--- src/table.ts | 75 ++++++++++++++++++++++++++++++----------------- src/tsconfig.json | 37 ----------------------- src/tslint.json | 13 ++++++++ tsconfig.json | 15 ++++++++++ 10 files changed, 87 insertions(+), 74 deletions(-) delete mode 100644 gulpfile.js delete mode 100644 src/tsconfig.json create mode 100644 src/tslint.json create mode 100644 tsconfig.json diff --git a/bin/markdowny b/bin/markdowny index 27d94ce..9354a17 100755 --- a/bin/markdowny +++ b/bin/markdowny @@ -1,4 +1,4 @@ #!/bin/bash rdlkf() { [ -L "$1" ] && (local lk="$(readlink "$1")"; local d="$(dirname "$1")"; cd "$d"; local l="$(rdlkf "$lk")"; ([[ "$l" = /* ]] && echo "$l" || echo "$d/$l")) || echo "$1"; } DIR="$(dirname "$(rdlkf "$0")")" -exec /usr/bin/env node --harmony "$DIR/../lib/cli.js" "$@" +exec /usr/bin/env node --harmony "$DIR/../src/cli.js" "$@" diff --git a/bin/markdowny-wc b/bin/markdowny-wc index ad696ea..5a21887 100755 --- a/bin/markdowny-wc +++ b/bin/markdowny-wc @@ -1,4 +1,4 @@ #!/bin/bash rdlkf() { [ -L "$1" ] && (local lk="$(readlink "$1")"; local d="$(dirname "$1")"; cd "$d"; local l="$(rdlkf "$lk")"; ([[ "$l" = /* ]] && echo "$l" || echo "$d/$l")) || echo "$1"; } DIR="$(dirname "$(rdlkf "$0")")" -exec /usr/bin/env node --harmony "$DIR/../lib/cli.js" count "$@" +exec /usr/bin/env node --harmony "$DIR/../src/cli.js" count "$@" diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index e69de29..0000000 diff --git a/package.json b/package.json index 0446a78..4573a40 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,10 @@ "type": "git", "url": "git+https://git.mfgames.com/author-intrusion/markdowny.git" }, - "main": "index.js", + "main": "src/cli", + "types": "src/cli.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "build": "tsc" }, "keywords": [ "markdown" @@ -35,7 +36,7 @@ "gulp": "^3.9.1", "lodash": "^4.16.5", "markdown-table": "^1.0.0", - "typescript": "^2.0.6", + "typescript": "^2.5.3", "yaml-front-matter": "^3.4.0", "yargs": "^6.3.0" } diff --git a/src/scanner.ts b/src/scanner.ts index 45285c0..b560b69 100644 --- a/src/scanner.ts +++ b/src/scanner.ts @@ -8,7 +8,7 @@ import * as yamlFrontMatter from "yaml-front-matter"; */ export function scanFiles(argv, files: string[]) { - var list = []; + var list: any[] = []; for (var file of files) { diff --git a/src/sections.ts b/src/sections.ts index 566f324..33e9846 100644 --- a/src/sections.ts +++ b/src/sections.ts @@ -1,5 +1,5 @@ +import * as _ from "lodash"; import * as comma from "add-commas"; -import * as dotted from "dotted"; import * as markdownTable from "markdown-table"; import * as scanner from "./scanner"; @@ -30,11 +30,11 @@ export function run(argv) { export function render(argv, data) { for (var item of data) { - var title = dotted.getNested(item, argv.title); - var value = dotted.getNested(item, argv.field); + var title = _.get(item, argv.title); + var value = _.get(item, argv.field); console.log(`# ${title}`); console.log(); - console.log(value.replace("\n", "\n\n"); + console.log(value.replace("\n", "\n\n")); } } diff --git a/src/table.ts b/src/table.ts index 5095a36..3d98264 100644 --- a/src/table.ts +++ b/src/table.ts @@ -1,11 +1,12 @@ +import * as _ from "lodash"; import * as comma from "add-commas"; -import * as dotted from "dotted"; import * as markdownTable from "markdown-table"; import * as scanner from "./scanner"; export var help = "Create a summary table of requested fields"; -export function args(argv) { +export function args(argv) +{ return argv .help("help") @@ -35,20 +36,23 @@ export function args(argv) { .argv; } -export function run(argv) { +export function run(argv) +{ 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 = []; + var header: any[] = []; - for (var column of columns) { + for (var column of columns) + { header.push(column.header); } @@ -56,32 +60,37 @@ export function render(argv, data) { var table = [header]; // Loop through the results and get the fields we need to display. - var totals = ["Totals"]; + var totals: any = ["Totals"]; - for (var metadata of data) { + for (var metadata of data) + { // Add the row to the table. - var row = []; + 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 = dotted.getNested(metadata, column.ref); + 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); } @@ -91,10 +100,13 @@ export function render(argv, data) { } // If we have totals, then add it at the bottom. - if (totals.length > 1) { - for (var index = 0; index < columns.length && index < totals.length; index++) { + if (totals.length > 1) + { + for (var index = 0; index < columns.length && index < totals.length; index++) + { var column = columns[index]; - if (column.comma) { + if (column.comma) + { totals[index] = comma(totals[index]); } } @@ -112,35 +124,42 @@ export function render(argv, data) { }); // If we don't want the header row, strip off the first line. - if (!argv.tableHeader) { + 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': @@ -164,12 +183,14 @@ class Column { } } -function parse(argv, titles, fields): Column[] { +function parse(argv, titles, fields): 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(); column.set( diff --git a/src/tsconfig.json b/src/tsconfig.json deleted file mode 100644 index 4497915..0000000 --- a/src/tsconfig.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "compilerOptions": { - "target": "es5", - "module": "umd", - "moduleResolution": "node", - "isolatedModules": false, - "jsx": "react", - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "declaration": true, - "noImplicitAny": false, - "removeComments": true, - "noLib": false, - "preserveConstEnums": true, - "suppressImplicitAnyIndexErrors": true, - "inlineSourceMap": true, - "outDir": "../lib" - }, - "filesGlob": [ - "**/*.ts", - "**/*.tsx", - "!node_modules/**" - ], - "compileOnSave": true, - "buildOnSave": false, - "files": [ - "cli.ts", - "count.ts", - "scanner.ts", - "sections.ts", - "table.ts", - "version.ts" - ], - "atom": { - "rewriteTsconfig": true - } -} diff --git a/src/tslint.json b/src/tslint.json new file mode 100644 index 0000000..83e2d60 --- /dev/null +++ b/src/tslint.json @@ -0,0 +1,13 @@ +{ + "defaultSeverity": "error", + "extends": [ + "tslint:recommended" + ], + "jsRules": {}, + "rules": { + "indent": [true, "spaces", 4], + "interface-name": [true, "never-prefix"], + "max-line-length": [true, 80] + }, + "rulesDirectory": [] +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..c5acc28 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compileOnSave": true, + "compilerOptions": { + "target": "es5", + "lib": ["es6", "dom"], + "module": "commonjs", + "moduleResolution": "node", + "types": ["node"], + "declaration": true, + "noImplicitAny": false, + "strictNullChecks": true, + "sourceMap": true, + "experimentalDecorators": true + } +}