openfin-cli 3.0.2 → 4.0.0-alpha.2
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/LICENSE.md +1 -0
- package/README.md +15 -90
- package/dist/cli.js +75 -0
- package/dist/index.js +201 -0
- package/dist/logger.js +50 -0
- package/dist/report-usage.js +50 -0
- package/dist/utils.js +28 -0
- package/dist/validateManifest.js +23 -0
- package/dist/version.js +1 -0
- package/package.json +25 -49
- package/LICENSE +0 -201
- package/cli.js +0 -35
- package/index.js +0 -177
- package/report-usage.js +0 -44
- package/utils.js +0 -25
package/LICENSE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Please refer to the [OpenFin Developer License Agreement](https://www.openfin.co/developer-agreement/).
|
package/README.md
CHANGED
|
@@ -1,90 +1,15 @@
|
|
|
1
|
-
# OpenFin
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
```sh
|
|
21
|
-
$ openfin --help
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Examples
|
|
25
|
-
|
|
26
|
-
#### Launching OpenFin Demos
|
|
27
|
-
```
|
|
28
|
-
$ openfin --launch --config http://cdn.openfin.co/demos/hyperblotter/app.json
|
|
29
|
-
$ openfin --launch --config https://demoappdirectory.openf.in/desktop/config/apps/OpenFin/HelloOpenFin/app.json
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
#### Launching an application
|
|
33
|
-
|
|
34
|
-
```sh
|
|
35
|
-
$ openfin --launch --url http://www.openfin.co
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Shorthand
|
|
39
|
-
```sh
|
|
40
|
-
$ openfin -l -u http://www.openfin.co
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
#### Launch application and save manifest to the working directory
|
|
44
|
-
|
|
45
|
-
```sh
|
|
46
|
-
$ openfin --launch --url http://www.openfin.co --save myconfig.json
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Shorthand
|
|
50
|
-
```sh
|
|
51
|
-
$ openfin -l -u http://www.openfin.co -s myconfig.json
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
#### Launching a given config file
|
|
56
|
-
|
|
57
|
-
```sh
|
|
58
|
-
$ openfin --launch --config myconfig.json
|
|
59
|
-
$ openfin --launch --config http://goo.gl/w2747v
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
Shorthand
|
|
63
|
-
```sh
|
|
64
|
-
$ openfin -l -c myconfig.json
|
|
65
|
-
$ openfin -l -c http://goo.gl/w2747v
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
#### Launching URLs into an OpenFin Platform
|
|
69
|
-
```
|
|
70
|
-
$ openfin --launch --platform --url https://openfin.co,http://cdn.openfin.co/demos/hyperblotter/index.html,https://google.com
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
```
|
|
74
|
-
## License
|
|
75
|
-
|
|
76
|
-
Apache 2.0
|
|
77
|
-
|
|
78
|
-
The code in this repository is covered by the included license.
|
|
79
|
-
|
|
80
|
-
However, if you run this code, it may call on the OpenFin RVM or OpenFin Runtime, which are covered by OpenFin’s Developer, Community, and Enterprise licenses. You can learn more about OpenFin licensing at the links listed below or just email us at support@openfin.co with questions.
|
|
81
|
-
|
|
82
|
-
https://openfin.co/developer-agreement/ <br/>
|
|
83
|
-
https://openfin.co/licensing/
|
|
84
|
-
|
|
85
|
-
[npm-url]: https://npmjs.org/package/openfin-cli
|
|
86
|
-
[npm-image]: https://badge.fury.io/js/openfin-cli.svg
|
|
87
|
-
[travis-url]: https://travis-ci.org/rdepena/openfin-cli
|
|
88
|
-
[travis-image]: https://travis-ci.org/rdepena/openfin-cli.svg?branch=master
|
|
89
|
-
[daviddm-url]: https://david-dm.org/rdepena/openfin-cli.svg?theme=shields.io
|
|
90
|
-
[daviddm-image]: https://david-dm.org/rdepena/openfin-cli
|
|
1
|
+
# OpenFin CLI
|
|
2
|
+
|
|
3
|
+
The OpenFin CLI tool will allow you to launch the OpenFin runtime given a url or a configuration file, it will also allow you to create configuration files by giving only name and url.
|
|
4
|
+
|
|
5
|
+
For more information please refer to the [developer guide](https://developers.openfin.co/of-docs/docs/openfin-cli-tool).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
With npm:
|
|
10
|
+
|
|
11
|
+
> npm -i -g openfin-cli
|
|
12
|
+
|
|
13
|
+
With yarn:
|
|
14
|
+
|
|
15
|
+
> yarn global add openfin-cli
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { hideBin } from 'yargs/helpers';
|
|
3
|
+
import yargs from 'yargs/yargs';
|
|
4
|
+
import { openfinCli } from './index.js';
|
|
5
|
+
import { Logger } from './logger.js';
|
|
6
|
+
import { API_VERSION } from './version.js';
|
|
7
|
+
global.logger = new Logger();
|
|
8
|
+
const yargsParser = yargs(hideBin(process.argv))
|
|
9
|
+
.scriptName('OpenFin Runtime CLI tool')
|
|
10
|
+
.option('config', {
|
|
11
|
+
alias: 'c',
|
|
12
|
+
type: 'string',
|
|
13
|
+
description: 'path to config file',
|
|
14
|
+
})
|
|
15
|
+
.option('url', {
|
|
16
|
+
alias: 'u',
|
|
17
|
+
type: 'string',
|
|
18
|
+
description: 'application url or comma separated list of urls',
|
|
19
|
+
})
|
|
20
|
+
.option('launch', {
|
|
21
|
+
alias: 'l',
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
description: 'launch this configuration',
|
|
24
|
+
})
|
|
25
|
+
.option('devtools-port', {
|
|
26
|
+
alias: 'p',
|
|
27
|
+
type: 'number',
|
|
28
|
+
description: 'devtools port number',
|
|
29
|
+
default: 9090,
|
|
30
|
+
// make it devtoolsPort
|
|
31
|
+
})
|
|
32
|
+
.option('runtime-version', {
|
|
33
|
+
alias: 'r',
|
|
34
|
+
type: 'string',
|
|
35
|
+
description: 'runtime version',
|
|
36
|
+
default: 'stable',
|
|
37
|
+
})
|
|
38
|
+
.option('platform', {
|
|
39
|
+
alias: 't',
|
|
40
|
+
type: 'boolean',
|
|
41
|
+
default: false,
|
|
42
|
+
description: 'launch as a platform window with multiple URLs',
|
|
43
|
+
})
|
|
44
|
+
.option('save', {
|
|
45
|
+
alias: 's',
|
|
46
|
+
type: 'string',
|
|
47
|
+
description: 'save the manifest to the current directory <manifest name>',
|
|
48
|
+
})
|
|
49
|
+
.option('log-level', {
|
|
50
|
+
type: 'string',
|
|
51
|
+
description: 'Run with custom log level',
|
|
52
|
+
choices: ['DEBUG', 'INFO', 'WARN', 'ERROR', 'NONE'],
|
|
53
|
+
default: 'INFO',
|
|
54
|
+
})
|
|
55
|
+
.check((argv) => {
|
|
56
|
+
if (argv.config && argv.url) {
|
|
57
|
+
throw new Error('Cannot use both config and url options at the same time');
|
|
58
|
+
}
|
|
59
|
+
if (argv.url &&
|
|
60
|
+
(argv.platform || argv['devtools-port'] !== 9090 || argv['runtime-version'] !== 'stable' || argv.save)) {
|
|
61
|
+
throw new Error('While using the URL option, you cannot use the platform, devtools-port, runtime-version, or save options cannot be used');
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
})
|
|
65
|
+
.command('*', 'OpenFin CLI', () => ({}), (v) => {
|
|
66
|
+
// TODO: Validate commands + show help
|
|
67
|
+
if (!v.url && !v.launch) {
|
|
68
|
+
yargsParser.showHelp();
|
|
69
|
+
}
|
|
70
|
+
global.logger.setLogLevelString(v.logLevel);
|
|
71
|
+
openfinCli(v);
|
|
72
|
+
})
|
|
73
|
+
.example('openfin --launch --config https://cdn.openfin.co/release/apps/openfin/processmanager/app.json', "Launches OpenFin's Process Manager app hosted on the OpenFin CDN")
|
|
74
|
+
.version(API_VERSION);
|
|
75
|
+
yargsParser.parse();
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import crypto from 'crypto';
|
|
11
|
+
import dns from 'dns';
|
|
12
|
+
import fs from 'fs/promises';
|
|
13
|
+
import { connect, launch as launchOpenFinFromAdapter } from 'openfin-adapter';
|
|
14
|
+
import os from 'os';
|
|
15
|
+
import path from 'path';
|
|
16
|
+
import { reportUsage } from './report-usage.js';
|
|
17
|
+
import { fetch, formatTimeFromMs, isURL } from './utils.js';
|
|
18
|
+
import { manifestSchema } from './validateManifest.js';
|
|
19
|
+
if (typeof dns.setDefaultResultOrder === 'function') {
|
|
20
|
+
dns.setDefaultResultOrder('ipv4first');
|
|
21
|
+
}
|
|
22
|
+
let launchTime;
|
|
23
|
+
export const openfinCli = (cli) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const { config, url, launch, devtoolsPort, runtimeVersion, save, platform } = cli;
|
|
25
|
+
let manifestUrl = config;
|
|
26
|
+
let buildConfig;
|
|
27
|
+
let configObject;
|
|
28
|
+
try {
|
|
29
|
+
if (url) {
|
|
30
|
+
buildConfig = true;
|
|
31
|
+
const manifestInfo = yield writeManifest(url.split(','), platform, devtoolsPort, runtimeVersion, save);
|
|
32
|
+
manifestUrl = manifestInfo.filepath;
|
|
33
|
+
configObject = manifestInfo.manifest;
|
|
34
|
+
}
|
|
35
|
+
if (launch) {
|
|
36
|
+
if (!buildConfig && manifestUrl) {
|
|
37
|
+
if (manifestUrl && isURL(manifestUrl)) {
|
|
38
|
+
try {
|
|
39
|
+
global.logger.debug(`Fetching manifest from: ${manifestUrl}`);
|
|
40
|
+
const fetchedConfig = yield fetch(manifestUrl);
|
|
41
|
+
configObject = manifestSchema.parse(fetchedConfig);
|
|
42
|
+
global.logger.debug('Manifest', JSON.stringify(config));
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error instanceof Error) {
|
|
46
|
+
global.logger.error(`Failed to fetch manifest from ${manifestUrl} with error: ${error.message}`);
|
|
47
|
+
global.logger.debug(JSON.stringify(error));
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
manifestUrl = path.resolve(manifestUrl);
|
|
57
|
+
try {
|
|
58
|
+
global.logger.debug(`Reading manifest from: ${manifestUrl}`);
|
|
59
|
+
const configBuffer = yield fs.readFile(manifestUrl);
|
|
60
|
+
configObject = JSON.parse(configBuffer.toString());
|
|
61
|
+
global.logger.debug('Manifest:', JSON.stringify(config));
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (error instanceof Error) {
|
|
65
|
+
global.logger.error(`Failed to get manifest from ${manifestUrl} with error: ${error.message}`);
|
|
66
|
+
global.logger.debug(JSON.stringify(error));
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (!configObject) {
|
|
76
|
+
throw new Error('No config object found');
|
|
77
|
+
}
|
|
78
|
+
if (!manifestUrl) {
|
|
79
|
+
throw new Error('No manifest url found');
|
|
80
|
+
}
|
|
81
|
+
reportUsage('START', manifestUrl, configObject);
|
|
82
|
+
launchOpenfin(manifestUrl, config, configObject);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
globalThis.logger.error('Failed:', JSON.stringify(error));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
const launchOpenfin = (manifestUrl, config, configObject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
try {
|
|
91
|
+
global.logger.info(`Launching OpenFin with manifest: ${manifestUrl}`);
|
|
92
|
+
launchTime = Date.now();
|
|
93
|
+
const port = yield launchOpenFinFromAdapter({ manifestUrl });
|
|
94
|
+
global.logger.debug('Application Launched');
|
|
95
|
+
global.logger.debug(`Connecting to devtool port: ${port}`);
|
|
96
|
+
const fin = yield connect({
|
|
97
|
+
uuid: `adapter-connection-${crypto.randomUUID()}`,
|
|
98
|
+
address: `ws://localhost:${port}`,
|
|
99
|
+
nonPersistent: true,
|
|
100
|
+
});
|
|
101
|
+
global.logger.debug(`Connected to devtool port: ${port}`);
|
|
102
|
+
fin.once('disconnected', () => {
|
|
103
|
+
global.logger.info(`Disconnected from application, exiting after ${formatTimeFromMs(Date.now() - launchTime)}`);
|
|
104
|
+
process.exit();
|
|
105
|
+
});
|
|
106
|
+
global.logger.debug('Disconnect Listener Added');
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
const err = error instanceof Error || error instanceof String ? error.toString() : JSON.stringify(error);
|
|
110
|
+
reportUsage(err.toString(), config, configObject);
|
|
111
|
+
// Maybe check what the error is and decide log level on that
|
|
112
|
+
// Sometimes errors are thrown when they shouldn't be
|
|
113
|
+
global.logger.warn('Error thrown launching/connecting to application instance', JSON.stringify(err));
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
const writeManifest = (urls, isPlatform, devtoolsPort, runtime, manifestName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
const uuid = `app-${crypto.randomUUID()}`;
|
|
118
|
+
const version = runtime;
|
|
119
|
+
let manifest;
|
|
120
|
+
const generateViewObjWithUrl = (url) => ({
|
|
121
|
+
type: 'component',
|
|
122
|
+
componentName: 'view',
|
|
123
|
+
componentState: {
|
|
124
|
+
name: `view-${crypto.randomUUID()}`,
|
|
125
|
+
url,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
const buildContent = () => {
|
|
129
|
+
const content = [];
|
|
130
|
+
urls.forEach((url) => {
|
|
131
|
+
content.push(generateViewObjWithUrl(url));
|
|
132
|
+
});
|
|
133
|
+
return content;
|
|
134
|
+
};
|
|
135
|
+
if (isPlatform) {
|
|
136
|
+
const content = buildContent();
|
|
137
|
+
manifest = {
|
|
138
|
+
runtime: {
|
|
139
|
+
version,
|
|
140
|
+
},
|
|
141
|
+
platform: {
|
|
142
|
+
uuid,
|
|
143
|
+
autoShow: false,
|
|
144
|
+
},
|
|
145
|
+
snapshot: {
|
|
146
|
+
windows: [
|
|
147
|
+
{
|
|
148
|
+
saveWindowState: false,
|
|
149
|
+
backgroundThrottling: true,
|
|
150
|
+
layout: {
|
|
151
|
+
content: [
|
|
152
|
+
{
|
|
153
|
+
type: 'row',
|
|
154
|
+
id: 'no-drop-target',
|
|
155
|
+
content,
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
manifest = {
|
|
166
|
+
devtools_port: devtoolsPort,
|
|
167
|
+
startup_app: {
|
|
168
|
+
name: uuid,
|
|
169
|
+
url: urls[0],
|
|
170
|
+
uuid,
|
|
171
|
+
saveWindowState: false,
|
|
172
|
+
autoShow: true,
|
|
173
|
+
},
|
|
174
|
+
runtime: {
|
|
175
|
+
version,
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
global.logger.debug('Stringifying manifest');
|
|
180
|
+
const manifestJson = JSON.stringify(manifest, null, 4);
|
|
181
|
+
global.logger.debug(`Manifest stringified successfully ${manifestJson}`);
|
|
182
|
+
let filepath;
|
|
183
|
+
if (manifestName) {
|
|
184
|
+
filepath = path.join(process.cwd(), manifestName);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
filepath = path.join(os.tmpdir(), `${uuid}.json`);
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
global.logger.debug(`Writing manifest to: ${path.resolve(filepath)}`);
|
|
191
|
+
yield fs.writeFile(filepath, manifestJson);
|
|
192
|
+
global.logger.info(`Manifest written to: ${path.resolve(filepath)}`);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
global.logger.error(`Failed to write manifest ${JSON.stringify(error)}`);
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
manifest,
|
|
199
|
+
filepath,
|
|
200
|
+
};
|
|
201
|
+
});
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export class Logger {
|
|
2
|
+
constructor(logLevel = 1 /* LogLevel.INFO */) {
|
|
3
|
+
this._logLevel = logLevel;
|
|
4
|
+
}
|
|
5
|
+
setLogLevel(logLevel) {
|
|
6
|
+
this._logLevel = logLevel;
|
|
7
|
+
}
|
|
8
|
+
setLogLevelString(logLevel) {
|
|
9
|
+
switch (logLevel.toLowerCase()) {
|
|
10
|
+
case 'debug':
|
|
11
|
+
this._logLevel = 0 /* LogLevel.DEBUG */;
|
|
12
|
+
break;
|
|
13
|
+
case 'info':
|
|
14
|
+
this._logLevel = 1 /* LogLevel.INFO */;
|
|
15
|
+
break;
|
|
16
|
+
case 'warn':
|
|
17
|
+
this._logLevel = 2 /* LogLevel.WARN */;
|
|
18
|
+
break;
|
|
19
|
+
case 'error':
|
|
20
|
+
this._logLevel = 3 /* LogLevel.ERROR */;
|
|
21
|
+
break;
|
|
22
|
+
case 'none':
|
|
23
|
+
this._logLevel = 4 /* LogLevel.NONE */;
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
this._logLevel = 1 /* LogLevel.INFO */;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
debug(message, ...args) {
|
|
31
|
+
if (this._logLevel <= 0 /* LogLevel.DEBUG */) {
|
|
32
|
+
console.log(`[DEBUG] ${message}`, ...args);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
info(message, ...args) {
|
|
36
|
+
if (this._logLevel <= 1 /* LogLevel.INFO */) {
|
|
37
|
+
console.log(`[INFO] ${message}`, ...args);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
warn(message, ...args) {
|
|
41
|
+
if (this._logLevel <= 2 /* LogLevel.WARN */) {
|
|
42
|
+
console.log(`[WARN] ${message}`, ...args);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
error(message, ...args) {
|
|
46
|
+
if (this._logLevel <= 3 /* LogLevel.ERROR */) {
|
|
47
|
+
console.log(`[ERROR] ${message}`, ...args);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import axios from 'axios';
|
|
11
|
+
import machineId from 'node-machine-id';
|
|
12
|
+
import os from 'os';
|
|
13
|
+
const getAppName = (configObject) => {
|
|
14
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
15
|
+
return ((_h = (_f = (_d = (_b = (_a = configObject.startup_app) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : (_c = configObject.startup_app) === null || _c === void 0 ? void 0 : _c.uuid) !== null && _d !== void 0 ? _d : (_e = configObject.platform) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : (_g = configObject.platform) === null || _g === void 0 ? void 0 : _g.uuid) !== null && _h !== void 0 ? _h : 'no-app-name-or-uuid');
|
|
16
|
+
};
|
|
17
|
+
export const reportUsage = (status, config, configObject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
var _a, _b, _c;
|
|
19
|
+
if (process.platform === 'win32')
|
|
20
|
+
return;
|
|
21
|
+
const reportUrl = new URL('https://install.openfin.co/installer-usage?');
|
|
22
|
+
const reportUrlParams = new URLSearchParams({
|
|
23
|
+
appName: getAppName(configObject),
|
|
24
|
+
appLocation: typeof __dirname !== 'undefined' ? __dirname : 'unknown',
|
|
25
|
+
version: (_b = (_a = configObject === null || configObject === void 0 ? void 0 : configObject.runtime) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : 'undefined',
|
|
26
|
+
machineId: yield machineId.machineId(true),
|
|
27
|
+
manifestUrl: config !== null && config !== void 0 ? config : 'undefined',
|
|
28
|
+
platform: `${os.platform()}-${os.release()})`,
|
|
29
|
+
licenseKey: (_c = configObject === null || configObject === void 0 ? void 0 : configObject.licenseKey) !== null && _c !== void 0 ? _c : 'contract_identifier',
|
|
30
|
+
launchMethod: 'openfin-cli',
|
|
31
|
+
launchStatus: status || 'SUCCESS',
|
|
32
|
+
});
|
|
33
|
+
reportUrl.search = reportUrlParams.toString();
|
|
34
|
+
try {
|
|
35
|
+
const reportUrlString = reportUrl.toString();
|
|
36
|
+
global.logger.debug(`OpenFin Reporting Usage Data: ${reportUrlString}`);
|
|
37
|
+
const response = yield axios.get(reportUrlString);
|
|
38
|
+
if (response.status !== 200) {
|
|
39
|
+
global.logger.error('OpenFin Report Usage Data Failed');
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
global.logger.debug(`OpenFin Report Usage Data: Status: ${response.status}`);
|
|
43
|
+
global.logger.debug(`OpenFin Report Usage Data: Response: ${response.data.toString()}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
const err = error instanceof Error || error instanceof String ? error.toString() : JSON.stringify(error);
|
|
48
|
+
global.logger.warn('OpenFin Report Usage Data Failed:', err);
|
|
49
|
+
}
|
|
50
|
+
});
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import axios from 'axios';
|
|
11
|
+
export const fetch = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
const response = yield axios.get(url);
|
|
13
|
+
if (response.status < 200 || response.status > 399) {
|
|
14
|
+
throw new Error(`Failed to load url: ${url}, status code:${response.status}`);
|
|
15
|
+
}
|
|
16
|
+
return response.data;
|
|
17
|
+
});
|
|
18
|
+
export const isURL = (str) => {
|
|
19
|
+
return str.lastIndexOf('http') >= 0;
|
|
20
|
+
};
|
|
21
|
+
export const formatTimeFromMs = (ms) => {
|
|
22
|
+
const seconds = Math.floor(ms / 1000);
|
|
23
|
+
const minutes = Math.floor(seconds / 60);
|
|
24
|
+
const hours = Math.floor(minutes / 60);
|
|
25
|
+
const secondsRemainder = seconds % 60;
|
|
26
|
+
const minutesRemainder = minutes % 60;
|
|
27
|
+
return `${hours ? `${hours}h ` : ''}${minutesRemainder ? `${minutesRemainder}m ` : ''}${secondsRemainder ? `${secondsRemainder}s` : ''}`;
|
|
28
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
// TODO: Maybe add all manifest options, then add a CLI feature to
|
|
3
|
+
// verify the manifest against the schema.
|
|
4
|
+
export const manifestSchema = z.object({
|
|
5
|
+
startup_app: z.optional(z.object({
|
|
6
|
+
name: z.optional(z.string()),
|
|
7
|
+
uuid: z.optional(z.string()),
|
|
8
|
+
url: z.optional(z.string()),
|
|
9
|
+
saveWindowState: z.optional(z.boolean()),
|
|
10
|
+
autoShow: z.optional(z.boolean()),
|
|
11
|
+
})),
|
|
12
|
+
platform: z.optional(z.object({
|
|
13
|
+
uuid: z.optional(z.string()),
|
|
14
|
+
name: z.optional(z.string()),
|
|
15
|
+
autoShow: z.optional(z.boolean()),
|
|
16
|
+
})),
|
|
17
|
+
runtime: z.optional(z.object({
|
|
18
|
+
version: z.optional(z.string()),
|
|
19
|
+
})),
|
|
20
|
+
snapshot: z.optional(z.any()),
|
|
21
|
+
licenseKey: z.optional(z.string()),
|
|
22
|
+
devtools_port: z.optional(z.number()),
|
|
23
|
+
});
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const API_VERSION = '4.0.0-alpha.2';
|
package/package.json
CHANGED
|
@@ -1,50 +1,26 @@
|
|
|
1
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
|
-
"hadouken-js-adapter": "^1.44.1",
|
|
28
|
-
"meow": "^7.0.1",
|
|
29
|
-
"node-machine-id": "^1.1.10"
|
|
30
|
-
},
|
|
31
|
-
"devDependencies": {
|
|
32
|
-
"grunt": "^1.0.3",
|
|
33
|
-
"grunt-cli": "^1.2.0",
|
|
34
|
-
"grunt-contrib-jshint": "^1.1.0",
|
|
35
|
-
"grunt-contrib-nodeunit": "^2.0.0",
|
|
36
|
-
"grunt-contrib-watch": "^1.1.0",
|
|
37
|
-
"grunt-jsbeautifier": "^0.2.7",
|
|
38
|
-
"grunt-mocha-cli": "^4.0.0",
|
|
39
|
-
"jshint-stylish": "^1.0.0",
|
|
40
|
-
"load-grunt-tasks": "^4.0.0",
|
|
41
|
-
"time-grunt": "^1.0.0"
|
|
42
|
-
},
|
|
43
|
-
"scripts": {
|
|
44
|
-
"start": "node cli",
|
|
45
|
-
"test": "grunt mochacli"
|
|
46
|
-
},
|
|
47
|
-
"bin": {
|
|
48
|
-
"openfin": "cli.js"
|
|
49
|
-
}
|
|
50
|
-
}
|
|
2
|
+
"name": "openfin-cli",
|
|
3
|
+
"version": "4.0.0-alpha.2",
|
|
4
|
+
"description": "Supports command line development in the OpenFin environment.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"homepage": "http://www.openfin.co",
|
|
7
|
+
"author": "OpenFin Inc.",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=16"
|
|
10
|
+
},
|
|
11
|
+
"license": "SEE LICENSE IN LICENSE.MD",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"openfin",
|
|
14
|
+
"cli"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"axios": "^1.1.3",
|
|
18
|
+
"node-machine-id": "^1.1.12",
|
|
19
|
+
"openfin-adapter": "^27.71.21",
|
|
20
|
+
"yargs": "^17.6.2",
|
|
21
|
+
"zod": "^3.19.1"
|
|
22
|
+
},
|
|
23
|
+
"bin": {
|
|
24
|
+
"openfin": "./dist/cli.js"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright {yyyy} {name of copyright owner}
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
package/cli.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
const meow = require('meow');
|
|
4
|
-
const openfinCli = require('./');
|
|
5
|
-
|
|
6
|
-
const options = {
|
|
7
|
-
flags: {
|
|
8
|
-
name: { alias: 'n', type: 'string' },
|
|
9
|
-
url: { alias: 'u', type: 'string' },
|
|
10
|
-
config: { alias: 'c', type: 'string' },
|
|
11
|
-
launch: { alias: 'l', type: 'boolean' },
|
|
12
|
-
devtoolsPort: { alias: 'p', type: 'integer' },
|
|
13
|
-
runtime: { alias: 'r', type: 'string' },
|
|
14
|
-
platform: { alias: 't', type: 'boolean' },
|
|
15
|
-
save: { alias: 's', type: 'string' }
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const cli = meow({
|
|
20
|
-
help: [
|
|
21
|
-
'OpenFin cli is capable of launching Application, and creating OpenFin config files.',
|
|
22
|
-
'Options:',
|
|
23
|
-
'-c --config <path to config file>',
|
|
24
|
-
'-u --url <application url>',
|
|
25
|
-
'-l --launch launch this configuration',
|
|
26
|
-
'-p --devtools-port devtools port number',
|
|
27
|
-
'-r --runtime-version runtime version',
|
|
28
|
-
'-s --save the manifest to the current directory <manifest name>',
|
|
29
|
-
'--version current version of the tool',
|
|
30
|
-
'Example',
|
|
31
|
-
' openfin -l -c myconfig.json -u http://www.openfin.co'
|
|
32
|
-
].join('\n')
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
openfinCli(cli);
|
package/index.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const { launch, connect } = require('hadouken-js-adapter');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const reportUsage = require('./report-usage');
|
|
6
|
-
const { getUuid, fetch, isURL } = require('./utils');
|
|
7
|
-
const os = require('os');
|
|
8
|
-
|
|
9
|
-
const main = async (cli) => {
|
|
10
|
-
const meow = cli;
|
|
11
|
-
const flags = cli.flags;
|
|
12
|
-
const url = flags.u || flags.url;
|
|
13
|
-
const launch = flags.l || flags.launch;
|
|
14
|
-
const devtoolsPort = flags.p || flags.devtoolsPort || null;
|
|
15
|
-
const runtime = flags.r || flags.runtime;
|
|
16
|
-
const isPlatform = flags.t || flags.platform;
|
|
17
|
-
const manifestName = flags.s || flags.save
|
|
18
|
-
let manifestUrl = flags.c || flags.config || null;
|
|
19
|
-
let buildConfig;
|
|
20
|
-
let configObj;
|
|
21
|
-
|
|
22
|
-
if (isEmpty(flags)) {
|
|
23
|
-
console.log(meow.help);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
if (url) {
|
|
29
|
-
buildConfig = true;
|
|
30
|
-
const manifestInfo = await writeManifest(url, devtoolsPort, runtime, isPlatform, manifestName);
|
|
31
|
-
manifestUrl = manifestInfo.filepath;
|
|
32
|
-
configObj = manifestInfo.manifest;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (launch) {
|
|
36
|
-
if (!buildConfig) {
|
|
37
|
-
if (isURL(manifestUrl)) {
|
|
38
|
-
const config = await fetch(manifestUrl);
|
|
39
|
-
configObj = config;
|
|
40
|
-
} else {
|
|
41
|
-
manifestUrl = path.resolve(manifestUrl);
|
|
42
|
-
const config = fs.readFileSync(manifestUrl);
|
|
43
|
-
configObj = JSON.parse(config);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
reportUsage('START', manifestUrl, configObj);
|
|
48
|
-
launchOpenfin(manifestUrl);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
console.log(`Failed: ${error}`);
|
|
53
|
-
console.log(meow.help);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
//makeshift is object empty function
|
|
58
|
-
const isEmpty = (flags) => {
|
|
59
|
-
for (var key in flags) {
|
|
60
|
-
if (flags.hasOwnProperty(key) && flags[key] !== false) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
//will launch download the rvm and launch openfin
|
|
68
|
-
const launchOpenfin = async (manifestUrl) => {
|
|
69
|
-
try {
|
|
70
|
-
const port = await launch({ manifestUrl, installerUI: true });
|
|
71
|
-
const fin = await connect({
|
|
72
|
-
uuid: `adapter-connection-${getUuid()}`,
|
|
73
|
-
address: `ws://localhost:${port}`,
|
|
74
|
-
nonPersistent: true,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
fin.once('disconnected', process.exit);
|
|
78
|
-
} catch (err) {
|
|
79
|
-
reportUsage(err.toString(), config, configObj);
|
|
80
|
-
console.error(err);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const writeManifest = (url, devtoolsPort, runtime, isPlatform, manifestName) => {
|
|
85
|
-
return new Promise((resolve, reject) => {
|
|
86
|
-
const uuid = `app-${getUuid()}`;
|
|
87
|
-
const devtools_port = devtoolsPort ? devtoolsPort : 9090;
|
|
88
|
-
const version = runtime ? runtime : 'stable';
|
|
89
|
-
const parsedUrls = url.split(',');
|
|
90
|
-
let manifest;
|
|
91
|
-
|
|
92
|
-
const generateViewObj = () => ({
|
|
93
|
-
type: "component",
|
|
94
|
-
componentName: "view",
|
|
95
|
-
componentState: {
|
|
96
|
-
name: `view-${getUuid()}`,
|
|
97
|
-
url: ''
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const buildContent = () => {
|
|
102
|
-
const content = [];
|
|
103
|
-
parsedUrls.forEach((url) => {
|
|
104
|
-
const viewObj = generateViewObj();
|
|
105
|
-
viewObj.componentState.url = url;
|
|
106
|
-
content.push(viewObj);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
return content;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (isPlatform) {
|
|
113
|
-
const content = buildContent();
|
|
114
|
-
|
|
115
|
-
manifest = {
|
|
116
|
-
runtime: {
|
|
117
|
-
version
|
|
118
|
-
},
|
|
119
|
-
platform: {
|
|
120
|
-
uuid,
|
|
121
|
-
autoShow: false
|
|
122
|
-
},
|
|
123
|
-
snapshot: {
|
|
124
|
-
windows: [
|
|
125
|
-
{
|
|
126
|
-
saveWindowState: false,
|
|
127
|
-
backgroundThrottling: true,
|
|
128
|
-
layout: {
|
|
129
|
-
content: [
|
|
130
|
-
{
|
|
131
|
-
type: 'row',
|
|
132
|
-
id: 'no-drop-target',
|
|
133
|
-
content
|
|
134
|
-
}
|
|
135
|
-
]
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
]
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
} else {
|
|
142
|
-
manifest = {
|
|
143
|
-
devtools_port,
|
|
144
|
-
startup_app: {
|
|
145
|
-
name: uuid,
|
|
146
|
-
url: parsedUrls[0],
|
|
147
|
-
uuid,
|
|
148
|
-
saveWindowState: false,
|
|
149
|
-
autoShow: true
|
|
150
|
-
},
|
|
151
|
-
runtime: {
|
|
152
|
-
version
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const manifestJson = JSON.stringify(manifest, null, 4);
|
|
158
|
-
let filepath;
|
|
159
|
-
|
|
160
|
-
if (manifestName) {
|
|
161
|
-
filepath = path.join(process.cwd(), manifestName);
|
|
162
|
-
} else {
|
|
163
|
-
filepath = path.join(os.tmpdir(), `${uuid}.json`);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
fs.writeFile(filepath, manifestJson, (error) => {
|
|
167
|
-
if (error) {
|
|
168
|
-
reject(error);
|
|
169
|
-
} else {
|
|
170
|
-
console.info(`Manifest written to: ${path.resolve(filepath)}`);
|
|
171
|
-
resolve({ filepath, manifest });
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
module.exports = main;
|
package/report-usage.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const https = require('https');
|
|
3
|
-
const mid = require('node-machine-id');
|
|
4
|
-
const os = require('os');
|
|
5
|
-
const querystring = require('querystring');
|
|
6
|
-
|
|
7
|
-
const getAppName = (configObj) => {
|
|
8
|
-
if (configObj.startup_app) {
|
|
9
|
-
return configObj.startup_app.name || configObj.startup_app.uuid;
|
|
10
|
-
} else if (configObj.platform) {
|
|
11
|
-
return configObj.platform.name || configObj.platform.uuid;
|
|
12
|
-
}
|
|
13
|
-
return 'no-app-name-or-uuid';
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
module.exports = function(status, config, configObj) {
|
|
17
|
-
if (process.platform === 'win32')
|
|
18
|
-
return;
|
|
19
|
-
|
|
20
|
-
var reportURL = 'https://install.openfin.co/installer-usage?';
|
|
21
|
-
var queryObj = {
|
|
22
|
-
appName: getAppName(configObj),
|
|
23
|
-
appLocation: __dirname,
|
|
24
|
-
version: configObj.runtime.version || 'undefined',
|
|
25
|
-
machineId: mid.machineIdSync({original: true}).toUpperCase(),
|
|
26
|
-
manifestUrl: config,
|
|
27
|
-
platform: os.platform().concat('-', os.release()),
|
|
28
|
-
licenseKey: configObj.licenseKey || "contract_identifier",
|
|
29
|
-
launchMethod: 'openfin-cli',
|
|
30
|
-
launchStatus : status || 'SUCCESS'
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
https.get(reportURL.concat(querystring.stringify(queryObj)), (resp) => {
|
|
34
|
-
let data = '';
|
|
35
|
-
resp.on('data', (chunk) => {
|
|
36
|
-
data += chunk;
|
|
37
|
-
});
|
|
38
|
-
resp.on('end', () => {
|
|
39
|
-
console.log('report usage data: ', data);
|
|
40
|
-
});
|
|
41
|
-
}).on("error", (err) => {
|
|
42
|
-
console.log("report usage data error: " + err.message);
|
|
43
|
-
});
|
|
44
|
-
};
|
package/utils.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const axios = require('axios');
|
|
2
|
-
|
|
3
|
-
const fetch = async (url) => {
|
|
4
|
-
const response = await axios.get(url);
|
|
5
|
-
|
|
6
|
-
if (response.status < 200 || response.status > 399) {
|
|
7
|
-
throw new Error(`Failed to load url: ${url}, status code:${response.status}`);
|
|
8
|
-
} else {
|
|
9
|
-
return response.data;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const isURL = (str) => {
|
|
14
|
-
return (typeof str === 'string') && str.lastIndexOf('http') >= 0;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const getUuid = () => {
|
|
18
|
-
return `${Date.now()}-${Math.floor(Math.random() * 10000)}`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = {
|
|
22
|
-
fetch,
|
|
23
|
-
isURL,
|
|
24
|
-
getUuid
|
|
25
|
-
};
|