fix: added package management

This commit is contained in:
Dylan R. E. Moonfire 2018-08-11 17:32:06 -05:00
parent f9a24a4ab0
commit c7c82819e5
21 changed files with 9819 additions and 755 deletions

View File

@ -13,11 +13,16 @@ insert_final_newline = true
max_line_length = 80
tab_width = 4
trim_trailing_whitespace = true
curly_bracket_next_line = true
curly_bracket_next_line = false
[*.{js,ts}]
quote_type = double
[*.json]
[*.yaml]
indent_size = 4
tab_width = 4
indent_style = space
[package.json]
indent_size = 2
tab_width = 2

46
.eslintrc.yml Normal file
View File

@ -0,0 +1,46 @@
env:
es6: true
node: true
extends: 'eslint:recommended'
parser: typescript-eslint-parser
parserOptions:
ecmaFeatures:
jsx: true
ecmaVersion: 2018
sourceType: module
plugins:
#- react
- typescript
rules:
typescript/class-name-casing:
- error
typescript/member-naming:
- error
typescript/member-ordering:
- error
typescript/no-unused-vars:
- off
typescript/no-var-requires:
- error
indent:
- error
- 4
linebreak-style:
- error
- unix
quotes:
- error
- double
semi:
- error
- always
# Eventually
no-console:
- off
# We are having trouble with these two, so we turn them off.
no-undef:
- off
no-unused-vars:
- off

26
.gitignore vendored
View File

@ -1,25 +1,11 @@
*~
.tscache
/.ntvs_analysis.dat
/.ntvs_analysis.dat.tmp
.baseDir.ts
npm-debug.log
*.tgz
*.swp
src/*.js
src/*.js.map
src/*.d.ts
lib/
es6/
amd/
umd/
dist/
commonjs/
spec/*.js
spec/*.js.map
spec/*.d.ts
npm-debug.log
yarn-error.log
node_modules/
typings/
build/
dist/
lib/

22
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,22 @@
image: node:latest
stages:
- publish
publish:
stage: publish
script:
# Remove the references so it builds cleanly.
- apt-get update
- apt-get install jq -y
- "cat tsconfig.json | jq 'del(.references)' > a && mv a tsconfig.json"
# Make sure the commits are clean
- npm ci
- npx commitlint --from=master to=CI_BUILD_REF_NAME
# Build the project
- npm run build
# Perform the automatic release process
- npx semantic-release

View File

@ -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/../src/cli.js" "$@"
exec /usr/bin/env node --harmony "$DIR/../lib/cli.js" "$@"

View File

@ -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/../src/cli.js" count "$@"
exec /usr/bin/env node --harmony "$DIR/../lib/cli.js" count "$@"

9978
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,10 +6,17 @@
"type": "git",
"url": "https://gitlab.com/mfgames-writing/markdowny.git"
},
"main": "src/cli",
"types": "src/cli.d.ts",
"main": "lib/index",
"types": "lib/index.d.ts",
"scripts": {
"build": "tsc"
"build": "tsc --build",
"barrels": "barrelsby --delete --location all --directory src --exclude '(tests|cli|tools)'",
"lint": "eslint -c .eslintrc.yml src/**/*.ts --fix",
"format": "tsfmt -r",
"clean": "rimraf lib",
"prebuild": "npm run barrels && npm run lint && npm run format && npm run clean",
"prepack": "npm run build",
"commitmsg": "commitlint -E GIT_PARAMS"
},
"keywords": [
"markdown"
@ -30,14 +37,65 @@
},
"dependencies": {
"@types/node": "^6.0.46",
"@types/yargs": "0.0.34",
"add-commas": "0.0.4",
"dotted": "^0.1.1",
"gulp": "^3.9.1",
"lodash": "^4.16.5",
"markdown-table": "^1.0.0",
"typescript": "^2.5.3",
"read-pkg-up": "^4.0.0",
"yaml-front-matter": "^3.4.0",
"yargs": "^6.3.0"
"yargs": "^12.0.1"
},
"devDependencies": {
"@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/read-pkg-up": "^3.0.1",
"@types/yargs": "^11.1.1",
"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",
"rimraf": "^2.6.2",
"semantic-release": "^15.9.8",
"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": []
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}

View File

