testilo 4.0.2 → 4.1.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.
Files changed (3) hide show
  1. package/aim.js +57 -0
  2. package/merge.js +1 -1
  3. package/package.json +1 -1
package/aim.js ADDED
@@ -0,0 +1,57 @@
1
+ /*
2
+ aim.js
3
+ Returns a script aimed at a host.
4
+ Arguments:
5
+ 0. base of name of script located in process.env.SCRIPTDIR.
6
+ 1. ID of the host.
7
+ 2. URL of the host.
8
+ 3. Name of the host.
9
+ 4. ID of the requester.
10
+ Usage example:
11
+ node aim tp18 w3c https://www.w3.org/ 'World Wide Web Consortium'
12
+ */
13
+
14
+ // ########## IMPORTS
15
+
16
+ // Module to keep secrets.
17
+ require('dotenv').config();
18
+ // Module to read and write files.
19
+ const fs = require('fs/promises');
20
+
21
+ // ########## CONSTANTS
22
+
23
+ const scriptDir = process.env.SCRIPTDIR || 'scripts';
24
+ const scriptName = process.argv[2];
25
+ const host = {
26
+ id: process.argv[3],
27
+ which: process.argv[4],
28
+ what: process.argv[5]
29
+ };
30
+ const requester = process.argv[6];
31
+
32
+ // ########## FUNCTIONS
33
+
34
+ // Returns a script, aimed at a host.
35
+ exports.aim = async () => {
36
+ // Copy the script.
37
+ const scriptFile = await fs.readFile(`${scriptDir}/${scriptName}.json`, 'utf8');
38
+ const script = JSON.parse(scriptFile);
39
+ const newScript = JSON.parse(JSON.stringify(script));
40
+ // In the copy, make all url commands visit the host.
41
+ newScript.commands.forEach(command => {
42
+ if (command.type === 'url') {
43
+ command.id = host.id;
44
+ command.which = host.which;
45
+ command.what = host.what;
46
+ }
47
+ });
48
+ // Add source information to the script.
49
+ newScript.source = {
50
+ script: script.id,
51
+ requester
52
+ }
53
+ // Change the script id property to include the host ID.
54
+ newScript.id += `-${host.id}`;
55
+ // Return the host-specific script.
56
+ return newScript;
57
+ };
package/merge.js CHANGED
@@ -6,7 +6,7 @@
6
6
  1. base of name of batch located in process.env.BATCHDIR.
7
7
  Usage example:
8
8
  node merge tp18 weborgs
9
- Note: The subdirectory for host scripts will be created if it does not exist.
9
+ Note: The subdirectory for host-specific scripts will be created if it does not exist.
10
10
  */
11
11
 
12
12
  // ########## IMPORTS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testilo",
3
- "version": "4.0.2",
3
+ "version": "4.1.0",
4
4
  "description": "Client that scores and digests Testaro reports",
5
5
  "main": "index.js",
6
6
  "scripts": {