Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
feat: added s3Url()
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Apr 10, 2018
1 parent ea3c0b4 commit 1930702
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as Lodash from 'lodash'
import * as os from 'os'
import * as path from 'path'
import {format} from 'util'
import {URL} from 'url'

import {Command} from './command'
import Debug from './debug'
Expand Down Expand Up @@ -114,6 +115,7 @@ export interface IConfig {
scopedEnvVar(key: string): string | undefined
scopedEnvVarKey(key: string): string
scopedEnvVarTrue(key: string): boolean
s3Url(key: string): string
s3Key(type: 'versioned' | 'unversioned', ext: '.tar.gz' | '.tar.xz', options?: IConfig.s3Key.Options): string
s3Key(type: keyof PJSON.S3.Templates, options?: IConfig.s3Key.Options): string
}
Expand Down Expand Up @@ -366,6 +368,13 @@ export class Config implements IConfig {
const _: typeof Lodash = require('lodash')
return _.template(this.pjson.oclif.update.s3.templates[options.platform ? 'target' : 'vanilla'][type])({...this as any, ...options})
}
s3Url(key: string) {
const host = this.pjson.oclif.update.s3.host
if (!host) throw new Error('no s3 host is set')
const url = new URL(host)
url.pathname = path.join(url.pathname, key)
return url.toString()
}

protected dir(category: 'cache' | 'data' | 'config'): string {
const base = process.env[`XDG_${category.toUpperCase()}_HOME`]
Expand Down
8 changes: 8 additions & 0 deletions test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,12 @@ describe('Config', () => {
.hasS3Key('versioned', '@oclif/config/channels/beta/oclif-cli-v2.0.0-beta/oclif-cli-v2.0.0-beta.tar.gz', beta)
.hasS3Key('versioned', '@oclif/config/channels/beta/oclif-cli-v2.0.0-beta/oclif-cli-v2.0.0-beta-darwin-x64.tar.gz', {...beta, ...target})
})

testConfig()
.it('has s3Url', config => {
const orig = config.pjson.oclif.update.s3.host
config.pjson.oclif.update.s3.host = 'https://bar.com/a/'
expect(config.s3Url('/b/c')).to.equal('https://bar.com/a/b/c')
config.pjson.oclif.update.s3.host = orig
})
})

0 comments on commit 1930702

Please sign in to comment.