Skip to content

Commit 7c9a7c3

Browse files
committed
Squashed commit of the following:
commit f69102e Author: Hyeonmin Seon <[email protected]> Date: Mon Aug 4 09:20:53 2025 +0900 C#에서 Electron 버전 업데이트 방식 변경 및 버전 수정 변경 사항: - BuildCommand.cs에서 Electron 버전을 C# 코드로 직접 업데이트하도록 변경 - StartElectronCommand.cs에서 manifest 파일에서 Electron 버전을 읽어와 package.json 업데이트 - build-helper.js에서 Electron 버전 업데이트 로직 제거 - electron.manifest.json에서 Electron 버전을 23.2.0에서 25.9.0으로 업데이트 commit 855e830 Author: Hyeonmin Seon <[email protected]> Date: Fri Aug 1 17:43:43 2025 +0900 버전 업데이트: 23.6.2-messe로 변경 변경 사항: * `Version` 요소의 값이 `99.0.0.0`에서 `23.6.2-messe`로 변경되었습니다. * 패키지의 버전을 업데이트하여 새로운 기능이나 수정 사항을 반영하였습니다. commit 498ab0a Author: Hyeonmin Seon <[email protected]> Date: Fri Aug 1 17:37:16 2025 +0900 fix #767 - Added Electron version management and package.json updates. * BuildCommand.cs now reads the Electron version from the manifest file and updates package.json. * StartElectronCommand.cs now reads the electronicVersion from the manifest file and updates package.json. * Improved package.json updates and JSON response direction in build-helper.js. * Added the electronicVersion property to Electron.manifest.json.
1 parent 4c880cb commit 7c9a7c3

File tree

4 files changed

+248
-35
lines changed

4 files changed

+248
-35
lines changed

src/ElectronNET.CLI/Commands/BuildCommand.cs

Lines changed: 127 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using System.Threading.Tasks;
6+
using System.Text.Json;
67
using ElectronNET.CLI.Commands.Actions;
78

89
namespace ElectronNET.CLI.Commands
@@ -139,28 +140,138 @@ public Task<bool> ExecuteAsync()
139140
File.Copy(parser.Arguments[_paramPackageJson][0], Path.Combine(tempPath, "package.json"), true);
140141
}
141142

142-
var checkForNodeModulesDirPath = Path.Combine(tempPath, "node_modules");
143+
// Read electron version from manifest file and update package.json BEFORE npm install
144+
string manifestFileName = "electron.manifest.json";
143145

144-
if (Directory.Exists(checkForNodeModulesDirPath) == false || parser.Contains(_paramForceNodeInstall) || parser.Contains(_paramPackageJson))
146+
if (parser.Arguments.ContainsKey(_manifest))
147+
{
148+
manifestFileName = parser.Arguments[_manifest].First();
149+
}
145150

146-
Console.WriteLine("Start npm install...");
147-
ProcessHelper.CmdExecute("npm install --production", tempPath);
151+
// Read electron version from manifest file
152+
string electronVersion = "23.2.0"; // default fallback version
153+
string manifestPath = Path.Combine(Directory.GetCurrentDirectory(), manifestFileName);
154+
155+
Console.WriteLine($"Reading electronVersion from manifest file: {manifestPath}");
156+
157+
if (File.Exists(manifestPath))
158+
{
159+
try
160+
{
161+
string manifestContent = File.ReadAllText(manifestPath);
162+
using (JsonDocument document = JsonDocument.Parse(manifestContent))
163+
{
164+
if (document.RootElement.TryGetProperty("electronVersion", out JsonElement electronVersionElement))
165+
{
166+
string manifestElectronVersion = electronVersionElement.GetString();
167+
if (!string.IsNullOrWhiteSpace(manifestElectronVersion))
168+
{
169+
electronVersion = manifestElectronVersion;
170+
Console.WriteLine($"Using Electron version {electronVersion} from manifest file");
171+
}
172+
else
173+
{
174+
Console.WriteLine($"electronVersion property found but empty in manifest file, using fallback version {electronVersion}");
175+
}
176+
}
177+
else
178+
{
179+
Console.WriteLine($"electronVersion property not found in manifest file, using fallback version {electronVersion}");
180+
}
181+
}
182+
}
183+
catch (Exception ex)
184+
{
185+
Console.WriteLine($"Warning: Could not read electronVersion from manifest file: {ex.Message}");
186+
Console.WriteLine($"Using fallback Electron version {electronVersion}");
187+
}
188+
}
189+
else
190+
{
191+
Console.WriteLine($"Warning: Manifest file not found at {manifestPath}");
192+
Console.WriteLine($"Using fallback Electron version {electronVersion}");
193+
}
148194

