@beauraines/bacon-ipsum-cli 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,32 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [0.2.0](https://github.com/beauraines/bacon-ipsum-cli/compare/v0.1.5...v0.2.0) (2024-05-27)
6
+
7
+
8
+ ### ⚠ BREAKING CHANGES
9
+
10
+ * does not display returned text to the console anymore. By default it copies to the clipboard.
11
+ If `--no-clip` or `--nc` are passed with the command, output is _only_ output to the console, bypassing the clipboard.
12
+
13
+ ### Features
14
+
15
+ * adds completion command ([fed1266](https://github.com/beauraines/bacon-ipsum-cli/commit/fed12669bfcb30bf40b3789ad2b2ed76f95b9f47))
16
+ * calls API from utils module ([6c64902](https://github.com/beauraines/bacon-ipsum-cli/commit/6c64902ecdc28f9ac4a15c613239b8020ecf64ec))
17
+ * enables no-clip option ([aff861e](https://github.com/beauraines/bacon-ipsum-cli/commit/aff861e75ca0bc9ddf0320d008faa41fa672312c))
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * fixes no clip option ([c108a77](https://github.com/beauraines/bacon-ipsum-cli/commit/c108a774c87ec028c13a0aa9bbedee435912b9b7))
23
+
24
+ ### [0.1.5](https://github.com/beauraines/bacon-ipsum-cli/compare/v0.1.4...v0.1.5) (2024-05-27)
25
+
26
+
27
+ ### Features
28
+
29
+ * adds support for more options ([#4](https://github.com/beauraines/bacon-ipsum-cli/issues/4)) ([4b9f87e](https://github.com/beauraines/bacon-ipsum-cli/commit/4b9f87e2971868cd15f92ca632571ec7d245aa94))
30
+
5
31
  ### [0.1.4](https://github.com/beauraines/bacon-ipsum-cli/compare/v0.1.3...v0.1.4) (2024-05-27)
6
32
 
7
33
 
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Bacon Ipsum CLI
2
+
3
+ A CLI for the [Bacon Ipsum API](https://baconipsum.com/json-api/)
4
+
5
+
6
+ ## Usage
7
+
8
+ ```
9
+ bacon [command]
10
+
11
+ Commands:
12
+ bacon completion generate completion script
13
+
14
+ Options:
15
+ --version Show version number [boolean]
16
+ -t, --type Type of meat
17
+ [choices: "all-meat", "meat-and-filler"] [default: "all-meat"]
18
+ -p, --paras Number of paragraphs [number] [default: 1]
19
+ -s, --sentences Number of sentences. This overrides paragraph
20
+ s. [number]
21
+ -l, --start-with-lorem, --lorem Starts the first paragraph with 'Bacon ipsum
22
+ dolor sit amet' [boolean]
23
+ --help Show help [boolean]
24
+ ```
package/TODO.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # TODO
2
2
 
3
- - [ ] Move API call to module for testing
4
- - [ ] Add other options
5
- - [ ] Add debug
6
- - [ ] Add unit tests
7
- - [ ] Add completion command
3
+ - [x] Move API call to module for testing
4
+ - [x] Add other options
5
+ - [x] Add debug
6
+ - [x] Add unit tests
7
+ - [x] Add completion command
8
8
  - [x] Configure linter - 'dont warn for Node globals like console'
9
- - [ ] Swith to ESM and import latest versions of dependencies
10
- - [ ] Add README
9
+ - [x] Swith to ESM and import latest versions of dependencies
10
+ - [x] Add README
11
+ - [ ] Add output format options
12
+ - [x] Add clipboard bypass option
13
+ - [ ] change getBacon to async/await and separate data processing
package/cli.js CHANGED
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const fetch = require('node-fetch');
4
- const yargs = require('yargs');
5
- const copyPaste = require('copy-paste');
3
+ import yargs from "yargs";
4
+ import debugClient from 'debug'
5
+ import { buildQueryString, getBacon } from './utils.js';
6
6
 
7
+ const debug = debugClient('bacon-ipsum-cli');
7
8
  const apiUrl = 'https://baconipsum.com/api/';
8
9
 
9
10
  // Define command-line options using yargs
10
- const argv = yargs
11
+ const argv = yargs(process.argv.slice(2))
11
12
  .scriptName('bacon')
12
13
  .option('type', {
13
14
  alias: 't',
@@ -21,44 +22,37 @@ const argv = yargs
21
22
  default: 1,
22
23
  type: 'number',
23
24
  })
24
- // .option('sentences',{
25
- // alias: 's',
26
- // describe: 'Number of sentences. This overrides paragraphs.',
27
- // type: 'number'
28
- // })
29
- // .option('start-with-lorem',{
30
- // alias: ['l','lorem'],
31
- // describe: 'Starts the first paragraph with ‘Bacon ipsum dolor sit amet’',
32
- // type: 'boolean'
33
- // })
25
+ .option('sentences',{
26
+ alias: 's',
27
+ describe: 'Number of sentences. This overrides paragraphs.',
28
+ type: 'number'
29
+ })
30
+ .option('start-with-lorem',{
31
+ alias: ['l','lorem'],
32
+ describe: 'Starts the first paragraph with ‘Bacon ipsum dolor sit amet’',
33
+ type: 'boolean'
34
+ })
34
35
  // .option('format',{
35
36
  // alias: 'f',
36
37
  // describe:'Output format. Defaults to `text`',
37
38
  // default: 'text',
38
39
  // choices: ['text','json','html']
39
40
  // })
40
- // .option('no-clip',{
41
- // alias: 'nc',
42
- // describe:'Only outputs to console, bypassing the clipboard.',
43
- // type: 'boolean'
44
- // })
41
+ .option('nc',{
42
+ alias: 'nc',
43
+ describe:'Only outputs to console, bypassing the clipboard.',
44
+ type: 'boolean'
45
+ })
46
+ .completion()
45
47
  .help()
46
48
  .argv;
47
-
48
- // Build the API URL with the specified options
49
- // TODO support additional parameters
50
- const apiUrlWithParams = `${apiUrl}?type=${argv.type}&paras=${argv.paras}`;
49
+
50
+ debug(argv)
51
+ const apiUrlWithParams = `${apiUrl}?${buildQueryString(argv)}`
52
+ debug(apiUrlWithParams)
51
53
 
52
54
  // Fetch data from the Bacon Ipsum API
53
- fetch(apiUrlWithParams)
54
- .then((response) => response.json())
55
- .then((data) => {
56
- // Display the fetched text in the console
57
- console.log(data.join('\n'));
55
+ let noClip = argv.nc
56
+ debug(argv.noClip)
58
57
 
59
- // Copy the text to the clipboard
60
- copyPaste.copy(data.join('\n'), () => {
61
- console.log('Text copied to clipboard!');
62
- });
63
- })
64
- .catch((error) => console.error('Error fetching data:', error));
58
+ getBacon(apiUrlWithParams,noClip)
package/eslint.config.mjs CHANGED
@@ -5,7 +5,7 @@ import jestPlugin from "eslint-plugin-jest";
5
5
  export default [
6
6
  {
7
7
  files: ["**/*.js"],
8
- languageOptions: { sourceType: "commonjs", globals: globals.nodeBuiltin}
8
+ languageOptions: { sourceType: "module", ecmaVersion: "latest", globals: globals.nodeBuiltin}
9
9
  },
10
10
  { languageOptions: { ...jestPlugin.environments.globals } },
11
11
  pluginJs.configs.recommended,
package/package.json CHANGED
@@ -1,28 +1,38 @@
1
1
  {
2
2
  "name": "@beauraines/bacon-ipsum-cli",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "CLI for Bacon Ipsum text",
5
- "main": "cli.js",
5
+ "exports": "./cli.js",
6
+ "type": "module",
6
7
  "bin": {
7
- "bacon-ipsum": "cli.js"
8
+ "bacon": "cli.js"
8
9
  },
9
10
  "scripts": {
10
- "test": "jest --passWithNoTests",
11
+ "test": "NODE_OPTIONS=--experimental-vm-modules npx jest --passWithNoTests --silent",
11
12
  "lint": "eslint . ./**/*.js ./**/*.mjs",
12
13
  "lint:fix": "eslint . ./**/*.js ./**/*.mjs --fix",
13
14
  "release": "standard-version",
14
15
  "should-release": "should-release"
15
16
  },
16
- "author": "Beau Raines",
17
- "license": "ISC",
17
+ "author": "Beau Raines <beau.raines@gmail.com>",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/beauraines/bacon-ipsum-cli.git"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/beauraines/bacon-ipsum-cli/issues"
24
+ },
25
+ "license": "MIT",
18
26
  "dependencies": {
19
27
  "chalk": "^4.1.2",
20
28
  "copy-paste": "^1.5.3",
21
29
  "node-fetch": "^2.6.7",
30
+ "query-string": "^9.0.0",
22
31
  "yargs": "^17.7.2"
23
32
  },
24
33
  "devDependencies": {
25
34
  "@eslint/js": "^9.3.0",
35
+ "debug": "^4.3.4",
26
36
  "eslint": "^9.3.0",
27
37
  "eslint-plugin-jest": "^28.5.0",
28
38
  "globals": "^15.3.0",
package/utils.js ADDED
@@ -0,0 +1,37 @@
1
+ import copyPaste from "copy-paste";
2
+ import debugClient from 'debug'
3
+ import fetch from "node-fetch";
4
+ import queryString from "query-string";
5
+
6
+ const debug = debugClient('bacon-ipsum-cli-utils');
7
+
8
+ export const buildQueryString = (argv) => {
9
+ // Build the API URL with the specified options
10
+ let queryParams = {
11
+ type: argv.type,
12
+ paras: argv.paras,
13
+ sentences: argv.sentences,
14
+ "start-with-lorem" : argv['start-with-lorem'] ? 1 : undefined
15
+ }
16
+ const qs = queryString.stringify(queryParams);
17
+ debug(qs)
18
+ return qs
19
+ }
20
+
21
+ export const getBacon = (apiUrlWithParams,noClip) => {
22
+ fetch(apiUrlWithParams)
23
+ .then((response) => response.json())
24
+ .then((data) => {
25
+ if (noClip) { // noClip is alias for no-clip
26
+ // Display the fetched text in the console
27
+ console.log(data.join('\n'));
28
+ } else {
29
+ // Copy the text to the clipboard
30
+ copyPaste.copy(data.join('\n'), () => {
31
+ console.log('Bacon ipsum text copied to the clipboard!');
32
+ });
33
+ }
34
+
35
+ })
36
+ .catch((error) => console.error('Error fetching data:', error));
37
+ }
package/utils.test.js ADDED
@@ -0,0 +1,60 @@
1
+ /* eslint-disable jest/no-disabled-tests */
2
+ import { buildQueryString, getBacon } from "./utils.js";
3
+ import copyPaste from "copy-paste";
4
+ import debugClient from 'debug'
5
+ const debug = debugClient('utils-tests');
6
+
7
+
8
+
9
+ describe('utilities', () => {
10
+
11
+ // eslint-disable-next-line no-unused-vars
12
+ const apiUrl = 'https://baconipsum.com/api/';
13
+
14
+ test('should return multiple paragraphs', () => {
15
+ const paragraphs = 2;
16
+ const output = `Turkey flank meatball, ham t-bone pancetta ham hock drumstick beef boudin ground round short loin pig buffalo. Flank pork pork loin chislic spare ribs. Pork loin tenderloin kevin, bresaola picanha ham hock shoulder shank venison rump. Shankle short loin fatback venison salami. Capicola short ribs landjaeger, beef ribs shankle bacon meatloaf sirloin frankfurter venison chicken ham hock burgdoggen chuck. Burgdoggen tri-tip salami beef shoulder boudin flank andouille pancetta tongue fatback short ribs t-bone.
17
+ Tongue venison ham tri-tip. Pig porchetta bacon, kielbasa pork chop spare ribs turducken landjaeger brisket. Capicola chicken pancetta short ribs kevin tenderloin, alcatra fatback beef ribs. Beef spare ribs sirloin fatback, rump burgdoggen doner ham beef ribs leberkas jowl shankle shank.`;
18
+ let newLineCount = output.split(/\n/).length
19
+ expect(newLineCount).toBe(paragraphs)
20
+ });
21
+
22
+ test('build a query string', () => {
23
+ let argv = {}
24
+ argv.type = "all-meat"
25
+ expect(buildQueryString(argv)).toBe('type=all-meat')
26
+ argv.paras=5
27
+ expect(buildQueryString(argv)).toBe('paras=5&type=all-meat')
28
+ argv['start-with-lorem'] = undefined
29
+ expect(buildQueryString(argv)).toBe('paras=5&type=all-meat')
30
+ argv['start-with-lorem'] = true
31
+ expect(buildQueryString(argv)).toBe('paras=5&start-with-lorem=1&type=all-meat')
32
+ });
33
+
34
+ test.skip('skip copying to the clipboard',() => {
35
+ let argv = {}
36
+ const noClip = true;
37
+ const currentClipboardContents = copyPaste.paste()
38
+ debug(currentClipboardContents)
39
+
40
+ const apiUrlWithParams = `${apiUrl}?${buildQueryString(argv)}`
41
+ getBacon(apiUrlWithParams,noClip)
42
+ const newClipboardContents = copyPaste.paste()
43
+ debug(newClipboardContents)
44
+
45
+ expect(newClipboardContents).toBe(currentClipboardContents)
46
+ });
47
+
48
+ test.skip('copying to the clipboard',async () => {
49
+ let argv = {}
50
+ const noClip = undefined;
51
+ const currentClipboardContents = copyPaste.paste()
52
+ debug(currentClipboardContents)
53
+ const apiUrlWithParams = `${apiUrl}?${buildQueryString(argv)}`
54
+ getBacon(apiUrlWithParams, noClip)
55
+ const newClipboardContents = copyPaste.paste()
56
+ debug(newClipboardContents)
57
+ expect(newClipboardContents).not.toBe(currentClipboardContents)
58
+ });
59
+
60
+ });