Skip to content

Commit 5300609

Browse files
implement electron-builder support, remove electron-packager
1 parent 4e95322 commit 5300609

File tree

12 files changed

+91
-726
lines changed

12 files changed

+91
-726
lines changed

ElectronNET.CLI/Commands/Actions/DeployEmbeddedElectronFiles.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public static void Do(string tempPath)
88
{
99
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js");
1010
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json");
11+
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "build-helper.js");
1112

1213
string hostApiFolder = Path.Combine(tempPath, "api");
1314
if (Directory.Exists(hostApiFolder) == false)

ElectronNET.CLI/Commands/BuildCommand.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,19 @@ public Task<bool> ExecuteAsync()
105105
Console.WriteLine("Start npm install...");
106106
ProcessHelper.CmdExecute("npm install --production", tempPath);
107107

108-
Console.WriteLine("Start npm install electron-packager...");
108+
Console.WriteLine("Start npm install electron-builder...");
109109

110110
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
111111

112112
{
113113
// Works proper on Windows...
114-
ProcessHelper.CmdExecute("npm install electron-packager --global", tempPath);
114+
ProcessHelper.CmdExecute("npm install electron-builder --global", tempPath);
115115
}
116116
else
117117
{
118118
// ToDo: find another solution or document it proper
119119
// GH Issue https://github.com/electron-userland/electron-prebuilt/issues/48
120-
Console.WriteLine("Electron Packager - make sure you invoke 'sudo npm install electron-packager --global' at " + tempPath + " manually. Sry.");
120+
Console.WriteLine("Electron Builder - make sure you invoke 'sudo npm install electron-builder --global' at " + tempPath + " manually. Sry.");
121121
}
122122

123123
Console.WriteLine("ElectronHostHook handling started...");
@@ -132,9 +132,11 @@ public Task<bool> ExecuteAsync()
132132
Console.WriteLine("Start npm install for hosthooks...");
133133
ProcessHelper.CmdExecute("npm install --production", hosthookDir);
134134

135-
string tscPath = Path.Combine(tempPath, "node_modules", ".bin");
135+
// ToDo: Global TypeScript installation is needed for ElectronHostHook
136+
//string tscPath = Path.Combine(tempPath, "node_modules", ".bin");
137+
136138
// ToDo: Not sure if this runs under linux/macos
137-
ProcessHelper.CmdExecute(@"tsc -p ../../ElectronHostHook --sourceMap false", tscPath);
139+
ProcessHelper.CmdExecute(@"tsc -p . --sourceMap false", hosthookDir);
138140
}
139141

140142
Console.WriteLine("Build Electron Desktop Application...");
@@ -166,15 +168,17 @@ public Task<bool> ExecuteAsync()
166168
electronParams = parser.Arguments[_paramElectronParams][0];
167169
}
168170

171+
// ToDo: Make the same thing easer with native c# - we can save a tmp file in production code :)
172+
Console.WriteLine("Create electron-builder configuration file...");
173+
ProcessHelper.CmdExecute($"node build-helper.js", tempPath);
174+
169175
Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform}...");
170-
ProcessHelper.CmdExecute($"electron-packager . --platform={platformInfo.ElectronPackerPlatform} --arch={electronArch} {electronParams} --out=\"{buildPath}\" --overwrite", tempPath);
176+
ProcessHelper.CmdExecute($"electron-builder . --config=./bin/electron-builder.json --platform={platformInfo.ElectronPackerPlatform} --arch={electronArch} {electronParams}", tempPath);
171177

172178
Console.WriteLine("... done");
173179

174180
return true;
175181
});
176182
}
177-
178-
179183
}
180184
}

ElectronNET.CLI/Commands/StartElectronCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics;
43
using System.IO;
54
using System.Runtime.InteropServices;
65
using System.Threading.Tasks;

