From 1f27a109b3b502782e519f80e443a7540eb8687f Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Mon, 9 Apr 2018 13:49:01 -0700 Subject: [PATCH] fix: new template format for stable channels --- package.json | 2 ++ src/config.ts | 8 ++++---- test/config.test.ts | 19 +++++++++++++++++++ yarn.lock | 4 ++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 170edfa4..e69bbe38 100644 --- a/package.json +++ b/package.json @@ -14,12 +14,14 @@ "@types/chai": "^4.1.2", "@types/globby": "^6.1.0", "@types/indent-string": "^3.0.0", + "@types/lodash": "^4.14.106", "@types/mocha": "^5.0.0", "@types/node": "^9.6.2", "@types/wrap-ansi": "^3.0.0", "chai": "^4.1.2", "fancy-test": "^1.0.4", "globby": "^8.0.1", + "lodash": "^4.17.5", "mocha": "^5.0.5", "ts-node": "^5.0.1", "tslint": "^5.9.1", diff --git a/src/config.ts b/src/config.ts index 9ea4db46..a16131c2 100644 --- a/src/config.ts +++ b/src/config.ts @@ -186,10 +186,10 @@ export class Config implements IConfig { s3.templates = { platformBaseDir: '<%- bin %>', vanillaBaseDir: '<%- bin %>', - platformTarball: '<%- name %>/channels/<%- channel %>/<%- bin %>-v<%- version %>/<%- bin %>-v<%- version %>-<%- platform %>-<%- arch %>', - vanillaTarball: '<%- name %>/channels/<%- channel %>/<%- bin %>-v<%- version %>/<%- bin %>-v<%- version %>', - platformManifest: '<%- name %>/channels/<%- channel %>/<%- platform %>-<%- arch %>', - vanillaManifest: '<%- name %>/channels/<%- channel %>/version', + platformTarball: "<%- name %><%- channel === 'stable' ? '' : '/channels/' + channel %>/<%- bin %>-v<%- version %>/<%- bin %>-v<%- version %>-<%- platform %>-<%- arch %>", + vanillaTarball: "<%- name %><%- channel === 'stable' ? '' : '/channels/' + channel %>/<%- bin %>-v<%- version %>/<%- bin %>-v<%- version %>", + platformManifest: "<%- name %><%- channel === 'stable' ? '' : '/channels/' + channel %>/<%- platform %>-<%- arch %>", + vanillaManifest: "<%- name %><%- channel === 'stable' ? '' : '/channels/' + channel %>/version", ...s3.templates, } diff --git a/test/config.test.ts b/test/config.test.ts index a92fc92c..5d507fc4 100644 --- a/test/config.test.ts +++ b/test/config.test.ts @@ -1,3 +1,4 @@ +import * as _ from 'lodash' import * as os from 'os' import * as path from 'path' @@ -20,6 +21,24 @@ describe('PluginConfig', () => { dataDir: path.join('/my/home/.local/share/@oclif/config'), home: path.join('/my/home'), }) + const checkTemplate = (k: keyof Config.PJSON.Plugin['oclif']['update']['s3']['templates'], expected: string, extra: any = {}) => { + expect(_.template(config.pjson.oclif.update.s3.templates[k])({ + ...config, + bin: 'oclif-cli', + version: '1.0.0', + ...extra + })).to.equal(expected) + } + checkTemplate('platformBaseDir', 'oclif-cli') + checkTemplate('vanillaBaseDir', 'oclif-cli') + checkTemplate('platformTarball', '@oclif/config/oclif-cli-v1.0.0/oclif-cli-v1.0.0-darwin-x64') + checkTemplate('platformManifest', '@oclif/config/darwin-x64') + checkTemplate('vanillaManifest', '@oclif/config/version') + checkTemplate('vanillaTarball', '@oclif/config/channels/beta/oclif-cli-v2.0.0-beta/oclif-cli-v2.0.0-beta', {version: '2.0.0-beta', channel: 'beta'}) + checkTemplate('platformTarball', '@oclif/config/channels/beta/oclif-cli-v2.0.0-beta/oclif-cli-v2.0.0-beta-darwin-x64', {version: '2.0.0-beta', channel: 'beta'}) + checkTemplate('platformManifest', '@oclif/config/channels/beta/darwin-x64', {version: '2.0.0-beta', channel: 'beta'}) + checkTemplate('vanillaManifest', '@oclif/config/channels/beta/version', {version: '2.0.0-beta', channel: 'beta'}) + checkTemplate('vanillaTarball', '@oclif/config/channels/beta/oclif-cli-v2.0.0-beta/oclif-cli-v2.0.0-beta', {version: '2.0.0-beta', channel: 'beta'}) }) fancy diff --git a/yarn.lock b/yarn.lock index 08ad0161..2390104f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -55,6 +55,10 @@ version "3.0.0" resolved "https://registry.yarnpkg.com/@types/indent-string/-/indent-string-3.0.0.tgz#9ebb391ceda548926f5819ad16405349641b999f" +"@types/lodash@^4.14.106": + version "4.14.106" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.106.tgz#6093e9a02aa567ddecfe9afadca89e53e5dce4dd" + "@types/minimatch@*": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"