-
Notifications
You must be signed in to change notification settings - Fork 115
/
compile_testing.js
85 lines (74 loc) · 3.03 KB
/
compile_testing.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var fs = require('fs');
var dir = './testing-folder';
const excluded_folders = [
"Code-Documentation-QA-Bot",
"Youtube-Search-QA-Bot",
"reducing_hallucinations_ai_agents",
"product-recommender"
];
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
var package_files = [];
var command_list = [];
// For each folder in ./examples
var examples = fs.readdirSync('./examples');
for (var i = 0; i < examples.length; i++) {
var example = examples[i];
var examplePath = './examples/' + example;
if (fs.lstatSync(examplePath).isDirectory() && !excluded_folders.includes(example)) {
var files = fs.readdirSync(examplePath);
for (var j = 0; j < files.length; j++) {
var file = files[j];
// If file is a .js file, copy it to ./testing-folder
if (file.endsWith('.js')) {
let dup_name = example + '_' + file;
var filePath = examplePath + '/' + file;
fs.copyFile(filePath, './testing-folder/' + dup_name, (err) => {
if (err) throw err;
console.log('Copied to ./testing-folder/' + dup_name);
});
}
// If file is a package.json file, copy it to ./testing-folder
if (file.endsWith('package.json')) {
let dup_name = example + '_' + file;
var filePath = examplePath + '/' + file;
fs.copyFile(filePath, './testing-folder/' + dup_name, (err) => {
if (err) throw err;
console.log('Copied to ./testing-folder/' + dup_name);
});
package_files.push(dup_name);
}
// If file is a README.md, add the dataset download command to a list of commands
if (file.endsWith('README.md')) {
var filePath = examplePath + '/' + file;
var data = fs.readFileSync(filePath, 'utf8');
var lines = data.split('\n');
let start = false;
for (var k = 0; k < lines.length; k++) {
if (lines[k].startsWith('```bash')) {
start = true;
continue;
}
else if (lines[k].startsWith('```')) {
start = false;
continue;
}
if (start) {
command_list.push(lines[k]);
}
}
}
}
}
}
fs.copyFile("package.json", './testing-folder/' + "old-package.json", (err) => {
if (err) throw err;
console.log('package.json was copied to ./testing-folder/old-package.json');
});
package_files.push("old-package.json");
// Create package merge command
var command = "package-json-merge " + package_files.join(' ') + " > temp.json";
fs.writeFile('./testing-folder/merge-package.sh', command, function (err) {});
// Create dataset download command
fs.writeFile('./testing-folder/commands.sh', command_list.join('\n'), function (err) {});