textrun-repo 0.0.11 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -8
- package/dist/existing-file-content.js +42 -0
- package/dist/existing-file.js +7 -22
- package/dist/index.js +2 -0
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ actions for verifying documentation containing the content of source code files
|
|
|
5
5
|
from the repository.
|
|
6
6
|
|
|
7
7
|
- [installation](#installation)
|
|
8
|
-
- [repo/existing-file](#repoexisting-file)
|
|
8
|
+
- [repo/existing-file-content](#repoexisting-file-content)
|
|
9
9
|
- [repo/executable](#repoexecutable)
|
|
10
10
|
|
|
11
11
|
### installation
|
|
@@ -16,17 +16,38 @@ To use these actions, add this package as a development dependency by running
|
|
|
16
16
|
|
|
17
17
|
### repo/existing-file
|
|
18
18
|
|
|
19
|
+
Sometimes you want to mention the name of a file from your application's source
|
|
20
|
+
code in the documentation. The
|
|
21
|
+
<b type="action/name-full">source/existing-file</b> action verifies this. As an
|
|
22
|
+
example, consider a codebase contains a file
|
|
23
|
+
<a type="workspace/new-file">**config.yml** with content `foo: bar`</a>. The
|
|
24
|
+
documentation for this codebase might want to mention this configuration file:
|
|
25
|
+
|
|
26
|
+
<a type="extension/runnable-region">
|
|
27
|
+
|
|
28
|
+
```markdown
|
|
29
|
+
The file <b type="repo/existing-file">config.yml</b> defines configuration
|
|
30
|
+
values.
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
</a>
|
|
34
|
+
|
|
35
|
+
The filename of the source code file is relative to the Markdown file describing
|
|
36
|
+
it.
|
|
37
|
+
|
|
38
|
+
### repo/existing-file-content
|
|
39
|
+
|
|
19
40
|
Sometimes you want to just display a file from your application's source code in
|
|
20
|
-
the documentation. The
|
|
21
|
-
action verifies such
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
file:
|
|
41
|
+
the documentation. The
|
|
42
|
+
<b type="action/name-full">source/existing-file-content</b> action verifies such
|
|
43
|
+
documentation. As an example, consider a codebase contains a file
|
|
44
|
+
<a type="workspace/new-file">**config.yml** with content `foo: bar`</a>. The
|
|
45
|
+
documentation for this codebase might want to mention this configuration file:
|
|
25
46
|
|
|
26
47
|
<a type="extension/runnable-region">
|
|
27
48
|
|
|
28
49
|
````markdown
|
|
29
|
-
<a type="repo/existing-file">
|
|
50
|
+
<a type="repo/existing-file-content">
|
|
30
51
|
|
|
31
52
|
The **config.yml** file defines configuration values. The current settings are:
|
|
32
53
|
|
|
@@ -50,7 +71,7 @@ You can display its content in your documentation via this active region:
|
|
|
50
71
|
<a type="extension/runnable-region">
|
|
51
72
|
|
|
52
73
|
```markdown
|
|
53
|
-
<a type="repo/existing-file">
|
|
74
|
+
<a type="repo/existing-file-content">
|
|
54
75
|
|
|
55
76
|
The **hello.txt** file in the [bar folder](foo/bar) contains this section:
|
|
56
77
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.existingFileContent = void 0;
|
|
4
|
+
const assertNoDiff = require("assert-no-diff");
|
|
5
|
+
const color = require("colorette");
|
|
6
|
+
const eol = require("eol");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const tr = require("text-runner-core");
|
|
10
|
+
async function existingFileContent(action) {
|
|
11
|
+
const fileName = action.region.textInNodeOfType("em_open", "strong_open");
|
|
12
|
+
let relativeBaseDir = ".";
|
|
13
|
+
if (action.region.hasNodeOfType("link_open")) {
|
|
14
|
+
const linkNode = action.region.nodeOfTypes("link_open");
|
|
15
|
+
relativeBaseDir = linkNode.attributes.href;
|
|
16
|
+
}
|
|
17
|
+
const expectedContent = action.region.textInNodeOfTypes("fence", "code");
|
|
18
|
+
const filePath = path.join(action.location.file.directory().platformified(), relativeBaseDir, fileName);
|
|
19
|
+
action.name(`document content matches source code file ${color.cyan(filePath)}`);
|
|
20
|
+
const fullPath = action.configuration.sourceDir.joinStr(filePath);
|
|
21
|
+
action.log(`cat ${fullPath}`);
|
|
22
|
+
let actualContent;
|
|
23
|
+
try {
|
|
24
|
+
actualContent = await fs_1.promises.readFile(fullPath, "utf8");
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
if (err.code === "ENOENT") {
|
|
28
|
+
throw new Error(`file not found: ${color.cyan(filePath)}`);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
assertNoDiff.trimmedLines(eol.lf(actualContent.trim()), eol.lf(expectedContent.trim()));
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
throw new tr.UserError(`mismatching content in ${color.cyan(color.bold(filePath))}`, err.message);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.existingFileContent = existingFileContent;
|
|
42
|
+
//# sourceMappingURL=existing-file-content.js.map
|
package/dist/existing-file.js
CHANGED
|
@@ -1,41 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.existingFile = void 0;
|
|
4
|
-
const assertNoDiff = require("assert-no-diff");
|
|
5
4
|
const color = require("colorette");
|
|
6
|
-
const eol = require("eol");
|
|
7
5
|
const fs_1 = require("fs");
|
|
8
|
-
const path = require("path");
|
|
9
|
-
const tr = require("text-runner-core");
|
|
10
6
|
async function existingFile(action) {
|
|
11
|
-
const fileName = action.region.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const linkNode = action.region.nodeOfTypes("link_open");
|
|
15
|
-
relativeBaseDir = linkNode.attributes.href;
|
|
16
|
-
}
|
|
17
|
-
const expectedContent = action.region.textInNodeOfTypes("fence", "code");
|
|
18
|
-
const filePath = path.join(action.location.file.directory().platformified(), relativeBaseDir, fileName);
|
|
19
|
-
action.name(`document content matches source code file ${color.cyan(filePath)}`);
|
|
20
|
-
const fullPath = action.configuration.sourceDir.joinStr(filePath);
|
|
7
|
+
const fileName = action.region.text();
|
|
8
|
+
action.name(`document mentions source code file ${color.cyan(fileName)}`);
|
|
9
|
+
const fullPath = action.configuration.sourceDir.joinStr(fileName);
|
|
21
10
|
action.log(`ls ${fullPath}`);
|
|
22
|
-
let actualContent;
|
|
23
11
|
try {
|
|
24
|
-
|
|
12
|
+
var stats = await fs_1.promises.stat(fullPath);
|
|
25
13
|
}
|
|
26
14
|
catch (err) {
|
|
27
15
|
if (err.code === "ENOENT") {
|
|
28
|
-
throw new Error(`file not found: ${color.cyan(
|
|
16
|
+
throw new Error(`file not found: ${color.cyan(fileName)}`);
|
|
29
17
|
}
|
|
30
18
|
else {
|
|
31
19
|
throw err;
|
|
32
20
|
}
|
|
33
21
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
throw new tr.UserError(`mismatching content in ${color.cyan(color.bold(filePath))}`, err.message);
|
|
22
|
+
if (stats.isDirectory()) {
|
|
23
|
+
throw new Error(`expected ${color.cyan(fileName)} to be a file but is a directory`);
|
|
39
24
|
}
|
|
40
25
|
}
|
|
41
26
|
exports.existingFile = existingFile;
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.textrunActions = void 0;
|
|
4
4
|
const executable_1 = require("./executable");
|
|
5
5
|
const existing_file_1 = require("./existing-file");
|
|
6
|
+
const existing_file_content_1 = require("./existing-file-content");
|
|
6
7
|
exports.textrunActions = {
|
|
7
8
|
executable: executable_1.executable,
|
|
8
9
|
existingFile: existing_file_1.existingFile,
|
|
10
|
+
existingFileContent: existing_file_content_1.existingFileContent,
|
|
9
11
|
};
|
|
10
12
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textrun-repo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Text-Runner actions for verifying the content of the current repository",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "ISC",
|
|
@@ -8,19 +8,19 @@
|
|
|
8
8
|
"dist/**/*.js"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
+
"assert-no-diff": "3.0.6",
|
|
11
12
|
"eol": "0.9.1",
|
|
12
|
-
"text-runner-core": "5.0.
|
|
13
|
+
"text-runner-core": "5.0.1"
|
|
13
14
|
},
|
|
14
15
|
"devDependencies": {
|
|
15
|
-
"
|
|
16
|
-
"colorette": "1.2.1",
|
|
16
|
+
"colorette": "1.2.2",
|
|
17
17
|
"cucumber": "6.0.5",
|
|
18
|
-
"mocha": "
|
|
18
|
+
"mocha": "9.2.0",
|
|
19
19
|
"shared-cucumber-steps": "0.0.0",
|
|
20
|
-
"text-runner": "5.0.
|
|
21
|
-
"textrun-action": "0.
|
|
22
|
-
"textrun-extension": "0.
|
|
23
|
-
"textrun-npm": "0.
|
|
20
|
+
"text-runner": "5.0.1",
|
|
21
|
+
"textrun-action": "0.1.1",
|
|
22
|
+
"textrun-extension": "0.1.1",
|
|
23
|
+
"textrun-npm": "0.1.1"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "1380706cc871cb3a5adfeba9e996694c6d8bf892"
|
|
26
26
|
}
|