1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { promises as fs } from 'node:fs';
- import { join } from 'node:path';
- const rootDir = process.cwd();
- async function cleanTargetsRecursively(currentDir, targets) {
- const items = await fs.readdir(currentDir);
- for (const item of items) {
- try {
- const itemPath = join(currentDir, item);
- if (targets.includes(item)) {
-
- await fs.rm(itemPath, { force: true, recursive: true });
- console.log(`Deleted: ${itemPath}`);
- }
- const stat = await fs.lstat(itemPath);
- if (stat.isDirectory()) {
- await cleanTargetsRecursively(itemPath, targets);
- }
- } catch {
-
-
-
- }
- }
- }
- (async function startCleanup() {
-
- const targets = ['node_modules', 'dist', '.turbo', 'dist.zip'];
- const deleteLockFile = process.argv.includes('--del-lock');
- const cleanupTargets = [...targets];
- if (deleteLockFile) {
- cleanupTargets.push('pnpm-lock.yaml');
- }
- console.log(
- `Starting cleanup of targets: ${cleanupTargets.join(', ')} from root: ${rootDir}`,
- );
- try {
- await cleanTargetsRecursively(rootDir, cleanupTargets);
- console.log('Cleanup process completed.');
- } catch (error) {
- console.error(`Unexpected error during cleanup: ${error.message}`);
- }
- })();
|