Skip to content

Commit

Permalink
fix up webui path loading
Browse files Browse the repository at this point in the history
  • Loading branch information
jwetzell committed Apr 25, 2024
1 parent 444d411 commit 89b940a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@
import { Config, Router, Utils } from '@showbridge/lib';
import { Option, program } from 'commander';
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { createRequire } from 'module';
import path from 'path';

function readJSON(relativePath){
return JSON.parse(readFileSync(path.join(import.meta.dirname,relativePath)))
// TODO(jwetzell): this seems error prone....
function readJSON(relativePath) {
return JSON.parse(readFileSync(path.join(import.meta.dirname, relativePath)));
}

export const defaultConfig = readJSON('./sample/config/default.json');
export const defaultVars = readJSON('./sample/vars/default.json');
export const schema = readJSON('./schema/config.schema.json');

const packageInfo = readJSON('./package.json');
export const packageInfo = readJSON('./package.json');

// TODO(jwetzell): would be nice to get rid of this require
const require = createRequire(import.meta.url);
const defaultWebUIPath = path.dirname(require.resolve('@showbridge/webui/dist/webui/index.html'));

program.name(packageInfo.name);
program.version(packageInfo.version);
program.description('Simple protocol router /s');
program.option('-c, --config <path>', 'location of config file', undefined);
program.option('-v, --vars <path>', 'location of file containing vars', undefined);
program.option(
'-w, --webui <path>',
'location of webui html to serve',
path.dirname(import.meta.resolve('@showbridge/webui/dist/webui'))
);
program.option('-w, --webui <path>', 'location of webui html to serve', defaultWebUIPath);
program.option('--disable-action <action-type...>', 'action type(s) to disable');
program.option('--disable-protocol <protocol-type...>', 'protocol type(s) to disable');
program.option('--disable-trigger <trigger-type...>', 'trigger type(s) to disable');
Expand Down Expand Up @@ -109,6 +111,7 @@ if (options.vars) {
if (options.webui) {
if (existsSync(options.webui)) {
const filePath = path.resolve(options.webui);
console.log(filePath);
router.servePath(filePath);
} else {
logger.error(`app: provided webui path = ${options.webui} does not seem to exist skipping...`);
Expand Down

0 comments on commit 89b940a

Please sign in to comment.