Skip to content
代码片段 群组 项目
提交 828bdc6c 编辑于 作者: Timotej Ecimovic's avatar Timotej Ecimovic
浏览文件

Migrate args to common JS module.

上级 ec8b3aae
No related branches found
No related tags found
无相关合并请求
...@@ -19,8 +19,8 @@ const yargs = require('yargs') ...@@ -19,8 +19,8 @@ const yargs = require('yargs')
const { logInfo } = require('../util/env.js') const { logInfo } = require('../util/env.js')
// TODO how to handle relative pathing for things like properties file. // TODO how to handle relative pathing for things like properties file.
export var zclPropertiesFile = './test/zcl/zcl-test.properties' exports.zclPropertiesFile = './test/zcl/zcl-test.properties'
export var httpPort = 9070 exports.httpPort = 9070
/** /**
* Process the command line arguments and resets the state in this file * Process the command line arguments and resets the state in this file
...@@ -30,7 +30,7 @@ export var httpPort = 9070 ...@@ -30,7 +30,7 @@ export var httpPort = 9070
* @param {*} argv * @param {*} argv
* @returns parsed argv object * @returns parsed argv object
*/ */
export function processCommandLineArguments(argv) { function processCommandLineArguments(argv) {
var ret = yargs var ret = yargs
.command('generate', 'Generate ZCL artifacts.', (yargs) => { .command('generate', 'Generate ZCL artifacts.', (yargs) => {
yargs.positional('outputDir', { yargs.positional('outputDir', {
...@@ -44,13 +44,13 @@ export function processCommandLineArguments(argv) { ...@@ -44,13 +44,13 @@ export function processCommandLineArguments(argv) {
desc: 'Port used for the HTTP server', desc: 'Port used for the HTTP server',
alias: 'p', alias: 'p',
type: 'number', type: 'number',
default: httpPort, default: exports.httpPort,
}) })
.option('zclProperties', { .option('zclProperties', {
desc: 'zcl.properties file to read in.', desc: 'zcl.properties file to read in.',
alias: 'zcl', alias: 'zcl',
type: 'string', type: 'string',
default: zclPropertiesFile, default: exports.zclPropertiesFile,
}) })
.option('noUi', { .option('noUi', {
desc: "Don't show the main window when starting.", desc: "Don't show the main window when starting.",
...@@ -75,8 +75,10 @@ export function processCommandLineArguments(argv) { ...@@ -75,8 +75,10 @@ export function processCommandLineArguments(argv) {
logInfo('Command line arguments:') logInfo('Command line arguments:')
logInfo(ret) logInfo(ret)
zclPropertiesFile = ret.zclProperties exports.zclPropertiesFile = ret.zclProperties
httpPort = ret.httpPort exports.httpPort = ret.httpPort
return ret return ret
} }
exports.processCommandLineArguments = processCommandLineArguments
...@@ -21,7 +21,7 @@ import { version } from '../../package.json' ...@@ -21,7 +21,7 @@ import { version } from '../../package.json'
import { closeDatabase, initDatabase, loadSchema } from '../db/db-api.js' import { closeDatabase, initDatabase, loadSchema } from '../db/db-api.js'
import { initHttpServer, httpServerPort } from '../server/http-server.js' import { initHttpServer, httpServerPort } from '../server/http-server.js'
import { loadZcl } from '../zcl/zcl-loader.js' import { loadZcl } from '../zcl/zcl-loader.js'
import * as Args from './args.js' const Args = require('./args.js')
const { const {
logError, logError,
logInfo, logInfo,
...@@ -59,7 +59,7 @@ function startSelfCheck() { ...@@ -59,7 +59,7 @@ function startSelfCheck() {
initDatabase(sqliteFile()) initDatabase(sqliteFile())
.then((db) => attachToDb(db)) .then((db) => attachToDb(db))
.then((db) => loadSchema(db, schemaFile(), version)) .then((db) => loadSchema(db, schemaFile(), version))
.then((db) => loadZcl(db, Args.zclPropertiesFile)) .then((db) => loadZcl(db, args.zclPropertiesFile))
.then(() => { .then(() => {
logInfo('Self-check done!') logInfo('Self-check done!')
}) })
...@@ -73,8 +73,8 @@ function startNormal(ui, showUrl) { ...@@ -73,8 +73,8 @@ function startNormal(ui, showUrl) {
initDatabase(sqliteFile()) initDatabase(sqliteFile())
.then((db) => attachToDb(db)) .then((db) => attachToDb(db))
.then((db) => loadSchema(db, schemaFile(), version)) .then((db) => loadSchema(db, schemaFile(), version))
.then((db) => loadZcl(db, Args.zclPropertiesFile)) .then((db) => loadZcl(db, args.zclPropertiesFile))
.then((db) => initHttpServer(db, Args.httpPort)) .then((db) => initHttpServer(db, args.httpPort))
.then(() => { .then(() => {
if (ui) { if (ui) {
initializeElectronUi(httpServerPort()) initializeElectronUi(httpServerPort())
...@@ -111,7 +111,7 @@ function applyGenerationSettings( ...@@ -111,7 +111,7 @@ function applyGenerationSettings(
.then((db) => .then((db) =>
loadZcl( loadZcl(
db, db,
zclPropertiesFilePath ? zclPropertiesFilePath : Args.zclPropertiesFile zclPropertiesFilePath ? zclPropertiesFilePath : args.zclPropertiesFile
) )
) )
.then((db) => .then((db) =>
...@@ -148,7 +148,7 @@ export function startSdkGeneration( ...@@ -148,7 +148,7 @@ export function startSdkGeneration(
.then((db) => .then((db) =>
loadZcl( loadZcl(
db, db,
zclPropertiesFilePath ? zclPropertiesFilePath : Args.zclPropertiesFile zclPropertiesFilePath ? zclPropertiesFilePath : args.zclPropertiesFile
) )
) )
.then((db) => .then((db) =>
...@@ -162,7 +162,7 @@ export function startSdkGeneration( ...@@ -162,7 +162,7 @@ export function startSdkGeneration(
} }
app.on('ready', () => { app.on('ready', () => {
var argv = Args.processCommandLineArguments(process.argv) var argv = args.processCommandLineArguments(process.argv)
logInfo(argv) logInfo(argv)
...@@ -189,7 +189,7 @@ app.on('window-all-closed', () => { ...@@ -189,7 +189,7 @@ app.on('window-all-closed', () => {
app.on('activate', () => { app.on('activate', () => {
logInfo('Activate...') logInfo('Activate...')
windowCreateIfNotThere(Args.httpPort) windowCreateIfNotThere(args.httpPort)
}) })
app.on('quit', () => { app.on('quit', () => {
......
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
* @jest-environment node * @jest-environment node
*/ */
import { processCommandLineArguments } from '../src-electron/main-process/args' const args = require('../src-electron/main-process/args')
import yargs from 'yargs' const yargs = require('yargs')
test('Test basic command line processing', () => { test('Test basic command line processing', () => {
var args = processCommandLineArguments([ var a = args.processCommandLineArguments([
'node', 'node',
'test.js', 'test.js',
'--noUI', '--noUI',
...@@ -33,11 +33,11 @@ test('Test basic command line processing', () => { ...@@ -33,11 +33,11 @@ test('Test basic command line processing', () => {
'XmlRoot', 'XmlRoot',
]) ])
expect(args.noUI).toBeTruthy() expect(a.noUI).toBeTruthy()
expect(args.httpPort).toBeTruthy() expect(a.httpPort).toBeTruthy()
expect(args.httpPort).toEqual(123) expect(a.httpPort).toEqual(123)
expect(args.arglessArg).toBeTruthy() expect(a.arglessArg).toBeTruthy()
expect(args.xmlRoot).toBe('XmlRoot') expect(a.xmlRoot).toBe('XmlRoot')
}) })
test('Verify how yargs works', () => { test('Verify how yargs works', () => {
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册