Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: desktop build #768

Merged
merged 15 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions .depcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ ignores: [
"@pinata/sdk",
"expo-optimize",
"sharp-cli",
"cross-env",
"electron",
"rimraf",
"assert",
]
ignorePatterns: [
"/cache",
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
/.github
/cache
/.git
/electron
37 changes: 37 additions & 0 deletions .github/workflows/desktop-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build Desktop App

on:
push:
branches:
- main
pull_request:

jobs:
build-mac-amd64:
runs-on: macos-12
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
cache: "yarn"
node-version: 18

- uses: actions/setup-go@v3
with:
go-version: "1.19"

- name: Install node modules
run: yarn

- name: Prepare
run: make prepare-electron

- name: Build
run: make build-electron-mac-amd64

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: teritori-desktop-mac-amd64
path: electron/dist/artifacts/local/Teritori-*.dmg
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CANDYMACHINE_REPO=teritori-nfts
BUNKER_MINTER_PACKAGE=teritori-bunker-minter
GO?=go

TOKEN_REPO=teritori-nfts
TOKEN_PACKAGE=teritori-nft
Expand Down Expand Up @@ -260,3 +261,45 @@ networks.json: node_modules validate-networks
unused-exports: node_modules
## TODO unexclude all paths except packages/api;packages/contracts-clients;packages/evm-contracts-clients
npx ts-unused-exports ./tsconfig.json --excludePathsFromReport="packages/api;packages/contracts-clients;packages/evm-contracts-clients;packages/components/socialFeed/RichText/inline-toolbar;./App.tsx;.*\.web|.electron|.d.ts" --ignoreTestFiles

.PHONY: prepare-electron
prepare-electron: node_modules
yarn rimraf ./web-build
yarn cross-env isElectron=prod expo export:web
yarn rimraf ./electron/web-build
mkdir ./electron/web-build
cp -r ./web-build/* ./electron/web-build
cd ./electron && npm i

# requires prepare-electron
.PHONY: build-electron-mac-amd64
build-electron-mac-amd64:
yarn rimraf ./electron/dist
yarn rimraf ./electron/build
cd ./electron && GOOS=darwin GOARCH=amd64 $(GO) build -o ./build/mac ./prod.go
cd ./electron && node ./builder/mac.js

# requires prepare-electron
.PHONY: build-electron-mac-arm64
build-electron-mac-arm64:
yarn rimraf ./electron/dist
yarn rimraf ./electron/build
cd ./electron && GOOS=darwin GOARCH=arm64 $(GO) build -o ./build/mac ./prod.go
cd ./electron && node ./builder/mac.js

# requires prepare-electron
.PHONY: build-electron-win
build-electron-win:
yarn rimraf ./electron/dist
yarn rimraf ./electron/build
cd ./electron && GOOS=windows GOARCH=amd64 $(GO) build -o ./build/win.exe ./prod.go
cd ./electron && node ./builder/win.js

# requires prepare-electron
.PHONY: build-electron-linux
build-electron-linux:
yarn rimraf ./electron/dist
yarn rimraf ./electron/build
cd ./electron && GOOS=linux GOARCH=amd64 $(GO) build -o ./build/linux ./prod.go
cd ./electron && node ./builder/linux.js

64 changes: 64 additions & 0 deletions electron/builder/linux.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"use strict";

const builder = require("electron-builder");
const Platform = builder.Platform;

// Let's get that intellisense working
/**
* @type {import('electron-builder').Configuration}
* @see https://www.electron.build/configuration/configuration
*/
const options = {
appId: `com.teritori`,
productName: "Teritori",
compression: "normal",
removePackageScripts: true,
files: [
"build/linux",
"web-build/**/*",
"node_modules/**/*",
"package.json",
"main.js",
"icon.icns",
"splash.html",
"splash.png",
"preload.js",
],
nodeGypRebuild: false,
buildDependenciesFromSource: false,
directories: {
output: "dist/artifacts/local",
buildResources: "installer/resources",
},

linux: {
desktop: {
StartupNotify: "false",
Encoding: "UTF-8",
MimeType: "x-scheme-handler/deeplink",
},
target: ["AppImage", "rpm", "deb"],
asar: true,
asarUnpack: ["build/*"],
},
deb: {
priority: "optional",
afterInstall: "installer/linux/after-install.tpl",
},
rpm: {
fpm: ["--before-install", "installer/linux/before-install.tpl"],
afterInstall: "installer/linux/after-install.tpl",
},
};

builder
.build({
targets: Platform.LINUX.createTarget(),
config: options,
})
.then((result) => {
console.log(JSON.stringify(result));
})
.catch((error) => {
console.error(error);
});
77 changes: 77 additions & 0 deletions electron/builder/mac.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"use strict";

const builder = require("electron-builder");
const Platform = builder.Platform;

// Let's get that intellisense working
/**
* @type {import('electron-builder').Configuration}
* @see https://www.electron.build/configuration/configuration
*/
const options = {
appId: `com.teritori`,
productName: "Teritori",
compression: "normal",
removePackageScripts: true,
files: [
"build/mac",
"web-build/**/*",
"node_modules/**/*",
"package.json",
"main.js",
"icon.icns",
"splash.html",
"splash.png",
"preload.js",
],

nodeGypRebuild: false,
buildDependenciesFromSource: false,

directories: {
output: "dist/artifacts/local",
buildResources: "installer/resources",
},

mac: {
target: "dmg",
asar: true,
asarUnpack: ["build/*"],
hardenedRuntime: true,
gatekeeperAssess: true,
icon: "./icon.icns",
extendInfo: {
// NSAppleEventsUsageDescription: "Let me use Apple Events.",
// NSCameraUsageDescription: "Let me use the camera.",
// NSScreenCaptureDescription: "Let me take screenshots.",
},
},
dmg: {
iconSize: 100,
contents: [
{
x: 255,
y: 85,
type: "file",
},
{
x: 253,
y: 325,
type: "link",
path: "/Applications",
},
],
},
};

builder
.build({
targets: Platform.MAC.createTarget(),
config: options,
})
.then((result) => {
console.log(JSON.stringify(result));
})
.catch((error) => {
console.error(error);
});
58 changes: 58 additions & 0 deletions electron/builder/win.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"use strict";

const builder = require("electron-builder");
const Platform = builder.Platform;

// Let's get that intellisense working
/**
* @type {import('electron-builder').Configuration}
* @see https://www.electron.build/configuration/configuration
*/
const options = {
appId: `com.teritori`,
productName: "Teritori",

compression: "normal",
removePackageScripts: true,
files: [
"build/win.exe",
"web-build/**/*",
"node_modules/**/*",
"package.json",
"main.js",
"icon.icns",
"splash.html",
"splash.png",
"preload.js",
],

nodeGypRebuild: false,
buildDependenciesFromSource: false,

directories: {
output: "dist/artifacts/local",
buildResources: "installer/resources",
},

win: {
target: "nsis",
asar: true,
asarUnpack: ["build/*"],
},
nsis: {
deleteAppDataOnUninstall: true,
include: "installer/win/nsis-installer.nsh",
},
};

builder
.build({
targets: Platform.WINDOWS.createTarget(),
config: options,
})
.then((result) => {
console.log(JSON.stringify(result));
})
.catch((error) => {
console.error(error);
});
Binary file added electron/icon.icns
Binary file not shown.
Loading
Loading