testilo 4.1.0 → 5.0.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/aim.js +13 -14
- package/merge.js +11 -3
- package/package.json +2 -2
package/aim.js
CHANGED
|
@@ -21,24 +21,18 @@ const fs = require('fs/promises');
|
|
|
21
21
|
// ########## CONSTANTS
|
|
22
22
|
|
|
23
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
24
|
|
|
32
25
|
// ########## FUNCTIONS
|
|
33
26
|
|
|
27
|
+
// Returns a string representing the date and time.
|
|
28
|
+
const nowString = () => (new Date()).toISOString().slice(0, 19);
|
|
34
29
|
// Returns a script, aimed at a host.
|
|
35
|
-
exports.aim = async () => {
|
|
30
|
+
exports.aim = async (scriptName, host, requester) => {
|
|
36
31
|
// Copy the script.
|
|
37
32
|
const scriptFile = await fs.readFile(`${scriptDir}/${scriptName}.json`, 'utf8');
|
|
38
33
|
const script = JSON.parse(scriptFile);
|
|
39
|
-
const newScript = JSON.parse(JSON.stringify(script));
|
|
40
34
|
// In the copy, make all url commands visit the host.
|
|
41
|
-
|
|
35
|
+
script.commands.forEach(command => {
|
|
42
36
|
if (command.type === 'url') {
|
|
43
37
|
command.id = host.id;
|
|
44
38
|
command.which = host.which;
|
|
@@ -46,12 +40,17 @@ exports.aim = async () => {
|
|
|
46
40
|
}
|
|
47
41
|
});
|
|
48
42
|
// Add source information to the script.
|
|
49
|
-
|
|
43
|
+
script.source = {
|
|
50
44
|
script: script.id,
|
|
45
|
+
host,
|
|
51
46
|
requester
|
|
52
47
|
}
|
|
53
|
-
//
|
|
54
|
-
|
|
48
|
+
// Create a job-creation time stamp.
|
|
49
|
+
const timeStamp = Math.floor((Date.now() - Date.UTC(2022, 1)) / 2000).toString(36);
|
|
50
|
+
// Change the script id property to include the time stamp and the host ID.
|
|
51
|
+
script.id = `${timeStamp}-${script.id}-${host.id}`;
|
|
52
|
+
// Add the job-creation time to the script.
|
|
53
|
+
script.jobCreationTime = nowString();
|
|
55
54
|
// Return the host-specific script.
|
|
56
|
-
return
|
|
55
|
+
return script;
|
|
57
56
|
};
|
package/merge.js
CHANGED
|
@@ -26,10 +26,14 @@ const batchName = process.argv[3];
|
|
|
26
26
|
|
|
27
27
|
// ########## FUNCTIONS
|
|
28
28
|
|
|
29
|
+
// Returns a string representing the date and time.
|
|
30
|
+
const nowString = () => (new Date()).toISOString().slice(0, 19);
|
|
29
31
|
// Merges a batch into a script and writes host-specific scripts.
|
|
30
32
|
const merge = async (script, batch) => {
|
|
31
33
|
// Create the watch directory if it does not exist.
|
|
32
34
|
await fs.mkdir(watchDir, {recursive: true});
|
|
35
|
+
// Create a job-creation time stamp.
|
|
36
|
+
const timeStamp = Math.floor((Date.now() - Date.UTC(2022, 1)) / 2000).toString(36);
|
|
33
37
|
// For each host in the batch:
|
|
34
38
|
const {hosts} = batch;
|
|
35
39
|
const newScripts = hosts.map(host => {
|
|
@@ -48,8 +52,12 @@ const merge = async (script, batch) => {
|
|
|
48
52
|
script: script.id,
|
|
49
53
|
batch: batch.id
|
|
50
54
|
}
|
|
51
|
-
//
|
|
52
|
-
newScript.
|
|
55
|
+
// Add a job-creation time stamp to the script.
|
|
56
|
+
newScript.timeStamp = timeStamp;
|
|
57
|
+
// Add the job-creation time to the script.
|
|
58
|
+
newScript.jobCreationTime = nowString();
|
|
59
|
+
// Change the script id property to include the time stamp and the host ID.
|
|
60
|
+
newScript.id = `${timeStamp}-${newScript.id}-${host.id}`;
|
|
53
61
|
// Return the host-specific script.
|
|
54
62
|
return newScript;
|
|
55
63
|
});
|
|
@@ -57,7 +65,7 @@ const merge = async (script, batch) => {
|
|
|
57
65
|
for (const newScript of newScripts) {
|
|
58
66
|
await fs.writeFile(`${watchDir}/${newScript.id}.json`, JSON.stringify(newScript, null, 2));
|
|
59
67
|
};
|
|
60
|
-
console.log(`Merger completed.
|
|
68
|
+
console.log(`Merger completed. Script count: ${hosts.length}. Time stamp: ${timeStamp}`);
|
|
61
69
|
};
|
|
62
70
|
|
|
63
71
|
// ########## OPERATION
|
package/package.json
CHANGED