149-
Console.WriteLine("ElectronHostHook handling started...");
195+
// Update package.json with electronVersion directly in C# before npm install
196+
string packageJsonPath = Path.Combine(tempPath, "package.json");
197+
if (File.Exists(packageJsonPath))
198+
{
199+
try
200+
{
201+
string packageJsonContent = File.ReadAllText(packageJsonPath);
202+
using (JsonDocument packageDocument = JsonDocument.Parse(packageJsonContent))
203+
{
204+
var packageJsonObject = new Dictionary<string, object>();
205+
206+
// Copy existing properties
207+
foreach (var property in packageDocument.RootElement.EnumerateObject())
208+
{
209+
if (property.Name == "devDependencies")
210+
{
211+
var devDeps = new Dictionary<string, object>();
212+
foreach (var dep in property.Value.EnumerateObject())
213+
{
214+
devDeps[dep.Name] = dep.Value.GetString();
215+
}
216+
// Update electron version
217+
devDeps["electron"] = $"^{electronVersion}";
218+
packageJsonObject["devDependencies"] = devDeps;
219+
}
220+
else if (property.Value.ValueKind == JsonValueKind.String)
221+
{
222+
packageJsonObject[property.Name] = property.Value.GetString();
223+
}
224+
else if (property.Value.ValueKind == JsonValueKind.Object)
225+
{
226+
var subObject = new Dictionary<string, object>();
227+
foreach (var subProp in property.Value.EnumerateObject())
228+
{
229+
subObject[subProp.Name] = subProp.Value.GetString();
230+
}
231+
packageJsonObject[property.Name] = subObject;
232+
}
233+
else
234+
{
235+
packageJsonObject[property.Name] = property.Value.ToString();
236+
}
237+
}
238+
239+
// Ensure devDependencies exists and contains electron
240+
if (!packageJsonObject.ContainsKey("devDependencies"))
241+
{
242+
packageJsonObject["devDependencies"] = new Dictionary<string, object>();
243+
}
244+
var devDependencies = (Dictionary<string, object>)packageJsonObject["devDependencies"];
245+
devDependencies["electron"] = $"^{electronVersion}";
246+
247+
string updatedPackageJson = JsonSerializer.Serialize(packageJsonObject, new JsonSerializerOptions
248+
{
249+
WriteIndented = true
250+
});
251+
252+
File.WriteAllText(packageJsonPath, updatedPackageJson);
253+
Console.WriteLine($"Updated package.json with Electron version {electronVersion}");
254+
}
255+
}
256+
catch (Exception ex)
257+
{
258+
Console.WriteLine($"Warning: Could not update package.json with electronVersion: {ex.Message}");
259+
}
260+
}
150261

151-
string electronhosthookDir = Path.Combine(Directory.GetCurrentDirectory(), "ElectronHostHook");
262+
var checkForNodeModulesDirPath = Path.Combine(tempPath, "node_modules");
152263

153-
if (Directory.Exists(electronhosthookDir))
154-
{
155-
string hosthookDir = Path.Combine(tempPath, "ElectronHostHook");
156-
DirectoryCopy.Do(electronhosthookDir, hosthookDir, true, new List<string>() { "node_modules" });
264+
if (Directory.Exists(checkForNodeModulesDirPath) == false || parser.Contains(_paramForceNodeInstall) || parser.Contains(_paramPackageJson))
265+
Console.WriteLine("Start npm install...");
157266

158-
Console.WriteLine("Start npm install for hosthooks...");
159-
ProcessHelper.CmdExecute("npm install", hosthookDir);
267+
ProcessHelper.CmdExecute("npm install --production", tempPath);
160268

161-
// ToDo: Not sure if this runs under linux/macos
162-
ProcessHelper.CmdExecute(@"npx tsc -p . --sourceMap false", hosthookDir);
163-
}
269+
// Update build helper and configuration files after npm install
270+
Console.WriteLine("Create electron-builder configuration file...");
271+
ProcessHelper.CmdExecute(
272+
string.IsNullOrWhiteSpace(version)
273+
? $"node build-helper.js {manifestFileName}"
274+
: $"node build-helper.js {manifestFileName} {version}", tempPath);
164275

