Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit 1b24cfb

Browse files
author
Heiko Does
committed
ref(builders/electron): installAppDeps via runModuleAsObservableFork
1 parent 6e945cb commit 1b24cfb

4 files changed

Lines changed: 207 additions & 49 deletions

File tree

packages/builders/package-lock.json

Lines changed: 184 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/builders/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@ng-electron-devkit/builders",
33
"description": "Development, test and build tools for angular applications running in electron",
4-
"version": "7.0.0-alpha5",
4+
"version": "7.0.0-alpha7",
55
"builders": "builders.json",
66
"scripts": {
77
"build": "../../node_modules/.bin/tsc",
@@ -21,7 +21,8 @@
2121
"@types/rimraf": "^2.0.2",
2222
"glob": "^7.1.3",
2323
"rimraf": "^2.6.3",
24-
"tree-kill": "^1.2.1"
24+
"tree-kill": "^1.2.1",
25+
"yargs": "13.3.0"
2526
},
2627
"author": "Provinzial Rheinland Versicherung AG",
2728
"license": "MPL-2.0",

packages/builders/src/electron/build-electron.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {BuildElectronArgs} from "./build-electron-args";
2+
import * as yargs from 'yargs';
23

34
let builder = require('electron-builder');
5+
let installAppDeps = require('electron-builder/out/cli/install-app-deps.js');
46

57
module.exports.build = function (args: BuildElectronArgs) {
68

@@ -21,3 +23,14 @@ module.exports.build = function (args: BuildElectronArgs) {
2123
process.exit(1)
2224
})
2325
};
26+
27+
module.exports.installAppDeps = function (args: any) {
28+
installAppDeps.installAppDeps(installAppDeps.configureInstallAppDepsCommand(yargs).argv).then(()=>{
29+
console.log('electron-builder installAppDeps completed successful.');
30+
process.exit(0)
31+
}).catch((error: any) => {
32+
console.error(`error invoking electron-builer installAppDeps: ${error}`);
33+
process.exit(1)
34+
})
35+
};
36+

packages/builders/src/electron/index.ts

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -75,53 +75,14 @@ export class ElectronBuilder extends BrowserBuilder {
7575
);
7676
}
7777

78-
installElectronApplicationDependencies(builderConfig: BuilderConfiguration<ElectronBuilderSchema>): Observable<BuildEvent>{
79-
80-
81-
return new Observable<BuildEvent>( obs =>{
82-
const electronProjectPath : Path = resolve(this.context.workspace.root, normalize(builderConfig.options.electronProjectDir));
83-
const electronNodeModulesPath = getSystemPath(resolve( electronProjectPath ,normalize('node_modules')));
84-
rimraf(electronNodeModulesPath,{rmdir: rmdir}, (error)=>{
85-
if(error){
86-
this.context.logger.info(error.message);
87-
obs.error(error);
88-
obs.next({success: false});
89-
obs.complete();
90-
}
91-
});
92-
let electronBuilderExecutable : string ;
93-
if(process.platform === 'win32'){
94-
electronBuilderExecutable= 'electron-builder.cmd';
95-
}else{
96-
electronBuilderExecutable= 'electron-builder';
97-
}
98-
const electronBuilderExecutablePath : string = getSystemPath(join(this.context.workspace.root, 'node_modules' , '.bin', electronBuilderExecutable));
99-
const childProcess: ChildProcess = spawn(electronBuilderExecutablePath , ['install-app-deps'] ,{cwd:getSystemPath(electronProjectPath)});
100-
const killForkedProcess = () => {
101-
if (childProcess && childProcess.pid) {
102-
treeKill(childProcess.pid, 'SIGTERM');
103-
}
104-
};
105-
// Handle child process exit.
106-
const handleChildProcessExit = (code) => {
107-
killForkedProcess();
108-
if (code && code !== 0) {
109-
obs.error();
110-
}
111-
obs.next({ success: true });
112-
obs.complete();
113-
};
114-
childProcess.once('exit', handleChildProcessExit);
115-
childProcess.once('SIGINT', handleChildProcessExit);
116-
childProcess.once('uncaughtException', handleChildProcessExit);
117-
const handleParentProcessExit = () => {
118-
killForkedProcess();
119-
};
120-
process.once('exit', handleParentProcessExit);
121-
process.once('SIGINT', handleParentProcessExit);
122-
process.once('uncaughtException', handleParentProcessExit);
123-
})
78+
installElectronApplicationDependencies(builderConfig: BuilderConfiguration<ElectronBuilderSchema>): Observable<BuildEvent> {
12479

80+
return runModuleAsObservableFork(
81+
getSystemPath(this.context.workspace.root),
82+
'@ng-electron-devkit/builders/dist/electron/build-electron',
83+
'installAppDeps',
84+
[],
85+
);
12586
}
12687
}
12788

0 commit comments

Comments
 (0)