Skip to content

Commit

Permalink
feat(formatters): add markdown formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
gregswindle committed May 2, 2018
1 parent 6a64790 commit 0fa768b
Show file tree
Hide file tree
Showing 36 changed files with 9,818 additions and 5,773 deletions.
478 changes: 478 additions & 0 deletions .github/config/.eslintrc.yml

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions .github/spike-templates-readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# template-spike

> Spike for "Filling issues and pull requests with custom templates"
## Overview

According to the GitHub Help article "[Creating an issue template for your repository][adding-multiple-templates-url]:"

> You can create an ISSUE_TEMPLATE/ subdirectory in any of the supported folders to contain multiple
> issue templates. Use the template query parameter to specify the template that will automatically
> fill the issue body. For more information, see "[About automation for issues and pull requests with query parameters][automation-for-multiple-issues-url]."
>
> Creating an issue template for your repository - User Documentation . (2018). Help.github.com. Retrieved 23 February 2018, from <https://help.github.com/articles/creating-an-issue-template-for-your-repository/#adding-multiple-issue-templates>
## Pull request templates `.github/PULL_REQUEST_TEMPLATE/` instructions

### User story

As an engineer,<br>
I want to select the most appropriate ADR for my proposal<br>
In order to make the best case for my proposal.

### Acceptance criterion

- [ ] People can prepopulate a new pull request body with the ADR template of their choice by selecting a hyperlink.

### Examples

1. Load a template with an absolute-path URL:

_Link:_

> [**Propose an architecture decision (MADR)**][adr-pr-madr-url].
_Template path:_

> `.github/PULL_REQUEST_TEMPLATE/adr_template_madr.md`
_URL:_

> <https://github.com/gregswindle/template-spike/compare/adr-0001?expand=1&title=docs(techniques):%20add%20MADR%20template&template=adr_template_madr.md>
_Query parameters:_

> | Parameter Name | Value |
> |:---------------|:-------------------------------------------|
> | `expand` | `1` |
> | `title` | `docs(techniques):%20add%20MADR%20template`|
> | `template` | `adr_template_madr.md` |
### Issue templates `.github/ISSUE_TEMPLATE/`

1. [`.github/ISSUE_TEMPLATE/feat-request-template.md`][.github/ISSUE_TEMPLATE/feat-request-template.md]
1. [`.github/ISSUE_TEMPLATE/defect-report-template.md`][.github/ISSUE_TEMPLATE/defect-report-template.md]
1. [`.github/ISSUE_TEMPLATE/feat-request-template.md`][.github/ISSUE_TEMPLATE/feat_request_template.md]
1. [`.github/ISSUE_TEMPLATE/defect-report-template.md`][.github/ISSUE_TEMPLATE/defect_report_template.md]
1. [`.github/ISSUE_TEMPLATE/issue_template.md`][.github/ISSUE_TEMPLATE/issue_template.md]
1. [`.github/ISSUE_TEMPLATE/issue_template.md`][.github/ISSUE_TEMPLATE/new_issue_template.md]

<!-- ⛔️ LINK REFERENCES: please alphabetize these ⛔️ -->

[adding-multiple-templates-url]: https://help.github.com/articles/creating-an-issue-template-for-your-repository/#adding-multiple-issue-templates
[automation-for-multiple-issues-url]: https://help.github.com/articles/about-automation-for-issues-and-pull-requests-with-query-parameters
[adr-pr-madr-url]: https://github.com/gregswindle/template-spike/compare/adr-0001?expand=1&title=docs(techniques):%20add%20MADR%20template&template=adr_template_madr.md
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
## Table of contents

<!-- ⛔️ AUTO-GENERATED-CONTENT:START (TOC:excludeText=Table of contents) -->

