forked from hashgraph/hedera-sdk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-all-examples.js
69 lines (57 loc) · 1.8 KB
/
run-all-examples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import fs from "fs";
import path from "path";
import { spawnSync } from "child_process";
import dotenv from "dotenv";
dotenv.config();
const examplesDirectory = "./";
const excludedDirectories = [
"./node_modules",
"./precompile-example",
"./react-native-example",
"./simple_rest_signature_provider",
];
const excludedJSFile = "run-all-examples.js";
const cmd = process.env.NODE_COMMAND;
fs.readdir(examplesDirectory, (err, files) => {
if (err) {
console.error("Error reading directory:", err);
return;
}
if (cmd === undefined) {
throw new Error("Environment variable NODE_COMMAND is required.");
}
let completed = 0;
let failed = 0;
const isPathStartsWith = (
/** @type {string} */ file,
/** @type {string} */ directory,
) => path.join(examplesDirectory, file).startsWith(directory);
const examples = files.filter(
(file) =>
file.endsWith(".js") &&
file !== excludedJSFile &&
excludedDirectories.some(
(directory) => !isPathStartsWith(directory, file),
),
);
const total = examples.length;
examples.forEach((file, index) => {
console.log(`\n⏳ ${index + 1}. Running ${file}...`);
const examplePath = path.join(examplesDirectory, file);
const result = spawnSync(cmd, [examplePath], {
stdio: "ignore",
});
if (result.status === 0) {
completed += 1;
console.log(`✅ Successfully executed.`);
} else {
failed += 1;
console.error(`❌ Failed.`);
}
});
console.log(
`\nTotal: [${total}] \n✅ Completed: [${completed}] \n❌ Failed: [${failed}] ${
failed === 0 ? " \nGreat job! 🎉" : ""
} `,
);
});