Skip to content

Commit 2fdadb3

Browse files
committed
feat: support CR and CRLF line breaks (#13)
1 parent 6e714b0 commit 2fdadb3

13 files changed

+256
-109
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[*]
2+
end_of_line = lf
3+
insert_final_newline = true
4+
5+
[*.crlf]
6+
end_of_line = crlf
7+
tab_width = 20

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,5 @@ typings/
9494
.DS_Store
9595
Thumbs.db
9696

97-
.npmrc
97+
.npmrc
98+
lib

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ The following options are available via the CLI
4141

4242
```
4343
Options:
44-
--help Show help [boolean]
45-
--version Show version number [boolean]
46-
-t, --toc-level TOC level used for markdown
44+
--help Show help [boolean]
45+
--version Show version number [boolean]
46+
-t, --toc-level TOC level used for markdown
4747
[number] [required] [default: 2]
48-
-a, --action GitHub action file [string] [default: "action.yml"]
49-
--no-banner Print no banner
50-
-u, --update-readme Update readme file. [string]
48+
-a, --action GitHub action file [string] [default: "action.yml"]
49+
--no-banner Print no banner
50+
-u, --update-readme Update readme file. [string]
51+
--line-breaks, --lb Used line breaks in the generated docs.
52+
[string] [choices: "CR", "LF", "CRLF"] [default: "LF"]
5153
```
5254

5355

__tests__/index.test.ts renamed to __tests__/action-docs.test.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { generateActionMarkdownDocs } from "../src";
1+
import { generateActionMarkdownDocs, Options } from "../src";
22
import { readFileSync, writeFileSync } from "fs";
3+
import { option } from "yargs";
34

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

52+
test("Update readme (all fields) CRLF", async () => {
53+
await testReadme(
54+
"__tests__/fixtures/all_fields_action.yml.crlf",
55+
"__tests__/fixtures/all_fields_readme.input.crlf",
56+
"__tests__/fixtures/all_fields_readme.output.crlf",
57+
{ lineBreaks: "CRLF" }
58+
);
59+
});
60+
5161
async function testReadme(
5262
actionFile: string,
5363
originalReadme: string,
54-
fixtureReadme: string
64+
fixtureReadme: string,
65+
overwriteOptions?: Options
5566
) {
5667
const expected = <string>readFileSync(fixtureReadme, "utf-8");
5768
const original = <string>readFileSync(originalReadme, "utf-8");
@@ -60,6 +71,7 @@ async function testReadme(
6071
actionFile: actionFile,
6172
updateReadme: true,
6273
readmeFile: originalReadme,
74+
...overwriteOptions,
6375
});
6476

6577
const updated = <string>readFileSync(originalReadme, "utf-8");
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: 'An Action'
2+
description: 'Default test'
3+
author: 'Niek Palm'
4+
inputs:
5+
inputA:
6+
description: 'A description A'
7+
required: false
8+
inputB:
9+
description: 'A description B'
10+
required: true
11+
inputC:
12+
description: 'A description C'
13+
required: true
14+
default: C
15+
inputD:
16+
description: 'A description D'
17+
required: false
18+
default: D
19+
20+
outputs:
21+
outputA:
22+
description: 'A description A'
23+
outputB:
24+
description: 'A description B'
25+
26+
runs:
27+
using: 'node12'
28+
main: 'dist/index.js'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!-- action-docs-description -->
2+
3+
<!-- action-docs-inputs -->
4+
5+
<!-- action-docs-outputs -->
6+
7+
<!-- action-docs-runs -->
Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
1-
<!-- action-docs-description -->
2-
## Description
3-
4-
Default test
5-
6-
7-
<!-- action-docs-description -->
8-
9-
<!-- action-docs-inputs -->
10-
## Inputs
11-
12-
| parameter | description | required | default |
13-
| - | - | - | - |
14-
| inputA | A description A | `false` | |
15-
| inputB | A description B | `true` | |
16-
| inputC | A description C | `true` | C |
17-
| inputD | A description D | `false` | D |
18-
19-
20-
21-
<!-- action-docs-inputs -->
22-
23-
<!-- action-docs-outputs -->
24-
## Outputs
25-
26-
| parameter | description |
27-
| - | - |
28-
| outputA | A description A |
29-
| outputB | A description B |
30-
31-
32-
33-
<!-- action-docs-outputs -->
1+
<!-- action-docs-description -->
2+
## Description
3+
4+
Default test
5+
6+
7+
<!-- action-docs-description -->
8+
9+
<!-- action-docs-inputs -->
10+
## Inputs
11+
12+
| parameter | description | required | default |
13+
| - | - | - | - |
14+
| inputA | A description A | `false` | |
15+
| inputB | A description B | `true` | |
16+
| inputC | A description C | `true` | C |
17+
| inputD | A description D | `false` | D |
18+
19+
20+
21+
<!-- action-docs-inputs -->
22+
23+
<!-- action-docs-outputs -->
24+
## Outputs
25+
26+
| parameter | description |
27+
| - | - |
28+
| outputA | A description A |
29+
| outputB | A description B |
30+
31+
32+
33+
<!-- action-docs-outputs -->
34+
35+
<!-- action-docs-runs -->
36+
## Runs
37+
38+
This action is an `node12` action.
39+
40+
41+
<!-- action-docs-runs -->

__tests__/linebreak.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as lb from "../src/linebreak";
2+
3+
test("Line break types", () => {
4+
expect(lb.getLineBreakType("CR")).toEqual("CR");
5+
expect(lb.getLineBreakType("CRLF")).toEqual("CRLF");
6+
expect(lb.getLineBreakType("LF")).toEqual("LF");
7+
expect(lb.getLineBreakType("unknown")).toEqual("LF");
8+
});
9+
10+
test("Line break types", () => {
11+
expect(lb.getLineBreak("CR")).toEqual("\r");
12+
expect(lb.getLineBreak("CRLF")).toEqual("\r\n");
13+
expect(lb.getLineBreak("LF")).toEqual("\n");
14+
});

package-lock.json

Lines changed: 58 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@types/jest": "^26.0.15",
5555
"@types/js-yaml": "^4.0.0",
5656
"@types/node": "^14.14.30",
57-
"@typescript-eslint/parser": "^4.8.1",
57+
"@typescript-eslint/parser": "^4.16.1",
5858
"conventional-changelog-conventionalcommits": "^4.5.0",
5959
"eslint": "^7.17.0",
6060
"eslint-plugin-github": "^4.1.1",
@@ -74,4 +74,4 @@
7474
"directories": {
7575
"dist": "lib"
7676
}
77-
}
77+
}

0 commit comments

Comments
 (0)