diff --git a/packages/core/installMachine/index.ts b/packages/core/installMachine/index.ts index 74e912d..c6bca00 100644 --- a/packages/core/installMachine/index.ts +++ b/packages/core/installMachine/index.ts @@ -306,7 +306,8 @@ const createInstallMachine = (initialContext: InstallMachineContext) => { installTailwindActor: createStepMachine( fromPromise(async ({ input }) => { try { - installTailwind(input.projectDir); + const currentDir = process.cwd(); + await installTailwind(currentDir); input.stateData.stepsCompleted.installTailwind = true; saveStateToRcFile(input.stateData, input.projectDir); } catch (error) { @@ -318,7 +319,7 @@ const createInstallMachine = (initialContext: InstallMachineContext) => { modifyHomepageActor: createStepMachine( fromPromise(async ({ input }) => { try { - modifyHomepage(input.projectDir); + await modifyHomepage(input.projectDir); input.stateData.stepsCompleted.modifyHomepage = true; saveStateToRcFile(input.stateData, input.projectDir); } catch (error) { diff --git a/packages/core/installMachine/installSteps/homepage/install.ts b/packages/core/installMachine/installSteps/homepage/install.ts index a8b2026..9fa35b3 100644 --- a/packages/core/installMachine/installSteps/homepage/install.ts +++ b/packages/core/installMachine/installSteps/homepage/install.ts @@ -8,6 +8,7 @@ export const modifyHomepage = async (destinationDirectory: string) => { try { const templateDirectory = getTemplateDirectory(`/templates/homepage/files/`); templateGenerator(homepageFiles, templateDirectory, destinationDirectory); + spinner.succeed('Homepage setup completed.'); } catch (error) { spinner.fail('Tailwind installation failed'); console.error('Error during tailwind installation:', error); diff --git a/packages/core/installMachine/installSteps/tailwind/install.ts b/packages/core/installMachine/installSteps/tailwind/install.ts index b56c845..dff1edd 100644 --- a/packages/core/installMachine/installSteps/tailwind/install.ts +++ b/packages/core/installMachine/installSteps/tailwind/install.ts @@ -1,16 +1,32 @@ -import { execSync } from 'child_process'; import fs from 'fs'; import path from 'path'; import { tailwindFiles } from '../../../templates/tailwind/installConfig'; import { templateGenerator } from '../../../utils/generator/generator'; import { getTemplateDirectory } from '../../../utils/getTemplateDirectory'; import { logger } from '../../../utils/logger'; +import { execAsync } from '../../../utils/execAsync'; -export const installTailwind = async (destinationDirectory: string) => { +const copyTailwindFiles = (currentDir: string) => { + const templateDirectory = getTemplateDirectory(`/templates/tailwind/files/`); + templateGenerator(tailwindFiles, templateDirectory, currentDir); +}; + +const installTailwindPackage = async (currentDir: string) => { + const packageJsonPath = path.join(currentDir, 'apps/web/package.json'); + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); + delete packageJson.dependencies['@repo/ui']; + fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); + process.chdir(path.join(currentDir, 'apps/web')); + await execAsync('pnpm add -D tailwindcss postcss autoprefixer'); + process.chdir(currentDir); + await execAsync('pnpm install --reporter silent'); +}; + +export const installTailwind = async (currentDir: string) => { await logger.withSpinner('tailwind', 'Adding Tailwind...', async (spinner) => { try { - installTailwindPackage(destinationDirectory); - copyTailwindFiles(destinationDirectory); + await installTailwindPackage(currentDir); + copyTailwindFiles(currentDir); spinner.succeed('Tailwind installed.'); } catch (error) { spinner.fail('Tailwind installation failed'); @@ -18,19 +34,3 @@ export const installTailwind = async (destinationDirectory: string) => { } }); }; - -const copyTailwindFiles = (destinationDirectory: string) => { - const templateDirectory = getTemplateDirectory(`/templates/tailwind/files/`); - templateGenerator(tailwindFiles, templateDirectory, destinationDirectory); -}; - -const installTailwindPackage = async (destinationDirectory: string) => { - const packageJsonPath = path.join(destinationDirectory, 'apps/web/package.json'); - const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); - delete packageJson.dependencies['@repo/ui']; - fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); - process.chdir(path.join(destinationDirectory, 'apps/web')); - execSync('pnpm add -D tailwindcss postcss autoprefixer', { stdio: 'inherit' }); - process.chdir(destinationDirectory); - execSync('pnpm install', { stdio: 'inherit' }); -};