textrun-shell 0.4.0 → 0.5.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 CHANGED
@@ -66,6 +66,20 @@ echo Hello world!
66
66
  </pre>
67
67
  ```
68
68
 
69
+ ### command attribute
70
+
71
+ You can provide the command to run via an HTML attribute:
72
+
73
+ <a type="extension/runnable-region">
74
+
75
+ ```html
76
+ The "echo" command prints text on the command line. For example, let's run:
77
+
78
+ <pre type="shell/command" command="echo Hello world!"></pre>
79
+ ```
80
+
81
+ </a>
82
+
69
83
  ## shell/command-output
70
84
 
71
85
  The <b type="action/name-full">shell/command-output</b> action verifies the
@@ -155,6 +169,32 @@ for, and the last one text to enter once the output from the first column has
155
169
  appeared. Middle columns are ignored. `<th>` elements are considered
156
170
  descriptions and are also ignored.
157
171
 
172
+ ### command attribute
173
+
174
+ You can provide the command to run via the `command` HTML attribute. As an
175
+ example, if you run the previous script with this other input:
176
+
177
+ <table type="shell/command-with-input" command="node greeter.js">
178
+ <tr>
179
+ <th>Output to wait for</th>
180
+ <th>input</th>
181
+ </tr>
182
+ <tr>
183
+ <td>your name</td>
184
+ <td>Text-Runner</td>
185
+ </tr>
186
+ <tr>
187
+ <td>which day is today</td>
188
+ <td>Tuesday</td>
189
+ </tr>
190
+ </table>
191
+
192
+ Then it prints:
193
+
194
+ <pre type="shell/command-output">
195
+ Hello Text-Runner, happy Tuesday!
196
+ </pre>
197
+
158
198
  ## shell/server
159
199
 
160
200
  Long-running processes, for example web or database servers, keep running while
@@ -188,6 +228,11 @@ node server.js
188
228
 
189
229
  </a>
190
230
 
231
+ ### command attribute
232
+
233
+ You can also provide the command to start the server via the `command`
234
+ attribute.
235
+
191
236
  ## shell/server-output
192
237
 
193
238
  After we started a long-running server through
@@ -1,20 +1,24 @@
1
1
  import { styleText } from "node:util";
2
2
  import * as observableProcess from "observable-process";
3
3
  import { callArgs } from "textrun-extension";
4
+ import { Configuration } from "../helpers/configuration.js";
4
5
  import { CurrentCommand } from "../helpers/current-command.js";
5
- import { trimDollar } from "../helpers/trim-dollar.js";
6
+ import { parseCommand } from "../helpers/parse-command.js";
6
7
  /**
7
8
  * The "runConsoleCommand" action runs the given commands on the console
8
9
  * and waits until the command is finished.
9
10
  */
10
11
  export async function commandWithInput(action) {
11
- const content = action.region.textInNodeOfTypes("fence", "code");
12
- const commandsToRun = content
13
- .split("\n")
14
- .map((command) => command.trim())
15
- .filter((e) => e)
16
- .map(trimDollar)
17
- .join(" && ");
12
+ var commandText = action.region[0].attributes["command"];
13
+ if (commandText === "") {
14
+ throw new Error('empty "command" attribute');
15
+ }
16
+ if (!commandText) {
17
+ commandText = action.region.textInNodeOfTypes("fence", "code");
18
+ }
19
+ const configPath = action.configuration.sourceDir.joinStr("textrun-shell.js");
20
+ const config = await Configuration.load(configPath);
21
+ const commandsToRun = parseCommand(commandText, config.pathMapper().globalizePathFunc());
18
22
  if (commandsToRun === "") {
19
23
  throw new Error(`the <${action.region[0].tag} ${action.configuration.regionMarker}="exec-with-input"> region contains no commands to run`);
20
24
  }
@@ -3,20 +3,20 @@ import * as observableProcess from "observable-process";
3
3
  import * as trExt from "textrun-extension";
4
4
  import { Configuration } from "../helpers/configuration.js";
5
5
  import { CurrentCommand } from "../helpers/current-command.js";
6
- import { trimDollar } from "../helpers/trim-dollar.js";
6
+ import { parseCommand } from "../helpers/parse-command.js";
7
7
  /** Runs the given commands synchronously on the console. */
8
8
  export async function command(action) {
9
9
  action.name("run shell command");
10
10
  const configPath = action.configuration.sourceDir.joinStr("textrun-shell.js");
11
11
  const config = await Configuration.load(configPath);
12
- const commandsToRun = action.region
13
- .text()
14
- .split("\n")
15
- .map((line) => line.trim())
16
- .map(trimDollar)
17
- .filter((line) => line.length > 0)
18
- .map(config.pathMapper().globalizePathFunc())
19
- .join(" && ");
12
+ var commandText = action.region[0].attributes["command"];
13
+ if (commandText === "") {
14
+ throw new Error('empty "command" attribute');
15
+ }
16
+ if (!commandText) {
17
+ commandText = action.region.text();
18
+ }
19
+ const commandsToRun = parseCommand(commandText, config.pathMapper().globalizePathFunc());
20
20
  if (commandsToRun === "") {
21
21
  throw new Error(`the <${action.region[0].tag} ${action.configuration.regionMarker}="shell/command"> region contains no commands to run`);
22
22
  }
@@ -1,20 +1,27 @@
1
1
  import { styleText } from "node:util";
2
2
  import * as observableProcess from "observable-process";
3
3
  import * as trExt from "textrun-extension";
4
+ import { Configuration } from "../helpers/configuration.js";
4
5
  import { CurrentServer } from "../helpers/current-server.js";
5
- import { trimDollar } from "../helpers/trim-dollar.js";
6
+ import { parseCommand } from "../helpers/parse-command.js";
6
7
  /**
7
8
  * The "start" action runs the given commands on the console.
8
9
  * It leaves the command running.
9
10
  */
10
- export function server(action) {
11
- const commandsToRun = action.region
12
- .text()
13
- .split("\n")
14
- .map((line) => line.trim())
15
- .filter((line) => line.length > 0)
16
- .map(trimDollar)
17
- .join(" && ");
11
+ export async function server(action) {
12
+ const configPath = action.configuration.sourceDir.joinStr("textrun-shell.js");
13
+ const config = await Configuration.load(configPath);
14
+ var commandText = action.region[0].attributes["command"];
15
+ if (commandText === "") {
16
+ throw new Error('empty "command" attribute');
17
+ }
18
+ if (!commandText) {
19
+ commandText = action.region.text();
20
+ }
21
+ const commandsToRun = parseCommand(commandText, config.pathMapper().globalizePathFunc());
22
+ if (commandsToRun === "") {
23
+ throw new Error(`the <${action.region[0].tag} ${action.configuration.regionMarker}="shell/command"> region contains no commands to run`);
24
+ }
18
25
  action.name(`starting a server process: ${styleText(["bold", "cyan"], commandsToRun)}`);
19
26
  CurrentServer.instance().set(observableProcess.start(trExt.callArgs(commandsToRun, process.platform), {
20
27
  cwd: action.configuration.workspace.platformified()
@@ -0,0 +1,11 @@
1
+ import { trimDollar } from "../helpers/trim-dollar.js";
2
+ export function parseCommand(text, globalizePathFunc) {
3
+ return text
4
+ .split("\n")
5
+ .map((line) => line.trim())
6
+ .map(trimDollar)
7
+ .filter((line) => line.length > 0)
8
+ .map(globalizePathFunc)
9
+ .join(" && ");
10
+ }
11
+ //# sourceMappingURL=parse-command.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "textrun-shell",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "exports": "./dist/index.js",
@@ -22,16 +22,16 @@
22
22
  "end-child-processes": "2.0.3",
23
23
  "observable-process": "8.0.0",
24
24
  "strip-ansi": "7.1.2",
25
- "text-runner-engine": "7.2.0",
26
- "textrun-extension": "0.4.0"
25
+ "text-runner-engine": "7.3.0",
26
+ "textrun-extension": "0.5.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "shared-cucumber-steps": "*",
30
- "text-runner": "7.2.0",
31
- "textrun-action": "0.4.0",
32
- "textrun-extension": "0.4.0",
33
- "textrun-workspace": "0.4.0",
30
+ "text-runner": "7.3.0",
31
+ "textrun-action": "0.5.0",
32
+ "textrun-extension": "0.5.0",
33
+ "textrun-workspace": "0.5.0",
34
34
  "tsx": "4.20.6"
35
35
  },
36
- "gitHead": "aecf7efd5e22e88535fe97ad7341b1a057520268"
36
+ "gitHead": "b369f2fba1f9182c9c1d5569a351aa057dd81f1e"
37
37
  }