-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.ts
54 lines (47 loc) · 1.76 KB
/
index.ts
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
import {
BuilderContext,
BuilderOutput,
createBuilder,
Target
} from '@angular-devkit/architect';
import { spawn } from 'child_process';
import * as path from 'path';
interface Options {
workspaceConfig?: string;
devTools?: boolean;
allowIntegration?: boolean;
}
export default createBuilder((options: Options, context: BuilderContext) => {
return new Promise<BuilderOutput>(async () => {
// create a target for building the app
const buildTarget: Target = {
target: 'serve',
project: (context.target as Target).project,
configuration: options.workspaceConfig ? options.workspaceConfig : ''
};
// start building the app
const build = await context.scheduleTarget(buildTarget);
const result = await build.result;
// find the path of the Electron binary and run it passing the shell.js as a parameter
const electronPath = path.resolve('node_modules/.bin/electron');
const appPath = path.resolve('node_modules/ngx-electronify/shell.js');
// the port of the Angular Live Development Server is passed to the Electron window
// so that it knows exactly which URL should load
const port = result.port as string;
// the following parameters are checked in that way because we explicitly want to have a boolean value.
// If the user passes a string, we assume that it is a boolean value
const devTools =
options.devTools != null && `${options.devTools}` !== 'false';
const allowIntegration =
options.allowIntegration != null &&
`${options.allowIntegration}` !== 'false';
spawn(
electronPath,
[appPath, port, devTools.toString(), allowIntegration.toString()],
{
shell: true
}
);
context.logger.info('Launching Electron window...');
});
});