165276
Console.WriteLine("Build Electron Desktop Application...");
166277

@@ -189,23 +300,8 @@ public Task<bool> ExecuteAsync()
189300
electronParams = parser.Arguments[_paramElectronParams][0];
190301
}
191302

192-
// ToDo: Make the same thing easer with native c# - we can save a tmp file in production code :)
193-
Console.WriteLine("Create electron-builder configuration file...");
194-
195-
string manifestFileName = "electron.manifest.json";
196-
197-
if (parser.Arguments.ContainsKey(_manifest))
198-
{
199-
manifestFileName = parser.Arguments[_manifest].First();
200-
}
201-
202-
ProcessHelper.CmdExecute(
203-
string.IsNullOrWhiteSpace(version)
204-
? $"node build-helper.js {manifestFileName}"
205-
: $"node build-helper.js {manifestFileName} {version}", tempPath);
206-
207303
Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform}...");
208-
ProcessHelper.CmdExecute($"npx electron-builder --config=./bin/electron-builder.json --{platformInfo.ElectronPackerPlatform} --{electronArch} -c.electronVersion=30.0.3 {electronParams}", tempPath);
304+
ProcessHelper.CmdExecute($"npx electron-builder --config=./bin/electron-builder.json --{platformInfo.ElectronPackerPlatform} --{electronArch} -c.electronVersion={electronVersion} {electronParams}", tempPath);
209305

210306
Console.WriteLine("... done");
211307

src/ElectronNET.CLI/Commands/StartElectronCommand.cs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Runtime.InteropServices;
66
using System.Threading.Tasks;
7+
using System.Text.Json;
78
using ElectronNET.CLI.Commands.Actions;
89

910
namespace ElectronNET.CLI.Commands
@@ -118,13 +119,118 @@ public Task<bool> ExecuteAsync()
118119

119120
DeployEmbeddedElectronFiles.Do(tempPath);
120121

122+
// Update package.json with electronVersion from manifest before npm install
123+
string manifestFileName = "electron.manifest.json";
124+
if (parser.Arguments.ContainsKey(_manifest))
125+
{
126+
manifestFileName = parser.Arguments[_manifest].First();
127+
}
128+
129+
// Read electron version from manifest file
130+
string electronVersion = "23.2.0"; // default fallback version
131+
string manifestPath = Path.Combine(aspCoreProjectPath, manifestFileName);
132+
133+
if (File.Exists(manifestPath))
134+
{
135+
try
136+
{
137+
string manifestContent = File.ReadAllText(manifestPath);
138+
using (JsonDocument document = JsonDocument.Parse(manifestContent))
139+
{
140+
if (document.RootElement.TryGetProperty("electronVersion", out JsonElement electronVersionElement))
141+
{
142+
string manifestElectronVersion = electronVersionElement.GetString();
143+
if (!string.IsNullOrWhiteSpace(manifestElectronVersion))
144+
{
145+
electronVersion = manifestElectronVersion;
146+
Console.WriteLine($"Using Electron version {electronVersion} from manifest file");
147+
}
148+
}
149+
}
150+
}
151+
catch (Exception ex)
152+
{
153+
Console.WriteLine($"Warning: Could not read electronVersion from manifest file: {ex.Message}");
154+
}
155+
}
156+
157+
// Update package.json with electronVersion directly in C# before npm install
158+
string packageJsonPath = Path.Combine(tempPath, "package.json");
159+
if (File.Exists(packageJsonPath))
160+
{
161+
try
162+
{
163+
string packageJsonContent = File.ReadAllText(packageJsonPath);
164+
using (JsonDocument packageDocument = JsonDocument.Parse(packageJsonContent))
165+
{
166+
var packageJsonObject = new Dictionary<string, object>();
167+
168+
// Copy existing properties
169+
foreach (var property in packageDocument.RootElement.EnumerateObject())
170+
{
171+
if (property.Name == "devDependencies")
172+
{
173+
var devDeps = new Dictionary<string, object>();
174+
foreach (var dep in property.Value.EnumerateObject())
175+
{
176+
devDeps[dep.Name] = dep.Value.GetString();
177+
}
178+
// Update electron version
179+
devDeps["electron"] = $"^{electronVersion}";
180+
packageJsonObject["devDependencies"] = devDeps;
181+
}
182+
else if (property.Value.ValueKind == JsonValueKind.String)
183+
{
184+
packageJsonObject[property.Name] = property.Value.GetString();
185+
}
186+
else if (property.Value.ValueKind == JsonValueKind.Object)
187+
{
188+
var subObject = new Dictionary<string, object>();
189+
foreach (var subProp in property.Value.EnumerateObject())
190+
{
191+
subObject[subProp.Name] = subProp.Value.GetString();
192+
}
193+
packageJsonObject[property.Name] = subObject;
194+
}
195+
else
196+
{
197+
packageJsonObject[property.Name] = property.Value.ToString();
198+
}
199+
}
200+
201+
// Ensure devDependencies exists and contains electron
202+
if (!packageJsonObject.ContainsKey("devDependencies"))
203+
{
204+
packageJsonObject["devDependencies"] = new Dictionary<string, object>();
205+
}
206+
var devDependencies = (Dictionary<string, object>)packageJsonObject["devDependencies"];
207+
devDependencies["electron"] = $"^{electronVersion}";
208+
209+
string updatedPackageJson = JsonSerializer.Serialize(packageJsonObject, new JsonSerializerOptions
210+
{
211+
WriteIndented = true
212+
});
213+
214+
File.WriteAllText(packageJsonPath, updatedPackageJson);
215+
Console.WriteLine($"Updated package.json with Electron version {electronVersion}");
216+
}
217+
}
218+
catch (Exception ex)
219+
{
220+
Console.WriteLine($"Warning: Could not update package.json with electronVersion: {ex.Message}");
221+
}
222+
}
223+
121224
var nodeModulesDirPath = Path.Combine(tempPath, "node_modules");
122225

