testilo 4.0.1 → 4.0.2
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/merge.js +24 -23
- package/package.json +1 -1
package/merge.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
2
|
merge.js
|
|
3
|
-
Merges a batch and a script to produce
|
|
3
|
+
Merges a batch and a script to produce host-specific scripts.
|
|
4
4
|
Arguments:
|
|
5
5
|
0. base of name of script located in process.env.SCRIPTDIR.
|
|
6
6
|
1. base of name of batch located in process.env.BATCHDIR.
|
|
7
|
-
2. name of subdirectory of process.env.JOBDIR into which to write host scripts.
|
|
8
7
|
Usage example:
|
|
9
|
-
node merge tp18 weborgs
|
|
8
|
+
node merge tp18 weborgs
|
|
10
9
|
Note: The subdirectory for host scripts will be created if it does not exist.
|
|
11
10
|
*/
|
|
12
11
|
|
|
@@ -21,40 +20,44 @@ const fs = require('fs/promises');
|
|
|
21
20
|
|
|
22
21
|
const scriptDir = process.env.SCRIPTDIR || 'scripts';
|
|
23
22
|
const batchDir = process.env.BATCHDIR || 'batches';
|
|
24
|
-
const
|
|
23
|
+
const watchDir = process.env.WATCHDIR || 'watch';
|
|
25
24
|
const scriptName = process.argv[2];
|
|
26
25
|
const batchName = process.argv[3];
|
|
27
|
-
const jobSubdir = process.argv[4];
|
|
28
26
|
|
|
29
27
|
// ########## FUNCTIONS
|
|
30
28
|
|
|
31
|
-
// Merges a batch into a script and writes host scripts.
|
|
32
|
-
const merge = async (script, batch
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
// Merges a batch into a script and writes host-specific scripts.
|
|
30
|
+
const merge = async (script, batch) => {
|
|
31
|
+
// Create the watch directory if it does not exist.
|
|
32
|
+
await fs.mkdir(watchDir, {recursive: true});
|
|
35
33
|
// For each host in the batch:
|
|
36
|
-
const
|
|
34
|
+
const {hosts} = batch;
|
|
35
|
+
const newScripts = hosts.map(host => {
|
|
37
36
|
// Copy the script.
|
|
38
37
|
const newScript = JSON.parse(JSON.stringify(script));
|
|
39
38
|
// In the copy, make all url commands visit the host.
|
|
40
39
|
newScript.commands.forEach(command => {
|
|
41
40
|
if (command.type === 'url') {
|
|
41
|
+
command.id = host.id;
|
|
42
42
|
command.which = host.which;
|
|
43
43
|
command.what = host.what;
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
// Add source information to the script.
|
|
47
|
+
newScript.sources = {
|
|
48
|
+
script: script.id,
|
|
49
|
+
batch: batch.id
|
|
50
|
+
}
|
|
51
|
+
// Change the script id property to include the host ID.
|
|
52
|
+
newScript.id += `-${host.id}`;
|
|
53
|
+
// Return the host-specific script.
|
|
54
|
+
return newScript;
|
|
52
55
|
});
|
|
53
|
-
// Write the host scripts.
|
|
54
|
-
for (const
|
|
55
|
-
await fs.writeFile(`${
|
|
56
|
+
// Write the host-specific scripts.
|
|
57
|
+
for (const newScript of newScripts) {
|
|
58
|
+
await fs.writeFile(`${watchDir}/${newScript.id}.json`, JSON.stringify(newScript, null, 2));
|
|
56
59
|
};
|
|
57
|
-
console.log(`Merger completed. Count of
|
|
60
|
+
console.log(`Merger completed. Count of scripts created: ${hosts.length}`);
|
|
58
61
|
};
|
|
59
62
|
|
|
60
63
|
// ########## OPERATION
|
|
@@ -65,8 +68,6 @@ fs.readFile(`${scriptDir}/${scriptName}.json`, 'utf8')
|
|
|
65
68
|
.then(async batchFile => {
|
|
66
69
|
const script = JSON.parse(scriptFile);
|
|
67
70
|
const batch = JSON.parse(batchFile);
|
|
68
|
-
|
|
69
|
-
const outDir = `${jobDir}/${jobSubdir}`;
|
|
70
|
-
await merge(script, batch, timeStamp, outDir);
|
|
71
|
+
await merge(script, batch);
|
|
71
72
|
});
|
|
72
73
|
});
|