Skip to content

DO NOT MERGE - Chore/typescript migration #2978

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

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
173f888
chore: convert aborted-error.js to TypeScript
elylucas Apr 14, 2025
23dfd04
chore: convert actions.js to TypeScript
elylucas Apr 14, 2025
faec07b
chore: rename assertions.js to assertions.ts
elylucas Apr 14, 2025
54f057a
chore: convert assertions.js content to TypeScript
elylucas Apr 14, 2025
50be409
chore: rename contentful-clients.js to contentful-clients.ts
elylucas Apr 14, 2025
ea4f814
chore: convert contentful-clients.js content to TypeScript
elylucas Apr 14, 2025
7ed3d3f
chore: rename emojis.js to emojis.ts
elylucas Apr 14, 2025
b746d5d
chore: convert emojis.js content to TypeScript
elylucas Apr 14, 2025
80922d3
chore: rename error.js to error.ts
elylucas Apr 14, 2025
6c260e4
chore: convert error.js content to TypeScript
elylucas Apr 14, 2025
41cb634
chore: rename fs.js to fs.ts
elylucas Apr 14, 2025
306cd23
chore: convert fs.js content to TypeScript
elylucas Apr 14, 2025
9e82c17
chore: rename github.js to github.ts
elylucas Apr 14, 2025
c260671
chore: convert github.js content to TypeScript
elylucas Apr 14, 2025
3b5b10b
chore: rename headers.js to headers.ts
elylucas Apr 14, 2025
f20bfec
chore: convert headers.js content to TypeScript
elylucas Apr 14, 2025
218d8b7
chore: rename helpers.js to helpers.ts
elylucas Apr 14, 2025
7bd48fa
chore: convert helpers.js content to TypeScript
elylucas Apr 14, 2025
0b5fa84
chore: rename markdown.js to markdown.ts
elylucas Apr 14, 2025
6dff80c
chore: convert markdown.js content to TypeScript
elylucas Apr 14, 2025
1a6bb64
chore: rename middlewares.js to middlewares.ts
elylucas Apr 14, 2025
2470b26
chore: convert middlewares.js content to TypeScript
elylucas Apr 14, 2025
1ba1417
chore: rename pagination.js to pagination.ts
elylucas Apr 14, 2025
6a335da
chore: convert pagination.js content to TypeScript
elylucas Apr 14, 2025
b8e2740
chore: rename proxy.js to proxy.ts
elylucas Apr 14, 2025
8c2ac09
chore: convert proxy.js content to TypeScript
elylucas Apr 14, 2025
938f75f
chore: rename styles.js to styles.ts
elylucas Apr 14, 2025
f4cd4da
chore: convert styles.js content to TypeScript
elylucas Apr 14, 2025
d5d0e96
chore: rename text.js to text.ts
elylucas Apr 14, 2025
eda6564
chore: convert text.js content to TypeScript
elylucas Apr 14, 2025
bc09e07
chore: rename log.js to log.ts
elylucas Apr 14, 2025
2f95348
chore: convert log.js content to TypeScript
elylucas Apr 14, 2025
1948c6a
chore: adding other missing converted files
elylucas Apr 15, 2025
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
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module.exports = {
testTimeout: 15000,
transform: {
'\\.[jt]sx?$': 'babel-jest'
'.[jt]sx?$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
testEnvironment: 'node',
testEnvironmentOptions: {
url: 'http://localhost/'
Expand Down
22 changes: 22 additions & 0 deletions lib/types/emojic.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
declare module 'emojic' {
interface EmojicInterface {
wave: string
sparkles: string
rotatingLight: string
bulb: string
zero: string
one: string
two: string
three: string
four: string
five: string
six: string
seven: string
eight: string
nine: string
[key: string]: string
}

const emojic: EmojicInterface
export = emojic
}
23 changes: 23 additions & 0 deletions lib/types/nixt.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
declare module 'nixt' {
interface NixtInstance {
cwd(path: string): NixtInstance
base(command: string): NixtInstance
clone(): NixtInstance
run(command: string): NixtInstance
code(code: number): NixtInstance
expect(
callback: (result: { stdout: string; stderr: string }) => void
): NixtInstance
end(callback: (err?: Error) => void): void
}

interface NixtOptions {
newlines?: boolean
colors?: boolean
[key: string]: any
}

function nixt(options?: NixtOptions): NixtInstance

export default nixt
}
13 changes: 13 additions & 0 deletions lib/types/wrap-ansi.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
declare module 'wrap-ansi' {
function wrapAnsi(
input: string,
columns: number,
options?: {
hard?: boolean
trim?: boolean
wordWrap?: boolean
}
): string

export default wrapAnsi
}
2 changes: 0 additions & 2 deletions lib/utils/aborted-error.js

This file was deleted.

12 changes: 12 additions & 0 deletions lib/utils/aborted-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Error class for when a process is aborted
export class AbortedError extends Error {
constructor(message?: string) {
super(message)
this.name = 'AbortedError'

// Maintains proper stack trace for where our error was thrown (only available on V8)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, AbortedError)
}
}
}
19 changes: 0 additions & 19 deletions lib/utils/actions.js

This file was deleted.

21 changes: 21 additions & 0 deletions lib/utils/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import inquirer from 'inquirer'

/**
* Simple yes/no question
* @param text The confirmation message to display
* @returns A boolean indicating the user's response
*/
export async function confirmation(text?: string): Promise<boolean> {
text = text || 'Are you ready?'

const readyAnswer = await inquirer.prompt([
{
type: 'confirm',
name: 'ready',
message: text,
default: true
}
])

return readyAnswer.ready
}
28 changes: 20 additions & 8 deletions lib/utils/assertions.js → lib/utils/assertions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
const { getContext } = require('../context')
const { PreconditionFailedError } = require('./error')
const { highlightStyle } = require('./styles')
import { getContext } from '../context'
import { PreconditionFailedError } from './error'
import { highlightStyle } from './styles'

async function assertLoggedIn({ managementToken, paramName } = {}) {
interface AssertLoggedInOptions {
managementToken?: string
paramName?: string
}

export async function assertLoggedIn({
managementToken,
paramName
}: AssertLoggedInOptions = {}): Promise<void> {
let noToken = !managementToken
if (!managementToken) {
const context = await getContext()
Expand All @@ -18,9 +26,15 @@ async function assertLoggedIn({ managementToken, paramName } = {}) {
}
}

module.exports.assertLoggedIn = assertLoggedIn
interface AssertSpaceIdProvidedOptions {
spaceId?: string
activeSpaceId?: string
}

async function assertSpaceIdProvided({ spaceId, activeSpaceId } = {}) {
export async function assertSpaceIdProvided({
spaceId,
activeSpaceId
}: AssertSpaceIdProvidedOptions = {}): Promise<void> {
let noSpaceId = !spaceId && !activeSpaceId
if (noSpaceId) {
const context = await getContext()
Expand All @@ -34,5 +48,3 @@ async function assertSpaceIdProvided({ spaceId, activeSpaceId } = {}) {
)
}
}

module.exports.assertSpaceIdProvided = assertSpaceIdProvided
43 changes: 0 additions & 43 deletions lib/utils/contentful-clients.js

This file was deleted.

68 changes: 68 additions & 0 deletions lib/utils/contentful-clients.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {
createClient,
PlainClientAPI,
ClientAPI,
ClientOptions
} from 'contentful-management'
import { version } from '../../package.json'
import { getContext } from '../context'
import { agentFromProxy } from './proxy'

// Extending ClientOptions type but making specific adjustments for compatibility
type ClientParams = Omit<ClientOptions, 'apiAdapter' | 'accessToken'> & {
accessToken?: string | (() => Promise<string>)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
apiAdapter?: any // Using any here to match how the original JS file behaved
}

export async function createManagementClient(
params: ClientParams
): Promise<ClientAPI> {
params.application = `contentful.cli/${version}`

const context = await getContext()
const { rawProxy, proxy, host, insecure } = context

const proxyConfig: Record<string, unknown> = {}
if (!rawProxy) {
const { httpsAgent } = agentFromProxy(proxy)
proxyConfig.httpsAgent = httpsAgent
} else {
proxyConfig.proxy = proxy
}

return createClient({
...params,
...proxyConfig,
host,
insecure
} as ClientOptions)
}

export async function createPlainClient(
params: ClientParams,
defaults: Record<string, unknown> = {}
): Promise<PlainClientAPI> {
params.application = `contentful.cli/${version}`

const context = await getContext()
const { rawProxy, proxy, host, insecure } = context

const proxyConfig: Record<string, unknown> = {}
if (!rawProxy) {
const { httpsAgent } = agentFromProxy(proxy)
proxyConfig.httpsAgent = httpsAgent
} else {
proxyConfig.proxy = proxy
}

return createClient(
{
...params,
...proxyConfig,
host,
insecure
} as ClientOptions,
{ type: 'plain', defaults }
) as PlainClientAPI
}
30 changes: 0 additions & 30 deletions lib/utils/emojis.js

This file was deleted.

32 changes: 32 additions & 0 deletions lib/utils/emojis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import emojic = require('emojic')

interface NumberMap {
[key: string]: string
}

const numberMap: NumberMap = {
0: 'zero',
1: 'one',
2: 'two',
3: 'three',
4: 'four',
5: 'five',
6: 'six',
7: 'seven',
8: 'eight',
9: 'nine'
}

export const welcomeEmoji = `${emojic.wave} `
export const successEmoji = `${emojic.sparkles} `
export const errorEmoji = `${emojic.rotatingLight} `
export const infoEmoji = `${emojic.bulb} `

export function generateNumberEmoji(number: number): string {
if (process.platform !== 'darwin') {
return number.toString()
}
return number
.toString()
.replace(/\d/g, match => `${emojic[numberMap[match]]} `)
}
29 changes: 0 additions & 29 deletions lib/utils/error.js

This file was deleted.

Loading