123226
Console.WriteLine("node_modules missing in: " + nodeModulesDirPath);
124227

125228
Console.WriteLine("Start npm install...");
126229
ProcessHelper.CmdExecute("npm install", tempPath);
127230

231+
// Execute build-helper.js to setup other configurations after npm install
232+
ProcessHelper.CmdExecute($"node build-helper.js {manifestFileName}", tempPath);
233+
128234
Console.WriteLine("ElectronHostHook handling started...");
129235

130236
string electronhosthookDir = Path.Combine(Directory.GetCurrentDirectory(), "ElectronHostHook");

src/ElectronNET.Host/build-helper.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,30 @@ const builderConfiguration = { ...manifestFile.build };
88
if(process.argv.length > 3) {
99
builderConfiguration.buildVersion = process.argv[3];
1010
}
11+
12+
// @ts-ignore
13+
const packageJson = require('./package');
14+
15+
// Update package.json if buildVersion is provided
1116
if(builderConfiguration.hasOwnProperty('buildVersion')) {
12-
// @ts-ignore
13-
const packageJson = require('./package');
1417
packageJson.name = dasherize(manifestFile.name || 'electron-net');
1518
packageJson.author = manifestFile.author || '';
1619
packageJson.version = builderConfiguration.buildVersion;
1720
packageJson.description = manifestFile.description || '';
1821

19-
fs.writeFile('./package.json', JSON.stringify(packageJson), (error) => {
22+
// Write updated package.json
23+
fs.writeFile('./package.json', JSON.stringify(packageJson, null, 2), (error) => {
2024
if(error) {
2125
console.log(error.message);
2226
}
2327
});
24-
28+
}
29+
30+
// Note: electronVersion is now handled directly in C# before npm install
31+
// No need to update it here anymore
32+
33+
// Update package-lock.json if it exists
34+
if(builderConfiguration.hasOwnProperty('buildVersion')) {
2535
try {
2636
// @ts-ignore
2737
const packageLockJson = require('./package-lock');

src/ElectronNET.WebApp/electron.manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
},
66
"environment": "Production",
77
"singleInstance": false,
8+
"electronVersion": "25.9.0",
89
"build": {
910
"appId": "com.electronnetapidemos.app",
1011
"productName": "ElectronNET API Demos",

0 commit comments

Comments
 (0)