const fs = require('fs'); const path = require('path'); const prompts = require('prompts'); export const getInstalledProjects = async () => { const parentDirectory = path.resolve('./'); const nextApps: any = []; const storybookApps: any = []; fs.readdirSync(parentDirectory).forEach((directory: any) => { const currentDirectory = path.join(parentDirectory, directory); if (fs.existsSync(path.join(currentDirectory, 'next.config.js'))) { nextApps.push(directory); } else if (fs.existsSync(path.join(currentDirectory, '.storybook'))) { storybookApps.push(directory); } }); if (storybookApps.length === 0 && nextApps.length === 0) { console.error( '\x1b[31m', 'Error:', '\x1b[0m', ' No storybook or next app instance found in your current directory.' ); } else if (storybookApps.length === 0) { console.error( '\x1b[31m', 'Error:', '\x1b[0m', ' No storybook instance found in your current directory.' ); } else if (nextApps.length === 0) { console.error( '\x1b[31m', 'Error:', '\x1b[0m', ' No next app instance found in your current directory.' ); } else { const responseStorybook = await prompts({ type: 'select', name: 'selectedOption', message: 'Select storybook instance which you want to link to webapp:', choices: storybookApps, initial: 0, }); const responseNext = await prompts({ type: 'select', name: 'selectedOption', message: 'Select webapp instance where you want to link storybook: ', choices: nextApps, initial: 0, }); return { storybook: storybookApps[responseStorybook.selectedOption], next: nextApps[responseNext.selectedOption], }; } return {}; };