Files
firebase-tools/scripts/tweet.js
Bryan Kendall 4ca1528ed8 Format scripts directory (#1513)
* format and lint scripts

* allow ecma 2017 format (async/await in Node 8)

* format and fix scripts directory
2019-07-23 09:51:57 -07:00

53 lines
1.1 KiB
JavaScript

"use strict";
const fs = require("fs");
const Twitter = require("twitter");
function printUsage() {
console.error(
`
Usage: tweet.js <version>
Credentials must be stored in "twitter.json" in this directory.
Arguments:
- version: Version of module that was released. e.g. "1.2.3"
`
);
process.exit(1);
}
function getUrl(version) {
return `https://github.com/firebase/firebase-tools/releases/tag/v${version}`;
}
if (process.argv.length !== 3) {
console.error("Missing arguments.");
printUsage();
}
const version = process.argv.pop();
if (!version.match(/^\d+\.\d+\.\d+$/)) {
console.error(`Version "${version}" not a version number.`);
printUsage();
}
if (!fs.existsSync(`${__dirname}/twitter.json`)) {
console.error("Missing credentials.");
printUsage();
}
const creds = require("./twitter.json");
const client = new Twitter(creds);
client.post(
"statuses/update",
{ status: `v${version} of @Firebase CLI is available. Release notes: ${getUrl(version)}` },
(err) => {
if (err) {
console.error(err);
process.exit(1);
}
}
);