Skip to content

Commit

Permalink
feat: introduce chooseVercelTeam step (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
maneike authored Nov 20, 2024
1 parent d4878e3 commit b960a86
Show file tree
Hide file tree
Showing 5 changed files with 50 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 @@ -17,6 +17,7 @@ import { createTurboRepo } from './installSteps/turbo/create';
import { deployVercelProject } from './installSteps/vercel/deploy';
import { linkVercelProject } from './installSteps/vercel/link';
import { updateVercelProjectSettings } from './installSteps/vercel/updateProjectSettings';
import { chooseVercelTeam } from './installSteps/vercel/chooseTeam';

const isStepCompleted = (stepName: keyof StepsCompleted) => {
return ({ context }: { context: InstallMachineContext; event: AnyEventObject }) => {
Expand Down Expand Up @@ -190,12 +191,26 @@ const createInstallMachine = (initialContext: InstallMachineContext) => {
always: [
{
guard: isStepCompleted('createSupabaseProject'),
target: 'linkVercelProject',
target: 'chooseVercelTeam',
},
],
invoke: {
input: ({ context }) => context,
src: 'createSupabaseProjectActor',
onDone: 'chooseVercelTeam',
onError: 'failed',
},
},
chooseVercelTeam: {
always: [
{
guard: isStepCompleted('chooseVercelTeam'),
target: 'linkVercelProject',
},
],
invoke: {
input: ({ context }) => context,
src: 'chooseVercelTeamActor',
onDone: 'linkVercelProject',
onError: 'failed',
},
Expand Down Expand Up @@ -416,6 +431,18 @@ const createInstallMachine = (initialContext: InstallMachineContext) => {
}
}),
),
chooseVercelTeamActor: createStepMachine(
fromPromise<void, InstallMachineContext, AnyEventObject>(async ({ input }) => {
try {
await chooseVercelTeam();
input.stateData.stepsCompleted.chooseVercelTeam = true;
saveStateToRcFile(input.stateData, input.projectDir);
} catch (error) {
console.error('Error in chooseVercelTeamActor:', error);
throw error;
}
}),
),
linkVercelProjectActor: createStepMachine(
fromPromise<void, InstallMachineContext, AnyEventObject>(async ({ input }) => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const connectSupabaseProject = async (projectName: string, currentDir: st
}

attempts++;
spinner.text = `Checking integration status ${chalk.hex('#259764')(`[${attempts}/${maxAttempts}]`)}`;
spinner.text = `Waiting for user to complete integration...`;
await delay(interval);
} catch (error) {
spinner.fail('Failed to check Vercel integration status');
Expand Down
20 changes: 20 additions & 0 deletions packages/core/installMachine/installSteps/vercel/chooseTeam.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { execSync } from 'child_process';
import boxen from 'boxen';
import chalk from 'chalk';

export const chooseVercelTeam = async () => {
console.log(
boxen(
chalk.bold('Choose a Vercel team to link your project to.\n\n') +
'If you are not sure, you can skip this step by choosing "Cancel". This will link the project to the current logged-in user.',
{
padding: 1,
margin: 1,
borderStyle: 'round',
borderColor: '#FFFFFF',
},
),
);

execSync('npx vercel teams switch', { stdio: 'inherit' });
};
1 change: 0 additions & 1 deletion packages/core/installMachine/installSteps/vercel/link.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { execSync } from 'child_process';
import chalk from 'chalk';
import { logger } from '../../../utils/logger';
import { execAsync } from '../../../utils/execAsync';

Expand Down
1 change: 1 addition & 0 deletions packages/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface StepsCompleted {
initializeRepository: boolean;
pushToGitHub: boolean;
createSupabaseProject: boolean;
chooseVercelTeam: boolean;
linkVercelProject: boolean;
updateVercelProjectSettings: boolean;
connectSupabaseProject: boolean;
Expand Down

0 comments on commit b960a86

Please sign in to comment.