-
Notifications
You must be signed in to change notification settings - Fork 1
/
updateScripts.js
83 lines (61 loc) · 2.1 KB
/
updateScripts.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
const { readdir, readFile, writeFile } = require("fs").promises;
async function main() {
const files = await readdir(__dirname, {
recursive: true
});
const modelPathObjects = [];
for (const file of files) {
const parts = file.split("/");
if (parts.length === 3 && !file.includes(".git")) {
const [task, org, model] = parts;
const filePath = `${__dirname}/${file}`;
modelPathObjects.push({
model,
githubLink: `https://github.com/Bytez-com/models/tree/main/${task}/${org}/${model}`,
file,
filePath
});
}
}
const nameOfFileToUpdate = "environment.py";
const newFilePath = `${__dirname}/../templates/default/${nameOfFileToUpdate}`;
const newFileBuffer = await readFile(newFilePath);
const newFileContents = newFileBuffer.toString();
console.log("New file is:\n\n", newFileContents);
const updatedModels = [];
const notUpdatedModels = [];
const failedModels = [];
for (const [index, modelPathObject] of modelPathObjects.map((v, i) => [
i,
v
])) {
const { model, githubLink, file, filePath } = modelPathObject;
console.log(`On model: ${model} (${index + 1}/${modelPathObjects.length})`);
const fileToUpdatePath = `${filePath}/${nameOfFileToUpdate}`;
// overwrite the target file with the new file contents
try {
const buffer = await readFile(fileToUpdatePath);
const oldFileContents = buffer.toString();
if (oldFileContents !== newFileContents) {
await writeFile(fileToUpdatePath, newFileBuffer);
updatedModels.push(modelPathObject);
} else {
notUpdatedModels.push(modelPathObject);
}
} catch (error) {
failedModels.push(modelPathObject);
}
}
console.log(`Total models: ${modelPathObjects.length}`);
console.log(
`File: ${nameOfFileToUpdate} updated for ${updatedModels.length} models`
);
console.log(
`${notUpdatedModels.length} models had the same contents and were not updated`
);
console.log("Number of models that failed: ", failedModels.length);
const a = 2;
}
if (require.main === module) {
main();
}