-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from tonik/feat/link-vercel
feat: link Vercel - add functions to login, link, deploy, connect
- Loading branch information
Showing
6 changed files
with
3,895 additions
and
1,469 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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$`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ''; | ||
} | ||
} |
Oops, something went wrong.