'use strict';

const logger = require('./log');

let fs = require('fs-extra'); // eslint-disable-line

module.exports = (incrementalBuildsEnabled, patternlab) => {
  const paths = patternlab.config.paths;

  if (incrementalBuildsEnabled) {
    logger.info('Incremental builds enabled.');
    return Promise.resolve();
  } else {
    // needs to be done BEFORE processing patterns

    // TODO make this a promise that loops over all uikits

    return fs
      .emptyDir(paths.public.patterns)
      .then(() => {
        return Promise.resolve();
      })
      .catch(reason => {
        logger.error(reason);
      });
  }
};

@@ -8,16 +8,76 @@
 rict';%0A%0A
+const _ = require('lodash');%0Aconst path = require('path');%0A%0A
 const lo
@@ -390,146 +390,150 @@
     
-// needs to be done BEFORE processing patterns%0A%0A    // TODO make this a promise that loops over all uikits%0A%0A    return fs%0A      .emptyDir(
+return Promise.all(%0A      _.map(patternlab.uikits, uikit =%3E %7B%0A        return fs.emptyDir(%0A          path.join(process.cwd(), uikit.outputDir, 
 path
@@ -561,53 +561,10 @@
     
-.then(() =%3E %7B%0A        return Promise.resolve(
+  
 );%0A 
@@ -575,18 +575,17 @@
  %7D)%0A    
-  
+)
 .catch(r
@@ -591,26 +591,24 @@
 reason =%3E %7B%0A
-  
       logger
@@ -623,18 +623,16 @@
 eason);%0A
-  
     %7D);%0A

clean each build directory if configured