Skip to content

Commit

Permalink
fix: propagate channel information
Browse files Browse the repository at this point in the history
  • Loading branch information
sumwatshade committed Jun 2, 2021
1 parent 2476e71 commit d676bb8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default class UpdateCommand extends Command {
await extraction
}

protected async update(manifest: IManifest, channel = 'stable') {
protected async update(manifest: IManifest, channel = this.channel) {
const {channel: manifestChannel} = manifest
if (manifestChannel) channel = manifestChannel
cli.action.start(`${this.config.name}: Updating CLI from ${color.green(this.currentVersion)} to ${color.green(this.updatedVersion)}${channel === 'stable' ? '' : ' (' + color.yellow(channel) + ')'}`)
Expand All @@ -195,6 +195,7 @@ export default class UpdateCommand extends Command {
}

protected async updateToExistingVersion(version: string) {
await this.setChannel()
await this.createBin(version)
await this.touch()
}
Expand All @@ -214,9 +215,11 @@ export default class UpdateCommand extends Command {

protected async determineChannel(): Promise<string> {
const channelPath = path.join(this.config.dataDir, 'channel')
this.debug(`Reading channel from ${channelPath}`)
if (fs.existsSync(channelPath)) {
const channel = await fs.readFile(channelPath, 'utf8')
return String(channel).trim()
this.debug(`Read channel from data: ${channel.toString()}`)
return channel.toString().trim()
}
return this.config.channel || 'stable'
}
Expand All @@ -240,6 +243,7 @@ export default class UpdateCommand extends Command {

protected async setChannel() {
const channelPath = path.join(this.config.dataDir, 'channel')
this.debug(`Writing channel (${this.channel}) to ${channelPath}`)
fs.writeFile(channelPath, this.channel, 'utf8')
}

Expand Down Expand Up @@ -315,7 +319,8 @@ export default class UpdateCommand extends Command {
cli.action.stop()
return new Promise((_, reject) => {
this.debug('restarting CLI after update', this.clientBin)
spawn(this.clientBin, ['update'], {
const commandArgs = ['update', this.channel ? this.channel : ''].filter(Boolean)
spawn(this.clientBin, commandArgs, {
stdio: 'inherit',
env: {...process.env, [this.config.scopedEnvVarKey('HIDE_UPDATED_MESSAGE')]: '1'},
})
Expand Down

0 comments on commit d676bb8

Please sign in to comment.