Skip to content

Commit

Permalink
Introduced DMG builds
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Jul 4, 2024
1 parent 6c2ff06 commit 369e21d
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 55 deletions.
25 changes: 8 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,27 @@ jobs:
- name: Install Dependencies
run: npm ci

- name: Build app
run: npm run build
- name: Build and package app
run: npm run build:release

- name: Get version from package.json
id: get_version
run: echo "VERSION=$(jq -r .version package.json)" >> $GITHUB_ENV

- name: Zip artifacts
run: |
cd dist
for dir in */; do
zip -r "${dir%/}_${VERSION}.zip" "$dir"
done
env:
VERSION: ${{ env.VERSION }}

- name: Upload (mac_x64)
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}_x64_${{ env.VERSION }}
path: dist/mac_x64_${{ env.VERSION }}.zip
name: dist/AppleBlox-${{ env.VERSION }}_x64.dmg
path: dist/AppleBlox-${{ env.VERSION }}_x64.dmg

- name: Upload (mac_universal)
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}_universal_${{ env.VERSION }}
path: dist/mac_universal_${{ env.VERSION }}.zip
name: AppleBlox-${{ env.VERSION }}_universal.dmg
path: dist/AppleBlox-${{ env.VERSION }}_universal.dmg

- name: Upload (mac_arm64)
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}_arm64_${{ env.VERSION }}
path: dist/mac_arm64_${{ env.VERSION }}.zip
name: AppleBlox-${{ env.VERSION }}_arm64.dmg
path: dist/AppleBlox-${{ env.VERSION }}_arm64.dmg
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ If you're worried that those could be modified by me or another contributor to i

## Developpement

To setup the app on your machine, clone this repo and run `npm install`.
To setup the app on your machine, clone this repo and run `npm install`. You will also need to install some packages with the command: `brew install create-dmg`.

To start the **dev environnement**, run `npm run dev`.
To **build and package the app**, run `npm run build`.

To **build**, run `npm run build`. (If you don't want to create dmgs)

To **build and package the app**, run `npm run build:release`.

The app is made with [Svelte](https://svelte.dev) (Frontend) and [NeutralinoJS](https://neutralino.js.org) (Backend).
If you haven't heard about NeutralinoJS, it is a lightweight alternative coded in **c++** to frameworks like Electron or NW.JS. It is still growing, but is stable enough to be used on one platform. You can learn more about it on https://neutralino.js.org/docs.
Expand Down
Binary file added build/assets/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/assets/mac.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed build/lib/MacOS/alerter_ablox
Binary file not shown.
Binary file removed build/lib/MacOS/discordrpc_ablox
Binary file not shown.
25 changes: 0 additions & 25 deletions build/lib/MacOS/process_manager

This file was deleted.

57 changes: 46 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"vite:dev": "vite",
"dev": "vite-node scripts/package/dev.ts",
"build": "vite-node scripts/build/ts/index.ts",
"build:release": "npm run build && vite-node scripts/build/ts/dmg.ts",
"check": "svelte-check --tsconfig ./tsconfig.json",
"neu:empty": ""
},
Expand All @@ -24,11 +25,13 @@
"@neutralinojs/neu": "^10.1.0",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@tsconfig/svelte": "^5.0.2",
"@types/fs-extra": "^11.0.4",
"@types/path-browserify": "^1.0.2",
"@types/signale": "^1.4.7",
"@types/tar": "^6.1.11",
"autoprefixer": "^10.4.19",
"await-exec-typescript": "github:artemhp/await-exec-typescript",
"fs-extra": "^11.2.0",
"jszip": "^3.10.1",
"postcss": "^8.4.38",
"resedit": "^2.0.0",
Expand Down
113 changes: 113 additions & 0 deletions scripts/build/ts/dmg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import * as child_process from "child_process";
import * as path from "path";
import * as fs from "fs-extra";
import BuildConfig from "@root/build.config";
import { Signale } from "signale";
import { version } from "../../../package.json";

interface DmgOptions {
sourceFolder: string;
outputName: string;
volumeName?: string;
backgroundPath?: string;
windowPos?: string;
windowSize?: string;
textSize?: number;
iconSize?: number;
iconPos?: string;
appDropLink?: string;
}

async function createCustomDMG(options: DmgOptions) {
const {
sourceFolder,
outputName,
volumeName,
backgroundPath,
windowPos,
windowSize,
textSize,
iconSize,
iconPos,
appDropLink,
} = options;

// Prepare command arguments
const args = [
`--volname "${volumeName || outputName}"`,
`--background "${backgroundPath}"`,
`--window-pos ${windowPos || "200 120"}`, // Default to '200 120' if not provided
`--window-size ${windowSize || "800 400"}`, // Default to '800 400' if not provided
`--text-size ${textSize || 12}`, // Default to 12 if not provided
`--icon-size ${iconSize || 100}`, // Default to 100
iconPos ? `--icon "${BuildConfig.appName}.app" ${iconPos}` : "", // Icon position (left, y centered)
`--app-drop-link ${appDropLink || "600 120"}`, // Default to '600 120' (right side) if not provided
`"${outputName}.dmg"`,
`"${sourceFolder}"`,
];

const createDmgCommand = `create-dmg ${args.join(" ")}`;

console.log("Creating DMG...");
try {
await executeCommand(createDmgCommand);
console.log("DMG created successfully");
} catch (error) {
console.error("Failed to create DMG:", error);
console.error(error)
throw new Error("Failed to create dmg:\n" + error)
}
}

async function executeCommand(command: string): Promise<void> {
return new Promise<void>((resolve, reject) => {
child_process.exec(command, (error, stdout, stderr) => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
}

async function build() {
const logger = new Signale();
if (!BuildConfig.mac) {
logger.fatal("No mac config was found in build.config.js!");
return;
}

for (const app of BuildConfig.mac.architecture) {
const appTime = performance.now();

const l = new Signale({ scope: "build-mac-" + app, interactive: true });
l.await(`Packaging mac-${app}`);

const appFolder = path.resolve(`./dist/mac_${app}/${BuildConfig.appName}.app`);
if (!fs.existsSync(appFolder)) {
l.fatal(`The '${appFolder}' app bundle was not found in the ./dist directory`);
return;
}

await createCustomDMG({
sourceFolder: appFolder,
outputName: path.join(path.resolve("./dist"), `${BuildConfig.appName}-${version}_${app}`),
volumeName: `${BuildConfig.appName}_${app}`,
backgroundPath: path.resolve("./build/assets/bg.png"),
windowPos: "200 120",
windowSize: "600 360",
iconSize: 90,
iconPos: "160 180",
appDropLink: "440 180",
}).catch(()=>{
l.fatal(`failed to package mac_${app}, skipping.`)
break;
});

l.complete(`mac_${app} packaged in ${((performance.now() - appTime) / 1000).toFixed(3)}s`);
console.log("");
}
}

build();

0 comments on commit 369e21d

Please sign in to comment.