-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor FlowVersionProvider & use
cadence.flowCommand
from Settings (
#518)
- Loading branch information
Showing
8 changed files
with
121 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Settings } from '../settings/settings' | ||
import { execDefault } from '../utils/shell/exec' | ||
import { StateCache } from '../utils/state-cache' | ||
import * as semver from 'semver' | ||
|
||
const CHECK_FLOW_CLI_CMD = (flowCommand: string): string => `${flowCommand} version` | ||
|
||
export class FlowVersionProvider { | ||
#settings: Settings | ||
#stateCache: StateCache<semver.SemVer | null> | ||
#parseCliVersion: (buffer: Buffer | string) => string | ||
|
||
constructor (settings: Settings, parseCliVersion: (buffer: Buffer | string) => string = parseFlowCliVersion) { | ||
this.#stateCache = new StateCache<semver.SemVer | null>(async () => await this.#fetchFlowVersion()) | ||
this.#settings = settings | ||
this.#parseCliVersion = parseCliVersion | ||
} | ||
|
||
async #fetchFlowVersion (): Promise<semver.SemVer | null> { | ||
try { | ||
// Get user's version informaton | ||
const buffer: string = (await execDefault(CHECK_FLOW_CLI_CMD( | ||
this.#settings.getSettings().flowCommand | ||
))).stdout | ||
|
||
// Format version string from output | ||
let versionStr: string | null = this.#parseCliVersion(buffer) | ||
|
||
versionStr = semver.clean(versionStr) | ||
if (versionStr === null) return null | ||
|
||
// Ensure user has a compatible version number installed | ||
const version: semver.SemVer | null = semver.parse(versionStr) | ||
if (version === null) return null | ||
|
||
return version | ||
} catch { | ||
return null | ||
} | ||
} | ||
|
||
refresh (): void { | ||
this.#stateCache.invalidate() | ||
} | ||
|
||
async getVersion (): Promise<semver.SemVer | null> { | ||
return await this.#stateCache.getValue() | ||
} | ||
|
||
get state$ (): StateCache<semver.SemVer | null> { | ||
return this.#stateCache | ||
} | ||
} | ||
|
||
export function parseFlowCliVersion (buffer: Buffer | string): string { | ||
return (buffer.toString().split('\n')[0]).split(' ')[1] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters