Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Electron builder rebuild zip and update blockmap to work with auto-updater.
const path = require('path');
const { execSync } = require('child_process');
const fs = require('fs');
const yaml = require('js-yaml');
const { appBuilderPath } = require('app-builder-bin');
const currentWorkingDirectory = process.cwd();
const packageInfo = require(path.join(currentWorkingDirectory, 'package.json'));
const APP_NAME =;
const APP_VERSION = process.argv[2] ? process.argv[2] : packageInfo.version;
const APP_DIST_PATH = path.join(currentWorkingDirectory, 'dist');
console.log('Zipping Started');
`ditto -c -k --sequesterRsrc --keepParent --zlibCompressionLevel 9 "${APP_DIST_PATH}/mac/${APP_NAME}.app" "${APP_DIST_PATH}/${APP_NAME}-${APP_VERSION}"`
console.log('Zipping Completed');
(function() {
try {
let output = execSync(
`${appBuilderPath} blockmap --input="${APP_GENERATED_BINARY_PATH}" --output="${APP_DIST_PATH}/${APP_NAME}-${APP_VERSION}" --compression=gzip`
let { sha512, size } = JSON.parse(output);
const ymlPath = path.join(APP_DIST_PATH, 'latest-mac.yml');
let ymlData = yaml.safeLoad(fs.readFileSync(ymlPath, 'utf8'));
ymlData.sha512 = sha512;
ymlData.files[0].sha512 = sha512;
ymlData.files[0].size = size;
let yamlStr = yaml.safeDump(ymlData);
fs.writeFileSync(ymlPath, yamlStr, 'utf8');
console.log('Successfully updated YAML file and configurations with blockmap.');
} catch (e) {
console.log('Error in updating YAML file and configurations with blockmap.', e);

This comment has been minimized.

Copy link

@thomasdarde thomasdarde commented Jul 23, 2020

Thanks for the gist , 2 changes on my side

line 11: (latest is the deploy channel)

const APP_DIST_PATH = path.join(currentWorkingDirectory, 'dist/latest');

line 25 to allow app names with spaces some quotes where needed :

let output = execSync(
      `${appBuilderPath} blockmap --input="${APP_GENERATED_BINARY_PATH}" --output="${APP_DIST_PATH}/${APP_NAME}-${APP_VERSION}" --compression=gzip`

This comment has been minimized.

Copy link
Owner Author

@harshitsilly harshitsilly commented Jul 24, 2020

thanks thomas , i will add the channel mentioned in package.json and the second one also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment