Electron-builder: Allow pass configuration to custom electron-publisher provider

Created on 21 Aug 2018  路  6Comments  路  Source: electron-userland/electron-builder


  • Electron-builder version: 20.28.1

  • Electron-updater version: 3.1.1

  • Target: Windows


Hi.

I try to make custom electron-publisher provider and i have two problems:

  1. I cannot pass any configuration to it by package.json ex:
  "build": {
    "appId": "appId",
    "productName": "productName",
    "publish": [
      {
        "provider": "generic",
        "url": "http://hostname:port/${name}/${os}/${arch}/${channel}/${version}/"
      },
      {
         "provider":  "custom",
         "url": "http://hostname:port/${name}/${os}/${arch}/${channel}/${version}/"
      }
    ]
  }

Will not pass configuration validation.

  1. I d`not know how to get installer meta info - os, channel, version etc. in doUpload function.

I have almost working solution but everything is hard coded into it:

node_modules/electron-publisher-custom/index.js

const {
  getCiTag,
  HttpPublisher,
  PublishContext,
  PublishOptions
} = require("electron-publish/out/publisher");
const { httpExecutor } = require("builder-util/out/nodeHttpExecutor");
const mime = require("mime");
const { configureRequestOptions } = require("builder-util-runtime");

class Publisher extends HttpPublisher {
  async doUpload(fileName, arch, dataLength, requestProcessor, file) {
    return await httpExecutor.doApiRequest(
      configureRequestOptions({
        hostname: "my.host.name", // TODO: from configuration
        protocol: "http:", // TODO: from configuration
        port: 8888, // TODO: from configuration
        path: "/some/path", // TODO: from configuration mixed with file meta about name/os/channel etc
        method: "POST",
        headers: {
          "X-File-Name": fileName,
          "Content-Type": mime.getType(fileName) || "application/octet-stream",
          "Content-Length": dataLength
        }
      }),
      this.context.cancellationToken,
      requestProcessor
    );
  }
}

module.exports = {
  default: Publisher
};

package.json:

  "build": {
    "appId": "appId",
    "productName": "productName",
    "publish": [
      {
        "provider": "generic",
        "url": "http://hostname:port/${name}/${os}/${arch}/${channel}/${version}/"
      },
      "custom"
    ]
  }
feature

Most helpful comment

    publish: {
      provider: "custom",
      boo: "foo",
    },

is allowed now (upcoming 20.31.1). Any property is allowed under publish configuration if provider is set to custom.

In addition to this, now you can put electron-publisher-${provider} under build resources dir (see custom provider test for example).

All 6 comments

I just create a project that describe my problem:

https://github.com/zalewskip123/electron-publisher-simple-http

For what do you need simple http publisher if you can use https://www.minio.io?

@develar
To integrate publishing process with my company infrastructure and processes.

We are doing not use minio or other cloud solutions at the moment.

Anyway my current implementation is good enough 馃槈 for company purposes so if there will be more 馃憥 for this I will close this issue.

Ok, if you want to use your own solution instead of deploy minio and understand what are you doing, issue makes sense.

In terms of getting installer info dynamically, you could always try using file macros.

    publish: {
      provider: "custom",
      boo: "foo",
    },

is allowed now (upcoming 20.31.1). Any property is allowed under publish configuration if provider is set to custom.

In addition to this, now you can put electron-publisher-${provider} under build resources dir (see custom provider test for example).

Was this page helpful?
0 / 5 - 0 ratings