All files / bin wizard.js

100% Statements 53/53
53.84% Branches 7/13
100% Functions 1/1
100% Lines 53/53

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 54250x 250x 250x 250x 250x 250x 250x 250x 250x 51x 51x 51x 51x 51x 51x 51x 51x 51x 51x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 51x 51x 51x  
import { promptQuestion } from './utils.js';
import { bold, cyan } from './colors.js';
 
/**
 * Runs the interactive project wizard prompts if interactive mode is enabled.
 * @param {string[]} [args] - CLI arguments.
 * @returns {Promise<{stylePreprocessor: string, layoutTemplate: string, isInteractive: boolean}>}
 */
export async function runWizard(args = []) {
  const isInteractive =
    (process.stdin.isTTY && process.stdout.isTTY && !args.includes('-y') && !args.includes('--yes')) ||
    args.includes('--interactive') ||
    args.includes('-i') ||
    process.env.AVENX_FORCE_INTERACTIVE === 'true';
 
  let stylePreprocessor = 'none';
  let layoutTemplate = 'blank';
 
  if (isInteractive) {
    console.log(`\n${bold(cyan('--- Avenx-JS Project Wizard ---'))}\n`);
 
    const preprocessorInput = await promptQuestion(
      'Select style preprocessor:\n' +
        '  1. None (Vanilla CSS)\n' +
        '  2. Sass (SCSS)\n' +
        '  3. Less\n' +
        '  4. PostCSS\n' +
        'Choose an option (1-4, default: 1): ',
      '1',
      (val) => (['1', '2', '3', '4'].includes(val) ? true : 'Please enter a number between 1 and 4'),
    );
 
    const mapping = {
      1: 'none',
      2: 'sass',
      3: 'less',
      4: 'postcss',
    };
    stylePreprocessor = mapping[preprocessorInput];
 
    const layoutInput = await promptQuestion(
      'Select layout template:\n' +
        '  1. Blank (Minimal setup)\n' +
        '  2. Routing (Basic navigation with Navbar, Home and About pages)\n' +
        'Choose an option (1-2, default: 1): ',
      '1',
      (val) => (['1', '2'].includes(val) ? true : 'Please enter 1 or 2'),
    );
    layoutTemplate = layoutInput === '2' ? 'routing' : 'blank';
  }
 
  return { stylePreprocessor, layoutTemplate, isInteractive };
}