@beauraines/bacon-ipsum-cli 0.2.6 → 0.2.8
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 +4 -0
- package/cli.js +8 -3
- package/eslint.config.js +34 -0
- package/package.json +3 -3
- package/utils.js +28 -16
- package/utils.test.js +20 -24
- package/eslint.config.mjs +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [0.2.8](https://github.com/beauraines/bacon-ipsum-cli/compare/v0.2.7...v0.2.8) (2024-06-21)
|
|
6
|
+
|
|
7
|
+
## [0.2.7](https://github.com/beauraines/bacon-ipsum-cli/compare/v0.2.6...v0.2.7) (2024-06-21)
|
|
8
|
+
|
|
5
9
|
## [0.2.6](https://github.com/beauraines/bacon-ipsum-cli/compare/v0.2.5...v0.2.6) (2024-06-16)
|
|
6
10
|
|
|
7
11
|
## [0.2.5](https://github.com/beauraines/bacon-ipsum-cli/compare/v0.2.4...v0.2.5) (2024-06-05)
|
package/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import yargs from "yargs";
|
|
4
4
|
import debugClient from 'debug'
|
|
5
|
-
import { buildQueryString, getBacon } from './utils.js';
|
|
5
|
+
import { buildQueryString, getBacon, processOutput } from './utils.js';
|
|
6
6
|
|
|
7
7
|
const debug = debugClient('bacon-ipsum-cli');
|
|
8
8
|
const apiUrl = 'https://baconipsum.com/api/';
|
|
@@ -53,6 +53,11 @@ debug(apiUrlWithParams)
|
|
|
53
53
|
|
|
54
54
|
// Fetch data from the Bacon Ipsum API
|
|
55
55
|
let noClip = argv.nc
|
|
56
|
-
debug(argv.noClip)
|
|
57
56
|
|
|
58
|
-
getBacon(apiUrlWithParams
|
|
57
|
+
let bacon = await getBacon(apiUrlWithParams)
|
|
58
|
+
debug(bacon)
|
|
59
|
+
let outputOptions = {
|
|
60
|
+
noClip: noClip
|
|
61
|
+
}
|
|
62
|
+
debug(outputOptions)
|
|
63
|
+
processOutput(bacon, outputOptions);
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import globals from "globals";
|
|
2
|
+
import pluginJs from "@eslint/js";
|
|
3
|
+
import jestPlugin from "eslint-plugin-jest";
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
{
|
|
7
|
+
files: ["**/*.js"],
|
|
8
|
+
ignores: ["node_modules/"], // Ignore node_modules
|
|
9
|
+
languageOptions: {
|
|
10
|
+
sourceType: "module",
|
|
11
|
+
ecmaVersion: "latest",
|
|
12
|
+
globals: globals.nodeBuiltin
|
|
13
|
+
},
|
|
14
|
+
rules: {
|
|
15
|
+
...pluginJs.configs.recommended.rules,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
files: ["**/*.test.js", "**/__tests__/**/*.js"], // Apply Jest configurations to test files
|
|
20
|
+
ignores: ["node_modules/"], // Ignore node_modules
|
|
21
|
+
languageOptions: {
|
|
22
|
+
globals: {
|
|
23
|
+
...globals.jest, // Merging Jest globals
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
plugins: {
|
|
27
|
+
jest: jestPlugin,
|
|
28
|
+
},
|
|
29
|
+
rules: {
|
|
30
|
+
...jestPlugin.configs.recommended.rules, // Use recommended rules from eslint-plugin-jest
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beauraines/bacon-ipsum-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "CLI for Bacon Ipsum text",
|
|
5
5
|
"exports": "./cli.js",
|
|
6
6
|
"type": "module",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest --passWithNoTests --silent",
|
|
12
|
-
"lint": "eslint .
|
|
13
|
-
"lint:fix": "eslint .
|
|
12
|
+
"lint": "eslint .",
|
|
13
|
+
"lint:fix": "eslint . --fix",
|
|
14
14
|
"release": "commit-and-tag-version",
|
|
15
15
|
"should-release": "should-release"
|
|
16
16
|
},
|
package/utils.js
CHANGED
|
@@ -18,20 +18,32 @@ export const buildQueryString = (argv) => {
|
|
|
18
18
|
return qs
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Returns an array of paragraphs from the Bacon Ipsum API
|
|
23
|
+
* @param {String} apiUrlWithParams The bacon ipsum endpoint including any parameters
|
|
24
|
+
* @returns {Array}
|
|
25
|
+
*/
|
|
26
|
+
export const getBacon = async (apiUrlWithParams) => {
|
|
27
|
+
try {
|
|
28
|
+
let response = await fetch(apiUrlWithParams)
|
|
29
|
+
if (response.ok) {
|
|
30
|
+
return await response.json()
|
|
31
|
+
} else {
|
|
32
|
+
throw new Error(response.statusText);
|
|
33
|
+
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error('Error fetching data:', error);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
export const processOutput = (data, options) => {
|
|
40
|
+
if (options.noClip) { // noClip is alias for no-clip
|
|
41
|
+
// Display the fetched text in the console
|
|
42
|
+
console.log(data.join('\n'));
|
|
43
|
+
} else {
|
|
44
|
+
// Copy the text to the clipboard
|
|
45
|
+
copyPaste.copy(data.join('\n'), () => {
|
|
46
|
+
console.log('Bacon ipsum text copied to the clipboard!');
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
package/utils.test.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
/* eslint-disable jest/no-disabled-tests */
|
|
2
|
-
import { buildQueryString,
|
|
2
|
+
import { buildQueryString, processOutput } from "./utils.js";
|
|
3
3
|
import copyPaste from "copy-paste";
|
|
4
4
|
import debugClient from 'debug'
|
|
5
|
+
// eslint-disable-next-line no-unused-vars
|
|
5
6
|
const debug = debugClient('utils-tests');
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
describe('utilities', () => {
|
|
10
11
|
|
|
11
|
-
// eslint-disable-next-line no-unused-vars
|
|
12
|
-
const apiUrl = 'https://baconipsum.com/api/';
|
|
13
|
-
|
|
14
12
|
test('should return multiple paragraphs', () => {
|
|
15
13
|
const paragraphs = 2;
|
|
16
14
|
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.
|
|
@@ -31,30 +29,28 @@ Tongue venison ham tri-tip. Pig porchetta bacon, kielbasa pork chop spare ribs
|
|
|
31
29
|
expect(buildQueryString(argv)).toBe('paras=5&start-with-lorem=1&type=all-meat')
|
|
32
30
|
});
|
|
33
31
|
|
|
34
|
-
|
|
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)
|
|
32
|
+
});
|
|
44
33
|
|
|
45
|
-
|
|
34
|
+
// Skipped because GitHub runner doesn't include xclip
|
|
35
|
+
describe.skip("skip copy to clipboard", () => {
|
|
36
|
+
test('skip copying to the clipboard',async () => {
|
|
37
|
+
let bacon = ["bacon ipsum","turkey"]
|
|
38
|
+
await copyPaste.copy("foo")
|
|
39
|
+
processOutput(bacon, {noClip: true});
|
|
40
|
+
const newClipboardContents = await copyPaste.paste()
|
|
41
|
+
expect(newClipboardContents).not.toBe("foo")
|
|
46
42
|
});
|
|
43
|
+
});
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
// Skipped because GitHub runner doesn't include xclip
|
|
46
|
+
describe.skip("copy to clipboard", () => {
|
|
47
|
+
test('processes output to clipboard',async () => {
|
|
48
|
+
let bacon = ["bacon ipsum","turkey"]
|
|
50
49
|
const noClip = undefined;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const newClipboardContents = copyPaste.paste()
|
|
56
|
-
debug(newClipboardContents)
|
|
57
|
-
expect(newClipboardContents).not.toBe(currentClipboardContents)
|
|
50
|
+
await copyPaste.copy("")
|
|
51
|
+
processOutput(bacon, {noClip});
|
|
52
|
+
const newClipboardContents = await copyPaste.paste()
|
|
53
|
+
expect(newClipboardContents).toBe("bacon ipsum\nturkey")
|
|
58
54
|
});
|
|
59
55
|
|
|
60
56
|
});
|
package/eslint.config.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import globals from "globals";
|
|
2
|
-
import pluginJs from "@eslint/js";
|
|
3
|
-
import jestPlugin from "eslint-plugin-jest";
|
|
4
|
-
|
|
5
|
-
export default [
|
|
6
|
-
{
|
|
7
|
-
files: ["**/*.js"],
|
|
8
|
-
languageOptions: { sourceType: "module", ecmaVersion: "latest", globals: globals.nodeBuiltin}
|
|
9
|
-
},
|
|
10
|
-
{ languageOptions: { ...jestPlugin.environments.globals } },
|
|
11
|
-
pluginJs.configs.recommended,
|
|
12
|
-
{
|
|
13
|
-
plugins: {
|
|
14
|
-
jest: jestPlugin
|
|
15
|
-
},
|
|
16
|
-
rules: {
|
|
17
|
-
...jestPlugin.configs.recommended.rules, // Use recommended rules from eslint-plugin-jest
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
];
|