Skip to content

Commit

Permalink
fix: tailwind addition
Browse files Browse the repository at this point in the history
  • Loading branch information
maneike committed Nov 19, 2024
1 parent ee08a29 commit 2eda2a6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
5 changes: 3 additions & 2 deletions packages/core/installMachine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ const createInstallMachine = (initialContext: InstallMachineContext) => {
installTailwindActor: createStepMachine(
fromPromise<void, InstallMachineContext, AnyEventObject>(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) {
Expand All @@ -318,7 +319,7 @@ const createInstallMachine = (initialContext: InstallMachineContext) => {
modifyHomepageActor: createStepMachine(
fromPromise<void, InstallMachineContext, AnyEventObject>(async ({ input }) => {
try {
modifyHomepage(input.projectDir);
await modifyHomepage(input.projectDir);
input.stateData.stepsCompleted.modifyHomepage = true;
saveStateToRcFile(input.stateData, input.projectDir);
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 20 additions & 20 deletions packages/core/installMachine/installSteps/tailwind/install.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
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');
console.error('Error during tailwind installation:', error);
}
});
};

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' });
};

0 comments on commit 2eda2a6

Please sign in to comment.