Skip to content

Commit

Permalink
Merge pull request #10 from carvilsi/usage
Browse files Browse the repository at this point in the history
Usage
  • Loading branch information
carvilsi authored Mar 21, 2024
2 parents 467524e + 941e15c commit e7eb1b9
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 23 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

# [v1.1.0](https://github.com/carvilsi/facetxt/releases/tag/v1.1.0) (2024-03-21)

- adding 2 faces
- added usage message for cli
- more test coverage for cli
- adding pre-release script
- Created CODE_OF_CONDUCT.md
- adding CONTRIBUTING.md

# [v1.0.0](https://github.com/carvilsi/facetxt/releases/tag/v1.0.0) (2024-03-20)

- first release with 537 faces

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

<div align="center">
<p>Have a random text face, or the one that you choose, on your command line or in your project.</p>
<p></p>
<p></p>
<p>Now with 539 awesome faces! o_O</p>
</div>

## Usage
Expand Down Expand Up @@ -69,6 +72,19 @@ console.log(facetxt.list);

`$ npm install -g facetxt`

```
Commands:
version toutput the version number
help display this text
rand get a random face
randDesc get a random face with description
list pretty prints all the faces
all get an array with all faces
like get one face by name; if more than one, will be return randomly
likes get an array of faces by name
```

```bash
# get one random face
$ facetxt rand
Expand Down Expand Up @@ -586,6 +602,8 @@ custom:
(p_-) (-_q)
star:
thinking nonocle:
õ_o o_Ô
```
---
Expand Down
22 changes: 11 additions & 11 deletions benchmark/report.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
┌─────────┬──────────────────────────────────────┬──────────────┬───────────────────┬──────────┬─────────┐
│ (index) │ Task Name │ ops/sec │ Average Time (ns) │ Margin │ Samples │
├─────────┼──────────────────────────────────────┼──────────────┼───────────────────┼──────────┼─────────┤
│ 0 │ 'random face' │ '884,214' │ 1130.947659242501 │ '±9.16%' │ 88497
│ 1 │ 'random face with description' │ '1,170,516' │ 854.3239073231738 │ '±2.12%' │ 117052
│ 2 │ 'get array with all the faces' │ '8,995' │ 111169.4766666642 │ '±1.66%' │ 900
│ 3 │ 'get all the faces for pretty print' │ '11,540,558' │ 86.65091988613777 │ '±0.34%' │ 1154056
│ 4 │ 'get one by name; more than one' │ '20,015' │ 49960.50449551036 │ '±2.01%' │ 2002
│ 5 │ 'get one by name; just one' │ '13,818' │ 72366.4204052115 │ '±2.70%' │ 1382
│ 6 │ 'get array of faces by name' │ '18,619' │ 53707.17991407953 │ '±3.89%' │ 1862
└─────────┴──────────────────────────────────────┴──────────────┴───────────────────┴──────────┴─────────┘
┌─────────┬──────────────────────────────────────┬──────────────┬───────────────────┬──────────┬─────────┐
│ (index) │ Task Name │ ops/sec │ Average Time (ns) │ Margin │ Samples │
├─────────┼──────────────────────────────────────┼──────────────┼───────────────────┼──────────┼─────────┤
│ 0 │ 'random face' │ '1,781,396' │ 561.3574584178862 │ '±2.47%' │ 178141
│ 1 │ 'random face with description' │ '982,049' │ 1018.2782444884268 │ '±1.98%' │ 98205
│ 2 │ 'get array with all the faces' │ '9,455' │ 105762.12896405775 │ '±1.20%' │ 946
│ 3 │ 'get all the faces for pretty print' │ '11,448,288' │ 87.3493002011936 │ '±0.55%' │ 1144829
│ 4 │ 'get one by name; more than one' │ '22,234' │ 44975.79721222785 │ '±1.92%' │ 2224
│ 5 │ 'get one by name; just one' │ '24,619' │ 40618.138911455986 │ '±1.54%' │ 2462
│ 6 │ 'get array of faces by name' │ '23,586' │ 42396.40568036955 │ '±1.25%' │ 2359
└─────────┴──────────────────────────────────────┴──────────────┴───────────────────┴──────────┴─────────┘
45 changes: 38 additions & 7 deletions bin/facetxt.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
#! /usr/bin/env node

