forked from rabix/composer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
electron-build.js
145 lines (121 loc) · 4.16 KB
/
electron-build.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
const path = require("path");
const builder = require("electron-builder");
const fs = require("fs-extra");
const archiver = require("archiver");
const glob = require("glob");
const projectRoot = path.resolve(__dirname + "/");
const ngDistDir = projectRoot + "/ng-dist";
const electronDir = projectRoot + "/electron";
const appDistDir = projectRoot + "/dist";
// Copy ng-dist to dist
console.log("Copying compiled frontend code...");
fs.copySync(ngDistDir, appDistDir);
// Generate package.json for the distribution build
console.log("Generating production package.json file...");
const electronPackage = JSON.parse(fs.readFileSync(electronDir + "/package.json", "utf8"));
const mainPackage = JSON.parse(fs.readFileSync(projectRoot + "/package.json", "utf8"));
const merged = Object.assign(mainPackage, {
dependencies: electronPackage.dependencies,
devDependencies: electronPackage.devDependencies,
main: "main.js"
});
fs.writeFileSync(appDistDir + "/package.json", JSON.stringify(merged, null, 4));
// Copy Electron main.js file to dist
console.log("Copying main.js...");
fs.copySync(electronDir + "/dist/main.prod.js", appDistDir + "/main.js", {
overwrite: true
});
// Copy compiled electron code to dist
console.log("Copying electron code...");
fs.copySync(electronDir + "/dist/src", appDistDir + "/src", {
overwrite: true,
dereference: true
});
fs.copySync(electronDir + "/executor", appDistDir + "/executor", {
overwrite: true,
dereference: true
});
fs.copySync(electronDir + "/src/splash", appDistDir + "/src/splash");
// Copy electron node modules
console.log("Copying electron node_modules...");
fs.copySync(electronDir + "/node_modules", appDistDir + "/node_modules", {
overwrite: true,
dereference: true
});
console.log("Starting build process...");
builder.build({
config: {
appId: "io.rabix.composer",
productName: "rabix-composer",
asar: true,
asarUnpack: ["executor/**"],
directories: {
output: "build",
app: "dist",
buildResources: "build-resources"
},
protocols: [{
"name": "rabix-composer",
"role": "Editor",
"schemes": ["rabix-composer"]
}],
mac: {
target: ["dmg"],
hardenedRuntime: true,
gatekeeperAssess: false,
entitlements: electronDir + "/config/entitlements.mac.plist",
entitlementsInherit: electronDir + "/config/entitlements.mac.plist",
},
win: {
target: ["nsis"],
},
linux: {
target: ["AppImage"],
},
nsis: {
oneClick: false,
perMachine: true,
allowElevation: true,
allowToChangeInstallationDirectory: true
},
fileAssociations: [{
ext: "cwl",
name: "CWL"
}],
afterSign: projectRoot + "/build-scripts/notarize.js",
dmg: {
sign: false
}
}
});
// maybeZipWindowsInstaller();
function maybeZipWindowsInstaller() {
/**
* For Windows, we can't take a single-file artifact because of missing libraries.
* We need to pack the installer with other stuff that come with the build (.dll libs)
*/
if (process.platform !== "win32") {
return data;
}
console.log("Archiving Windows installer...");
const [installerFilepath] = glob.sync("*.exe", {cwd: "build"});
if (!installerFilepath) {
throw new Error("Cannot find installer binary.");
}
const zipPath = "build/" + installerFilepath.slice(0, -3) + "zip";
const buildInfoPath = "latest.yml";
const unpackedDir = "win-unpacked";
const output = fs.createWriteStream(zipPath);
const archive = archiver("zip");
output.on("close", () => {
console.log("Archived " + archive.pointer() + " bytes");
});
archive.on("error", err => {
throw err;
});
archive.pipe(output);
archive.file(`build/${installerFilepath}`, {name: installerFilepath});
archive.file(`build/${buildInfoPath}`, {name: buildInfoPath});
archive.directory(`build/${unpackedDir}`, {name: unpackedDir});
return archive.finalize();
}