From 31c30e52731e60e0610e25e71b6a115994bd4d94 Mon Sep 17 00:00:00 2001 From: Jason Zou Date: Sun, 1 Oct 2023 17:44:22 -0400 Subject: [PATCH] Added function to check the size of the user's current dir, exiting if too large. --- lib/commands/detect_dir_size.mjs | 31 +++++++++++++++++++++++++++++++ lib/commands/init.mjs | 8 ++++++++ 2 files changed, 39 insertions(+) create mode 100644 lib/commands/detect_dir_size.mjs diff --git a/lib/commands/detect_dir_size.mjs b/lib/commands/detect_dir_size.mjs new file mode 100644 index 00000000..2a240f55 --- /dev/null +++ b/lib/commands/detect_dir_size.mjs @@ -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 + } +} \ No newline at end of file diff --git a/lib/commands/init.mjs b/lib/commands/init.mjs index 430da590..bcc702b2 100644 --- a/lib/commands/init.mjs +++ b/lib/commands/init.mjs @@ -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