From 3ff59250ec9e8f58eb9dcba083f6af251e68fce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Che=C5=82miniak?= Date: Mon, 25 Nov 2024 19:07:19 +0100 Subject: [PATCH] feat: introduce modifyGitignore and add it to installMachine (#44) --- packages/core/installMachine/index.ts | 29 ++++++++++++++++++- .../installSteps/stapler/modifyGitignore.ts | 4 +-- packages/core/types.ts | 1 + packages/core/utils/rcFileManager/index.ts | 1 + 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/packages/core/installMachine/index.ts b/packages/core/installMachine/index.ts index e3db3e0..e10a5fb 100644 --- a/packages/core/installMachine/index.ts +++ b/packages/core/installMachine/index.ts @@ -18,6 +18,7 @@ import { deployVercelProject } from './installSteps/vercel/deploy'; import { linkVercelProject } from './installSteps/vercel/link'; import { updateVercelProjectSettings } from './installSteps/vercel/updateProjectSettings'; import { chooseVercelTeam } from './installSteps/vercel/chooseTeam'; +import { modifyGitignore } from './installSteps/stapler/modifyGitignore'; const isStepCompleted = (stepName: keyof StepsCompleted) => { return ({ context }: { context: InstallMachineContext; event: AnyEventObject }) => { @@ -61,12 +62,26 @@ const createInstallMachine = (initialContext: InstallMachineContext) => { always: [ { guard: isStepCompleted('initializeProject'), - target: 'installTailwind', + target: 'modifyGitignore', }, ], invoke: { src: 'initializeProjectActor', input: ({ context }) => context, + onDone: 'modifyGitignore', + onError: 'failed', + }, + }, + modifyGitignore: { + always: [ + { + guard: isStepCompleted('modifyGitignore'), + target: 'installTailwind', + }, + ], + invoke: { + src: 'modifyGitignoreActor', + input: ({ context }) => context, onDone: 'installTailwind', onError: 'failed', }, @@ -318,6 +333,18 @@ const createInstallMachine = (initialContext: InstallMachineContext) => { } }), ), + modifyGitignoreActor: createStepMachine( + fromPromise(async ({ input }) => { + try { + await modifyGitignore('.staplerrc'); + input.stateData.stepsCompleted.modifyGitignore = true; + saveStateToRcFile(input.stateData, input.projectDir); + } catch (error) { + console.error('Error in modifyGitignoreActor:', error); + throw error; + } + }), + ), installTailwindActor: createStepMachine( fromPromise(async ({ input }) => { try { diff --git a/packages/core/installMachine/installSteps/stapler/modifyGitignore.ts b/packages/core/installMachine/installSteps/stapler/modifyGitignore.ts index ba6dcae..a90759a 100644 --- a/packages/core/installMachine/installSteps/stapler/modifyGitignore.ts +++ b/packages/core/installMachine/installSteps/stapler/modifyGitignore.ts @@ -7,7 +7,7 @@ const readFileAsync = promisify(fs.readFile); const writeFileAsync = promisify(fs.writeFile); export const modifyGitignore = async (entry: string) => { - await logger.withSpinner('stapler', `Adding ${entry} to .gitignore..`, async (spinner) => { + await logger.withSpinner('stapler', `Adding entries to .gitignore..`, async (spinner) => { const gitignorePath = path.join(process.cwd(), '.gitignore'); try { @@ -22,7 +22,7 @@ export const modifyGitignore = async (entry: string) => { // Write the updated .gitignore back to the file await writeFileAsync(gitignorePath, updatedData); - spinner.succeed(`${entry} added to .gitignore.`); + spinner.succeed(`File .gitignore updated.`); } else { spinner.info(`${entry} is already listed in .gitignore.`); } diff --git a/packages/core/types.ts b/packages/core/types.ts index b8c7370..4b8dda3 100644 --- a/packages/core/types.ts +++ b/packages/core/types.ts @@ -5,6 +5,7 @@ export interface ProjectOptions { export interface StepsCompleted { initializeProject: boolean; + modifyGitignore: boolean; installTailwind: boolean; modifyHomepage: boolean; installSupabase: boolean; diff --git a/packages/core/utils/rcFileManager/index.ts b/packages/core/utils/rcFileManager/index.ts index 83504f9..11f6524 100644 --- a/packages/core/utils/rcFileManager/index.ts +++ b/packages/core/utils/rcFileManager/index.ts @@ -16,6 +16,7 @@ export const initializeRcFile = (projectDir: string, name: string, usePayload: b projectName: name, stepsCompleted: { initializeProject: false, + modifyGitignore: false, installTailwind: false, modifyHomepage: false, installSupabase: false,