textrun-npm 0.2.1 → 0.3.0
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 +84 -24
- package/dist/actions/exported-executable.js +4 -1
- package/dist/actions/installed-executable.js +1 -1
- package/dist/actions/script-call.js +22 -0
- package/dist/actions/script-name.js +16 -0
- package/dist/helpers/starts-with-npm-run.js +4 -0
- package/dist/helpers/trim-npm-run.js +4 -0
- package/dist/index.js +4 -0
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
# Text-Runner Actions for npm
|
|
2
2
|
|
|
3
|
-
hello
|
|
4
|
-
|
|
5
3
|
This package provides [Text-Runner](https://github.com/kevgo/text-runner)
|
|
6
4
|
actions for verifying the documentation of npm packages.
|
|
7
5
|
|
|
8
6
|
### Installation
|
|
9
7
|
|
|
10
8
|
To use these actions, add this package as a development dependency by running
|
|
11
|
-
<code type="npm/install">npm i -D textrun-npm</code
|
|
12
|
-
<code type="npm/install">yarn i -D textrun-npm</code>.
|
|
9
|
+
<code type="npm/install">npm i -D textrun-npm</code>.
|
|
13
10
|
|
|
14
11
|
## Verify installation instructions
|
|
15
12
|
|
|
@@ -27,23 +24,22 @@ other things:
|
|
|
27
24
|
|
|
28
25
|
</a>
|
|
29
26
|
|
|
30
|
-
<a type="workspace/new-file">
|
|
27
|
+
<a type="workspace/new-file" filename="README.md">
|
|
31
28
|
|
|
32
|
-
In the documentation of this npm package,
|
|
33
|
-
|
|
34
|
-
looks something like this:
|
|
29
|
+
In the documentation of this npm package, we want to document how to install
|
|
30
|
+
this package. It would contain a section that looks something like this:
|
|
35
31
|
|
|
36
32
|
```md
|
|
37
33
|
Install the foobar package by running:
|
|
38
34
|
|
|
39
35
|
<pre type="npm/install">
|
|
40
|
-
|
|
36
|
+
npm install foobar
|
|
41
37
|
</pre>
|
|
42
38
|
|
|
43
39
|
or with Yarn:
|
|
44
40
|
|
|
45
41
|
<pre type="npm/install">
|
|
46
|
-
|
|
42
|
+
yarn add foobar
|
|
47
43
|
</pre>
|
|
48
44
|
```
|
|
49
45
|
|
|
@@ -59,10 +55,10 @@ of the npm package.
|
|
|
59
55
|
## Verify exported binaries
|
|
60
56
|
|
|
61
57
|
The <b type="action/name-full">npm/exported-executable</b> action verifies
|
|
62
|
-
documentation of exported binaries of npm packages. Let's say
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
documentation of exported binaries of npm packages. Let's say our `foobar`
|
|
59
|
+
package provides an executable file <b type="bundled-executable">bin/foo</b>,
|
|
60
|
+
which is listed as a binary in the <a type="workspace/new-file">**package.json**
|
|
61
|
+
file:
|
|
66
62
|
|
|
67
63
|
```js
|
|
68
64
|
{
|
|
@@ -75,28 +71,26 @@ our `foobar` package contains an executable file
|
|
|
75
71
|
|
|
76
72
|
</a>
|
|
77
73
|
|
|
78
|
-
<a type="workspace/
|
|
74
|
+
<a type="workspace/new-file" filename="README.md">
|
|
79
75
|
|
|
80
|
-
The
|
|
81
|
-
something like this:
|
|
76
|
+
The documentation for the "foobar" package would document this binary like this:
|
|
82
77
|
|
|
83
78
|
```md
|
|
84
79
|
After you install the "foobar" package, you can run the
|
|
85
80
|
<code type="npm/exported-executable">foo</code> command in the terminal.
|
|
86
81
|
```
|
|
87
82
|
|
|
88
|
-
<a type="extension/run-textrunner">
|
|
89
|
-
</a>
|
|
83
|
+
<a type="extension/run-textrunner"></a>
|
|
90
84
|
|
|
91
85
|
### Verify installed binaries
|
|
92
86
|
|
|
93
87
|
The <b type="action/name-full">npm/installed-executable</b> action verifies
|
|
94
|
-
binaries installed by other npm packages. Let's say you
|
|
95
|
-
for a codebase that uses the
|
|
96
|
-
command provided by the npm
|
|
97
|
-
package:
|
|
88
|
+
binaries installed by other npm packages. Let's say you develop technical
|
|
89
|
+
documentation for a codebase that uses the
|
|
90
|
+
<code type="create-npm-executable">cucumber</code> command provided by the npm
|
|
91
|
+
[cucumber](https://www.npmjs.com/package/@cucumber/cucumber) package:
|
|
98
92
|
|
|
99
|
-
<a type="
|
|
93
|
+
<a type="workspace/new-file" filename="README.md">
|
|
100
94
|
|
|
101
95
|
```html
|
|
102
96
|
To run the end-to-end tests, run
|
|
@@ -104,3 +98,69 @@ To run the end-to-end tests, run
|
|
|
104
98
|
```
|
|
105
99
|
|
|
106
100
|
</a>
|
|
101
|
+
|
|
102
|
+
<a type="extension/run-textrunner"></a>
|
|
103
|
+
|
|
104
|
+
### Verify script names defined in package.json
|
|
105
|
+
|
|
106
|
+
The <b type="action/name-full">npm/script-name</b> action verifies that you
|
|
107
|
+
document scripts that your `package.json` file defines correctly.
|
|
108
|
+
|
|
109
|
+
Let's say your npm package has this
|
|
110
|
+
<a type="workspace/new-file">**package.json** file:
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"name": "foobar",
|
|
115
|
+
"scripts": {
|
|
116
|
+
"lint": "echo linting"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
</a>
|
|
122
|
+
|
|
123
|
+
<a type="workspace/new-file" filename="README.md">
|
|
124
|
+
|
|
125
|
+
And your documentation says:
|
|
126
|
+
|
|
127
|
+
```html
|
|
128
|
+
To run the linters, please run the
|
|
129
|
+
<code type="npm/script-name">lint</code> script.
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
</a>
|
|
133
|
+
|
|
134
|
+
<a type="extension/run-textrunner"></a>
|
|
135
|
+
|
|
136
|
+
### Verify calls of scripts defined in package.json
|
|
137
|
+
|
|
138
|
+
The <b type="action/name-full">npm/script-call</b> action verifies that you
|
|
139
|
+
document calls of scripts defined in your `package.json` file correctly.
|
|
140
|
+
|
|
141
|
+
Let's say your npm package has this
|
|
142
|
+
<a type="workspace/new-file">**package.json** file:
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"name": "foobar",
|
|
147
|
+
"scripts": {
|
|
148
|
+
"lint": "echo linting"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
</a>
|
|
154
|
+
|
|
155
|
+
<a type="workspace/new-file" filename="README.md">
|
|
156
|
+
|
|
157
|
+
And your documentation says:
|
|
158
|
+
|
|
159
|
+
```html
|
|
160
|
+
To run the linters, please execute
|
|
161
|
+
<code type="npm/script-call">npm run lint</code>.
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
</a>
|
|
165
|
+
|
|
166
|
+
<a type="extension/run-textrunner"></a>
|
|
@@ -10,7 +10,10 @@ export async function exportedExecutable(action) {
|
|
|
10
10
|
const packageJsonPath = action.configuration.sourceDir.joinStr("package.json");
|
|
11
11
|
const pkgText = await fs.readFile(packageJsonPath, "utf-8");
|
|
12
12
|
const pkgData = JSON.parse(pkgText);
|
|
13
|
-
if (!
|
|
13
|
+
if (!pkgData.bin) {
|
|
14
|
+
throw new Error(`package.json does not export commands`);
|
|
15
|
+
}
|
|
16
|
+
if (!Object.keys(pkgData === null || pkgData === void 0 ? void 0 : pkgData.bin).includes(commandName)) {
|
|
14
17
|
throw new Error(`package.json does not export a "${commandName}" command`);
|
|
15
18
|
}
|
|
16
19
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as color from "colorette";
|
|
2
2
|
import { promises as fsp } from "fs";
|
|
3
3
|
import * as path from "path";
|
|
4
|
-
import * as textRunner from "text-runner-
|
|
4
|
+
import * as textRunner from "text-runner-engine";
|
|
5
5
|
import { trimDollar } from "../helpers/trim-dollar.js";
|
|
6
6
|
export async function installedExecutable(action) {
|
|
7
7
|
const commandName = trimDollar(action.region.text().trim());
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as color from "colorette";
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
import { startsWithNpmRun } from "../helpers/starts-with-npm-run.js";
|
|
4
|
+
import { trimNpmRun } from "../helpers/trim-npm-run.js";
|
|
5
|
+
export async function scriptCall(action) {
|
|
6
|
+
const call = action.region.text().trim();
|
|
7
|
+
if (call === "") {
|
|
8
|
+
throw new Error("No script call specified");
|
|
9
|
+
}
|
|
10
|
+
if (!startsWithNpmRun(call)) {
|
|
11
|
+
throw new Error(`Does not start with "npm run": ${call}`);
|
|
12
|
+
}
|
|
13
|
+
const want = trimNpmRun(call);
|
|
14
|
+
action.name(`verify call of npm package script ${color.cyan(want)}`);
|
|
15
|
+
const packageJsonPath = action.configuration.sourceDir.joinStr("package.json");
|
|
16
|
+
const pkgText = await fs.readFile(packageJsonPath, "utf-8");
|
|
17
|
+
const pkgData = JSON.parse(pkgText);
|
|
18
|
+
if (!Object.keys(pkgData.scripts).includes(want)) {
|
|
19
|
+
throw new Error(`package.json does not contain a "${want}" script`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=script-call.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as color from "colorette";
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
export async function scriptName(action) {
|
|
4
|
+
const want = action.region.text().trim();
|
|
5
|
+
if (want === "") {
|
|
6
|
+
throw new Error("No script name specified");
|
|
7
|
+
}
|
|
8
|
+
action.name(`npm package has script ${color.cyan(want)}`);
|
|
9
|
+
const packageJsonPath = action.configuration.sourceDir.joinStr("package.json");
|
|
10
|
+
const pkgText = await fs.readFile(packageJsonPath, "utf-8");
|
|
11
|
+
const pkgData = JSON.parse(pkgText);
|
|
12
|
+
if (!Object.keys(pkgData.scripts).includes(want)) {
|
|
13
|
+
throw new Error(`package.json does not have a "${want}" script`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=script-name.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { exportedExecutable } from "./actions/exported-executable.js";
|
|
2
2
|
import { install } from "./actions/install.js";
|
|
3
3
|
import { installedExecutable } from "./actions/installed-executable.js";
|
|
4
|
+
import { scriptCall } from "./actions/script-call.js";
|
|
5
|
+
import { scriptName } from "./actions/script-name.js";
|
|
4
6
|
export const textrunActions = {
|
|
5
7
|
exportedExecutable,
|
|
6
8
|
install,
|
|
7
9
|
installedExecutable,
|
|
10
|
+
scriptCall,
|
|
11
|
+
scriptName
|
|
8
12
|
};
|
|
9
13
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textrun-npm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
@@ -10,23 +10,23 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc -p tsconfig-build.json",
|
|
12
12
|
"clean": "rm -rf dist",
|
|
13
|
-
"cuke": "cucumber-js --format=progress",
|
|
14
|
-
"doc": "
|
|
15
|
-
"fix": "eslint --fix --ignore-pattern=dist/ . &&
|
|
16
|
-
"lint": "
|
|
17
|
-
"unit": "
|
|
13
|
+
"cuke": "yarn run build && cucumber-js --format=progress",
|
|
14
|
+
"doc": "yarn run build && text-runner --format=dot",
|
|
15
|
+
"fix": "eslint --fix --ignore-pattern=dist/ . && dprint fmt && sort-package-json --quiet",
|
|
16
|
+
"lint": "dprint check && sort-package-json --check --quiet && eslint --ignore-pattern=dist/ . && depcheck --config=../.depcheckrc",
|
|
17
|
+
"unit": "node --test --import tsx 'src/**/*.test.ts'"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"colorette": "2.0.20",
|
|
21
|
-
"text-runner-
|
|
21
|
+
"text-runner-engine": "7.1.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"shared-cucumber-steps": "*",
|
|
25
|
-
"text-runner": "
|
|
26
|
-
"textrun-action": "0.
|
|
27
|
-
"textrun-extension": "0.
|
|
28
|
-
"textrun-workspace": "0.
|
|
25
|
+
"text-runner": "7.1.0",
|
|
26
|
+
"textrun-action": "0.3.0",
|
|
27
|
+
"textrun-extension": "0.3.0",
|
|
28
|
+
"textrun-workspace": "0.3.0",
|
|
29
29
|
"tsx": "4.19.3"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "bdf119a8e549f679af14f88952f7353648b50759"
|
|
32
32
|
}
|