Skip to content

Commit

Permalink
Merge pull request #4 from tonik/feat/link-vercel
Browse files Browse the repository at this point in the history
feat: link Vercel - add functions to login, link, deploy, connect
  • Loading branch information
KarolinaKopacz authored Oct 21, 2024
2 parents b814f1a + fbfdb82 commit 6385c0c
Show file tree
Hide file tree
Showing 6 changed files with 3,895 additions and 1,469 deletions.
15 changes: 11 additions & 4 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { createTurboRepo } from './utils/turbo/create';
import { prepareDrink } from './utils/bar/prepareDrink';
import { createEnvFile } from './utils/env/createEnvFile';
import { initializeRepository } from './utils/github/install';
import { preparePayload } from './utils/payload/install';
import { installSupabase } from './utils/supabase/install';
import { prettify } from './utils/prettier/prettify';
import { prepareDrink } from './utils/bar/prepareDrink';
import { initializeRepository } from './utils/github/install';
import { connectSupabaseProject } from './utils/supabase/connectProject';
import { createSupabaseProject } from './utils/supabase/createProject';
import { installSupabase } from './utils/supabase/install';
import { createTurboRepo } from './utils/turbo/create';
import { deployVercelProject } from './utils/vercel/deploy';
import { setupAndCreateVercelProject } from './utils/vercel/setupAndCreate';
import { createDocFiles } from './utils/docs/create';


interface ProjectOptions {
name: string;
usePayload: boolean;
Expand Down Expand Up @@ -41,7 +44,11 @@ export async function createProject(options: ProjectOptions) {

await createSupabaseProject(name);

await setupAndCreateVercelProject();

await connectSupabaseProject(name, currentDir);

await deployVercelProject();

prepareDrink(name);
}
2 changes: 1 addition & 1 deletion packages/core/utils/supabase/connectProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const connectSupabaseProject = async (projectName: string, currentDir: st
{
type: 'confirm',
name: 'isIntegrationReady',
message: '๐Ÿ–‡๏ธ Have you completed the GitHub and Vercel integration setup?',
message: 'Have you completed the GitHub and Vercel integration setup?',
default: false,
},
]);
Expand Down
30 changes: 30 additions & 0 deletions packages/core/utils/vercel/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { execSync } from 'child_process';
import { getDeploymentUrl } from './utils/getDeploymentUrl';

const fs = require('fs').promises;

export async function deployVercelProject() {
console.log('๐Ÿ–‡๏ธ Connecting to Git repository...');

execSync('vercel git connect', { stdio: 'inherit' });
// next step: when error git connect then need to add gh account to your vercel account

console.log('๐Ÿ–‡๏ธ Creating vercel.json...');

const vercelConfig = {
buildCommand: 'pnpm build',
outputDirectory: 'apps/web',
};

await fs.writeFile('vercel.json', JSON.stringify(vercelConfig, null, 2));

console.log('๐Ÿ–‡๏ธ Creating preview deployment...');
const previewUrl = getDeploymentUrl(false);

console.log('๐Ÿ–‡๏ธ Creating production deployment...');
const productionUrl = getDeploymentUrl(true);

console.log(`๐Ÿ–‡๏ธ You can access your preview deployment at: \x1b[36m${previewUrl}\x1b[0m$`);

console.log(`๐Ÿ–‡๏ธ You can access your production deployment at: \x1b[36m${productionUrl}\x1b[0m$`);
}
27 changes: 27 additions & 0 deletions packages/core/utils/vercel/setupAndCreate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { execSync } from 'child_process';

export async function setupAndCreateVercelProject() {
console.log('๐Ÿ–‡๏ธ Checking if Vercel CLI is installed...');

const isVercelInstalled = execSync('vercel --version', { encoding: 'utf8' });

if (!isVercelInstalled) {
console.log('๐Ÿ–‡๏ธ Installing Vercel CLI...');
execSync('npm install -g vercel');
}

const isLoggedInToVercel = execSync('vercel whoami', { stdio: 'pipe', encoding: 'utf-8' });

if (!isLoggedInToVercel) {
console.log('๐Ÿ–‡๏ธ Logging in to Vercel...');
execSync('vercel login');
} else {
console.log(`๐Ÿ–‡๏ธ You are logged to Vercel as \x1b[36m${isLoggedInToVercel}\x1b[0m`);
}

console.log('๐Ÿ–‡๏ธ Initializing Vercel project...');
execSync('vercel init');

console.log('๐Ÿ–‡๏ธ Linking Vercel project...');
execSync('vercel link', { stdio: 'inherit' });
}
19 changes: 19 additions & 0 deletions packages/core/utils/vercel/utils/getDeploymentUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { execSync } from 'child_process';

export function getDeploymentUrl(production: boolean = false): string {
const command = production ? 'vercel --prod' : 'vercel';

try {
const output = execSync(command, { encoding: 'utf8' });

if (output) {
return output;
} else {
console.error(`URL not found in ${production ? 'production' : 'preview'} deployment output`);
return '';
}
} catch (error) {
console.error(`Error during ${production ? 'production' : 'preview'} deployment:`, error);
return '';
}
}
Loading

0 comments on commit 6385c0c

Please sign in to comment.