Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support CR and CRLF line breaks (#13)
Browse files Browse the repository at this point in the history
npalm committed Mar 7, 2021

Unverified

This user has not yet uploaded their public signing key.
1 parent 7f2214d commit 6e14ae5
Showing 13 changed files with 256 additions and 109 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[*]
end_of_line = lf
insert_final_newline = true

[*.crlf]
end_of_line = crlf
tab_width = 20
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -94,4 +94,5 @@ typings/
.DS_Store
Thumbs.db

.npmrc
.npmrc
lib
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -41,13 +41,15 @@ The following options are available via the CLI

```
Options:
--help Show help [boolean]
--version Show version number [boolean]
-t, --toc-level TOC level used for markdown
--help Show help [boolean]
--version Show version number [boolean]
-t, --toc-level TOC level used for markdown
[number] [required] [default: 2]
-a, --action GitHub action file [string] [default: "action.yml"]
--no-banner Print no banner
-u, --update-readme Update readme file. [string]
-a, --action GitHub action file [string] [default: "action.yml"]
--no-banner Print no banner
-u, --update-readme Update readme file. [string]
--line-breaks, --lb Used line breaks in the generated docs.
[string] [choices: "CR", "LF", "CRLF"] [default: "LF"]
```


16 changes: 14 additions & 2 deletions __tests__/index.test.ts → __tests__/action-docs.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { generateActionMarkdownDocs } from "../src";
import { generateActionMarkdownDocs, Options } from "../src";
import { readFileSync, writeFileSync } from "fs";
import { option } from "yargs";

test("With defaults.", async () => {
const markdown = await generateActionMarkdownDocs();
@@ -48,10 +49,20 @@ test("Update filled readme (all fields)", async () => {
);
});

test("Update readme (all fields) CRLF", async () => {
await testReadme(
"__tests__/fixtures/all_fields_action.yml.crlf",
"__tests__/fixtures/all_fields_readme.input.crlf",
"__tests__/fixtures/all_fields_readme.output.crlf",
{ lineBreaks: "CRLF" }
);
});

async function testReadme(
actionFile: string,
originalReadme: string,
fixtureReadme: string
fixtureReadme: string,
overwriteOptions?: Options
) {
const expected = <string>readFileSync(fixtureReadme, "utf-8");
const original = <string>readFileSync(originalReadme, "utf-8");
@@ -60,6 +71,7 @@ async function testReadme(
actionFile: actionFile,
updateReadme: true,
readmeFile: originalReadme,
...overwriteOptions,
});

const updated = <string>readFileSync(originalReadme, "utf-8");
28 changes: 28 additions & 0 deletions __tests__/fixtures/all_fields_action.yml.crlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: 'An Action'
description: 'Default test'
author: 'Niek Palm'
inputs:
inputA:
description: 'A description A'
required: false
inputB:
description: 'A description B'
required: true
inputC:
description: 'A description C'
required: true
default: C
inputD:
description: 'A description D'
required: false
default: D

outputs:
outputA:
description: 'A description A'
outputB:
description: 'A description B'

runs:
using: 'node12'
main: 'dist/index.js'
7 changes: 7 additions & 0 deletions __tests__/fixtures/all_fields_readme.input.crlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- action-docs-description -->

<!-- action-docs-inputs -->

<!-- action-docs-outputs -->

<!-- action-docs-runs -->
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
<!-- action-docs-description -->
## Description

Default test


<!-- action-docs-description -->

<!-- action-docs-inputs -->
## Inputs

| parameter | description | required | default |
| - | - | - | - |
| inputA | A description A | `false` | |
| inputB | A description B | `true` | |
| inputC | A description C | `true` | C |
| inputD | A description D | `false` | D |



<!-- action-docs-inputs -->

<!-- action-docs-outputs -->
## Outputs

| parameter | description |
| - | - |
| outputA | A description A |
| outputB | A description B |



<!-- action-docs-outputs -->
<!-- action-docs-description -->
## Description

Default test


<!-- action-docs-description -->

<!-- action-docs-inputs -->
## Inputs

| parameter | description | required | default |
| - | - | - | - |
| inputA | A description A | `false` | |
| inputB | A description B | `true` | |
| inputC | A description C | `true` | C |
| inputD | A description D | `false` | D |



<!-- action-docs-inputs -->

<!-- action-docs-outputs -->
## Outputs

| parameter | description |
| - | - |
| outputA | A description A |
| outputB | A description B |



<!-- action-docs-outputs -->

<!-- action-docs-runs -->
## Runs

This action is an `node12` action.


<!-- action-docs-runs -->
14 changes: 14 additions & 0 deletions __tests__/linebreak.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as lb from "../src/linebreak";

test("Line break types", () => {
expect(lb.getLineBreakType("CR")).toEqual("CR");
expect(lb.getLineBreakType("CRLF")).toEqual("CRLF");
expect(lb.getLineBreakType("LF")).toEqual("LF");
expect(lb.getLineBreakType("unknown")).toEqual("LF");
});

test("Line break types", () => {
expect(lb.getLineBreak("CR")).toEqual("\r");
expect(lb.getLineBreak("CRLF")).toEqual("\r\n");
expect(lb.getLineBreak("LF")).toEqual("\n");
});
96 changes: 58 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@
"@types/jest": "^26.0.15",
"@types/js-yaml": "^4.0.0",
"@types/node": "^14.14.30",
"@typescript-eslint/parser": "^4.8.1",
"@typescript-eslint/parser": "^4.16.1",
"conventional-changelog-conventionalcommits": "^4.5.0",
"eslint": "^7.17.0",
"eslint-plugin-github": "^4.1.1",
@@ -74,4 +74,4 @@
"directories": {
"dist": "lib"
}
}
}
Loading

0 comments on commit 6e14ae5

Please sign in to comment.