{"size": 684, "ext": "js", "max_stars_repo_path": "publish-cli.js", "max_stars_repo_name": "BonnierNews/lu-broker", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "publish-cli.js", "max_issues_repo_name": "BonnierNews/lu-broker", "max_issues_repo_issues_event_min_datetime": "2022-02-19T11:22:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T06:29:24.000Z", "max_forks_repo_path": "publish-cli.js", "max_forks_repo_name": "BonnierNews/lu-broker", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 26.3076923077, "max_line_length": 79, "alphanum_fraction": 0.682748538}
#!/usr/bin/env node
"use strict";

const fs = require("fs");
const key = process.argv[2];
const hasStdinIn = !process.stdin.isTTY;
const broker = require("./lib/broker").crd;

async function main() {
  if (hasStdinIn) {
    const message = JSON.parse(fs.readFileSync(0).toString());
    await publish(key, message);
  } else {
    if (!process.argv[3]) throw new Error("No message given!");
    const message = JSON.parse(process.argv[3]);
    await publish(key, message);
  }
}

async function publish(routingKey, message) {
  console.log("Publishing:", message, "on", routingKey); // eslint-disable-line
  await broker.publishMessage(routingKey, message);
}

module.exports = main;
