Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 0 deletions src/command/root-command/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { parseHeaders } from '../../utils'
import { ConfigOption } from '../../utils/types/config-option'
import { CONFIG_OPTIONS, CommandConfig } from './command-config'
import { CommandLog, VerbosityLevel } from './command-log'
import { checkForUpdates } from '../../service/version_checker'

export class RootCommand {
@ExternalOption('bee-api-url')
Expand Down Expand Up @@ -57,6 +58,8 @@ export class RootCommand {
this.commandConfig = new CommandConfig(this.appName, this.console, this.configFile, this.configFolder)
this.sourcemap = Utils.getSourcemap()

checkForUpdates()

CONFIG_OPTIONS.forEach((option: ConfigOption) => {
this.maybeSetFromConfig(option)
})
Expand Down
22 changes: 22 additions & 0 deletions src/service/version_checker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import PackageJson from '../../package.json'
import { CommandLog, VerbosityLevel } from '../command/root-command/command-log'
import { warningText } from '../utils/text'

const LATEST_RELEASE_URL = 'https://api.github.com/repos/ethersphere/swarm-cli/releases/latest'

export async function checkForUpdates() {
const console = new CommandLog(VerbosityLevel.Normal)
await fetch(LATEST_RELEASE_URL)
.then(res => res.json())
.then((data: { tag_name: string }) => {
const latestVersion = data.tag_name.replace(/^v/, '')

if (latestVersion !== PackageJson.version) {
console.log(
warningText(
`A new version of swarm-cli is available: ${latestVersion}. You are using version ${PackageJson.version}. Please update to the latest version.`,
),
)
}
})
}
Loading