All files / api init.js

88.24% Statements 15/17
84.62% Branches 11/13
100% Functions 1/1
88.24% Lines 15/17
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60                      1x                                   7x           7x   7x   7x 3x 3x           7x 7x 7x 7x 7x 3x 1x     4x      
import debug from 'debug';
 
import initCustom from '../init/init-custom';
import initDirectory from '../init/init-directory';
import initGit from '../init/init-git';
import initNPM from '../init/init-npm';
import initStandardFix from '../init/init-standard-fix';
import initStarter from '../init/init-starter-files';
 
import asyncOra from '../util/ora-handler';
 
const d = debug('electron-forge:init');
 
/**
 * @typedef {Object} InitOptions
 * @property {string} [dir=process.cwd()] The path to the app to be initialized
 * @property {boolean} [interactive=false] Whether to use sensible defaults or prompt the user visually
 * @property {string} [lintstyle=airbnb] The lintstyle to pass through to the template creator
 * @property {string} [template] The custom template to use. If left empty, the default template is used
 */
 
/**
 * Initialize a new Electron Forge template project in the given directory.
 *
 * @param {InitOptions} providedOptions - Options for the init method
 * @return {Promise} Will resolve when the initialization process is complete
 */
export default async (providedOptions = {}) => {
  // eslint-disable-next-line prefer-const, no-unused-vars
  let { dir, interactive, lintstyle, template } = Object.assign({
    dir: process.cwd(),
    interactive: false,
    lintstyle: 'airbnb',
    template: null,
  }, providedOptions);
  asyncOra.interactive = interactive;
 
  d(`Initializing in: ${dir}`);
 
  if (!template) {
    lintstyle = lintstyle.toLowerCase();
    Iif (!['airbnb', 'standard'].includes(lintstyle)) {
      d(`Unrecognized lintstyle argument: '${lintstyle}' -- defaulting to 'airbnb'`);
      lintstyle = 'airbnb';
    }
  }
 
  await initDirectory(dir, interactive);
  await initGit(dir);
  await initStarter(dir, template ? undefined : lintstyle);
  await initNPM(dir, template ? undefined : lintstyle);
  if (!template) {
    if (lintstyle === 'standard') {
      await initStandardFix(dir);
    }
  } else {
    await initCustom(dir, template, lintstyle);
  }
};