const fs = require('fs');
const buildConstants = require('../buildConstants');

const cleanTask = (resolve, reject) => {
    fs.promises.rmdir(buildConstants.outputDirectory, { recursive: true })
        .then(() => {
            fs.promises.mkdir(buildConstants.outputDirectory)
                .then(resolve)
                .catch((mkdirError) => reject(mkdirError));
        })
        .catch((rmdirError) => reject(rmdirError));
};

module.exports = cleanTask;

const fs = require('fs');
const buildConstants = require('../buildConstants');

const cleanTask = (resolve, reject) => {
    const recreatedOutputDirectory = (res, rej) => {
        fs.promises.mkdir(buildConstants.outputDirectory)
            .then(res)
            .catch((mkdirError) => rej(mkdirError));
    };

    fs.promises.stat(buildConstants.outputDirectory)
        .then(() => {
            fs.promises.rmdir(buildConstants.outputDirectory, { recursive: true })
                .then(() => recreatedOutputDirectory(resolve, reject))
                .catch((rmdirError) => reject(rmdirError));
        })
        .catch(() => {
            recreatedOutputDirectory(resolve, reject);
        });
};

module.exports = cleanTask;

Make the clean task continue on if the output folder does not exist.
Make the clean task continue on if the output folder does not exist.

This should sort out build issues on AWS Amplify, where we are using an older
NodeJS version with an expeimental fs.promises API.
