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.
This commit is contained in:
D. Moonfire 2017-10-19 18:39:45 -05:00
parent 9e42f79fc2
commit dce80229c9
10 changed files with 87 additions and 74 deletions

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/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"; } 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")")" DIR="$(dirname "$(rdlkf "$0")")"
exec /usr/bin/env node --harmony "$DIR/../lib/cli.js" "$@" exec /usr/bin/env node --harmony "$DIR/../src/cli.js" "$@"

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/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"; } 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")")" 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 "$@"

View file

View file

@ -6,9 +6,10 @@
"type": "git", "type": "git",
"url": "git+https://git.mfgames.com/author-intrusion/markdowny.git" "url": "git+https://git.mfgames.com/author-intrusion/markdowny.git"
}, },
"main": "index.js", "main": "src/cli",
"types": "src/cli.d.ts",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "build": "tsc"
}, },
"keywords": [ "keywords": [
"markdown" "markdown"
@ -35,7 +36,7 @@
"gulp": "^3.9.1", "gulp": "^3.9.1",
"lodash": "^4.16.5", "lodash": "^4.16.5",
"markdown-table": "^1.0.0", "markdown-table": "^1.0.0",
"typescript": "^2.0.6", "typescript": "^2.5.3",
"yaml-front-matter": "^3.4.0", "yaml-front-matter": "^3.4.0",
"yargs": "^6.3.0" "yargs": "^6.3.0"
} }

View file

@ -8,7 +8,7 @@ import * as yamlFrontMatter from "yaml-front-matter";
*/ */
export function scanFiles(argv, files: string[]) export function scanFiles(argv, files: string[])
{ {
var list = []; var list: any[] = [];
for (var file of files) for (var file of files)
{ {

View file

@ -1,5 +1,5 @@
import * as _ from "lodash";
import * as comma from "add-commas"; import * as comma from "add-commas";
import * as dotted from "dotted";
import * as markdownTable from "markdown-table"; import * as markdownTable from "markdown-table";
import * as scanner from "./scanner"; import * as scanner from "./scanner";
@ -30,11 +30,11 @@ export function run(argv) {
export function render(argv, data) { export function render(argv, data) {
for (var item of data) { for (var item of data) {
var title = dotted.getNested(item, argv.title); var title = _.get(item, argv.title);
var value = dotted.getNested(item, argv.field); var value = _.get(item, argv.field);
console.log(`# ${title}`); console.log(`# ${title}`);
console.log(); console.log();
console.log(value.replace("\n", "\n\n"); console.log(value.replace("\n", "\n\n"));
} }
} }

View file

@ -1,11 +1,12 @@
import * as _ from "lodash";
import * as comma from "add-commas"; import * as comma from "add-commas";
import * as dotted from "dotted";
import * as markdownTable from "markdown-table"; import * as markdownTable from "markdown-table";
import * as scanner from "./scanner"; import * as scanner from "./scanner";
export var help = "Create a summary table of requested fields"; export var help = "Create a summary table of requested fields";
export function args(argv) { export function args(argv)
{
return argv return argv
.help("help") .help("help")
@ -35,20 +36,23 @@ export function args(argv) {
.argv; .argv;
} }
export function run(argv) { export function run(argv)
{
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 = []; var header: any[] = [];
for (var column of columns) { for (var column of columns)
{
header.push(column.header); header.push(column.header);
} }
@ -56,32 +60,37 @@ export function render(argv, data) {
var table = [header]; var table = [header];
// 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 = ["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 = []; 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 = dotted.getNested(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);
} }
@ -91,10 +100,13 @@ 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 (var index = 0; index < columns.length && index < totals.length; index++) { {
for (var index = 0; index < columns.length && index < totals.length; index++)
{
var column = columns[index]; var column = columns[index];
if (column.comma) { if (column.comma)
{
totals[index] = comma(totals[index]); 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 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); formattedTable = formattedTable.substring(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':
@ -164,12 +183,14 @@ 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(

View file

@ -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
}
}

13
src/tslint.json Normal file
View file

@ -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": []
}

15
tsconfig.json Normal file
View file

@ -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
}
}