Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
eablack committed Jan 23, 2025
1 parent a8bc1e3 commit eb29360
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 170 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
}
},
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"camelcase":"off",
"import/namespace": "off",
"indent": ["error", 2, {"MemberExpression": 1}],
"node/no-deprecated-api": "warn",
"node/no-missing-import": "off",
"perfectionist/sort-objects": "warn",
"unicorn/no-array-for-each": "off",
"unicorn/no-useless-undefined": "warn",
"unicorn/prefer-node-protocol": "warn",
Expand Down
8 changes: 4 additions & 4 deletions src/addon-client.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import {HTTPError} from '@heroku/http-call'
import {APIClient} from '@heroku-cli/command'
import {ux} from '@oclif/core'
import * as url from 'url'
import {HTTPError} from '@heroku/http-call'
import {URL} from 'node:url'

export default class AddonClient {
private readonly client: APIClient

private readonly options: any = {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'User-Agent': 'kensa future',
Accept: 'application/json',
},
}

constructor(config: any) {
const client = new APIClient(config, {})
const host = process.env.HEROKU_ADDONS_HOST
const herokuHost = process.env.HEROKU_HOST || 'heroku.com'
client.defaults.host = host ? url.parse(host).host : `addons.${herokuHost}`
client.defaults.host = host ? new URL(host).host : `addons.${herokuHost}`

this.client = client
}
Expand Down
55 changes: 27 additions & 28 deletions src/addon.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import {ux} from '@oclif/core'

import {HTTPError} from '@heroku/http-call'
import color from '@heroku-cli/color'

Check warning on line 2 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, ubuntu-latest)

Using exported name 'color' as identifier for default import

Check warning on line 2 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, macos-latest)

Using exported name 'color' as identifier for default import

Check warning on line 2 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, ubuntu-latest)

Using exported name 'color' as identifier for default import

Check warning on line 2 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, macos-latest)

Using exported name 'color' as identifier for default import

Check warning on line 2 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, windows-latest)

Using exported name 'color' as identifier for default import

Check warning on line 2 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, windows-latest)

Using exported name 'color' as identifier for default import
import {ux} from '@oclif/core'

Check warning on line 3 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, ubuntu-latest)

'/home/runner/work/heroku-cli-addons-admin/heroku-cli-addons-admin/node_modules/@oclif/core/lib/index.d.ts' imported multiple times

Check warning on line 3 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, macos-latest)

'/Users/runner/work/heroku-cli-addons-admin/heroku-cli-addons-admin/node_modules/@oclif/core/lib/index.d.ts' imported multiple times

Check warning on line 3 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, ubuntu-latest)

'/home/runner/work/heroku-cli-addons-admin/heroku-cli-addons-admin/node_modules/@oclif/core/lib/index.d.ts' imported multiple times

Check warning on line 3 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, macos-latest)

'/Users/runner/work/heroku-cli-addons-admin/heroku-cli-addons-admin/node_modules/@oclif/core/lib/index.d.ts' imported multiple times

Check warning on line 3 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, windows-latest)

'D:\a\heroku-cli-addons-admin\heroku-cli-addons-admin\node_modules\@oclif\core\lib\index.d.ts' imported multiple times

Check warning on line 3 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, windows-latest)

'D:\a\heroku-cli-addons-admin\heroku-cli-addons-admin\node_modules\@oclif\core\lib\index.d.ts' imported multiple times
import {Config} from '@oclif/core'

Check warning on line 4 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, ubuntu-latest)

'/home/runner/work/heroku-cli-addons-admin/heroku-cli-addons-admin/node_modules/@oclif/core/lib/index.d.ts' imported multiple times

Check warning on line 4 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, macos-latest)

'/Users/runner/work/heroku-cli-addons-admin/heroku-cli-addons-admin/node_modules/@oclif/core/lib/index.d.ts' imported multiple times

Check warning on line 4 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, ubuntu-latest)

'/home/runner/work/heroku-cli-addons-admin/heroku-cli-addons-admin/node_modules/@oclif/core/lib/index.d.ts' imported multiple times

