Skip to content

Commit

Permalink
Setup distributable options
Browse files Browse the repository at this point in the history
  • Loading branch information
zerebos committed Mar 29, 2021
1 parent 44b640f commit 06578e0
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 5 deletions.
Binary file added assets/icon.icns
Binary file not shown.
Binary file added assets/icon.ico
Binary file not shown.
31 changes: 26 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "betterdiscord",
"productName": "BetterDiscord",
"description": "test",
"author": "Zerebos",
"description": "Installer for BetterDiscord.",
"author": "BetterDiscord",
"version": "1.0.0",
"license": "MIT",
"scripts": {
Expand Down Expand Up @@ -33,11 +33,32 @@
"build": {
"appId": "app.betterdiscord.installer",
"productName": "BetterDiscord",
"copyright": "Copyright © 2021 BetterDiscord",
"afterAllArtifactBuild": "scripts/fixmac.js",
"win": {
"icon": "assets/icon.ico",
"target": {
"target": "portable",
"arch": ["ia32"]
}
},
"mac": {
"category": "your.app.category.type"
"icon": "assets/icon.icns",
"category": "public.app-category.social-networking",
"target": {
"target": "zip",
"arch": ["x64"]
}
},
"win": {
"target": "portable"
"linux": {
"category": "Utility",
"target": {
"target": "AppImage",
"arch": ["x64"]
}
},
"appImage": {
"license": "assets/license.txt"
}
},
"electronWebpack": {
Expand Down
49 changes: 49 additions & 0 deletions scripts/fixmac.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Exists due to https://github.com/electron-userland/electron-builder/issues/4299
// Tempfix adapted from: https://gist.github.com/harshitsilly/a1bd5a405f93966aad20358ae6c4cec5

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 = packageInfo.build.productName;
const APP_VERSION = process.argv[2] ? process.argv[2] : packageInfo.version;
const APP_DIST_PATH = path.join(currentWorkingDirectory, "dist");


/* eslint-disable no-console */
module.exports = function(buildResult) {
if (!buildResult.artifactPaths.some(p => p.endsWith("mac.zip"))) return console.log("No Mac build detected");
console.log("Zipping Started");

execSync(
`ditto -c -k --sequesterRsrc --keepParent --zlibCompressionLevel 9 "${APP_DIST_PATH}/mac/${APP_NAME}.app" "${APP_DIST_PATH}/${APP_NAME}-${APP_VERSION}-mac.zip"`
);

console.log("Zipping Completed");

const APP_GENERATED_BINARY_PATH = path.join(APP_DIST_PATH, `${APP_NAME}-${APP_VERSION}-mac.zip`);
try {
const output = execSync(
`${appBuilderPath} blockmap --input="${APP_GENERATED_BINARY_PATH}" --output="${APP_DIST_PATH}/${APP_NAME}-${APP_VERSION}-mac.zip.blockmap" --compression=gzip`
);
const {sha512, size} = JSON.parse(output);

const ymlPath = path.join(APP_DIST_PATH, "latest-mac.yml");
const ymlData = yaml.safeLoad(fs.readFileSync(ymlPath, "utf8"));
// console.log(ymlData);
ymlData.sha512 = sha512;
ymlData.files[0].sha512 = sha512;
ymlData.files[0].size = size;
const yamlStr = yaml.safeDump(ymlData);
// console.log(yamlStr);
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);
}
};

0 comments on commit 06578e0

Please sign in to comment.