- [1. Background](#1-background)
* [1.1. Anatomy of a CRC model](#11-anatomy-of-a-crc-model)
* [1.2. Sample report](#12-sample-report)
Expand All @@ -36,6 +37,7 @@
- [6. Version](#6-version)
- [7. License](#7-license)
- [8. References](#8-references)

<!-- ⛔️ AUTO-GENERATED-CONTENT:START (TOC:excludeText=Table of contents) -->
<!-- ⛔️ AUTO-GENERATED-CONTENT:END -->

Expand Down
4 changes: 1 addition & 3 deletions config/jsdoc.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
"template": "node_modules/docdash",
"package": "package.json"
},
"plugins": [
"plugins/markdown"
],
"plugins": ["plugins/markdown"],
"source": {
"include": [
".github/CONTRIBUTING.md",
Expand Down
26 changes: 13 additions & 13 deletions config/markdown.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/* eslint global-require: "off" */
/* eslint node/no-unpublished-require: "off" */
const path = require("path");
const markdownMagic = require("markdown-magic");
const markdownMagicDependencyTable = require("markdown-magic-dependency-table");
const markdownMagicPackageScripts = require("markdown-magic-package-scripts");
const path = require('path')
const markdownMagic = require('markdown-magic')
const markdownMagicDependencyTable = require('markdown-magic-dependency-table')
const markdownMagicPackageScripts = require('markdown-magic-package-scripts')

const config = {
"DEBUG": false,
"transforms": {
"DEPENDENCYTABLE": markdownMagicDependencyTable,
"SCRIPTS": markdownMagicPackageScripts
'DEBUG': false,
'transforms': {
'DEPENDENCYTABLE': markdownMagicDependencyTable,
'SCRIPTS': markdownMagicPackageScripts
}
};
}

let markdownPath = path.join(__dirname, "../*.md");
markdownMagic(markdownPath, config);
let markdownPath = path.join(__dirname, '../*.md')
markdownMagic(markdownPath, config)

markdownPath = path.join(__dirname, "../.github/CONTRIBUTING.md");
markdownMagic(markdownPath, config);
markdownPath = path.join(__dirname, '../.github/CONTRIBUTING.md')
markdownMagic(markdownPath, config)
22 changes: 11 additions & 11 deletions docs/common-vocabulary.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
## Index of terms

1. [**feat**](#feat) <sup>conventional-commit-type</sup>
1. [**fix**](#fix) <sup>conventional-commit-type</sup>
1. [**docs**](#docs) <sup>conventional-commit-type</sup>
1. [**style**](#style) <sup>conventional-commit-type</sup>
1. [**refactor**](#refactor) <sup>conventional-commit-type</sup>
1. [**perf**](#perf) <sup>conventional-commit-type</sup>
1. [**test**](#test) <sup>conventional-commit-type</sup>
1. [**build**](#build) <sup>conventional-commit-type</sup>
1. [**ci**](#ci) <sup>conventional-commit-type</sup>
1. [**chore**](#chore) <sup>conventional-commit-type</sup>
1. [**revert**](#revert) <sup>conventional-commit-type</sup>
1. [**feat**](#feat) <sup>conventional-commit-type</sup>
1. [**fix**](#fix) <sup>conventional-commit-type</sup>
1. [**docs**](#docs) <sup>conventional-commit-type</sup>
1. [**style**](#style) <sup>conventional-commit-type</sup>
1. [**refactor**](#refactor) <sup>conventional-commit-type</sup>
1. [**perf**](#perf) <sup>conventional-commit-type</sup>
1. [**test**](#test) <sup>conventional-commit-type</sup>
1. [**build**](#build) <sup>conventional-commit-type</sup>
1. [**ci**](#ci) <sup>conventional-commit-type</sup>
1. [**chore**](#chore) <sup>conventional-commit-type</sup>
1. [**revert**](#revert) <sup>conventional-commit-type</sup>

### Conventional Commit Specification Terms

Expand Down
84 changes: 42 additions & 42 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
*
*/

const crcLogger = require("./crc-logger");
const fs = require("fs-extra");
const meow = require("meow");
const path = require("path");
const {CLIEngine} = require("eslint");
const crcLogger = require('./crc-logger')
const fs = require('fs-extra')
const meow = require('meow')
const path = require('path')
const {CLIEngine} = require('eslint')

/**
* Create and copy resources to user-specified destination directories.
Expand All @@ -49,33 +49,33 @@ const {CLIEngine} = require("eslint");
*/

const copyAssets = async (destinationDirectory) => {
const from = path.resolve(__dirname, "./formatters/md/.templates/img");
const to = path.resolve(__dirname, path.dirname(destinationDirectory));
const from = path.resolve(__dirname, './formatters/md/.templates/img')
const to = path.resolve(__dirname, path.dirname(destinationDirectory))

try {
await fs.ensureDir(to);
await fs.copy(from, to);
crcLogger.info(`✅ Copied assets to ${to}`);
await fs.ensureDir(to)
await fs.copy(from, to)
crcLogger.info(`✅ Copied assets to ${to}`)
} catch (err) {
crcLogger.error(err, `❌ Unable to copy assets to ${to}.`);
crcLogger.error(err, `❌ Unable to copy assets to ${to}.`)
}
};
}

/**
* @private
* @ignore
*/

const msg = {
"error": "❌ There was a problem generating your CRC Model report.\n ",
'error': '❌ There was a problem generating your CRC Model report.\n ',

"success": "✅ CRC Model report generated at ",
'success': '✅ CRC Model report generated at ',

toString (message = "", type = msg.success) {
return type + message;
toString (message = '', type = msg.success) {
return type + message
},

"usage": `
'usage': `
Usage
$ crc input [options] [info]
$ eslint-plugin-crc input [options] [info]
Expand Down Expand Up @@ -105,7 +105,7 @@ const msg = {
❌ There was a problem generating your CRC Model report.
Error: ENOENT: no such file or directory, open '😱 '
`
};
}

/**
* Command-line interface options.
Expand All @@ -114,14 +114,14 @@ const msg = {
*/

const options = {
"flags": {
"output": {
"alias": "o",
"default": path.resolve(__dirname, "../reports/crc-model-report.md"),
"type": "string"
'flags': {
'output': {
'alias': 'o',
'default': path.resolve(__dirname, '../reports/crc-model-report.md'),
'type': 'string'
}
}
};
}

/**
* Creates (or overwrites) a CRC Model Report markdown file.
Expand All @@ -137,15 +137,15 @@ const options = {
const writeReportFile = (destinationDirectory, report) => {
// eslint-disable-next-line security/detect-non-literal-fs-filename
fs.writeFile(destinationDirectory, report, {
"flag": "w"
'flag': 'w'
}, (err) => {
if (err) {
crcLogger.error(err, msg.error);
crcLogger.error(err, msg.error)
} else {
crcLogger.info(msg.toString(destinationDirectory));
crcLogger.info(msg.toString(destinationDirectory))
}
});
};
})
}

/**
* Template function for report generation.
Expand All @@ -156,16 +156,16 @@ const writeReportFile = (destinationDirectory, report) => {
*/

const generateReport = () => {
const eslintCli = new CLIEngine("./lib/.eslintrc.yml");
const cli = meow(msg.usage, options);
const files = eslintCli.resolveFileGlobPatterns(cli.input);
const report = eslintCli.executeOnFiles(files);
const formatter = eslintCli.getFormatter("./lib/formatters/md/index.js");
const crcModelReport = formatter(report.results);
const destination = cli.flags.output || options.flags.output.default;
writeReportFile(destination, crcModelReport);
copyAssets(destination);
};
const eslintCli = new CLIEngine('./lib/.eslintrc.yml')
const cli = meow(msg.usage, options)
const files = eslintCli.resolveFileGlobPatterns(cli.input)
const report = eslintCli.executeOnFiles(files)
const formatter = eslintCli.getFormatter('./lib/formatters/md/index.js')
const crcModelReport = formatter(report.results)
const destination = cli.flags.output || options.flags.output.default
writeReportFile(destination, crcModelReport)
copyAssets(destination)
}

/**
* Invokes all other functions sequentially.
Expand All @@ -176,7 +176,7 @@ const generateReport = () => {
*/

const main = () => {
generateReport();
};
generateReport()
}

main();
main()

0 comments on commit 0fa768b

Please sign in to comment.