Check warning on line 4 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, macos-latest)

'/Users/runner/work/heroku-cli-addons-admin/heroku-cli-addons-admin/node_modules/@oclif/core/lib/index.d.ts' imported multiple times

Check warning on line 4 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, windows-latest)

'D:\a\heroku-cli-addons-admin\heroku-cli-addons-admin\node_modules\@oclif\core\lib\index.d.ts' imported multiple times

Check warning on line 4 in src/addon.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, windows-latest)

'D:\a\heroku-cli-addons-admin\heroku-cli-addons-admin\node_modules\@oclif\core\lib\index.d.ts' imported multiple times
import {HTTPError} from '@heroku/http-call'

import AddonClient from './addon-client'
import {ManifestInterface, ManifestLocal, ManifestRemote} from './manifest'

export default class Addon {
readonly argsSlug?: string
private readonly _client: AddonClient
private readonly _local: ManifestLocal
private readonly _remote: ManifestRemote
private readonly _client: AddonClient

constructor(config: Config, argsSlug?: string) {
this.argsSlug = argsSlug
Expand All @@ -21,26 +20,21 @@ export default class Addon {
this._client = new AddonClient(config)
}

local(): ManifestLocal {
return this._local
client(): AddonClient {
return this._client
}

remote(): ManifestRemote {
return this._remote
local(): ManifestLocal {
return this._local
}

async slug(): Promise<string> {
// allows users to pull without declaring slug
if (this.argsSlug) {
return this.argsSlug
}

const manifest = await this.local().get()
if (!manifest.id) {
ux.error('No slug found in manifest')
}
async manifest(uuid: string): Promise<ManifestInterface> {
const slug = await this.slug()
ux.action.start(`Fetching add-on manifest for ${color.addon(slug)}`)
const body = await this._client.get(`/api/v3/addons/${encodeURIComponent(slug)}/manifests/${encodeURIComponent(uuid)}`)
ux.action.stop()

return manifest.id
return body.contents
}

async manifests(): Promise<ManifestInterface[]> {
Expand All @@ -59,16 +53,21 @@ export default class Addon {
return body
}

async manifest(uuid: string): Promise<ManifestInterface> {
const slug = await this.slug()
ux.action.start(`Fetching add-on manifest for ${color.addon(slug)}`)
const body = await this._client.get(`/api/v3/addons/${encodeURIComponent(slug)}/manifests/${encodeURIComponent(uuid)}`)
ux.action.stop()

return body.contents
remote(): ManifestRemote {
return this._remote
}

client(): AddonClient {
return this._client
async slug(): Promise<string> {
// allows users to pull without declaring slug
if (this.argsSlug) {
return this.argsSlug
}

const manifest = await this.local().get()
if (!manifest.id) {
ux.error('No slug found in manifest')
}

return manifest.id
}
}
4 changes: 2 additions & 2 deletions src/commands/addons/admin/manifest/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export default class Diff extends Command {
const fetchedManifest = JSON.stringify(body, null, 2)
const localManifest = JSON.stringify(addon.local().get(), null, 2)

const diff = diffLines(fetchedManifest, localManifest, {newlineIsToken: true, ignoreCase: true})
const diff = diffLines(fetchedManifest, localManifest, {ignoreCase: true, newlineIsToken: true})
diff.forEach((substr: any) => {
let outputColor: 'white' | 'green' | 'red' = 'white'
let outputColor: 'green' | 'red' | 'white' = 'white'
if (substr.added) {
outputColor = 'green' // this is supposed to be a bold green (chalk.green.bold)
} else if (substr.removed) {
Expand Down
172 changes: 86 additions & 86 deletions src/commands/addons/admin/manifest/generate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import color from '@heroku-cli/color'

Check warning on line 1 in src/commands/addons/admin/manifest/generate.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, ubuntu-latest)

Using exported name 'color' as identifier for default import

Check warning on line 1 in src/commands/addons/admin/manifest/generate.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, macos-latest)

Using exported name 'color' as identifier for default import

Check warning on line 1 in src/commands/addons/admin/manifest/generate.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, ubuntu-latest)

Using exported name 'color' as identifier for default import

Check warning on line 1 in src/commands/addons/admin/manifest/generate.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, macos-latest)

Using exported name 'color' as identifier for default import

Check warning on line 1 in src/commands/addons/admin/manifest/generate.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, windows-latest)

Using exported name 'color' as identifier for default import

Check warning on line 1 in src/commands/addons/admin/manifest/generate.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, windows-latest)

Using exported name 'color' as identifier for default import
import {Command, flags} from '@heroku-cli/command'
import {ux} from '@oclif/core'
import * as Heroku from '@heroku-cli/schema'
import {ux} from '@oclif/core'
import * as fs from 'fs-extra'
import {prompt} from 'inquirer'
import {generate as generateString} from 'randomstring'
Expand All @@ -18,14 +18,14 @@ The file has been saved!`,
]

static flags = {
slug: flags.string({
char: 's',
description: 'slugname/manifest id',
}),
addon: flags.string({
char: 'a',
description: 'add-on name (name displayed on addon dashboard)',
}),
slug: flags.string({
char: 's',
description: 'slugname/manifest id',
}),
}

async run() {
Expand All @@ -42,70 +42,6 @@ The file has been saved!`,
await this.writeManifest(filename, manifest)
}

private slugQuestion(flags: any) {
return {
type: 'input',
name: 'id',
message: 'Enter slugname/manifest id:',
default: flags.slug,
validate: (input: any): boolean => {
if (input.trim() === '' || !isNaN(input)) {
this.error('Please use a string as a slug name.')
return false
}

return true
},
}
}

private nameQuestion(flags: any) {
return {
type: 'input',
name: 'name',
message: 'Addon name (Name displayed to on addon dashboard):',
default: flags.addon || 'MyAddon',
}
}

private regionsQuestion(regions: string[]) {
return {
type: 'checkbox',
name: 'regions',
default: ['us'],
pageSize: regions.length,
message: 'Choose regions to support',
choices: regions,
suffix: `\n ${color.bold('<space>')} - select\n ${color.bold('<a>')} - toggle all\n ${color.bold('<i>')} - invert all \n ${color.bold('↑↓')} use arrow keys to navigate\n`,
validate: (input: any): boolean => {
if (input.length === 0) {
this.error('Please select at least one region.')
return false
}

return true
},
}
}

private generateQuestion() {
return {
type: 'confirm',
name: 'toGenerate',
message: 'Would you like to generate the password and sso_salt?',
default: true,
}
}

private writeQuestion(filename: string) {
return {
type: 'confirm',
name: 'toWrite',
message: `This prompt will create/replace ${filename}. Is that okay with you?`,
default: true,
}
}

private async askQuestions(filename: string, flags: any, regions: string[]): Promise<any> {
const questions: any[] = [
this.slugQuestion(flags),
Expand All @@ -131,21 +67,6 @@ The file has been saved!`,
return promptAnswers
}

private async writeManifest(filename: string, manifest: any) {
// generating manifest
const manifestObj = JSON.stringify(manifest, null, 2)
ux.action.start('Generating add-on manifest')
await fs.writeFile(filename, manifestObj, err => {
ux.action.stop(color.green('done'))
if (err) {
this.log(`The file ${color.green(filename)} has NOT been saved! \n`, err)
return
}

this.log(`The file ${color.green(filename)} has been saved!`)
})
}

private generate(data: any = {}): ManifestInterface {
const manifest: ManifestInterface = {
id: 'myaddon',
Expand All @@ -167,15 +88,94 @@ The file has been saved!`,
name: 'MyAddon',
}

const configVarsPrefix = data.id && data.id.toUpperCase().replace(/-/g, '_')
const configVarsPrefix = data.id && data.id.toUpperCase().replaceAll('-', '_')

manifest.id = data.id || manifest.id
manifest.api.config_vars_prefix = (configVarsPrefix ? configVarsPrefix : manifest.api.config_vars_prefix)
manifest.api.config_vars_prefix = (configVarsPrefix ?? manifest.api.config_vars_prefix)
manifest.api.config_vars = (configVarsPrefix ? [`${configVarsPrefix}_URL`] : manifest.api.config_vars)
manifest.api.password = data.password || manifest.api.password
manifest.api.sso_salt = data.sso_salt || manifest.api.sso_salt
manifest.api.regions = data.regions || manifest.api.regions
manifest.name = data.name || manifest.name
return manifest
}

private generateQuestion() {
return {
default: true,
message: 'Would you like to generate the password and sso_salt?',
name: 'toGenerate',
type: 'confirm',
}
}

private nameQuestion(flags: any) {
return {
default: flags.addon || 'MyAddon',
message: 'Addon name (Name displayed to on addon dashboard):',
name: 'name',
type: 'input',
}
}

private regionsQuestion(regions: string[]) {
return {
choices: regions,
default: ['us'],
message: 'Choose regions to support',
name: 'regions',
pageSize: regions.length,
suffix: `\n ${color.bold('<space>')} - select\n ${color.bold('<a>')} - toggle all\n ${color.bold('<i>')} - invert all \n ${color.bold('↑↓')} use arrow keys to navigate\n`,
type: 'checkbox',
validate: (input: any): boolean => {
if (input.length === 0) {
this.error('Please select at least one region.')
return false
}

return true
},
}
}

private slugQuestion(flags: any) {
return {
default: flags.slug,
message: 'Enter slugname/manifest id:',
name: 'id',
type: 'input',
validate: (input: any): boolean => {
if (input.trim() === '' || !isNaN(input)) {

Check warning on line 148 in src/commands/addons/admin/manifest/generate.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, ubuntu-latest)

Prefer `Number.isNaN` over `isNaN`

Check warning on line 148 in src/commands/addons/admin/manifest/generate.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, macos-latest)

Prefer `Number.isNaN` over `isNaN`

Check warning on line 148 in src/commands/addons/admin/manifest/generate.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, ubuntu-latest)

Prefer `Number.isNaN` over `isNaN`

Check warning on line 148 in src/commands/addons/admin/manifest/generate.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, macos-latest)

Prefer `Number.isNaN` over `isNaN`

Check warning on line 148 in src/commands/addons/admin/manifest/generate.ts

View workflow job for this annotation

GitHub Actions / Node Tests (22.x, windows-latest)

Prefer `Number.isNaN` over `isNaN`

Check warning on line 148 in src/commands/addons/admin/manifest/generate.ts

View workflow job for this annotation

GitHub Actions / Node Tests (20.x, windows-latest)

Prefer `Number.isNaN` over `isNaN`
this.error('Please use a string as a slug name.')
return false
}

return true
},
}
}

private async writeManifest(filename: string, manifest: any) {
// generating manifest
const manifestObj = JSON.stringify(manifest, null, 2)
ux.action.start('Generating add-on manifest')
await fs.writeFile(filename, manifestObj, err => {
ux.action.stop(color.green('done'))
if (err) {
this.log(`The file ${color.green(filename)} has NOT been saved! \n`, err)
return
}

this.log(`The file ${color.green(filename)} has been saved!`)
})
}

private writeQuestion(filename: string) {
return {
default: true,
message: `This prompt will create/replace ${filename}. Is that okay with you?`,
name: 'toWrite',
type: 'confirm',
}
}
}
3 changes: 1 addition & 2 deletions src/commands/addons/admin/manifest/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Addon from '../../../../addon'
export default class Pull extends Command {
static args = {
slug: Args.string({
required: true,
description: 'slug name of add-on',
required: true,
}),
}

Expand All @@ -20,7 +20,6 @@ export default class Pull extends Command {
Updating addon-manifest.json... done`,
]


async run() {
const {args} = await this.parse(Pull)

Expand Down
Loading

0 comments on commit eb29360

Please sign in to comment.