{"version":3,"file":"cli.mjs","names":[],"sources":["../../src/bin/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n'use strict';\n\nimport { existsSync, readFileSync } from 'fs';\nimport { resolve } from 'path';\nimport PyAtvMqttBridge from '../lib/index.js';\nimport { type LogParam } from '../lib/types.js';\n\nconsole.log('# pyatv-mqtt-bridge');\nconsole.log('----------------------------');\n\nconst debug = process.argv.indexOf('--debug') > -1;\nconst configPath = resolve(\n    process.cwd(),\n    process.argv[process.argv.length - 1],\n);\nif (!existsSync(configPath)) {\n    console.log(\n        'Usage: pyatv-mqtt-bridge [--debug] ~/pyatv-mqtt-bridge-config.json',\n    );\n    process.exit(1);\n}\n\nlet config;\ntry {\n    config = JSON.parse(readFileSync(configPath, 'utf8'));\n} catch (err) {\n    console.log('Unable to parse configuration file:');\n    console.log(err);\n    console.log('\\nHave you removed the comments?\\n');\n    process.exit(1);\n}\n\ntry {\n    if (debug) {\n        Object.assign(config, {\n            log: (msg: LogParam) => {\n                let string = `[${msg.level}]`;\n                if (msg.host) {\n                    string += `[${msg.host}]`;\n                }\n                string += ' ';\n                if (msg.message) {\n                    string += msg.message;\n                }\n                if (msg.message && msg.error) {\n                    string += ': ';\n                }\n                if (msg.error && msg.error.stack) {\n                    string += msg.error.stack;\n                }\n                if (msg.error) {\n                    string += msg.error.toString();\n                }\n\n                console.log(string);\n            },\n        });\n    }\n\n    new PyAtvMqttBridge(config);\n} catch (err) {\n    console.log('Unable to start bridge:');\n    console.log(err);\n}\n"],"mappings":";iHAQA,QAAQ,IAAI,qBAAqB,EACjC,QAAQ,IAAI,8BAA8B,EAE1C,MAAM,EAAQ,QAAQ,KAAK,QAAQ,SAAS,EAAI,GAC1C,EAAa,EACf,QAAQ,IAAI,EACZ,QAAQ,KAAK,QAAQ,KAAK,OAAS,EACvC,EACK,EAAW,CAAU,IACtB,QAAQ,IACJ,oEACJ,EACA,QAAQ,KAAK,CAAC,GAGlB,IAAI,EACJ,GAAI,CACA,EAAS,KAAK,MAAM,EAAa,EAAY,MAAM,CAAC,CACxD,OAAS,EAAK,CACV,QAAQ,IAAI,qCAAqC,EACjD,QAAQ,IAAI,CAAG,EACf,QAAQ,IAAI;;CAAoC,EAChD,QAAQ,KAAK,CAAC,CAClB,CAEA,GAAI,CACI,GACA,OAAO,OAAO,EAAQ,CAClB,IAAM,GAAkB,CACpB,IAAI,EAAS,IAAI,EAAI,MAAM,GACvB,EAAI,OACJ,GAAU,IAAI,EAAI,KAAK,IAE3B,GAAU,IACN,EAAI,UACJ,GAAU,EAAI,SAEd,EAAI,SAAW,EAAI,QACnB,GAAU,MAEV,EAAI,OAAS,EAAI,MAAM,QACvB,GAAU,EAAI,MAAM,OAEpB,EAAI,QACJ,GAAU,EAAI,MAAM,SAAS,GAGjC,QAAQ,IAAI,CAAM,CACtB,CACJ,CAAC,EAGL,IAAI,EAAgB,CAAM,CAC9B,OAAS,EAAK,CACV,QAAQ,IAAI,yBAAyB,EACrC,QAAQ,IAAI,CAAG,CACnB"}