-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupdateBlob.ts
64 lines (56 loc) · 1.98 KB
/
updateBlob.ts
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
import * as fs from "fs";
import * as path from "path";
// Define the source and destination directory paths
const sourceDirectory: string = path.join(__dirname, "blob-report");
const destinationDirectory: string = path.join(__dirname, "all-blob-reports");
// Check for the 'clean' argument
const args = process.argv.slice(2);
const clean = args.includes("clean");
if (clean) {
// Remove all files from the destination directory
fs.readdir(destinationDirectory, (err, files) => {
if (err) {
console.error("Error reading destination directory:", err);
process.exit(1);
}
files.forEach((file) => {
const filePath = path.join(destinationDirectory, file);
fs.unlink(filePath, (err) => {
if (err) {
console.error(`Error deleting file ${file}:`, err);
} else {
console.log(`Deleted ${file} from ${destinationDirectory}`);
}
});
});
});
} else {
// Ensure the destination directory exists
fs.mkdir(destinationDirectory, { recursive: true }, (err) => {
if (err) {
console.error("Error creating destination directory:", err);
process.exit(1);
}
// Read the source directory
fs.readdir(sourceDirectory, (err, files) => {
if (err) {
console.error("Error reading source directory:", err);
process.exit(1);
}
// Filter files that match the pattern report.*.zip
const reportFiles = files.filter((file) => /^report.*\.zip$/.test(file));
// Copy each matching file to the destination directory
reportFiles.forEach((file) => {
const sourceFilePath = path.join(sourceDirectory, file);
const destinationFilePath = path.join(destinationDirectory, file);
fs.copyFile(sourceFilePath, destinationFilePath, (err) => {
if (err) {
console.error(`Error copying file ${file}:`, err);
} else {
console.log(`Copied ${file} to ${destinationDirectory}`);
}
});
});
});
});
}