From 5227ccce847fb06d7a36ed5597d6360a1bc64a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Che=C5=82miniak?= Date: Thu, 17 Oct 2024 15:29:59 +0200 Subject: [PATCH] refactor: rename id to refId + change linking command --- packages/core/index.ts | 2 +- packages/core/utils/shared/updateEnvFile.ts | 5 ++--- packages/core/utils/supabase/connectProject.ts | 13 +++++++------ packages/core/utils/supabase/utils/index.ts | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/core/index.ts b/packages/core/index.ts index 3857d84..eb86598 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -15,13 +15,13 @@ interface ProjectOptions { export async function createProject(options: ProjectOptions) { const { name, usePayload } = options; - const currentDir = process.cwd(); console.log(`🖇️ Stapling ${name}...`); await createTurboRepo(name); process.chdir(name); + const currentDir = process.cwd(); createEnvFile(currentDir); diff --git a/packages/core/utils/shared/updateEnvFile.ts b/packages/core/utils/shared/updateEnvFile.ts index 9bd63a2..8300ad1 100644 --- a/packages/core/utils/shared/updateEnvFile.ts +++ b/packages/core/utils/shared/updateEnvFile.ts @@ -10,7 +10,6 @@ type EnvPair = [string, string]; interface EnvUpdateConfig { currentDir: string; - projectName: string; pairs: EnvPair[]; } @@ -22,8 +21,8 @@ const updateLine = (line: string, key: string, value: string): string => { return line; }; -export async function updateEnvFile({ currentDir, projectName, pairs }: EnvUpdateConfig): Promise { - const envFilePath = path.join(currentDir, projectName, '.env'); +export async function updateEnvFile({ currentDir, pairs }: EnvUpdateConfig): Promise { + const envFilePath = path.join(currentDir, '.env'); try { // Check if the .env file exists try { diff --git a/packages/core/utils/supabase/connectProject.ts b/packages/core/utils/supabase/connectProject.ts index 7645cc1..f21338f 100644 --- a/packages/core/utils/supabase/connectProject.ts +++ b/packages/core/utils/supabase/connectProject.ts @@ -21,16 +21,17 @@ export const connectSupabaseProject = async (projectName: string, currentDir: st const newProject = projects.find((project) => project.name === projectName); console.log('🖇️ Getting Supabase project keys...'); - const projectAPIKeys = execSync(`supabase projects api-keys --project-ref ${newProject?.id}`, { encoding: 'utf-8' }); + const projectAPIKeys = execSync(`supabase projects api-keys --project-ref ${newProject?.refId}`, { + encoding: 'utf-8', + }); const SUPABASE_ANON_KEY = getSupabaseKeys(projectAPIKeys).anonKey; const SUPABASE_SERVICE_ROLE_KEY = getSupabaseKeys(projectAPIKeys).serviceRoleKey; - const SUPABASE_URL = `https://${newProject?.id}.supabase.co/`; + const SUPABASE_URL = `https://${newProject?.refId}.supabase.co/`; console.log(`🖇️ Saving keys to .env...`); await updateEnvFile({ currentDir, - projectName, pairs: [ ['SUPABASE_ANON_KEY', `${SUPABASE_ANON_KEY}`], ['SUPABASE_SERVICE_ROLE_KEY', `${SUPABASE_SERVICE_ROLE_KEY}`], @@ -39,7 +40,7 @@ export const connectSupabaseProject = async (projectName: string, currentDir: st }); console.log('🖇️ Linking Supabase project...'); - execSync(`supabase projects link ${newProject?.id}`, { + execSync(`supabase link --project-ref ${newProject?.refId}`, { stdio: 'inherit', }); @@ -49,7 +50,7 @@ export const connectSupabaseProject = async (projectName: string, currentDir: st await continueOnAnyKeypress('🖇️ When you are ready to be redirected to the Supabase page press any key'); - execSync(`open https://supabase.com/dashboard/project/${newProject?.id}/settings/integrations`); + execSync(`open https://supabase.com/dashboard/project/${newProject?.refId}/settings/integrations`); const { isIntegrationReady } = await inquirer.prompt([ { @@ -64,7 +65,7 @@ export const connectSupabaseProject = async (projectName: string, currentDir: st // Uncomment after CLI progress task is done. // console.log("🖇️ Run \x1b[36mcreate-stapler-app\x1b[0m again when you've completed the integration."); console.log( - `🖇️ You can access your project dashboard at: https://supabase.com/dashboard/project/${newProject?.id}/settings/integrations`, + `🖇️ You can access your project dashboard at: https://supabase.com/dashboard/project/${newProject?.refId}/settings/integrations`, ); } }; diff --git a/packages/core/utils/supabase/utils/index.ts b/packages/core/utils/supabase/utils/index.ts index 6b212e1..2d23255 100644 --- a/packages/core/utils/supabase/utils/index.ts +++ b/packages/core/utils/supabase/utils/index.ts @@ -1,7 +1,7 @@ interface SupabaseProjectInfo { linked: boolean; org_id: string; - id: string; + refId: string; name: string; region: string; created_at: string; @@ -12,11 +12,11 @@ export function parseProjectsList(output: string): SupabaseProjectInfo[] { lines.splice(0, 2); return lines.map((line) => { - const [linked, org_id, id, name, region, created_at] = line.split('│').map((item) => item.trim()); + const [linked, org_id, refId, name, region, created_at] = line.split('│').map((item) => item.trim()); return { linked: linked !== '', org_id, - id, + refId, name, region, created_at,