import facetxt from './../src/index.js';
import fs from 'node:fs';
import * as url from 'node:url';
import path from 'node:path';
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

const pckg = JSON.parse(
fs.readFileSync(path.join(__dirname, './../package.json')));

const usage = `${pckg.name}@${pckg.version} with <3 by char@omg.lol\n` +
`Commands:\n${
'\tversion'.padEnd(12) }toutput the version number\n${
'\thelp'.padEnd(12) }display this text\n\n${
'\trand'.padEnd(12) }get a random face\n${
'\trandDesc'.padEnd(12) }get a random face with description\n${
'\tlist'.padEnd(12) }pretty prints all the faces\n${
'\tall'.padEnd(12) }get an array with all faces\n${
'\tlike'.padEnd(12) }get one face by name; if more than one, will` +
` be return randomly\n${
'\tlikes'.padEnd(12) }get an array of faces by name\n`;
const UNKNOWN_COMMAND_FACE = 'shrug';
const NOT_FOUND_FACE = 'sad';
const unknownCommand = 'Unknown command: ' +
`"${process.argv[2]}"\t${facetxt.like(UNKNOWN_COMMAND_FACE)}` +
`\n\nUsage:\n${usage}`;
const faceNotFound = 'Could not find a face like: ' +
`"${process.argv[3]}"\t${facetxt.like(NOT_FOUND_FACE)}`;

/* eslint no-console: "off" */
(() => {
if (process.argv.length === 3) {
switch (process.argv[2]) {
case 'help':
console.log(usage);
break;
case 'version':
console.log(`${pckg.name}@${pckg.version}`);
break;
case 'list':
console.log(facetxt.list);
break;
Expand All @@ -21,32 +53,31 @@ import facetxt from './../src/index.js';
break;
}
default:
console.log(`Unknown command: ${process.argv[2]}`);
console.log(unknownCommand);
}
}
if (process.argv.length === 4) {
const nameLike = process.argv[3];
switch (process.argv[2]) {
case 'like': {
const faceLike = facetxt.like(nameLike);
const faceLike = facetxt.like(process.argv[3]);
if (typeof faceLike === 'undefined') {
console.log(`Could not find a face like: ${nameLike}`);
console.log(faceNotFound);
} else {
console.log(faceLike);
}
break;
}
case 'likes': {
const facesLike = facetxt.likes(nameLike);
const facesLike = facetxt.likes(process.argv[3]);
if (!facesLike.length) {
console.log(`Could not find faces like: ${nameLike}`);
console.log(faceNotFound);
} else {
console.log(facesLike);
}
break;
}
default:
console.log(`Unknown command: ${process.argv[2]}`);
console.log(unknownCommand);
}
}
})();
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "facetxt",
"version": "1.0.0",
"version": "1.1.0",
"description": "",
"main": "./src/index.js",
"type": "module",
Expand All @@ -21,6 +21,7 @@
"lint-bin-fix": "./node_modules/eslint/bin/eslint.js bin/facetxt.js --ext .js --fix",
"benchmark": "node ./benchmark/benchmark.js > ./benchmark/report.txt && cat ./benchmark/report.txt",
"dev": "nodemon -w . -x 'npm test && npm run benchmark'",
"pre-release": "npm audit && ./pre-release.sh",
"release": "tag=$(node -e \"console.log(require('./package.json').version)\"); git tag v${tag}; git push origin v${tag} && npm publish"
},
"keywords": [
Expand Down
18 changes: 18 additions & 0 deletions pre-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

CHNGLG=CHANGELOG.md
README_FILE=README.md
TEST_FILE=tests/main.test.js
NAME=$(node -e "console.log(require('./package.json').name)")
VERSION=$(node -e "console.log(require('./package.json').version)")
today=$(date +%Y-%m-%d)
line="# [v${VERSION}](https:\/\/github.com\/carvilsi\/${NAME}\/releases\/tag\/v${VERSION}) (${today})"
last_release_date=$(head -n 3 CHANGELOG.md | tail -1 | awk '{ print $3 }' | sed 's/(\|)//g')
commit_message=$(git log --after=${last_release_date} --format='- %s' | grep -v 'Merge' | sed '{:q;N;s/\n//g;t q}')

total_faces=$(awk '/TOTAL_FACES =/ { print $4 }' $TEST_FILE | sed 's/;//g');
sed -i "s/Now with [0-9]* awesome faces/Now with ${total_faces} awesome faces/g" $README_FILE

sed -i '2s/^/\nnewchangelogentry\n/' $CHNGLG
sed -i "s/newchangelogentry/${line}\n\n- ${commit_message}/g" $CHNGLG

3 changes: 2 additions & 1 deletion src/faces.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ const customs = {
facepalm: [ '(P,\')', '(p,\')' ],
horns_heavy: [ '\\m/,' ],
question: [ '(p_-)', '(-_q)' ],
star: [ '☆' ]
star: [ '☆' ],
thinking_nonocle: [ 'õ_o', 'o_Ô' ]
}
};

