Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 43 additions & 51 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ const gulp = require('gulp'),
princePackager = require('./src/js/prince-packager'),
debInstaller = require('electron-installer-debian'),
dmgInstaller = require('electron-installer-dmg'),
packageJson = require("./package.json"),
AdmZip = require('adm-zip');
packageJson = require("./package.json");

const APP_NAME = 'BTT-Writer',
JS_FILES = './src/js/**/*.js',
UNIT_TEST_FILES = './unit_tests/**/*.js',
BUILD_DIR = 'out/',
RELEASE_DIR = 'release/';
RELEASE_DIR = 'release/',
MAC_ARCHS = ['arm64', 'x64'];


function clean(done) {
Expand Down Expand Up @@ -55,14 +55,6 @@ gulp.task('prince', function(done) {
.catch(() => done());
});

function zipDirectory(sourceDir, destPath, outPath) {
return new Promise((resolve, reject) => {
const zip = new AdmZip(undefined, {});
zip.addLocalFolder(sourceDir, destPath);
zip.writeZip(outPath, err => err ? reject(err) : resolve());
});
}

function build(done) {

const platforms = [];
Expand Down Expand Up @@ -98,26 +90,28 @@ function build(done) {
// Also ignore all dot files and folders
ignored.push(/[/\\]\.[^/\\]+/);

packager({
arch: ['x64', 'universal'],
platform: platforms,
dir: '.',
prune: true,
ignore: ignored,
out: BUILD_DIR,
appVersion: packageJson.version,
icon: './icons/icon',
osxUniversal: {
'x64ArchFiles': '*'
},
afterCopy: [
(buildPath, electronVersion, platform, arch, callback) => {
rebuild.rebuild({ buildPath, electronVersion, arch })
.then(() => callback())
.catch((error) => callback(error));
},
],
}).then(() => done())
const packagePlatform = function (platform) {
return packager({
arch: platform === 'darwin' ? MAC_ARCHS : ['x64'],
platform: platform,
dir: '.',
prune: true,
ignore: ignored,
out: BUILD_DIR,
appVersion: packageJson.version,
icon: './icons/icon',
afterCopy: [
(buildPath, electronVersion, platform, arch, callback) => {
rebuild.rebuild({ buildPath, electronVersion, arch })
.then(() => callback())
.catch((error) => callback(error));
},
],
});
};

Promise.all(platforms.map(packagePlatform))
.then(() => done())
.catch(err => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, this catch() will log the error and then call done(), allowing the build to continue. I think we should consider erroring out instead so that we don't accidentally (and silently) release a broken build.

console.log(err)
done()
Expand Down Expand Up @@ -212,11 +206,12 @@ function release(done){
}

const releaseDmg = function (arch) {
const name = `BTT-Writer-${packageJson.version}-osx`;
const name = `BTT-Writer-${packageJson.version}-osx-${arch}`;
let buildPath = BUILD_DIR + `BTT-Writer-darwin-${arch}/BTT-Writer.app`;
const options = {
appPath: buildPath,
name: name,
title: APP_NAME,

@PurpleGuitar PurpleGuitar Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you made the title APP_NAME + "-" + ${arch}, would that remove the need for the "tricky" code below? It might let you run the builds in parallel too.

out: RELEASE_DIR,
icon: "icons/icon.icns"
}
Expand All @@ -237,37 +232,34 @@ function release(done){
return await releaseWin('64', os);

case 'darwin':
let arch = 'universal';
let macBuildPath = BUILD_DIR + `BTT-Writer-darwin-${arch}/`;
if (!fs.existsSync(macBuildPath)) {
// fallback to x64 arch
arch = "x64";
macBuildPath = BUILD_DIR + `BTT-Writer-darwin-${arch}/`;
}

if (!fs.existsSync(macBuildPath)) {
throw new Error('Missing build');
}
const macPaths = [];

const macDest = `${RELEASE_DIR}BTT-Writer-${packageJson.version}-osx-${arch}.zip`;
// TRICKY: appdmg mounts a volume per dmg, so the archs are
// released one after the other instead of in parallel
for (const arch of MAC_ARCHS) {
if (!fs.existsSync(BUILD_DIR + `BTT-Writer-darwin-${arch}/`)) {
throw new Error(`Missing ${arch} build`);
}

await zipDirectory(macBuildPath + 'BTT-Writer.app/', 'BTT-Writer.app', macDest);
await releaseDmg(arch);
await releaseDmg(arch);
macPaths.push(`${RELEASE_DIR}BTT-Writer-${packageJson.version}-osx-${arch}.dmg`);
}

return {os: os, status: 'ok', path: macDest};
return {os: os, status: 'ok', path: macPaths.join(', ')};

case 'linux':
const linuxBuildPath = BUILD_DIR + 'BTT-Writer-linux-x64/';
if (!fs.existsSync(linuxBuildPath)) {
throw new Error('Missing build');
}

const linuxDest = `${RELEASE_DIR}BTT-Writer-${packageJson.version}-linux-x64.zip`;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the Linux .zip download? The .deb target only works for Debian-based Linux targets.


await zipDirectory(linuxBuildPath, 'BTT-Writer', linuxDest);
await releaseDeb("amd64", os);

return {os: os, status: 'ok', path: linuxDest};
return {
os: os,
status: 'ok',
path: `${RELEASE_DIR}btt-writer_${packageJson.version}_amd64.deb`
};

default:
console.warn('No release procedure for ' + os);
Expand Down
Loading