import { addDependencies, addDocumentJs, addUIConfigJs, changeDirectory, replaceNextConfig, updateTsConfig, yarnInstall, } from './utils'; const path = require('path'); const prompts = require('prompts'); export const linkProjects = async (next: any, storybook: any) => { const webapp_instance = next; const storybook_instance = storybook; const parentDirectory = path.resolve('./'); const webFolder = `${parentDirectory}/${webapp_instance}`; const storybookFolder = `${parentDirectory}/${storybook_instance}`; console.log( '\x1b[33m', `\nThis script will make changes in your ${webapp_instance} folder to the following files:`, '\x1b[0m' ); console.log('\x1b[32m', '- package.json (to add certain dependencies)'); console.log(' - tsconfig.json (to add types)'); console.log(' - next.config.js (to add Next.js configuration)'); console.log(' - ui.config.ts (to add ui config)'); console.log( ' - pages/_document.tsx (to add custom document for Next.js)', '\x1b[0m' ); console.log( '\x1b[31m', '\nPlease note that if these files already exist, they will be replaced.\n', '\x1b[0m' ); const proceedResponse = await prompts({ type: 'text', name: 'proceed', message: 'Do you wish to continue? (yes/no) ', }); if (proceedResponse.proceed.toLowerCase() === 'yes') { console.log( '\x1b[32m', '\nMaking changes to the specified files...', '\x1b[0m' ); await addDependencies(webFolder); await updateTsConfig(webFolder, storybookFolder); await replaceNextConfig(webFolder, storybookFolder); await addDocumentJs(webFolder); await addUIConfigJs(webFolder); await changeDirectory(webFolder); await yarnInstall(); } else if (proceedResponse.proceed.toLowerCase() === 'no') { console.log('\nExiting script. No changes have been made.'); } else { console.log( '\x1b[31m', "\nInvalid Input, please type 'yes' or 'no' to continue or exit the script.", '\x1b[0m' ); } };