diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a2991cc --- /dev/null +++ b/CHANGELOG.md @@ -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 + diff --git a/README.md b/README.md index 7245fb5..40b4912 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,9 @@

Have a random text face, or the one that you choose, on your command line or in your project.

+

+

+

Now with 539 awesome faces! o_O

## Usage @@ -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 @@ -586,6 +602,8 @@ custom: (p_-) (-_q) star: ☆ + thinking nonocle: + õ_o o_Ô ``` --- diff --git a/benchmark/report.txt b/benchmark/report.txt index bea94b3..493e07e 100644 --- a/benchmark/report.txt +++ b/benchmark/report.txt @@ -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 │ +└─────────┴──────────────────────────────────────┴──────────────┴────────────────────┴──────────┴─────────┘ diff --git a/bin/facetxt.js b/bin/facetxt.js index 01e71de..ca4d376 100755 --- a/bin/facetxt.js +++ b/bin/facetxt.js @@ -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; @@ -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); } } })(); diff --git a/package.json b/package.json index e4881b6..2112060 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "facetxt", - "version": "1.0.0", + "version": "1.1.0", "description": "", "main": "./src/index.js", "type": "module", @@ -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": [ diff --git a/pre-release.sh b/pre-release.sh new file mode 100755 index 0000000..c1f0b18 --- /dev/null +++ b/pre-release.sh @@ -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 + diff --git a/src/faces.js b/src/faces.js index 5b3b0f6..fd81ffa 100644 --- a/src/faces.js +++ b/src/faces.js @@ -307,7 +307,8 @@ const customs = { facepalm: [ '(P,\')', '(p,\')' ], horns_heavy: [ '\\m/,' ], question: [ '(p_-)', '(-_q)' ], - star: [ '☆' ] + star: [ '☆' ], + thinking_nonocle: [ 'õ_o', 'o_Ô' ] } }; diff --git a/tests/facetxt-cli.bats b/tests/facetxt-cli.bats index 83f407d..d21cd84 100644 --- a/tests/facetxt-cli.bats +++ b/tests/facetxt-cli.bats @@ -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" ] } @@ -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 ] +} diff --git a/tests/main.test.js b/tests/main.test.js index 544170f..f49add7 100644 --- a/tests/main.test.js +++ b/tests/main.test.js @@ -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', '(^^ゞ',