Skip to content

Instantly share code, notes, and snippets.

@hgouveia
Last active December 2, 2020 11:13
Show Gist options
  • Save hgouveia/91727cade15fb931993eedc41efa9a62 to your computer and use it in GitHub Desktop.
Save hgouveia/91727cade15fb931993eedc41efa9a62 to your computer and use it in GitHub Desktop.
electron-builder s3 publisher, to be able to triggered it manually reusing a preexisting file
'use strict';
// Alternative version
const { PublishManager } = require('app-builder-lib/out/publish/PublishManager');
const { normalizeOptions } = require('electron-builder/out/builder');
const { Packager } = require('app-builder-lib/out/packager');
const pkg = require('../package.json');
const argv = require('yargs').argv;
const buildFile = argv.file.replace('${version}', pkg.version);
const buildDir = argv.buildDir || './build/';
const channel = argv.channel || 'latest';
const publisherInfo = {
path: null,
provider: "s3",
channel: channel,
bucket: "bucket-name",
region: "region-name"
};
const options = normalizeOptions({
x64: true,
windows: [],
publish: 'always'
});
const packager = new Packager(options);
const publishManager = new PublishManager(packager, options);
const upload = async () => {
const artifacts = [
`${buildDir}/${buildFile}`,
`${buildDir}/${buildFile}.blockmap`,
`${buildDir}/${channel}.yml`,
];
for (const artifact of artifacts) {
publishManager.scheduleUpload(publisherInfo,
{ file: artifact, arch: null },
{
version: pkg.version,
buildNumber: undefined,
buildVersion: pkg.version,
});
}
await publishManager.awaitTasks();
}
try {
upload();
} catch (err) {
packager.cancellationToken.cancel();
publishManager.cancelTasks();
}
'use strict';
/**
* Usage: node s3publisher.js --file=MyApp-v1.0.0.exe --channel=beta
* Options:
* --file: distributable file, normally nsis installer, dmg, snap, etc
* --buildDir: (optional) folder where the files are located (default: ./build)
* --channel: (optional) channel to upload yml
*/
const { MultiProgress } = require("electron-publish/out/multiProgress");
const { CancellationToken } = require('builder-util-runtime');
// is using s3 but you could choose another one under the 'app-builder-lib/out/publish' folder
const S3Publisher = require('app-builder-lib/out/publish/s3/s3Publisher').default;
// const S3Publisher = require('electron-publisher-s3').default;
const argv = require('yargs').argv;
const buildDir = argv.buildDir || './build/';
const channel = argv.channel || 'latest';
const publisherContext = {
cancellationToken: new CancellationToken(),
progress: new MultiProgress()
};
// it uses the same config: https://www.electron.build/configuration/publish#s3options
const publisherInfo = {
path: null,
provider: "s3",
channel: channel,
bucket: "bucket-name",
region: "region-name"
};
const publisher = new S3Publisher(publisherContext, publisherInfo);
const upload = async () => {
try {
await publisher.upload({ file: `${buildDir}/${argv.file}` });
await publisher.upload({ file: `${buildDir}/${argv.file}.blockmap` });
await publisher.upload({ file: `${buildDir}/${channel}.yml` });
} catch (err) {
console.error('Publisher Failed', err);
}
};
upload();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment