Skip to content

Commit

Permalink
feat: introduce modifyGitignore and add it to installMachine (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
maneike authored Nov 25, 2024
1 parent 30ce5c8 commit 3ff5925
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
29 changes: 28 additions & 1 deletion packages/core/installMachine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -318,6 +333,18 @@ const createInstallMachine = (initialContext: InstallMachineContext) => {
}
}),
),
modifyGitignoreActor: createStepMachine(
fromPromise<void, InstallMachineContext, AnyEventObject>(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<void, InstallMachineContext, AnyEventObject>(async ({ input }) => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.`);
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ProjectOptions {

export interface StepsCompleted {
initializeProject: boolean;
modifyGitignore: boolean;
installTailwind: boolean;
modifyHomepage: boolean;
installSupabase: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/core/utils/rcFileManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3ff5925

Please sign in to comment.