@ -1,37 +1,8 @@
import * as yargs from "yargs";
import * as count from "./count";
import * as sections from "./sections";
import * as table from "./table";
import * as version from "./version";
// Combine everything together to create a composite arguments which is used
// to parse the input and create the usage if required.
var argv = yargs
.usage("mfgames-writing-format command")
yargs
.usage("$0 <cmd> [args]")
.commandDir("tools")
.demandCommand(1)
.help("help")
.showHelpOnFail(true, "Specify --help for available options")
.demand(1)
.command("count", count.help, count.args)
.command("sections", sections.help, sections.args)
.command("table", table.help, table.args)
.command("version", version.help, version.args)
.argv;
// Use the first command to determine what we are going to do.
switch (argv._[0]) {
case "count":
count.run(argv);
break;
case "sections":
sections.run(argv);
break;
case "table":
table.run(argv);
break;
case "version":
version.run(argv);
break;
default:
console.error(`Unknown command: ${argv._[0]}`);
break;
}

View File

@ -1,65 +0,0 @@
import * as yargs from "yargs";
import * as table from "./table";
import * as scanner from "./scanner";
export var help = "Counts the number of works in the given input";
export function args(argv)
{
return argv
.help("help")
.default('fields', ['_basename', '_words:r'])
.describe(
'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.')
.default('table-start', '')
.default('table-end', '')
.default('table-delimiter', ': ')
.boolean('table-rule')
.default('table-rule', false)
.boolean('table-header')
.default('table-header', false)
.boolean('total')
.alias('t', 'total')
.describe(
'total',
'If provided, adds a special entry with a _basename of Totals ' +
'that adds up all the words.')
.boolean('separator')
.alias('s', 'separator')
.describe(
'separator',
'If provided, then the word counts will have comma separators ' +
'for thousands.'
)
.alias('o', 'output')
.default('output', '-')
.demand(1)
.argv;
}
export function run(argv)
{
var files = argv._.splice(1);
var data = scanner.scanFiles(argv, files);
if (argv.total)
{
argv.fields[1] += "t";
}
if (argv.separator)
{
argv.fields[1] += "s";
}
table.render(argv, data);
}

1
src/index.ts Normal file
View File

@ -0,0 +1 @@
export * from "./scanner";

View File

@ -13,7 +13,7 @@ export function scanFiles(argv, files: string[])
for (var file of files)
{
// Load the metadata from the given file.
var contents = fs.readFileSync(file, 'utf8')
var contents = fs.readFileSync(file, "utf8");
var metadata = yamlFrontMatter.loadFront(contents);
// Add in the standard fields as "_" entries.

View File

@ -1,40 +0,0 @@
import * as _ from "lodash";
import * as comma from "add-commas";
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) {
return argv
.help("help")
.alias('f', 'field')
.default('field', 'summary')
.alias('t', 'title')
.default('title', 'title')
.alias('o', 'output')
.default('output', '-')
.demand(1)
.argv;
}
export function run(argv) {
var files = argv._.splice(1);
var data = scanner.scanFiles(argv, files);
render(argv, 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();
console.log(value.replace("\n", "\n\n"));
}
}

65
src/tools/count.ts Normal file
View File

@ -0,0 +1,65 @@
import * as yargs from "yargs";
import * as scanner from "../scanner";
import * as table from "./table";
export var command = "count";
export var describe = "Counts the number of works in the given input";
export function builder(yargs: yargs.Arguments)
{
return yargs
.help("help")
.default("fields", ["_basename", "_words:r"])
.describe(
"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.")
.default("table-start", "")
.default("table-end", "")
.default("table-delimiter", ": ")
.boolean("table-rule")
.default("table-rule", false)
.boolean("table-header")
.default("table-header", false)
.boolean("total")
.alias("t", "total")
.describe(
"total",
"If provided, adds a special entry with a _basename of Totals " +
"that adds up all the words.")
.boolean("separator")
.alias("s", "separator")
.describe(
"separator",
"If provided, then the word counts will have comma separators " +
"for thousands."
)
.alias("o", "output")
.default("output", "-")
.demand(1);
}
export function handler(argv: any)
{
var files = argv._.splice(1);
var data = scanner.scanFiles(argv, files);
if (argv.total)
{
argv.fields[1] += "t";
}
if (argv.separator)
{
argv.fields[1] += "s";
}
table.render(argv, data);
}

47
src/tools/sections.ts Normal file
View File

@ -0,0 +1,47 @@
import * as _ from "lodash";
import * as yargs from "yargs";
import * as scanner from "../scanner";
export var command = "sections";
export var describe = "Create a summary table of requested fields";
export function builder(yargs: yargs.Arguments)
{
return yargs
.help("help")
.alias("f", "field")
.default("field", "summary")
.alias("t", "title")
.default("title", "title")
.alias("o", "output")
.default("output", "-")
.demand(1);
}
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)
{
var title = _.get(item, argv.title);
var value = _.get(item, argv.field);
console.log(`# ${title}`);
console.log();
if (value)
{
console.log(value.replace("\n", "\n\n"));
}
}
}