Expand Down
31 changes: 29 additions & 2 deletions tests/facetxt-cli.bats
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

@test "should not retrieve a foobar like face, since does not exists" {
run ./bin/facetxt.js like foobar
[ "$output" == "Could not find a face like: foobar" ]
[ $(expr "${lines[0]}" : "Could not find a face like: \"foobar\".*") -ne 0 ]
[ "${output}" != "undefined" ]
}

Expand All @@ -46,6 +46,33 @@

@test "should not retrieve a foobar likes face, since does not exists" {
run ./bin/facetxt.js likes foobar
[ "$output" == "Could not find faces like: foobar" ]
[ $(expr "${lines[0]}" : "Could not find a face like: \"foobar\".*") -ne 0 ]
[ "${output}" != "undefined" ]
}

@test "should retrieve help" {
run ./bin/facetxt.js help
[ $(expr "${lines[0]}" : "facetxt@.* with <3 by char@omg.lol") -ne 0 ]
[ "${lines[1]}" = "Commands:" ]
[ $(expr "${lines[2]}" : ".*version.*toutput the version number") -ne 0 ]
[ $(expr "${lines[3]}" : ".*help.*display this text") -ne 0 ]
[ $(expr "${lines[4]}" : ".*rand.*get a random face") -ne 0 ]
[ $(expr "${lines[5]}" : ".*randDesc.*get a random face with description") -ne 0 ]
[ $(expr "${lines[6]}" : ".*list.*pretty prints all the faces") -ne 0 ]
[ $(expr "${lines[7]}" : ".*all.*get an array with all faces") -ne 0 ]
[ $(expr "${lines[8]}" : ".*like.*get one face by name; if more than one, will be return randomly") -ne 0 ]
[ $(expr "${lines[9]}" : ".*likes.*get an array of faces by name") -ne 0 ]
}

@test "should retrieve help on unknown command" {
run ./bin/facetxt.js foobar
[ $(expr "${lines[0]}" : "Unknown command: \"foobar\".*") -ne 0 ]
[ "${lines[1]}" = "Usage:" ]
[ $(expr "${lines[2]}" : "facetxt@.* with <3 by char@omg.lol") -ne 0 ]
[ "${lines[3]}" = "Commands:" ]
}

@test "should retrieve version" {
run ./bin/facetxt.js version
[ $(expr "${lines[0]}" : "facetxt@.*") -ne 0 ]
}
2 changes: 1 addition & 1 deletion tests/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import test from 'ava';
import facetxt from '../src/index.js';

const TOTAL_FACES = 537;
const TOTAL_FACES = 539;
const WHOLE_EMBARRASSED_FACES = [
':$', '://)',
'://3', '(^^ゞ',
Expand Down

0 comments on commit e7eb1b9

Please sign in to comment.