'use babel';

import yarnExec from '../yarn/exec';
import reportError from '../report-error';

const cleanCache = async () => {
  const success = await yarnExec(null, 'cache', ['clean']);

  if (!success) {
    atom.notifications.addError(
      'An error occurred whilst cleaning cache. See output for more information.',
    );

    return;
  }

  atom.notifications.addSuccess('Global package cache has been cleaned');
};

const confirmation = async () => {
  atom.confirm({
    message: 'Are you sure you want to clean the global Yarn cache?',
    detailedMessage:
      'Cleaning your global package cache will force Yarn to download packages from the npm registry the next time a package is requested.',
    buttons: {
      'Clean Cache': () => {
        cleanCache().catch(reportError);
      },
      Cancel: null,
    },
  });
};

export default confirmation;

'use babel';

import yarnExec from '../yarn/exec';
import reportError from '../report-error';
import addProgressNotification from '../add-progress-notification';

const cleanCache = async () => {
  let progress;

  const options = {
    onStart: () => {
      progress = addProgressNotification('Cleaning global package cache...');
    },
  };

  const success = await yarnExec(null, 'cache', ['clean'], options);

  progress.dismiss();

  if (!success) {
    atom.notifications.addError(
      'An error occurred whilst cleaning global cache. See output for more information.',
    );

    return;
  }

  atom.notifications.addSuccess('Global package cache has been cleaned');
};

const confirmation = async () => {
  atom.confirm({
    message: 'Are you sure you want to clean the global Yarn cache?',
    detailedMessage:
      'Cleaning your global package cache will force Yarn to download packages from the npm registry the next time a package is requested.',
    buttons: {
      'Clean Cache': () => {
        cleanCache().catch(reportError);
      },
      Cancel: null,
    },
  });
};

export default confirmation;

Add progress notification to clean cache command
Add progress notification to clean cache command
