Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing types #3

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getSlugAndSection,
getLatestDeployment,
getProductionDeployment
} from '../src'
} from '../src/index.js'

async function main () {
const { _: args, ...flags } = mri(process.argv.slice(2))
Expand Down
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"@commitlint/cli": "latest",
"@commitlint/config-conventional": "latest",
"@ksmithut/prettier-standard": "latest",
"@types/node": "latest",
"@vercel/style-guide": "6",
"c8": "latest",
"ci-publish": "latest",
"finepack": "latest",
Expand All @@ -43,7 +45,6 @@
"nano-staged": "latest",
"simple-git-hooks": "latest",
"standard": "latest",
"standard-markdown": "latest",
"standard-version": "latest",
"tsup": "latest",
"vitest": "latest"
Expand All @@ -70,11 +71,7 @@
},
"nano-staged": {
"*.js": [
"prettier-standard",
"standard --fix"
],
"*.md": [
"standard-markdown"
"prettier-standard"
],
"package.json": [
"finepack"
Expand Down
37 changes: 17 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,36 @@ import { readFile } from 'fs/promises'
import { existsSync } from 'fs'
import path from 'path'

const vercelApi = pathname =>
const vercelApi = (pathname: string) =>
fetch(`${process.env.VERCEL_API}/${pathname}`, {
headers: {
'Accept-Encoding': 'identity'
}
})

const getProjectName = async (projectId: string) =>
vercelApi(`v9/projects/${projectId}`)
async function getProjectName (projectId: string) {
return vercelApi(`v9/projects/${projectId}`)
.then(res => res.json())
.then(payload => payload.name)
.then((payload: any) => payload.name)
}

const getOrganizationName = async (teamId: string) =>
vercelApi(`v2/teams/${teamId}`)
.then(res => res.json())
.then(payload => payload.name)
.then((payload: any) => payload.name)

export const getLatestDeployment = async () => {
const { projectId } = await readProjectFile()
return vercelApi(`v9/projects/${projectId}`)
.then(res => res.json())
.then(payload => payload.latestDeployments[0].id.replace('dpl_', ''))
.then((payload: any) => payload.latestDeployments[0].id.replace('dpl_', ''))
}

export const getProductionDeployment = async () => {
const { projectId } = await readProjectFile()
return vercelApi(`v9/projects/${projectId}`)
.then(res => res.json())
.then(payload => payload.targets.production.id.replace('dpl_', ''))
.then((payload: any) => payload.targets.production.id.replace('dpl_', ''))
}

async function readProjectFile (): Promise<{
Expand All @@ -52,20 +53,16 @@ async function readProjectFile (): Promise<{

async function fromPath (): Promise<{ org: string; project: string }> {
const { projectId, teamId } = await readProjectFile()
const [org, project] = await Promise.all([
getOrganizationName(teamId),
getProjectName(projectId)
])

const org = await getOrganizationName(teamId)
const project = await getProjectName(projectId)
return { org, project }
}

export async function getSlugAndSection ({
args = []
args
}: {
args?: string[]
cwd?: string
} = {}): Promise<{
args: string[]
} = { args: [] }): Promise<{
org: string
project: string
section: string
Expand All @@ -75,13 +72,13 @@ export async function getSlugAndSection ({
}

if (args.length === 1) {
if (!args[0].includes('/')) {
if (args[0] && !args[0].includes('/')) {
return {
...(await fromPath()),
section: args[0]
}
} else {
const [org, project] = args[0].split('/')
const [org = '', project = ''] = (args[0] || '').split('/')
return {
org,
project,
Expand All @@ -91,12 +88,12 @@ export async function getSlugAndSection ({
}

if (args.length === 2) {
const [org, project] = args[0].split('/')
const [org = '', project = ''] = (args[0] || '').split('/')

return {
org,
project,
section: args[1]
section: args[1] || ''
}
}

Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@vercel/style-guide/typescript/node20"
}
Loading