diff --git a/bin/cli.js b/bin/cli.js new file mode 100755 index 0000000..e4b8009 --- /dev/null +++ b/bin/cli.js @@ -0,0 +1,22 @@ +#!/usr/bin/env node + +const yargs = require("yargs"); +const checkKit = require("check-kit"); + +(async () => { + const { current, name, latest, updateAvailable } = await checkKit.check({ + pkg: require("../package.json"), + }); + + if (updateAvailable) { + console.log(`New version of ${name} available! ${current} -> ${latest}`); + } else { + yargs + .commandDir("../cmds") + .wrap(yargs.terminalWidth()) + .showHelpOnFail(true) + .demandCommand() + .recommendCommands() + .strict().argv; + } +})(); diff --git a/cmds/open.js b/cmds/open.js new file mode 100644 index 0000000..395407f --- /dev/null +++ b/cmds/open.js @@ -0,0 +1,30 @@ +"use strict"; +const open = require("open"); + +const locations = { + website: "http://romajs.org", + twitter: "https://twitter.com/roma_js", + facebook: "https://www.facebook.com/romajs.org", + youtube: "https://www.youtube.com/channel/UCFm8OPi5USbFybw9SaTLxeA", + slack: "https://romajs.slack.com/", + slackSignup: "https://romajs.herokuapp.com/", + github: "https://github.com/Roma-JS", + meetup: "http://www.meetup.com/RomaJS/", +}; + +exports.command = "open "; + +exports.desc = `open in a browser one of the following locations ${Object.keys( + locations, +)}`; + +exports.builder = (yargs) => { + yargs.option("location", { + describe: "one of the RomaJS pages", + choices: Object.keys(locations), + }); +}; + +exports.handler = async function (args) { + await open(locations[args.location]); +}; diff --git a/package.json b/package.json index 1e9d5cc..7d23e1a 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,9 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "bin": { + "romajs": "bin/cli.js" + }, "author": "RomaJS", "license": "MIT", "repository": { @@ -20,5 +23,10 @@ "bugs": { "url": "https://github.com/Roma-JS/romajs-cli/issues" }, - "homepage": "https://github.com/Roma-JS/romajs-cli#readme" + "homepage": "https://github.com/Roma-JS/romajs-cli#readme", + "dependencies": { + "check-kit": "^1.2.1", + "open": "^8.2.1", + "yargs": "^17.0.1" + } }