-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
- Loading branch information
There are no files selected for viewing
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 GitHub Actions / Node Tests (20.x, ubuntu-latest)
Check warning on line 2 in src/addon.ts GitHub Actions / Node Tests (22.x, macos-latest)
Check warning on line 2 in src/addon.ts GitHub Actions / Node Tests (22.x, ubuntu-latest)
Check warning on line 2 in src/addon.ts GitHub Actions / Node Tests (20.x, macos-latest)
Check warning on line 2 in src/addon.ts GitHub Actions / Node Tests (22.x, windows-latest)
|
||
import {ux} from '@oclif/core' | ||
Check warning on line 3 in src/addon.ts GitHub Actions / Node Tests (20.x, ubuntu-latest)
Check warning on line 3 in src/addon.ts GitHub Actions / Node Tests (22.x, macos-latest)
Check warning on line 3 in src/addon.ts GitHub Actions / Node Tests (22.x, ubuntu-latest)
Check warning on line 3 in src/addon.ts GitHub Actions / Node Tests (20.x, macos-latest)
Check warning on line 3 in src/addon.ts GitHub Actions / Node Tests (22.x, windows-latest)
Check warning on line 3 in src/addon.ts GitHub Actions / Node Tests (20.x, windows-latest)
|
||
import {Config} from '@oclif/core' | ||
Check warning on line 4 in src/addon.ts GitHub Actions / Node Tests (20.x, ubuntu-latest)
Check warning on line 4 in src/addon.ts GitHub Actions / Node Tests (22.x, macos-latest)
Check warning on line 4 in src/addon.ts GitHub Actions / Node Tests (22.x, ubuntu-latest)
Check warning on line 4 in src/addon.ts GitHub Actions / Node Tests (20.x, macos-latest)
Check warning on line 4 in src/addon.ts GitHub Actions / Node Tests (22.x, windows-latest)
Check warning on line 4 in src/addon.ts GitHub Actions / Node Tests (20.x, windows-latest)
|
||
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 | ||
|
@@ -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[]> { | ||
|
@@ -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 | ||
} | ||
} |