-
Notifications
You must be signed in to change notification settings - Fork 305
/
electron-builder.config.js
168 lines (154 loc) · 4.82 KB
/
electron-builder.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// @ts-check
const path = require("path");
const fs = require("fs");
const dotenv = require("dotenv");
const dotenvPath = path.join(process.cwd(), ".env.production");
dotenv.config({ path: dotenvPath });
const VOICEVOX_ENGINE_DIR =
process.env.VOICEVOX_ENGINE_DIR ?? "../voicevox_engine/dist/run/";
// ${productName} Web Setup ${version}.${ext}
const NSIS_WEB_ARTIFACT_NAME = process.env.NSIS_WEB_ARTIFACT_NAME;
// ${productName}-${version}.${ext}
const LINUX_ARTIFACT_NAME = process.env.LINUX_ARTIFACT_NAME;
// ${packageName}
const LINUX_EXECUTABLE_NAME = process.env.LINUX_EXECUTABLE_NAME;
// ${productName}-${version}.${ext}
const MACOS_ARTIFACT_NAME = process.env.MACOS_ARTIFACT_NAME;
// コード署名証明書
const WIN_CERTIFICATE_SHA1 = process.env.WIN_CERTIFICATE_SHA1;
const WIN_SIGNING_HASH_ALGORITHMS = process.env.WIN_SIGNING_HASH_ALGORITHMS
? JSON.parse(process.env.WIN_SIGNING_HASH_ALGORITHMS)
: undefined;
const isMac = process.platform === "darwin";
const isArm64 = process.arch === "arm64";
// electron-builderのextraFilesは、ファイルのコピー先としてVOICEVOX.app/Contents/を使用する。
// しかし、実行ファイルはVOICEVOX.app/Contents/MacOS/にあるため、extraFilesをVOICEVOX.app/Contents/ディレクトリにコピーするのは正しくない。
// VOICEVOX.app/Contents/MacOS/ディレクトリにコピーされるように修正する。
// cf: https://k-hyoda.hatenablog.com/entry/2021/10/23/000349#%E8%BF%BD%E5%8A%A0%E5%B1%95%E9%96%8B%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E5%85%88%E3%81%AE%E8%A8%AD%E5%AE%9A
const extraFilePrefix = isMac ? "MacOS/" : "";
const sevenZipFile = fs
.readdirSync(path.resolve(__dirname, "vendored", "7z"))
.find(
// Windows: 7za.exe, Linux: 7zzs, macOS: 7zz
(fileName) => ["7za.exe", "7zzs", "7zz"].includes(fileName),
);
if (!sevenZipFile) {
throw new Error(
"7z binary file not found. Run `node ./tools/download7z.js` first.",
);
}
/** @type {import("electron-builder").Configuration} */
const builderOptions = {
beforeBuild: async () => {
if (fs.existsSync(path.resolve(__dirname, "dist_electron"))) {
fs.rmSync(path.resolve(__dirname, "dist_electron"), { recursive: true });
}
},
directories: {
output: "dist_electron",
buildResources: "build",
},
files: ["dist/**/*", "package.json"],
fileAssociations: [
{
ext: "vvproj",
name: "VOICEVOX Project file",
description: "VOICEVOX Project file",
role: "Editor",
icon: "icons/vvproj." + (isMac ? "icns" : "ico"),
},
{
ext: "vvpp",
name: "VOICEVOX Plugin package",
description: "VOICEVOX Plugin package",
role: "Editor",
icon: "icons/vvpp." + (isMac ? "icns" : "ico"),
},
{
ext: "vvppp",
name: "VOICEVOX Plugin package (part)",
description: "VOICEVOX Plugin package (part)",
role: "Editor",
icon: "icons/vvpp." + (isMac ? "icns" : "ico"),
},
],
extraFiles: [
{
from: "build/README.txt",
to: extraFilePrefix + "README.txt",
},
{
from: VOICEVOX_ENGINE_DIR,
to: path.join(extraFilePrefix, "vv-engine"),
},
{
from: path.resolve(__dirname, "vendored", "7z", sevenZipFile),
to: extraFilePrefix + sevenZipFile,
},
],
// electron-builder installer
productName: "VOICEVOX",
appId: "jp.hiroshiba.voicevox",
copyright: "Hiroshiba Kazuyuki",
afterAllArtifactBuild: path.resolve(
__dirname,
"build",
"afterAllArtifactBuild.js",
),
win: {
icon: "public/icon.png",
target: [
{
target: "nsis-web",
arch: ["x64"],
},
],
certificateSha1:
WIN_CERTIFICATE_SHA1 !== "" ? WIN_CERTIFICATE_SHA1 : undefined,
signingHashAlgorithms:
WIN_SIGNING_HASH_ALGORITHMS !== ""
? WIN_SIGNING_HASH_ALGORITHMS
: undefined,
},
nsisWeb: {
artifactName:
NSIS_WEB_ARTIFACT_NAME !== "" ? NSIS_WEB_ARTIFACT_NAME : undefined,
include: "build/installer.nsh",
oneClick: false,
allowToChangeInstallationDirectory: true,
},
publish: {
provider: "github",
repo: "voicevox",
vPrefixedTagName: false,
},
linux: {
artifactName: LINUX_ARTIFACT_NAME !== "" ? LINUX_ARTIFACT_NAME : undefined,
executableName:
LINUX_EXECUTABLE_NAME !== "" ? LINUX_EXECUTABLE_NAME : undefined,
icon: "public/icon.png",
category: "AudioVideo",
mimeTypes: ["application/x-voicevox"],
target: [
{
target: "AppImage",
arch: ["x64"],
},
],
},
mac: {
artifactName: MACOS_ARTIFACT_NAME !== "" ? MACOS_ARTIFACT_NAME : undefined,
icon: "public/icon-mac.png",
category: "public.app-category.utilities",
target: [
{
target: "dmg",
arch: [isArm64 ? "arm64" : "x64"],
},
],
},
dmg: {
icon: "public/icon-dmg.icns",
},
};
module.exports = builderOptions;