@beauraines/bacon-ipsum-cli 0.1.5 → 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,25 @@
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
+
5
24
  ### [0.1.5](https://github.com/beauraines/bacon-ipsum-cli/compare/v0.1.4...v0.1.5) (2024-05-27)
6
25
 
7
26
 
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,11 +1,13 @@
1
1
  # TODO
2
2
 
3
- - [ ] Move API call to module for testing
3
+ - [x] Move API call to module for testing
4
4
  - [x] Add other options
5
5
  - [x] Add debug
6
- - [ ] Add unit tests
7
- - [ ] Add completion command
6
+ - [x] Add unit tests
7
+ - [x] Add completion command
8
8
  - [x] Configure linter - 'dont warn for Node globals like console'
9
9
  - [x] Swith to ESM and import latest versions of dependencies
10
- - [ ] Add README
11
- - [ ] Add output options (format and clipboard)
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,11 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import fetch from "node-fetch";
4
3
  import yargs from "yargs";
5
- import copyPaste from "copy-paste";
6
4
  import debugClient from 'debug'
7
- import { buildQueryString } from './utils.js';
8
-
5
+ import { buildQueryString, getBacon } from './utils.js';
9
6
 
10
7
  const debug = debugClient('bacon-ipsum-cli');
11
8
  const apiUrl = 'https://baconipsum.com/api/';
@@ -41,11 +38,12 @@ const argv = yargs(process.argv.slice(2))
41
38
  // default: 'text',
42
39
  // choices: ['text','json','html']
43
40
  // })
44
- // .option('no-clip',{
45
- // alias: 'nc',
46
- // describe:'Only outputs to console, bypassing the clipboard.',
47
- // type: 'boolean'
48
- // })
41
+ .option('nc',{
42
+ alias: 'nc',
43
+ describe:'Only outputs to console, bypassing the clipboard.',
44
+ type: 'boolean'
45
+ })
46
+ .completion()
49
47
  .help()
50
48
  .argv;
51
49
 
@@ -54,15 +52,7 @@ const apiUrlWithParams = `${apiUrl}?${buildQueryString(argv)}`
54
52
  debug(apiUrlWithParams)
55
53
 
56
54
  // Fetch data from the Bacon Ipsum API
57
- fetch(apiUrlWithParams)
58
- .then((response) => response.json())
59
- .then((data) => {
60
- // Display the fetched text in the console
61
- console.log(data.join('\n'));
55
+ let noClip = argv.nc
56
+ debug(argv.noClip)
62
57
 
63
- // Copy the text to the clipboard
64
- copyPaste.copy(data.join('\n'), () => {
65
- console.log('Text copied to clipboard!');
66
- });
67
- })
68
- .catch((error) => console.error('Error fetching data:', error));
58
+ getBacon(apiUrlWithParams,noClip)
package/package.json CHANGED
@@ -1,21 +1,28 @@
1
1
  {
2
2
  "name": "@beauraines/bacon-ipsum-cli",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "CLI for Bacon Ipsum text",
5
5
  "exports": "./cli.js",
6
6
  "type": "module",
7
7
  "bin": {
8
- "bacon-ipsum": "cli.js"
8
+ "bacon": "cli.js"
9
9
  },
10
10
  "scripts": {
11
- "test": "jest --passWithNoTests",
11
+ "test": "NODE_OPTIONS=--experimental-vm-modules npx jest --passWithNoTests --silent",
12
12
  "lint": "eslint . ./**/*.js ./**/*.mjs",
13
13
  "lint:fix": "eslint . ./**/*.js ./**/*.mjs --fix",
14
14
  "release": "standard-version",
15
15
  "should-release": "should-release"
16
16
  },
17
- "author": "Beau Raines",
18
- "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",
19
26
  "dependencies": {
20
27
  "chalk": "^4.1.2",
21
28
  "copy-paste": "^1.5.3",
package/utils.js CHANGED
@@ -1,5 +1,8 @@
1
- import queryString from "query-string";
1
+ import copyPaste from "copy-paste";
2
2
  import debugClient from 'debug'
3
+ import fetch from "node-fetch";
4
+ import queryString from "query-string";
5
+
3
6
  const debug = debugClient('bacon-ipsum-cli-utils');
4
7
 
5
8
  export const buildQueryString = (argv) => {
@@ -8,9 +11,27 @@ export const buildQueryString = (argv) => {
8
11
  type: argv.type,
9
12
  paras: argv.paras,
10
13
  sentences: argv.sentences,
11
- "start-with-lorem" : argv['start-with-lorem'] ? 1 : null
14
+ "start-with-lorem" : argv['start-with-lorem'] ? 1 : undefined
12
15
  }
13
16
  const qs = queryString.stringify(queryParams);
14
17
  debug(qs)
15
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));
16
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
+ });