Skip to content

Commit

Permalink
Added function to check the size of the user's current dir, exiting i…
Browse files Browse the repository at this point in the history
…f too large.
  • Loading branch information
zoujas committed Oct 1, 2023
1 parent 2bc922e commit 31c30e5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/commands/detect_dir_size.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from 'fs';
import path from 'path';

export function getDirectorySize(dir) {
let size = 0;
return traverse(dir);
// Helper function to traverse the directory and its subdirectories
function traverse(dirPath) {
// Read the contents of the directory
const files = fs.readdirSync(dirPath);

// Loop through each file and subdirectory
for (const file of files) {
const filePath = path.join(dirPath, file);
const stats = fs.statSync(filePath);

// If it's a file, add its size to the total
if (stats.isFile()) {
size += stats.size;
}
// If it's a subdirectory, recursively traverse it
else if (stats.isDirectory()) {
traverse(filePath);
}
if (size>200 *124 *124){

return true
}
}return false
}
}
8 changes: 8 additions & 0 deletions lib/commands/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ import { fileURLToPath } from 'url';
import { dirname } from 'path';
const filename = fileURLToPath(import.meta.url);
const directoryName = dirname(filename);
import {getDirectorySize} from "../commands/detect_dir_size.mjs"


let isSDirectory = isSystemDirectory(directoryName);
if(isSDirectory == true){
console.log("WARNING. You are currently in a system directory(ex: /bin,sys32), please switch to a subdirectory before proceeding.");
process.exit(1);
}
let fileSizeExceeded = getDirectorySize(directoryName);

if(fileSizeExceeded == true){
console.log("WARNING. The current directory exceeds 200MB in size. Please ensure that you are using the correct directory.");
process.exit(1);
}


// const TEST_TYPES = ['postman', 'curl', 'java', 'ruby', 'python', 'playwright-js', 'playwright-python', 'selenium-ruby', 'selenium-java', 'selenium-python', 'custom']; // Replace with your actual TEST_TYPES values
Expand Down

0 comments on commit 31c30e5

Please sign in to comment.