ElectronNET.CLI/ElectronNET.CLI.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ This package contains the dotnet tooling to electronize your application.</Descr
5151
<EmbeddedResource Include="..\ElectronNET.Host\main.js" Link="ElectronHost\main.js" />
5252
</ItemGroup>
5353

54+
<ItemGroup>
55+
<EmbeddedResource Include="..\ElectronNET.Host\build-helper.js" Link="ElectronHost\build-helper.js" />
56+
</ItemGroup>
57+
5458
<ItemGroup>
5559
<EmbeddedResource Include="..\ElectronNET.Host\api\ipc.js" Link="ElectronHost\api\ipc.js" />
5660
</ItemGroup>

ElectronNET.Host/ElectronHostHook/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@
1515
"devDependencies": {
1616
"@types/socket.io": "^2.1.2",
1717
"typescript": "^3.4.5"
18-
},
19-
"dependencies": {}
18+
}
2019
}

ElectronNET.Host/build-helper.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @ts-ignore
2+
const manifestFile = require('./bin/electron.manifest');
3+
const electronBuilderConfig = JSON.stringify({ ...manifestFile.build });
4+
5+
const fs = require('fs');
6+
fs.writeFile('./bin/electron-builder.json', electronBuilderConfig, (error) => {
7+
if(error) {
8+
console.log(error.message);
9+
}
10+
});
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
11
{
2-
"executable": "{{executable}}"
2+
"executable": "{{executable}}",
3+
"build": {
4+
"appId": "com.{{executable}}.app",
5+
"productName": "{{executable}}",
6+
"copyright": "Copyright © 2019",
7+
"buildVersion": "1.0.0",
8+
"compression": "maximum",
9+
"directories": {
10+
"output": "../../../bin/Desktop"
11+
},
12+
"extraResources": [
13+
{
14+
"from": "./bin",
15+
"to": "bin",
16+
"filter": ["**/*"]
17+
}
18+
],
19+
"files": [
20+
{
21+
"from": "./ElectronHostHook/node_modules",
22+
"to": "ElectronHostHook/node_modules",
23+
"filter": ["**/*"]
24+
},
25+
"**/*"
26+
]
27+
}
328
}

ElectronNET.Host/main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ let appApi, menu, dialogApi, notification, tray, webContents;
88
let globalShortcut, shellApi, screen, clipboard;
99
let splashScreen, mainWindowId, hostHook;
1010

11-
const manifestJsonFilePath = path.join(__dirname, 'bin', 'electron.manifest.json');
11+
const currentBinPath = path.join(__dirname.replace('app.asar', ''), 'bin');
12+
const manifestJsonFilePath = path.join(currentBinPath, 'electron.manifest.json');
1213
const manifestJsonFile = require(manifestJsonFilePath);
1314
if (manifestJsonFile.singleInstance) {
1415
const shouldQuit = app.requestSingleInstanceLock();
@@ -140,8 +141,8 @@ function startAspCoreBackend(electronPort) {
140141
binaryFile = binaryFile + '.exe';
141142
}
142143

143-
const binFilePath = path.join(__dirname, 'bin', binaryFile);
144-
var options = { cwd: path.join(__dirname, 'bin') };
144+
let binFilePath = path.join(currentBinPath, binaryFile);
145+
var options = { cwd: currentBinPath };
145146
apiProcess = process(binFilePath, parameters, options);
146147

147148
apiProcess.stdout.on('data', (data) => {

ElectronNET.Host/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
"start": "tsc -p ."
1313
},
1414
"dependencies": {
15-
"electron": "^5.0.1",
1615
"portscanner": "^2.2.0",
1716
"socket.io": "^2.2.0"
1817
},
1918
"devDependencies": {
2019
"@types/node": "^10.14.4",
2120
"@types/socket.io": "^2.1.2",
2221
"tslint": "^5.12.0",
23-
"typescript": "^3.2.2"
22+
"typescript": "^3.2.2",
23+
"electron": "^5.0.1"
2424
}
2525
}

0 commit comments

Comments
 (0)