0

This task work ok. I use path ".wwwroot/css/site.min.css"

var gulp = require("gulp");
const fs = require('fs').promises;

gulp.task('clean', async function (done) {
    try {
        await fs.rm(".wwwroot/js/temp/site.min.js", { recursive: true, force: true });
        done();
    } catch (error) {
        done(error);
    }
});

But if I use path '.wwwroot/js/temp/'. I get error: The following tasks did not complete: clean Did you forget to signal async completion?

"npm": "10.8.2", "node": "20.17.0"

The problem appeared after I decided to update to rimraf 2.2.8. It was suggested to use the built-in fs library

0

1 Answer 1

0
async function removeTempFolder(done) {
    const dirPath = 'wwwroot/js/temp/';

    try {
        const files = await fs.readdir(dirPath);

        if (!files || files.length === 0) {
            console.log('No files to delete.');
        } else {
            for (const file of files) {
                const filePath = path.join(dirPath, file);
                await fs.unlink(filePath);
                console.log(`Deleted file: ${filePath}`);
            }
        }

        await fs.rm(dirPath, { recursive: true, force: true });
        console.log('Directory deleted successfully');
        done();
    } catch (err) {
        if (err.code === 'ENOENT') {
            console.log('Directory does not exist:', dirPath);
        } else {
            console.error('Error deleting files or directory:', err);
        }
        done(err);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.