Massive Dependency Modernization Project
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Failing after 3m58s
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Failing after 3m58s
This commit is contained in:
70
scripts/clean.mjs
Normal file
70
scripts/clean.mjs
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Clean script to remove coverage directories.
|
||||
* Replaces rimraf dependency with native Node.js fs.rm API.
|
||||
*
|
||||
* Usage: node scripts/clean.mjs
|
||||
*
|
||||
* Behavior matches rimraf: errors are logged but script exits successfully.
|
||||
* This allows build pipelines to continue even if directories don't exist.
|
||||
*/
|
||||
|
||||
import { rm } from 'node:fs/promises';
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
/**
|
||||
* Directories to clean, relative to project root.
|
||||
* Add additional directories here as needed.
|
||||
*/
|
||||
const DIRECTORIES_TO_CLEAN = ['coverage', '.coverage'];
|
||||
|
||||
/**
|
||||
* Removes a directory recursively, handling errors gracefully.
|
||||
*
|
||||
* @param {string} dirPath - Absolute path to the directory to remove
|
||||
* @returns {Promise<boolean>} - True if removed successfully, false if error occurred
|
||||
*/
|
||||
async function removeDirectory(dirPath) {
|
||||
try {
|
||||
await rm(dirPath, { recursive: true, force: true });
|
||||
console.log(`Removed: ${dirPath}`);
|
||||
return true;
|
||||
} catch (error) {
|
||||
// Log error but don't fail - matches rimraf behavior
|
||||
// force: true should handle ENOENT, but log other errors
|
||||
console.error(`Warning: Could not remove ${dirPath}: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main entry point. Cleans all configured directories.
|
||||
*/
|
||||
async function main() {
|
||||
// Get project root (parent of scripts directory)
|
||||
const projectRoot = resolve(import.meta.dirname, '..');
|
||||
|
||||
console.log('Cleaning coverage directories...');
|
||||
|
||||
const results = await Promise.all(
|
||||
DIRECTORIES_TO_CLEAN.map((dir) => {
|
||||
const absolutePath = resolve(projectRoot, dir);
|
||||
return removeDirectory(absolutePath);
|
||||
})
|
||||
);
|
||||
|
||||
const successCount = results.filter(Boolean).length;
|
||||
console.log(
|
||||
`Clean complete: ${successCount}/${DIRECTORIES_TO_CLEAN.length} directories processed.`
|
||||
);
|
||||
|
||||
// Always exit successfully (matches rimraf behavior)
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
// Catch any unexpected errors in main
|
||||
console.error('Unexpected error during clean:', error.message);
|
||||
// Still exit successfully to not break build pipelines
|
||||
process.exit(0);
|
||||
});
|
||||
Reference in New Issue
Block a user