@morgan-stanley/composeui-node-launcher 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -0
- package/jest.config.ts +21 -0
- package/output/browserWindow.d.ts +8 -0
- package/output/browserWindow.js +16 -0
- package/output/cli/cli.d.ts +2 -0
- package/output/cli/cli.js +10 -0
- package/output/cli/executeScrtiptFile.d.ts +1 -0
- package/output/cli/executeScrtiptFile.js +12 -0
- package/output/index.d.ts +5 -0
- package/output/index.js +4 -0
- package/output/launcher.d.ts +7 -0
- package/output/launcher.js +29 -0
- package/output/windowConfig.d.ts +7 -0
- package/output/windowConfig.js +1 -0
- package/package.json +36 -0
- package/src/browserWindow.ts +19 -0
- package/src/cli/cli.ts +13 -0
- package/src/cli/executeScriptFile.spec.ts +11 -0
- package/src/cli/executeScrtiptFile.ts +13 -0
- package/src/cli/install.js +116 -0
- package/src/index.ts +5 -0
- package/src/launcher.spec.ts +38 -0
- package/src/launcher.ts +37 -0
- package/src/windowConfig.ts +7 -0
- package/tsconfig.json +15 -0
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<!-- Morgan Stanley makes this available to you under the Apache License, Version 2.0 (the "License"). You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
|
|
2
|
+
|
|
3
|
+
# @morgan-stanley/composeui-node-launcher
|
|
4
|
+
|
|
5
|
+
## Library
|
|
6
|
+
|
|
7
|
+
The library enables you to dynamically set properties for your window in your javascript code.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
function windowOpenExample() {
|
|
11
|
+
const window = new BrowserWindow(
|
|
12
|
+
{
|
|
13
|
+
url: "https://github.com/morganstanley/composeui",
|
|
14
|
+
title: "My Web App",
|
|
15
|
+
width: 1600,
|
|
16
|
+
height: 800
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
window.open();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
windowOpenExample();
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or with loadUrl
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
function loadUrlExample() {
|
|
30
|
+
const window = new BrowserWindow(
|
|
31
|
+
{
|
|
32
|
+
width: 1600,
|
|
33
|
+
height: 800
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
window.loadUrl("https://github.com/morganstanley/composeui");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
loadUrlExample();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
In order to set an icon for your application, set the _icon_ property when creating a new _BrowserWindow_. The url set for the icon must either be relative to the app url, or an http or https url. If the host part of the icon url is different from the app url, you must set the _COMPOSE_ALLOWED_IMAGE_SOURCES_ environment value to contain the allowed icon host(s). You may separate multiple allowed hosts with semicolons (;).
|
|
43
|
+
|
|
44
|
+
## CLI
|
|
45
|
+
|
|
46
|
+
The CLI enables you to execute your app with compose by executing the following command:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
composeui myapp.js
|
|
50
|
+
```
|
|
51
|
+
### Install.js
|
|
52
|
+
|
|
53
|
+
This script is downloading and extracting the necessary binaries from CDN during `npm install`.
|
|
54
|
+
By default it's downloading the binaries from the github tagged releases but the following variables can be overridden by setting an environment variable or including an .npmrc file:
|
|
55
|
+
|
|
56
|
+
CDN URL: `COMPOSEUI_CDN_URL` (or `npm_config_composeui_cdn_url`)
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
COMPOSEUI_CDN_URL='http://127.0.0.1:8080'
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
version: `COMPOSEUI_VERSION` (or `npm_config_composeui_version`)
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
COMPOSEUI_VERSION='0.1.0'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
skip download: `COMPOSEUI_SKIP_DOWNLOAD` (or `npm_config_composeui_skip_download`)
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
COMPOSEUI_SKIP_DOWNLOAD='true'
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
location of the binary: `COMPOSEUI_BINARY_FILE_PATH` (or `npm_config_composeui_binary_file_path`)
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
COMPOSEUI_BINARY_FILE_PATH='path\to\binary\ComposeUI-Shell.exe'
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Local Development
|
|
81
|
+
|
|
82
|
+
#### Developing the CLI
|
|
83
|
+
|
|
84
|
+
If you're developing the CLI itself you need to execute the following command
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
npm link
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
in the `./src/shell/js/composeui-node-launcher/` folder.
|
|
91
|
+
|
|
92
|
+
#### Developing the install.js script
|
|
93
|
+
|
|
94
|
+
If you're developing the install.js script and would like to test if the binaries downloading and extracting as expected you can serve a folder with a name of the version containing a zip with the binaries locally (e.g with http-server), and set that link for the `COMPOSEUI_CDN_URL` environment variable.
|
|
95
|
+
|
|
96
|
+
For example:
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
COMPOSEUI_CDN_URL='http://127.0.0.1:8080'
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### Working with the locally compiled shell binary:
|
|
103
|
+
|
|
104
|
+
To achieve this you can set the `COMPOSEUI_BINARY_FILE_PATH` variable to point to the exe compiled by Visual Studio:
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
COMPOSEUI_BINARY_FILE_PATH='path\to\your\project\folder\ComposeUI\src\shell\dotnet\Shell\bin\Debug\net6.0-windows\ComposeUI-Shell.exe'
|
|
108
|
+
```
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* For a detailed explanation regarding each configuration property and type check, visit:
|
|
3
|
+
* https://jestjs.io/docs/configuration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
// Automatically clear mock calls, instances, contexts and results before every test
|
|
8
|
+
clearMocks: true,
|
|
9
|
+
|
|
10
|
+
// Indicates whether the coverage information should be collected while executing the test
|
|
11
|
+
collectCoverage: true,
|
|
12
|
+
|
|
13
|
+
// The directory where Jest should output its coverage files
|
|
14
|
+
coverageDirectory: "coverage",
|
|
15
|
+
|
|
16
|
+
// Indicates which provider should be used to instrument code for coverage
|
|
17
|
+
coverageProvider: "v8",
|
|
18
|
+
|
|
19
|
+
// A preset that is used as a base for Jest's configuration
|
|
20
|
+
preset: "ts-jest"
|
|
21
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Launcher } from './launcher.js';
|
|
2
|
+
export class BrowserWindow {
|
|
3
|
+
config;
|
|
4
|
+
launcher;
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.config = config;
|
|
7
|
+
this.launcher = new Launcher();
|
|
8
|
+
}
|
|
9
|
+
open() {
|
|
10
|
+
this.launcher.launch(this.config);
|
|
11
|
+
}
|
|
12
|
+
loadUrl(url) {
|
|
13
|
+
this.config.url = url;
|
|
14
|
+
this.launcher.launch(this.config);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function executeScriptFile(fileName: string): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { fork } from 'child_process';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
"use strict";
|
|
4
|
+
export function executeScriptFile(fileName) {
|
|
5
|
+
if (fileName) {
|
|
6
|
+
let filePath = resolve(fileName);
|
|
7
|
+
const child = fork(filePath);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
throw new Error("Specify filename.");
|
|
11
|
+
}
|
|
12
|
+
}
|
package/output/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { execFile } from 'child_process';
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
export class Launcher {
|
|
4
|
+
composeuiBinaryFileName = process.platform === 'win32' ? 'ComposeUI-Shell.exe' : 'ComposeUI-Shell';
|
|
5
|
+
composeuiBinaryFilePath = process.env.npm_config_composeui_binary_file_path || process.env.COMPOSEUI_BINARY_FILE_PATH || fileURLToPath(new URL(`./../dist/${this.composeuiBinaryFileName}`, import.meta.url));
|
|
6
|
+
processArgs(config) {
|
|
7
|
+
let argsArray = [];
|
|
8
|
+
if (config) {
|
|
9
|
+
for (const [key, value] of Object.entries(config)) {
|
|
10
|
+
argsArray.push(`--${key}=${value}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return argsArray;
|
|
14
|
+
}
|
|
15
|
+
launch(config) {
|
|
16
|
+
let argsArray = this.processArgs(config);
|
|
17
|
+
if (!config?.url) {
|
|
18
|
+
throw new Error("At least the url must be specified!");
|
|
19
|
+
}
|
|
20
|
+
const child = execFile(this.composeuiBinaryFilePath, argsArray, (error, stdout, stderr) => {
|
|
21
|
+
console.log(stdout);
|
|
22
|
+
if (error) {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
let exithandler = function () { process.exit(); };
|
|
27
|
+
child.on('close', exithandler);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@morgan-stanley/composeui-node-launcher",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Package to launch ComposeUI from Node.js",
|
|
6
|
+
"main": "output/index.js",
|
|
7
|
+
"module": "output/index.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"author": "Morgan Stanley",
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/morganstanley/ComposeUI.git#main"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"clean": "rimraf output",
|
|
17
|
+
"build": "npm run clean && tsc",
|
|
18
|
+
"install": "node ./src/cli/install.js",
|
|
19
|
+
"test": "jest"
|
|
20
|
+
},
|
|
21
|
+
"bin": {
|
|
22
|
+
"composeui": "./output/cli/cli.js"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/jest": "29.4.0",
|
|
26
|
+
"@types/node": "^18.11.18",
|
|
27
|
+
"@deranged/unzipper": "^0.10.14",
|
|
28
|
+
"axios": "^1.3.4",
|
|
29
|
+
"jest": "29.4.3",
|
|
30
|
+
"rimraf": "^4.4.0",
|
|
31
|
+
"ts-jest": "29.0.5",
|
|
32
|
+
"ts-node": "10.9.1",
|
|
33
|
+
"tslib": "^2.4.0",
|
|
34
|
+
"typescript": "^4.7.4"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { WindowConfig } from './windowConfig';
|
|
2
|
+
import { Launcher } from './launcher.js';
|
|
3
|
+
|
|
4
|
+
export class BrowserWindow {
|
|
5
|
+
private launcher: Launcher;
|
|
6
|
+
|
|
7
|
+
constructor(private config: WindowConfig) {
|
|
8
|
+
this.launcher = new Launcher();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public open() {
|
|
12
|
+
this.launcher.launch(this.config);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public loadUrl(url: string) {
|
|
16
|
+
this.config.url = url
|
|
17
|
+
this.launcher.launch(this.config);
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/cli/cli.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { executeScriptFile } from './executeScrtiptFile';
|
|
2
|
+
|
|
3
|
+
describe('CLI', () => {
|
|
4
|
+
let testFileName: string;
|
|
5
|
+
|
|
6
|
+
test('executeScriptFile() - No filename specified', () => {
|
|
7
|
+
expect(() => {
|
|
8
|
+
executeScriptFile(testFileName);
|
|
9
|
+
}).toThrow("Specify filename.");
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { fork } from 'child_process';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
export function executeScriptFile(fileName: string){
|
|
7
|
+
if (fileName) {
|
|
8
|
+
let filePath: string = resolve(fileName);
|
|
9
|
+
const child = fork(filePath);
|
|
10
|
+
} else {
|
|
11
|
+
throw new Error("Specify filename.");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import os from 'os';
|
|
8
|
+
|
|
9
|
+
import axios from 'axios';
|
|
10
|
+
import unzipper from '@deranged/unzipper';
|
|
11
|
+
|
|
12
|
+
import pkg from './../../package.json' assert { type: "json" };
|
|
13
|
+
|
|
14
|
+
const DEFAULT_CDN_URL = 'https://github.com/morganstanley/ComposeUI/releases/download';
|
|
15
|
+
|
|
16
|
+
let cdnUrl = process.env.npm_config_composeui_cdn_url || process.env.COMPOSEUI_CDN_URL || DEFAULT_CDN_URL;
|
|
17
|
+
let downloadedFile = '';
|
|
18
|
+
|
|
19
|
+
let platform = validatePlatform();
|
|
20
|
+
|
|
21
|
+
const composeui_version = process.env.npm_config_composeui_version || process.env.COMPOSEUI_VERSION || pkg.version;
|
|
22
|
+
const skipDownload = process.env.npm_config_composeui_skip_download || process.env.COMPOSEUI_SKIP_DOWNLOAD;
|
|
23
|
+
|
|
24
|
+
const fileName = `composeui-v${composeui_version}-${platform}.zip`;
|
|
25
|
+
let composeuiBinaryFilePath = '';
|
|
26
|
+
|
|
27
|
+
if (skipDownload === 'true') {
|
|
28
|
+
console.log('Found COMPOSEUI_SKIP_DOWNLOAD variable, skipping installation.');
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function validatePlatform() {
|
|
33
|
+
let platform = process.platform;
|
|
34
|
+
|
|
35
|
+
if (platform !== 'win32') {
|
|
36
|
+
console.log('Unexpected platform or architecture:', process.platform, process.arch);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return platform;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ensureDirectoryExistence(filePath) {
|
|
44
|
+
let dirname = path.dirname(filePath);
|
|
45
|
+
if (fs.existsSync(dirname)) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
ensureDirectoryExistence(dirname);
|
|
49
|
+
fs.mkdirSync(dirname);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function downloadFile(dirToLoadTo) {
|
|
53
|
+
const tempDownloadedFile = path.resolve(dirToLoadTo, fileName);
|
|
54
|
+
downloadedFile = tempDownloadedFile;
|
|
55
|
+
const formattedDownloadUrl =`${cdnUrl}/v${composeui_version}/${fileName}`;
|
|
56
|
+
|
|
57
|
+
console.log('Downloading from file: ', formattedDownloadUrl);
|
|
58
|
+
console.log('Saving to file:', downloadedFile);
|
|
59
|
+
|
|
60
|
+
ensureDirectoryExistence(downloadedFile);
|
|
61
|
+
await axios.request({
|
|
62
|
+
method: 'get',
|
|
63
|
+
url: formattedDownloadUrl,
|
|
64
|
+
responseType: 'stream'
|
|
65
|
+
}).then(function (response) {
|
|
66
|
+
response.data.pipe(fs.createWriteStream(downloadedFile))
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function extractFile(zipPath, outPath) {
|
|
71
|
+
let zipFile = `${zipPath}/${fileName}`;
|
|
72
|
+
|
|
73
|
+
if (path.extname(zipFile) !== '.zip') {
|
|
74
|
+
console.log('Skipping zip extraction - binary file found.');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
console.log(`Extracting zip contents to ${outPath}.`);
|
|
78
|
+
try {
|
|
79
|
+
fs.createReadStream(zipFile).pipe(unzipper.Extract({ path: outPath }));
|
|
80
|
+
} catch (error) {
|
|
81
|
+
throw new Error('Error extracting archive: ' + error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function createTempFolder(){
|
|
86
|
+
let tempFolderPath
|
|
87
|
+
try {
|
|
88
|
+
tempFolderPath = fs.mkdtempSync(path.join(os.tmpdir(), 'composeui-'));
|
|
89
|
+
} catch (err) {
|
|
90
|
+
console.error(err);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return tempFolderPath;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function isInstalled (outPath) {
|
|
97
|
+
let composeuiBinaryFileName = process.platform === 'win32' ? 'ComposeUI-Shell.exe' : 'ComposeUI-Shell';
|
|
98
|
+
composeuiBinaryFilePath = path.resolve(outPath, composeuiBinaryFileName);
|
|
99
|
+
|
|
100
|
+
return fs.existsSync(composeuiBinaryFilePath);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function install() {
|
|
104
|
+
const tmpPath = createTempFolder();
|
|
105
|
+
const outPath = process.cwd() + "/dist";
|
|
106
|
+
|
|
107
|
+
if (isInstalled(outPath)){
|
|
108
|
+
console.log('ComposeUI is already installed.');
|
|
109
|
+
process.exit(0);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
await downloadFile(tmpPath);
|
|
113
|
+
await extractFile(tmpPath, outPath);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
install();
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { mocked } from 'jest-mock'
|
|
2
|
+
import { jest } from '@jest/globals';
|
|
3
|
+
|
|
4
|
+
import { Launcher } from './launcher';
|
|
5
|
+
import { WindowConfig } from './windowConfig';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
jest.mock('./launcher', () => {
|
|
9
|
+
return {
|
|
10
|
+
Launcher: jest.fn().mockImplementation(() => {
|
|
11
|
+
return {
|
|
12
|
+
launch: () => {throw new Error("At least the url must be specified!")},
|
|
13
|
+
};
|
|
14
|
+
})
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('Launcher', () => {
|
|
19
|
+
const MockedLauncher = mocked(Launcher, { shallow:true });
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
MockedLauncher.mockClear();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('constructor was called', () => {
|
|
26
|
+
const testLauncher = new Launcher();
|
|
27
|
+
expect(MockedLauncher).toHaveBeenCalledTimes(1);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('throws if Window config has no parameters', () => {
|
|
31
|
+
let testWindowConfig: WindowConfig = {};
|
|
32
|
+
|
|
33
|
+
expect(() => {
|
|
34
|
+
const testLauncher = new Launcher();
|
|
35
|
+
testLauncher.launch(testWindowConfig);
|
|
36
|
+
}).toThrow("At least the url must be specified!");
|
|
37
|
+
});
|
|
38
|
+
});
|
package/src/launcher.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { execFile } from 'child_process';
|
|
2
|
+
import { WindowConfig } from './windowConfig';
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
export class Launcher {
|
|
6
|
+
private composeuiBinaryFileName = process.platform === 'win32' ? 'ComposeUI-Shell.exe' : 'ComposeUI-Shell';
|
|
7
|
+
private composeuiBinaryFilePath = process.env.npm_config_composeui_binary_file_path || process.env.COMPOSEUI_BINARY_FILE_PATH || fileURLToPath(new URL(`./../dist/${this.composeuiBinaryFileName}`, import.meta.url));
|
|
8
|
+
|
|
9
|
+
private processArgs(config?: WindowConfig) {
|
|
10
|
+
let argsArray = [];
|
|
11
|
+
if (config) {
|
|
12
|
+
for (const [key, value] of Object.entries(config)) {
|
|
13
|
+
argsArray.push(`--${key}=${value}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return argsArray;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public launch(config?: WindowConfig) {
|
|
21
|
+
let argsArray = this.processArgs(config);
|
|
22
|
+
|
|
23
|
+
if (!config?.url) {
|
|
24
|
+
throw new Error("At least the url must be specified!");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const child = execFile(this.composeuiBinaryFilePath, argsArray, (error, stdout, stderr) => {
|
|
28
|
+
console.log(stdout);
|
|
29
|
+
if (error) {
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
let exithandler = function() { process.exit() };
|
|
35
|
+
child.on('close', exithandler);
|
|
36
|
+
}
|
|
37
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"moduleResolution": "node",
|
|
4
|
+
"types": [ "node", "jest" ],
|
|
5
|
+
"experimentalDecorators": true,
|
|
6
|
+
"module": "es2022",
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"target": "es2022",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"outDir": "output",
|
|
11
|
+
"lib": [ "es2022", "DOM" ],
|
|
12
|
+
"strict": true
|
|
13
|
+
},
|
|
14
|
+
"files": [ "src/index.ts" ]
|
|
15
|
+
}
|