Skip to content

Commit

Permalink
fix: use version string for channel
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Apr 9, 2018
1 parent ce54ecb commit f0095c3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/node_modules
/package-lock.json
/tmp
/oclif-plugin-update-*.tgz
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"@heroku-cli/color": "^1.1.3",
"@oclif/command": "^1.4.10",
"@oclif/config": "^1.4.7",
"@oclif/config": "^1.4.9",
"@oclif/errors": "^1.0.4",
"@types/semver": "^5.5.0",
"cli-ux": "^3.3.28",
Expand All @@ -21,7 +21,7 @@
"tar-fs": "^1.16.0"
},
"devDependencies": {
"@oclif/dev-cli": "^1.9.11",
"@oclif/dev-cli": "^1.9.14",
"@oclif/plugin-help": "^1.2.3",
"@oclif/test": "^1.0.4",
"@oclif/tslint": "^1.1.0",
Expand Down Expand Up @@ -71,7 +71,7 @@
"scripts": {
"postpack": "rm -f .oclif.manifest.json",
"posttest": "tsc -p test --noEmit && tslint -p test -t stylish",
"prepack": "rm -rf lib && tsc && oclif-dev manifest && oclif-dev readme",
"prepack": "rm -rf lib && tsc && oclif-dev manifest",
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
"version": "oclif-dev readme && git add README.md"
}
Expand Down
16 changes: 7 additions & 9 deletions src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import cli from 'cli-ux'
import * as spawn from 'cross-spawn'
import * as fs from 'fs-extra'
import HTTP from 'http-call'
import * as Lodash from 'lodash'
import * as _ from 'lodash'
import * as path from 'path'
import {URL} from 'url'

import {extract} from '../tar'
import {ls, wait} from '../util'
Expand Down Expand Up @@ -47,16 +48,14 @@ export default class UpdateCommand extends Command {
cli.action.stop()
}

private s3url(p: string): string {
if (!this.s3Host) throw new Error('S3 host not defined')
// TODO: handle s3Prefix
return `${this.s3Host}/${this.config.name}/channels/${this.channel}/${p}`
}

private async fetchManifest(): Promise<ITargetManifest> {
if (!this.s3Host) throw new Error('S3 host not defined')
const http: typeof HTTP = require('http-call').HTTP
try {
let {body} = await http.get(this.s3url(`${this.config.platform}-${this.config.arch}`))
const key = _.template(this.config.pjson.oclif.update.s3.templates.platformManifest)({...this.config, channel: this.channel})
const url = new URL(this.s3Host)
url.pathname = path.join(url.pathname, key)
let {body} = await http.get(url.toString())
return body
} catch (err) {
if (err.statusCode === 403) throw new Error(`HTTP 403: Invalid channel ${this.channel}`)
Expand All @@ -67,7 +66,6 @@ export default class UpdateCommand extends Command {
private async update(manifest: ITargetManifest) {
const {version, channel} = manifest
cli.action.start(`${this.config.name}: Updating CLI from ${color.green(this.config.version)} to ${color.green(version)}${channel === 'stable' ? '' : ' (' + color.yellow(channel) + ')'}`)
const _: typeof Lodash = require('lodash')
const http: typeof HTTP = require('http-call').HTTP
const filesize = require('filesize')
const output = path.join(this.clientRoot, version)
Expand Down
24 changes: 12 additions & 12 deletions test/commands/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,39 @@ describe('update', () => {
await qq.x(`yarn add ${tarball}`)
// await qq.x('yarn')

const release = async (version: string, channel?: string) => {
const release = async (version: string) => {
const pjson = await qq.readJSON('package.json')
pjson.version = version
await qq.writeJSON('package.json', pjson)
await qq.x(`./node_modules/.bin/oclif-dev pack${channel ? ` -c${channel}` : ''}`)
await qq.x(`./node_modules/.bin/oclif-dev publish${channel ? ` -c${channel}` : ''}`)
await qq.x('./node_modules/.bin/oclif-dev pack')
await qq.x('./node_modules/.bin/oclif-dev publish')
}
const checkVersion = async (version: string, nodeVersion = pjson.oclif.update.node.version) => {
const stdout = await qq.x.stdout('./tmp/example-cli/bin/example-cli', ['version'])
expect(stdout).to.equal(`s3-update-example-cli/${version} ${process.platform}-${process.arch} node-v${nodeVersion}`)
}
const resetLocalVersion = async () => {
const update = async (channel?: string) => {
const f = 'tmp/example-cli/package.json'
const pjson = await qq.readJSON(f)
pjson.version = '0.0.0'
await qq.writeJSON(f, pjson)
const args = ['update']
if (channel) args.push(channel)
await qq.x('./tmp/example-cli/bin/example-cli', args)
}
await release('1.0.0')
await checkVersion('1.0.0', process.versions.node)
await resetLocalVersion()
await qq.x('./tmp/example-cli/bin/example-cli', ['update'])
await update()
await checkVersion('1.0.0')

await release('1.0.1')
await checkVersion('1.0.0')
await qq.x.stdout('./tmp/example-cli/bin/example-cli', ['update'])
await update()
await checkVersion('1.0.1')

await release('2.0.0', 'beta')
await release('2.0.0-beta')
await checkVersion('1.0.1')
await qq.x.stdout('./tmp/example-cli/bin/example-cli', ['update'])
await update()
await checkVersion('1.0.1')
await qq.x.stdout('./tmp/example-cli/bin/example-cli', ['update', 'beta'])
await update('beta')
await checkVersion(`2.0.0-beta.${sha}`)
})
})
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@
dependencies:
debug "^3.1.0"

"@oclif/config@^1.4.7":
version "1.4.7"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.4.7.tgz#31edcbffa0f47ca14985cd0da31bf8a11cd9b540"
"@oclif/config@^1.4.9":
version "1.4.9"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.4.9.tgz#62712d1e528c082c5fa2de530da108ccbeedd51a"
dependencies:
debug "^3.1.0"

"@oclif/dev-cli@^1.9.11":
version "1.9.11"
resolved "https://registry.yarnpkg.com/@oclif/dev-cli/-/dev-cli-1.9.11.tgz#3f98c49f5c835f0daefaf474383270d521b1484d"
"@oclif/dev-cli@^1.9.14":
version "1.9.14"
resolved "https://registry.yarnpkg.com/@oclif/dev-cli/-/dev-cli-1.9.14.tgz#322e3eda493e64471cca1bacb902b69b8909fe86"
dependencies:
"@oclif/command" "^1.4.10"
"@oclif/config" "^1.4.7"
"@oclif/config" "^1.4.9"
"@oclif/errors" "^1.0.4"
"@oclif/plugin-help" "^1.2.3"
"@oclif/plugin-warn-if-update-available" "^1.3.0"
Expand Down

0 comments on commit f0095c3

Please sign in to comment.