diff --git a/src/commands/sites/sites-create-template.ts b/src/commands/sites/sites-create-template.ts index 5a88d6b8c2c..77e6792376f 100644 --- a/src/commands/sites/sites-create-template.ts +++ b/src/commands/sites/sites-create-template.ts @@ -13,25 +13,19 @@ import { configureRepo } from '../../utils/init/config.js' import { createRepo, getTemplatesFromGitHub, validateTemplate } from '../../utils/sites/utils.js' import { track } from '../../utils/telemetry/index.js' import BaseCommand from '../base-command.js' - +import { GithubRepo, Template } from '../../utils/types.js' import { getSiteNameInput } from './sites-create.js' -// @ts-expect-error TS(7006) FIXME: Parameter 'token' implicitly has an 'any' type. -export const fetchTemplates = async (token) => { - const templatesFromGithubOrg = await getTemplatesFromGitHub(token) +export const fetchTemplates = async (token: string): Promise => { + const templatesFromGithubOrg: GithubRepo[] = await getTemplatesFromGitHub(token) - return ( - // @ts-expect-error TS(18046) - 'templatesFromGithubOrg' if of type 'unknown' - templatesFromGithubOrg - // @ts-expect-error TS(7006) FIXME: Parameter 'repo' implicitly has an 'any' type. - .filter((repo) => !repo.archived && !repo.disabled) - // @ts-expect-error TS(7006) FIXME: Parameter 'template' implicitly has an 'any' type. - .map((template) => ({ - name: template.name, - sourceCodeUrl: template.html_url, - slug: template.full_name, - })) - ) + return templatesFromGithubOrg + .filter((repo: GithubRepo) => !repo.archived && !repo.disabled) + .map((template: GithubRepo) => ({ + name: template.name, + sourceCodeUrl: template.html_url, + slug: template.full_name, + })) } // @ts-expect-error TS(7031) FIXME: Binding element 'ghToken' implicitly has an 'any' ... Remove this comment to see the full error message @@ -55,7 +49,6 @@ const getTemplateName = async ({ ghToken, options, repository }) => { type: 'list', name: 'templateName', message: 'Template:', - // @ts-expect-error TS(7006) FIXME: Parameter 'template' implicitly has an 'any' type. choices: templates.map((template) => ({ value: template.slug, name: template.name, @@ -219,7 +212,6 @@ export const sitesCreateTemplate = async (repository: string, options: OptionVal if (options.withCi) { log('Configuring CI') - // @ts-expect-error TS(2345) FIXME: Argument of type '{ workingDir: any; }' is not ass... Remove this comment to see the full error message const repoData = await getRepoData({ workingDir: command.workingDir }) // @ts-expect-error TS(2532) FIXME: Object is possibly 'undefined'. await configureRepo({ command, siteId: site.id, repoData, manual: options.manual }) diff --git a/src/commands/sites/sites-create.ts b/src/commands/sites/sites-create.ts index 5fcbf5f2d16..2b68f5d5071 100644 --- a/src/commands/sites/sites-create.ts +++ b/src/commands/sites/sites-create.ts @@ -9,9 +9,9 @@ import { configureRepo } from '../../utils/init/config.js' import { track } from '../../utils/telemetry/index.js' import BaseCommand from '../base-command.js' import { link } from '../link/link.js' +import { Account } from '../../utils/types.js' -// @ts-expect-error TS(7006) FIXME: Parameter 'name' implicitly has an 'any' type. -export const getSiteNameInput = async (name) => { +export const getSiteNameInput = async (name: string | undefined): Promise<{ name: string }> => { if (!name) { const { name: nameInput } = await inquirer.prompt([ { @@ -22,7 +22,7 @@ export const getSiteNameInput = async (name) => { /^[a-zA-Z\d-]+$/.test(input || undefined) || 'Only alphanumeric characters and hyphens are allowed', }, ]) - name = nameInput || '' + name = typeof nameInput === 'string' ? nameInput : '' } return { name } @@ -33,16 +33,17 @@ export const sitesCreate = async (options: OptionValues, command: BaseCommand) = await command.authenticate() - const accounts = await api.listAccountsForUser() + const accounts: Account[] = await api.listAccountsForUser() - let { accountSlug } = options + let { accountSlug }: { accountSlug?: string } = options if (!accountSlug) { - const { accountSlug: accountSlugInput } = await inquirer.prompt([ + const { accountSlug: accountSlugInput }: { accountSlug: string } = await inquirer.prompt< + Promise<{ accountSlug: string }> + >([ { type: 'list', name: 'accountSlug', message: 'Team:', - // @ts-expect-error TS(7006) FIXME: Parameter 'account' implicitly has an 'any' type. choices: accounts.map((account) => ({ value: account.slug, name: account.name, @@ -55,13 +56,11 @@ export const sitesCreate = async (options: OptionValues, command: BaseCommand) = let site // Allow the user to reenter site name if selected one isn't available - // @ts-expect-error TS(7006) FIXME: Parameter 'name' implicitly has an 'any' type. - const inputSiteName = async (name) => { + const inputSiteName = async (name?: string) => { const { name: siteName } = await getSiteNameInput(name) - const body = {} + const body: { name?: string } = {} if (typeof siteName === 'string') { - // @ts-expect-error TS(2339) FIXME: Property 'name' does not exist on type '{}'. body.name = siteName.trim() } try { @@ -72,7 +71,6 @@ export const sitesCreate = async (options: OptionValues, command: BaseCommand) = } catch (error_) { if ((error_ as APIError).status === 422) { warn(`${siteName}.netlify.app already exists. Please try a different slug.`) - // @ts-expect-error TS(2554) FIXME: Expected 1 arguments, but got 0. await inputSiteName() } else { error(`createSiteInTeam error: ${(error_ as APIError).status}: ${(error_ as APIError).message}`) @@ -107,7 +105,6 @@ export const sitesCreate = async (options: OptionValues, command: BaseCommand) = if (options.withCi) { log('Configuring CI') - // @ts-expect-error TS(2345) FIXME: Argument of type '{ workingDir: any; }' is not ass... Remove this comment to see the full error message const repoData = await getRepoData({ workingDir: command.workingDir }) // @ts-expect-error TS(2532) FIXME: Object is possibly 'undefined'. await configureRepo({ command, siteId: site.id, repoData, manual: options.manual }) diff --git a/src/utils/get-repo-data.ts b/src/utils/get-repo-data.ts index 942548f4a0c..578a452d239 100644 --- a/src/utils/get-repo-data.ts +++ b/src/utils/get-repo-data.ts @@ -17,8 +17,8 @@ import { log } from './command-helpers.js' * @param {string} config.workingDir * @returns */ -// @ts-expect-error TS(7031) FIXME: Binding element 'remoteName' implicitly has an 'an... Remove this comment to see the full error message -const getRepoData = async function ({ remoteName, workingDir }) { + +const getRepoData = async function ({ remoteName, workingDir }: { remoteName?: string; workingDir: string }) { try { const [gitConfig, gitDirectory] = await Promise.all([ util.promisify(gitconfiglocal)(workingDir), diff --git a/src/utils/sites/utils.ts b/src/utils/sites/utils.ts index 79c980a2e45..61667f50050 100644 --- a/src/utils/sites/utils.ts +++ b/src/utils/sites/utils.ts @@ -1,7 +1,8 @@ import fetch from 'node-fetch' +import { error } from '../../utils/command-helpers.js' +import { GithubRepo } from '../../utils/types.js' -// @ts-expect-error TS(7006) FIXME: Parameter 'token' implicitly has an 'any' type. -export const getTemplatesFromGitHub = async (token) => { +export const getTemplatesFromGitHub = async (token: string): Promise => { const getPublicGitHubReposFromOrg = new URL(`https://api.github.com/orgs/netlify-templates/repos`) // GitHub returns 30 by default and we want to avoid our limit // due to our archived repositories at any given time @@ -12,14 +13,19 @@ export const getTemplatesFromGitHub = async (token) => { // @ts-expect-error TS(2345) FIXME: Argument of type 'number' is not assignable to par... Remove this comment to see the full error message getPublicGitHubReposFromOrg.searchParams.set('per_page', REPOS_PER_PAGE) - const templates = await fetch(getPublicGitHubReposFromOrg, { - method: 'GET', - headers: { - Authorization: `token ${token}`, - }, - }) - const allTemplates = await templates.json() - + let allTemplates: GithubRepo[] = [] + try { + const templates = await fetch(getPublicGitHubReposFromOrg, { + method: 'GET', + headers: { + Authorization: `token ${token}`, + }, + }) + allTemplates = (await templates.json()) as GithubRepo[] + } catch (error_) { + // @ts-expect-error TS(2345) FIXME: Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message + error(error_) + } return allTemplates } diff --git a/src/utils/types.ts b/src/utils/types.ts index 95f1b5266ba..6ac80539e95 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -62,3 +62,45 @@ export interface Request extends IncomingMessage { } export type Rewriter = (req: Request) => Match | null + +export interface Account { + id: string + name: string + slug: string + type: string + capabilities: { + sites: { + included: number + used: number + } + collaborators: { + included: number + used: number + } + } + billing_name: string + billing_email: string + billing_details: string + billing_period: string + payment_method_id: string + type_name: string + type_id: string + owner_ids: string[] + roles_allowed: string[] + created_at: string + updated_at: string +} + +export interface GithubRepo { + name: string + html_url: string + full_name: string + archived: boolean + disabled: boolean +} + +export interface Template { + name: string + sourceCodeUrl: string + slug: string +}