View File

@ -1,42 +1,43 @@
import * as _ from "lodash";
import * as comma from "add-commas";
import * as _ from "lodash";
import * as markdownTable from "markdown-table";
import * as scanner from "./scanner";
import * as yargs from "yargs";
import * as scanner from "../scanner";
export var help = "Create a summary table of requested fields";
export var command = "table";
export var describe = "Create a summary table of requested fields";
export function args(argv)
export function builder(yargs: yargs.Arguments)
{
return argv
return yargs
.help("help")
.alias('f', 'fields')
.array('fields')
.default('fields', ['_basename', 'title'])
.alias("f", "fields")
.array("fields")
.default("fields", ["_basename", "title"])
.alias('t', 'titles')
.array('titles')
.alias("t", "titles")
.array("titles")
.default('table-start', '| ')
.default('table-end', ' |')
.default('table-delimiter', ' | ')
.boolean('table-rule')
.default('table-rule', true)
.boolean('table-header')
.default('table-header', true)
.default("table-start", "| ")
.default("table-end", " |")
.default("table-delimiter", " | ")
.boolean("table-rule")
.default("table-rule", true)
.boolean("table-header")
.default("table-header", true)
.default('list-delimiter', ', ')
.default("list-delimiter", ", ")
.alias('o', 'output')
.default('output', '-')
.alias("o", "output")
.default("output", "-")
.default('prefix', '')
.default("prefix", "")
.demand(1)
.argv;
.demand(1);
}
export function run(argv)
export function handler(argv: any)
{
var files = argv._.splice(1);
var data = scanner.scanFiles(argv, files);
@ -51,9 +52,9 @@ export function render(argv, data)
// Create the header row.
var header: any[] = [];
for (var column of columns)
for (var column1 of columns)
{
header.push(column.header);
header.push(column1.header);
}
// Create the initial table with the header.
@ -102,12 +103,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++)
for (var index2 = 0; index2 < columns.length && index2 < totals.length; index2++)
{
var column = columns[index];
if (column.comma)
var column2 = columns[index2];
if (column2.comma)
{
totals[index] = comma(totals[index]);
totals[index2] = comma(totals[index2]);
}
}
@ -149,7 +151,7 @@ class Column
private parseSpecifier(spec): string
{
// See if we have options.
var m = spec.match(/^(.*?):([lcr\.st]+)?$/);
var m = spec.match(/^(.*?):([lcr.st]+)?$/);
if (m)
{
@ -160,18 +162,18 @@ class Column
{
switch (s)
{
case 'c':
case 'l':
case 'r':
case '.':
case "c":
case "l":
case "r":
case ".":
this.align = s;
break;
case 's':
case "s":
this.comma = true;
break;
case 't':
case "t":
this.total = true;
break;
}

20
src/tools/version.ts Normal file
View File

@ -0,0 +1,20 @@
import * as readPackage from "read-pkg-up";
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 handler(argv: any)
{
const pkg: any = readPackage.sync();
const json = pkg.pkg;
console.log(`${json.name} v${json.version}`);
}

View File

@ -1,13 +0,0 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {
"indent": [true, "spaces", 4],
"interface-name": [true, "never-prefix"],
"max-line-length": [true, 80]
},
"rulesDirectory": []
}

View File

@ -1,16 +0,0 @@
import * as yargs from "yargs";
export var help = "Displays version information about the program";
export function args(argv) {
return argv
.help("help")
.demand(0)
.argv;
}
export function run(argv) {
let json = require("../package.json");
console.log(`${json.name} v${json.version}`);
}

View File

@ -1,20 +1,24 @@
{
"compileOnSave": true,
"compilerOptions": {
"target": "es5",
"lib": [
"es6",
"dom"
],
"outDir": "lib",
"alwaysStrict": true,
"composite": true,
"declaration": true,
"declarationMap": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"lib": ["es6", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"types": [
"node"
],
"declaration": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": false,
"strictNullChecks": true,
"noImplicitReturns": true,
"rootDir": "./src",
"sourceMap": true,
"experimentalDecorators": true
"strictFunctionTypes": true,
"strictNullChecks": true,
"target": "es6",
"types": ["node"]
}
}
}

9
tsfmt.json Normal file
View File

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