-
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.
feat: get the shortest vercel production domain (#31)
Co-authored-by: Martin Chełminiak <[email protected]>
- Loading branch information
1 parent
01174bc
commit d4878e3
Showing
3 changed files
with
51 additions
and
12 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
33 changes: 33 additions & 0 deletions
33
packages/core/installMachine/installSteps/vercel/utils/getShortestVercelAlias.ts
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,33 @@ | ||
import { spawn } from 'child_process'; | ||
|
||
export const getShortestVercelAlias = (deploymentUrl: string): Promise<string | null> => { | ||
return new Promise((resolve) => { | ||
const vercel = spawn('vercel', ['inspect', deploymentUrl]); | ||
|
||
let urls: string[] = []; | ||
|
||
vercel.stderr.on('data', (data) => { | ||
const output = data.toString(); | ||
|
||
if (output.includes('.vercel.app')) { | ||
const matches = output.match(/https:\/\/[\w-]+\.vercel\.app/g); | ||
if (matches) { | ||
urls = [...urls, ...matches]; | ||
} | ||
} | ||
}); | ||
|
||
vercel.on('close', (code) => { | ||
if (code !== 0 || urls.length === 0) { | ||
resolve(null); | ||
} else { | ||
const shortestUrl = urls.reduce((shortest, current) => (current.length < shortest.length ? current : shortest)); | ||
resolve(shortestUrl); | ||
} | ||
}); | ||
|
||
vercel.on('error', () => { | ||
resolve(null); | ||
}); | ||
}); | ||
}; |