Skip to content

Commit

Permalink
feat: add Config.versionDetails (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley authored Mar 9, 2023
1 parent 503e263 commit ddddcd9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {fileURLToPath, URL} from 'url'
import {format} from 'util'

import {Options, Plugin as IPlugin} from '../interfaces/plugin'
import {Config as IConfig, ArchTypes, PlatformTypes, LoadOptions} from '../interfaces/config'
import {Config as IConfig, ArchTypes, PlatformTypes, LoadOptions, VersionDetails} from '../interfaces/config'
import {Hook, Hooks, PJSON, Topic} from '../interfaces'
import * as Plugin from './plugin'
import {Debug, compact, loadJSON, collectUsableIds, getCommandIdPermutations} from './util'
Expand Down Expand Up @@ -497,6 +497,19 @@ export class Config implements IConfig {
return [...this._topics.values()]
}

public get versionDetails(): VersionDetails {
const [cliVersion, architecture, nodeVersion] = this.userAgent.split(' ')
return {
cliVersion,
architecture,
nodeVersion,
pluginVersions: Object.fromEntries(this.plugins.map(p => [p.name, {version: p.version, type: p.type, root: p.root}])),
osVersion: `${os.type()} ${os.release()}`,
shell: this.shell,
rootPath: this.root,
}
}

public s3Key(type: keyof PJSON.S3.Templates, ext?: '.tar.gz' | '.tar.xz' | IConfig.s3Key.Options, options: IConfig.s3Key.Options = {}): string {
if (typeof ext === 'object') options = ext
else if (ext) options.ext = ext
Expand Down
10 changes: 10 additions & 0 deletions src/interfaces/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ export type LoadOptions = Options | string | Config | undefined
export type PlatformTypes = 'darwin' | 'linux' | 'win32' | 'aix' | 'freebsd' | 'openbsd' | 'sunos' | 'wsl'
export type ArchTypes = 'arm' | 'arm64' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x32' | 'x64' | 'x86'

export type VersionDetails = {
cliVersion: string;
architecture: string;
nodeVersion: string;
pluginVersions?: Record<string, {version: string; type: string; root: string}>;
osVersion?: string;
shell?: string;
rootPath?: string;
}

export interface Config {
name: string;
version: string;
Expand Down

0 comments on commit ddddcd9

Please sign in to comment.