Skip to content

Commit

Permalink
feat(deployment): expand macros in all publish options (#1349)
Browse files Browse the repository at this point in the history
S3 options can now contain macros to allow something like this:
```
"publish": {
    "provider": "s3",
    "bucket": "some-bucket",
    "path": "${os}/${env.SOME_ENV}"
}
```
Now `bucket`, `path` and `channel` can contain macros. Previously these options couldn't be configured with macros.
  • Loading branch information
piotrdubiel authored and develar committed Mar 11, 2017
1 parent 0601352 commit 24fdf1d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ export class PublishManager implements PublishContext {
}

let publishConfig = publishConfigs[0]
if ((<GenericServerOptions>publishConfig).url != null) {
publishConfig = Object.assign({}, publishConfig, {
url: packager.expandMacro((<GenericServerOptions>publishConfig).url, null)
})
}

if (packager.platform === Platform.WINDOWS) {
const publisherName = await (<WinPackager>packager).computedPublisherName.value
Expand Down Expand Up @@ -309,7 +304,7 @@ export function createPublisher(context: PublishContext, version: string, publis

export function computeDownloadUrl(publishConfig: PublishConfiguration, fileName: string | null, packager: PlatformPackager<any>, arch: Arch | null) {
if (publishConfig.provider === "generic") {
const baseUrlString = packager.expandMacro((<GenericServerOptions>publishConfig).url, arch)
const baseUrlString = (<GenericServerOptions>publishConfig).url
if (fileName == null) {
return baseUrlString
}
Expand Down Expand Up @@ -380,7 +375,22 @@ export async function getPublishConfigs(packager: PlatformPackager<any>, targetS
}

debug(`Explicit publish provider: ${JSON.stringify(publishers, null, 2)}`)
return await <Promise<Array<PublishConfiguration>>>BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(packager.info, typeof it === "string" ? {provider: it} : it))
return await (<Promise<Array<PublishConfiguration>>>BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(packager.info, typeof it === "string" ? {provider: it} : it)))
.then(publishConfigs => expandPublishConfigs(packager, publishConfigs))
}

function expandPublishConfigs(packager: PlatformPackager<any>, publishConfigs: Array<PublishConfiguration>) {
return publishConfigs.map(publishConfig => expandPublishConfig(packager, publishConfig))
}

function expandPublishConfig(packager: PlatformPackager<any>, publishConfig: any): PublishConfiguration {
return <PublishConfiguration>Object.keys(publishConfig).reduce((expandedPublishConfig: {[key: string]: string}, key) => {
const option = publishConfig[key]
if (option != null) {
expandedPublishConfig[key] = packager.expandMacro(option, null)
}
return expandedPublishConfig
}, {})
}

function sha256(file: string) {
Expand Down

0 comments on commit 24fdf1d

Please sign in to comment.