Skip to content

Commit

Permalink
fix: 【Electron】根据平台打包 Prisma 二进制文件 #435
Browse files Browse the repository at this point in the history
  • Loading branch information
meetqy committed Oct 5, 2023
1 parent 42b7bf7 commit ac927f6
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 552 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ const isTestBuilder = process.env.IS_TEST_BUILDER === "true";
* @type {import('electron-builder').Configuration}
* @see https://www.electron.build/configuration/configuration
*/
const options = {
const BaseConfig = {
appId: "com.rao-pics.app",
copyright: `Copyright © 2022 meetqy`,
productName: "Rao Pics",
directories: { buildResources: "build", output: "releases" },
icon: "resources/icon.icns",
directories: {
buildResources: "build",
output: "releases",
},
asar: !isTestBuilder,
files: [
"!**/.vscode/*",
"!src/*",
"!electron-builder",
"!electron.vite.config.{js,ts,mjs,cjs}",
"!{.eslintignore,.eslintrc.json,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md,tailwind.config.ts,postcss.config.cjs,electron-builder.cjs}",
"!{.env,.env.*,.npmrc,pnpm-lock.yaml}",
Expand All @@ -23,33 +27,10 @@ const options = {
"!**/.turbo/*",
"!**/node_modules/prisma/libquery_engine-*",
"!**/node_modules/@prisma/engines/**",
{
from: join(__dirname, "../../node_modules/.prisma"),
to: "node_modules/.prisma",
},
],
asarUnpack: ["resources/**/*"],
afterSign: "build/notarize.js",
mac: {
entitlementsInherit: "build/entitlements.mac.plist",
target: isTestBuilder
? "dir"
: {
target: "dmg",
arch: ["x64", "arm64"],
},
},
win: {
target: isTestBuilder ? "dir" : { target: "nsis", arch: ["x64"] },
},
npmRebuild: false,
publish: {
provider: "generic",
url: "https://example.com/auto-updates",
},
extraResources: [
{
from: join(__dirname, "./node_modules/@rao-pics/db/prisma/db.sqlite"),
from: join(__dirname, "../node_modules/@rao-pics/db/prisma/db.sqlite"),
to: "extraResources/db.sqlite",
},
...copyTheme("gallery"),
Expand All @@ -58,7 +39,7 @@ const options = {

function copyTheme(name) {
// 主题目录
const project = join(__dirname, "../../", "themes", name);
const project = join(__dirname, "../../../", "themes", name);
const to = `themes/${name}`;

return [
Expand All @@ -81,4 +62,4 @@ function copyTheme(name) {
];
}

module.exports = options;
module.exports = BaseConfig;
68 changes: 68 additions & 0 deletions apps/electron/electron-builder/mac.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const BaseConfig = require("./base.cjs");
const builder = require("electron-builder");
const { join } = require("path");

const { Platform } = builder;

const isTestBuilder = process.env.IS_TEST_BUILDER === "true";

const files = [];

/**
* @type {import('electron-builder').Configuration}
* @see https://www.electron.build/configuration/configuration
*/
const AppConfig = {
...BaseConfig,

mac: {
identity: null,
entitlementsInherit: "build/entitlements.mac.plist",
category: "public.app-category.photography",
icon: "resources/icon.icns",
darkModeSupport: true,
target: {
target: isTestBuilder ? "dir" : "dmg",
arch: ["x64", "arm64"],
},
files,
},

beforeBuild: (context) => {
files.splice(-1);

if (context.arch === "x64") {
files.push({
from: join(__dirname, "../../../node_modules/.prisma"),
to: "node_modules/.prisma",
filter: ["**/*", "!**/*.node", "**/libquery_engine-darwin.dylib.node"],
});
}

if (context.arch === "arm64") {
files.push({
from: join(__dirname, "../../../node_modules/.prisma"),
to: "node_modules/.prisma",
filter: [
"**/*",
"!**/*.node",
"**/libquery_engine-darwin-arm64.dylib.node",
],
});
}

return Promise.resolve(context);
},
};

builder
.build({
targets: Platform.MAC.createTarget(),
config: AppConfig,
})
.then((result) => {
console.log(JSON.stringify(result));
})
.catch((error) => {
console.error(error);
});
42 changes: 42 additions & 0 deletions apps/electron/electron-builder/win.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const BaseConfig = require("./base.cjs");
const builder = require("electron-builder");
const { join } = require("path");

const { Platform } = builder;

const isTestBuilder = process.env.IS_TEST_BUILDER === "true";

/**
* @type {import('electron-builder').Configuration}
* @see https://www.electron.build/configuration/configuration
*/
const AppConfig = {
...BaseConfig,

win: {
icon: "resources/icon.png",
target: {
target: isTestBuilder ? "dir" : "nsis",
arch: ["x64"],
},
files: [
{
from: join(__dirname, "../../../node_modules/.prisma"),
to: "node_modules/.prisma",
filter: ["**/*", "!**/*.node", "**/query_engine-windows.dll.node"],
},
],
},
};

builder
.build({
targets: Platform.WINDOWS.createTarget(),
config: AppConfig,
})
.then((result) => {
console.log(JSON.stringify(result));
})
.catch((error) => {
console.error(error);
});
6 changes: 2 additions & 4 deletions apps/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
"main": "./out/main/index.js",
"scripts": {
"build": "npm run typecheck && electron-vite build",
"build:linux": "electron-vite build && electron-builder --linux --config",
"build:mac": "electron-builder --mac --config ./electron-builder.cjs",
"build:win": "electron-builder --win --config ./electron-builder.cjs",
"build:mac": "node ./electron-builder/mac.cjs",
"build:win": "node ./electron-builder/win.cjs",
"clean": "git clean -xdf node_modules out releases .turbo",
"dev": "electron-vite dev",
"format": "prettier --check \"**/*.{mjs,ts,md,json}\"",
Expand Down Expand Up @@ -46,7 +45,6 @@
"devDependencies": {
"@electron-toolkit/tsconfig": "^1.0.1",
"@electron/notarize": "^1.2.3",
"@electron/rebuild": "^3.3.0",
"@rao-pics/eslint-config": "workspace:^",
"@rao-pics/prettier-config": "workspace:^",
"@rao-pics/tailwind-config": "workspace:*",
Expand Down
Binary file added apps/electron/resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion apps/electron/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
],
"include": [
"electron.vite.config.*",
"electron-builder.*",
"src/main/**/*",
"src/preload/*",
"tailwind.config.*"
Expand All @@ -15,5 +14,6 @@
"types": ["electron-vite/node"],
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
},

"exclude": ["node_modules"]
}
Loading

0 comments on commit ac927f6

Please sign in to comment.