All files / init init-directory.js

90.91% Statements 10/11
75% Branches 3/4
100% Functions 2/2
90.91% Lines 10/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26              1x     6x 6x 6x   6x 6x 1x 1x 1x 1x            
import debug from 'debug';
import fs from 'fs-promise';
import logSymbols from 'log-symbols';
 
import asyncOra from '../util/ora-handler';
import confirmIfInteractive from '../util/confirm-if-interactive';
 
const d = debug('electron-forge:init:directory');
 
export default async (dir, interactive) => {
  await asyncOra('Initializing Project Directory', async (initSpinner) => {
    d('creating directory:', dir);
    await fs.mkdirs(dir);
 
    const files = await fs.readdir(dir);
    if (files.length !== 0) {
      d('found', files.length, 'files in the directory.  warning the user');
      initSpinner.stop(logSymbols.warning);
      const confirm = await confirmIfInteractive(interactive, `WARNING: The specified path: "${dir}" is not empty, do you wish to continue?`);
      Iif (!confirm) {
        throw 'Cancelled by user'; // eslint-disable-line
      }
    }
  });
};