#!/usr/bin/env node import inquirer from 'inquirer'; import path from 'path'; import useChecker from './checker.js'; import { REPOSITORIES } from './constants.js'; import createDirectoryContents from './createDirectoryContents.js'; import { formatPath } from './utils/index.js'; // reduce repositories to array of strings const CHOICES = REPOSITORIES.map((repo) => repo.name); const QUESTIONS = [ { name: 'project-choice', type: 'list', message: 'Select template:', choices: CHOICES, }, { name: 'project-name', type: 'input', message: 'Enter the name of your app:', suffix: ' [Example: "hotel-cms"]', }, ]; const directorySet = [ { name: 'directorySet', type: 'confirm', message: 'Proceed?', }, ]; interface Answers { directorySet: any; } inquirer .prompt(QUESTIONS) .then((answers) => { const template = answers['project-choice'] as string; const projectName = answers['project-name'] as string; (async () => { const projectPath = formatPath(path.join(process.cwd(), projectName)); console.log('Installing template in: ', projectPath, '\n'); const answers: Answers = await inquirer.prompt(directorySet); if (!answers.directorySet) { console.log('\nAborting installation'); console.log( '\n\n F\'in sweet! You can always try again by running "npm init @finsweet/starter"' ); console.log('\n\n'); process.exit(0); } const response = await useChecker(projectPath); if (response) { // write contents to the directory createDirectoryContents(template, projectPath, projectName); return; } process.exit(1); })(); }) .catch((error) => { throw error; });