forked from rabix/composer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelectron-build.js
87 lines (73 loc) · 2.51 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
#!/usb/bin/env node
const path = require("path");
const builder = require("electron-builder");
const fs = require("fs-extra");
const platform = builder.Platform;
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 dist...");
fs.copySync(electronDir + "/dist/src", appDistDir + "/src", {
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...");
const targets = new Map();
targets.set(platform.MAC, new Map());
targets.set(platform.LINUX, new Map());
targets.set(platform.WINDOWS, new Map());
builder.build({
targets,
config: {
appId: "io.rabix.composer",
productName: "rabix-composer",
asar: true,
directories: {
output: "build",
app: "dist",
buildResources: "build-resources"
},
mac: {
target: ["zip", "dir"],
},
win: {
target: ["zip", "portable"],
},
linux: {
target: ["zip", "dir"],
},
}
});
function getCurrentGitBranchSlug() {
const gitHeadPath = path.join(process.cwd(), '.git/HEAD');
const ref = fs.readFileSync(gitHeadPath, "utf8");
const branchName = /ref: refs\/heads\/([^\n]+)/.exec(ref)[1];
return branchName.replace(/\//g, "-");
}