Skip to content

Commit

Permalink
fix: add missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Dec 11, 2024
1 parent b26c1d8 commit 8971df8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
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"
}

0 comments on commit 8971df8

Please sign in to comment.