openfin-cli
Version:
Supports command line development in the OpenFin environment.
75 lines (74 loc) • 2.45 kB
JavaScript
#!/usr/bin/env node
import { hideBin } from 'yargs/helpers';
import yargs from 'yargs/yargs';
import { openfinCli } from './index.js';
import { Logger } from './logger.js';
import { API_VERSION } from './version.js';
global.logger = new Logger();
const yargsParser = yargs(hideBin(process.argv))
.scriptName('OpenFin Runtime CLI tool')
.option('config', {
alias: 'c',
type: 'string',
description: 'path to config file',
})
.option('url', {
alias: 'u',
type: 'string',
description: 'application url or comma separated list of urls',
})
.option('launch', {
alias: 'l',
type: 'boolean',
description: 'launch this configuration',
})
.option('devtools-port', {
alias: 'p',
type: 'number',
description: 'devtools port number',
defaultDescription: '9090',
})
.option('runtime-version', {
alias: 'r',
type: 'string',
description: 'runtime version',
defaultDescription: 'stable',
})
.option('platform', {
alias: 't',
type: 'boolean',
default: false,
description: 'launch as a platform window with multiple URLs',
})
.option('save', {
alias: 's',
type: 'string',
description: 'save the manifest to the current directory <manifest name>',
})
.option('log-level', {
type: 'string',
description: 'Run with custom log level',
choices: ['DEBUG', 'INFO', 'WARN', 'ERROR', 'NONE'],
default: 'INFO',
})
.check((argv) => {
if (argv.config && argv.url) {
throw new Error('Cannot use both config and url options at the same time');
}
// These options have no effect when using the config option
if (argv.config && (argv.platform || argv['devtools-port'] || argv['runtime-version'] || argv.save)) {
throw new Error('While using the config option, you cannot use the platform, devtools-port, runtime-version, or save options.');
}
return true;
})
.command('*', 'OpenFin CLI', () => ({}), (v) => {
// TODO: Validate commands + show help
if (!v.url && !v.launch) {
yargsParser.showHelp();
}
global.logger.setLogLevelString(v.logLevel);
openfinCli(v);
})
.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")
.version(API_VERSION);
yargsParser.parse();