Skip to content

Commit 24fdf1d

Browse files
piotrdubieldevelar
authored andcommitted
feat(deployment): expand macros in all publish options (#1349)
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.
1 parent 0601352 commit 24fdf1d

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

packages/electron-builder/src/publish/PublishManager.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ export class PublishManager implements PublishContext {
8181
}
8282

8383
let publishConfig = publishConfigs[0]
84-
if ((<GenericServerOptions>publishConfig).url != null) {
85-
publishConfig = Object.assign({}, publishConfig, {
86-
url: packager.expandMacro((<GenericServerOptions>publishConfig).url, null)
87-
})
88-
}
8984

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

310305
export function computeDownloadUrl(publishConfig: PublishConfiguration, fileName: string | null, packager: PlatformPackager<any>, arch: Arch | null) {
311306
if (publishConfig.provider === "generic") {
312-
const baseUrlString = packager.expandMacro((<GenericServerOptions>publishConfig).url, arch)
307+
const baseUrlString = (<GenericServerOptions>publishConfig).url
313308
if (fileName == null) {
314309
return baseUrlString
315310
}
@@ -380,7 +375,22 @@ export async function getPublishConfigs(packager: PlatformPackager<any>, targetS
380375
}
381376

382377
debug(`Explicit publish provider: ${JSON.stringify(publishers, null, 2)}`)
383-
return await <Promise<Array<PublishConfiguration>>>BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(packager.info, typeof it === "string" ? {provider: it} : it))
378+
return await (<Promise<Array<PublishConfiguration>>>BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(packager.info, typeof it === "string" ? {provider: it} : it)))
379+
.then(publishConfigs => expandPublishConfigs(packager, publishConfigs))
380+
}
381+
382+
function expandPublishConfigs(packager: PlatformPackager<any>, publishConfigs: Array<PublishConfiguration>) {
383+
return publishConfigs.map(publishConfig => expandPublishConfig(packager, publishConfig))
384+
}
385+
386+
function expandPublishConfig(packager: PlatformPackager<any>, publishConfig: any): PublishConfiguration {
387+
return <PublishConfiguration>Object.keys(publishConfig).reduce((expandedPublishConfig: {[key: string]: string}, key) => {
388+
const option = publishConfig[key]
389+
if (option != null) {
390+
expandedPublishConfig[key] = packager.expandMacro(option, null)
391+
}
392+
return expandedPublishConfig
393+
}, {})
384394
}
385395

386396
function sha256(file: string) {

0 commit comments

Comments
 (0)