diff --git a/src-electron/main-process/args.js b/src-electron/main-process/args.js index 62a9c6e2977fed714377275bbca3b994e1e7b240..b127c6c8a6628af8cee502452818c51f9c1efae8 100644 --- a/src-electron/main-process/args.js +++ b/src-electron/main-process/args.js @@ -19,8 +19,8 @@ const yargs = require('yargs') const { logInfo } = require('../util/env.js') // TODO how to handle relative pathing for things like properties file. -export var zclPropertiesFile = './test/zcl/zcl-test.properties' -export var httpPort = 9070 +exports.zclPropertiesFile = './test/zcl/zcl-test.properties' +exports.httpPort = 9070 /** * Process the command line arguments and resets the state in this file @@ -30,7 +30,7 @@ export var httpPort = 9070 * @param {*} argv * @returns parsed argv object */ -export function processCommandLineArguments(argv) { +function processCommandLineArguments(argv) { var ret = yargs .command('generate', 'Generate ZCL artifacts.', (yargs) => { yargs.positional('outputDir', { @@ -44,13 +44,13 @@ export function processCommandLineArguments(argv) { desc: 'Port used for the HTTP server', alias: 'p', type: 'number', - default: httpPort, + default: exports.httpPort, }) .option('zclProperties', { desc: 'zcl.properties file to read in.', alias: 'zcl', type: 'string', - default: zclPropertiesFile, + default: exports.zclPropertiesFile, }) .option('noUi', { desc: "Don't show the main window when starting.", @@ -75,8 +75,10 @@ export function processCommandLineArguments(argv) { logInfo('Command line arguments:') logInfo(ret) - zclPropertiesFile = ret.zclProperties - httpPort = ret.httpPort + exports.zclPropertiesFile = ret.zclProperties + exports.httpPort = ret.httpPort return ret } + +exports.processCommandLineArguments = processCommandLineArguments diff --git a/src-electron/main-process/electron-main.js b/src-electron/main-process/electron-main.js index f550fe7ae94cfbeaa89158f0ca0966d257f5be54..6cf408bdaaa00bf16ad1c99e75ad5ba19cf58e98 100644 --- a/src-electron/main-process/electron-main.js +++ b/src-electron/main-process/electron-main.js @@ -21,7 +21,7 @@ import { version } from '../../package.json' import { closeDatabase, initDatabase, loadSchema } from '../db/db-api.js' import { initHttpServer, httpServerPort } from '../server/http-server.js' import { loadZcl } from '../zcl/zcl-loader.js' -import * as Args from './args.js' +const Args = require('./args.js') const { logError, logInfo, @@ -59,7 +59,7 @@ function startSelfCheck() { initDatabase(sqliteFile()) .then((db) => attachToDb(db)) .then((db) => loadSchema(db, schemaFile(), version)) - .then((db) => loadZcl(db, Args.zclPropertiesFile)) + .then((db) => loadZcl(db, args.zclPropertiesFile)) .then(() => { logInfo('Self-check done!') }) @@ -73,8 +73,8 @@ function startNormal(ui, showUrl) { initDatabase(sqliteFile()) .then((db) => attachToDb(db)) .then((db) => loadSchema(db, schemaFile(), version)) - .then((db) => loadZcl(db, Args.zclPropertiesFile)) - .then((db) => initHttpServer(db, Args.httpPort)) + .then((db) => loadZcl(db, args.zclPropertiesFile)) + .then((db) => initHttpServer(db, args.httpPort)) .then(() => { if (ui) { initializeElectronUi(httpServerPort()) @@ -111,7 +111,7 @@ function applyGenerationSettings( .then((db) => loadZcl( db, - zclPropertiesFilePath ? zclPropertiesFilePath : Args.zclPropertiesFile + zclPropertiesFilePath ? zclPropertiesFilePath : args.zclPropertiesFile ) ) .then((db) => @@ -148,7 +148,7 @@ export function startSdkGeneration( .then((db) => loadZcl( db, - zclPropertiesFilePath ? zclPropertiesFilePath : Args.zclPropertiesFile + zclPropertiesFilePath ? zclPropertiesFilePath : args.zclPropertiesFile ) ) .then((db) => @@ -162,7 +162,7 @@ export function startSdkGeneration( } app.on('ready', () => { - var argv = Args.processCommandLineArguments(process.argv) + var argv = args.processCommandLineArguments(process.argv) logInfo(argv) @@ -189,7 +189,7 @@ app.on('window-all-closed', () => { app.on('activate', () => { logInfo('Activate...') - windowCreateIfNotThere(Args.httpPort) + windowCreateIfNotThere(args.httpPort) }) app.on('quit', () => { diff --git a/test/arg.test.js b/test/arg.test.js index 2b1112017fe5254ce24436e34d547957d63baea0..ab838a40aa68be7181303945277c92195eaccf35 100644 --- a/test/arg.test.js +++ b/test/arg.test.js @@ -18,11 +18,11 @@ * @jest-environment node */ -import { processCommandLineArguments } from '../src-electron/main-process/args' -import yargs from 'yargs' +const args = require('../src-electron/main-process/args') +const yargs = require('yargs') test('Test basic command line processing', () => { - var args = processCommandLineArguments([ + var a = args.processCommandLineArguments([ 'node', 'test.js', '--noUI', @@ -33,11 +33,11 @@ test('Test basic command line processing', () => { 'XmlRoot', ]) - expect(args.noUI).toBeTruthy() - expect(args.httpPort).toBeTruthy() - expect(args.httpPort).toEqual(123) - expect(args.arglessArg).toBeTruthy() - expect(args.xmlRoot).toBe('XmlRoot') + expect(a.noUI).toBeTruthy() + expect(a.httpPort).toBeTruthy() + expect(a.httpPort).toEqual(123) + expect(a.arglessArg).toBeTruthy() + expect(a.xmlRoot).toBe('XmlRoot') }) test('Verify how yargs works', () => {