Skip to content

Commit

Permalink
Added cryptoRandomString option + updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
fklement committed Mar 25, 2020
1 parent e6ee6d1 commit 0f094c5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 49 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Changelog
=========

### v1.1.1, 25 Mar 2020, node.js `v12.16.1`
* Added cryptoRandomString pattern for more unpredictable room names

### v1.1.0, 21 Mar 2020, node.js `v12.16.1`
* Restructured code base
* Added travis-ci auto release build for executables (mac, linux, win)
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ After installing it, run jitsi --help without arguments to see list of options.

--pattern <selectedPattern> or -p <selectedPattern>:
Select the desired generation pattern.
<selectedPattern> = [beautifulFungiOrSpaghetti, amazinglyScaryToy,
<selectedPattern> = [cryptoRandomString, beautifulFungiOrSpaghetti, amazinglyScaryToy,
neitherTrashNorRifle, eitherCopulateOrInvestigate, wolvesComputeBadly
uniteFacilitateAndMerge, nastyWitchesAtThePub, defaultPattern]
```

## Pre-build executable
We are pre-building executables for the cli tool that you can use in MacOS, Linux and Windows. For building the executable we are using the single-command node.js binary compiler called Pkg from zeit. This command line interface enables us to package the complete project into an executable that then can be run even on devices without node.js installed. Thanks to Travis-CI this perfectly integrates into the deployment pipeline, which means that on every push to the master branch a new release is created and pushed into the release section.

You can find the latest release here: https://github.com/fklement/jitsi-cli/releases/latest

## General Informations

I started to develop this CLI-Tool because I really love jitsi and use it a lot in my daily life. Since I mainly work with the terminal, I found it useful to start a jitsi-meet session quickly with one command. Feel free to add more useful things to this tool (e.g. more name generators).
Expand Down
37 changes: 17 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"arg": "^4.1.3",
"boxen": "^4.2.0",
"clipboardy": "^2.3.0",
"crypto-random-string": "^3.2.0",
"esm": "^3.2.25",
"inquirer": "^7.1.0",
"opener": "^1.5.1",
Expand Down
48 changes: 30 additions & 18 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ const boxen = require("boxen");
const generateRoomName = require("./roomNameGenerator");

function parseArgumentsIntoOptions(rawArgs) {
const args = arg({
"--help": Boolean,
"--pattern": String,
"--clipboard": Boolean,
"-c": "--clipboard",
"-p": "--pattern",
"-h": "--help"
}, {
argv: rawArgs.slice(2)
});
const args = arg(
{
"--help": Boolean,
"--pattern": String,
"--clipboard": Boolean,
"-c": "--clipboard",
"-p": "--pattern",
"-h": "--help"
},
{
argv: rawArgs.slice(2)
}
);
return {
help: args["--help"] || false,
pattern: args["--pattern"] || false,
Expand All @@ -29,10 +32,11 @@ async function promptForMissingOptions(options) {
console.log(
boxen(
"🧪 How to use the jitsi-cli tool:\n\n" +
"<roomName>:\n Uses the given <roomName> as input for creating the room\n\n" +
"--clipboard or -c:\n Copies the generated jitsi room URL into your clipboard.\n\n" +
"--pattern <selectedPattern> or -p <selectedPattern>:\n Select the desired generation pattern.\n" +
" <selectedPattern> = [beautifulFungiOrSpaghetti, amazinglyScaryToy,\n neitherTrashNorRifle, eitherCopulateOrInvestigate, wolvesComputeBadly,\n uniteFacilitateAndMerge, nastyWitchesAtThePub, defaultPattern]", {
"<roomName>:\n Uses the given <roomName> as input for creating the room\n\n" +
"--clipboard or -c:\n Copies the generated jitsi room URL into your clipboard.\n\n" +
"--pattern <selectedPattern> or -p <selectedPattern>:\n Select the desired generation pattern.\n" +
" <selectedPattern> = [cryptoRandomString, beautifulFungiOrSpaghetti, amazinglyScaryToy,\n neitherTrashNorRifle, eitherCopulateOrInvestigate, wolvesComputeBadly,\n uniteFacilitateAndMerge, nastyWitchesAtThePub, defaultPattern]",
{
padding: 1,
margin: 1,
borderStyle: "round"
Expand All @@ -47,7 +51,12 @@ async function promptForMissingOptions(options) {
type: "list",
name: "pattern",
message: "Please choose which pattern you would like",
choices: [{
choices: [
{
name: "🔑 Generate cryptoRandomString",
value: "cryptoRandomString"
},
{
name: "🍝 Beautiful Fungi Or Spaghetti",
value: "beautifulFungiOrSpaghetti"
},
Expand Down Expand Up @@ -97,14 +106,15 @@ async function promptForMissingOptions(options) {
};
}

exports.start = async function (args) {
exports.start = async function(args) {
let slug = "";
let boxenOptions = {
padding: 1,
margin: 1,
borderStyle: "round"
};
let possiblePatterns = [
"cryptoRandomString",
"beautifulFungiOrSpaghetti",
"amazinglyScaryToy",
"neitherTrashNorRifle",
Expand All @@ -122,7 +132,8 @@ exports.start = async function (args) {
process.exit();
}

if (!options.roomName) slug = generateRoomName.generateRoomName(options.pattern);
if (!options.roomName)
slug = generateRoomName.generateRoomName(options.pattern);
else slug = options.roomName;
let jitsiURL = "https://meet.jit.si/" + slug;

Expand All @@ -134,4 +145,5 @@ exports.start = async function (args) {
boxenOptions
)
);
}
};

25 changes: 15 additions & 10 deletions src/roomNameGenerator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const rnd = require("./randomUtil");
const cryptoRandomString = require("crypto-random-string");

// TODO: think of some more nouns
const _NOUN_ = ["Cat", "Mountain", "Speaker", "Snow", "Rain", "Ship"];
Expand Down Expand Up @@ -726,24 +727,28 @@ const PATTERNS = {
*
* @returns {string} A newly-generated room name.
*/
exports.generateRoomName = function (pattern) {
exports.generateRoomName = function(pattern) {
// XXX Note that if more than one pattern is available, the choice of 'name'
// won't have a uniform distribution amongst all patterns (names from
// patterns with fewer options will have higher probability of being chosen
// that names from patterns with more options).
let name = rnd.randomElement(PATTERNS[pattern]);
let name = "";
if (pattern == "cryptoRandomString") {
name = cryptoRandomString({ length: 25, type: "url-safe" });
} else {
name = rnd.randomElement(PATTERNS[pattern]);

while (_hasTemplate(name)) {
for (const template in CATEGORIES) {
// eslint-disable-line guard-for-in
const word = rnd.randomElement(CATEGORIES[template]);
while (_hasTemplate(name)) {
for (const template in CATEGORIES) {
// eslint-disable-line guard-for-in
const word = rnd.randomElement(CATEGORIES[template]);

name = name.replace(template, word);
name = name.replace(template, word);
}
}
}

return name;
}
};

/**
* Determines whether a specific string contains at least one of the
Expand All @@ -762,4 +767,4 @@ function _hasTemplate(s) {
}

return false;
}
}

0 comments on commit 0f094c5

Please sign in to comment.