@beauraines/bacon-ipsum-cli 0.2.14 → 0.2.16

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.
@@ -0,0 +1,60 @@
1
+ on:
2
+ push:
3
+ branches:
4
+ - main
5
+
6
+ permissions:
7
+ contents: write
8
+ pull-requests: write
9
+
10
+ name: release-please
11
+
12
+ jobs:
13
+ release-please:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: googleapis/release-please-action@v4
17
+ with:
18
+ # this assumes that you have created a personal access token
19
+ # (PAT) and configured it as a GitHub action secret named
20
+ # `MY_RELEASE_PLEASE_TOKEN` (this secret name is not important).
21
+ token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
22
+ # this is a built-in strategy in release-please, see "Action Inputs"
23
+ # for more options
24
+ release-type: node
25
+ permissions:
26
+ contents: write
27
+ pull-requests: write
28
+
29
+ # The logic below handles the npm publication:
30
+ - uses: actions/checkout@v4
31
+ # these if statements ensure that a publication only occurs when
32
+ # a new release is created:
33
+ if: ${{ steps.release.outputs.release_created }}
34
+ - uses: actions/setup-node@v4
35
+ with:
36
+ node-version: 12
37
+ registry-url: 'https://registry.npmjs.org'
38
+ if: ${{ steps.release.outputs.release_created }}
39
+ - run: npm ci
40
+ if: ${{ steps.release.outputs.release_created }}
41
+ - run: npm publish
42
+ env:
43
+ NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
44
+ if: ${{ steps.release.outputs.release_created }}
45
+
46
+ - uses: actions/checkout@v4
47
+ - name: tag major and minor versions
48
+ if: ${{ steps.release.outputs.release_created }}
49
+ run: |
50
+ git config user.name github-actions[bot]
51
+ git config user.email 41898282+github-actions[bot]@users.noreply.github.com
52
+ git remote add gh-token "https://${{ secrets.GITHUB_TOKEN }}@github.com/googleapis/release-please-action.git"
53
+ git tag -d v${{ steps.release.outputs.major }} || true
54
+ git tag -d v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true
55
+ git push origin :v${{ steps.release.outputs.major }} || true
56
+ git push origin :v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true
57
+ git tag -a v${{ steps.release.outputs.major }} -m "Release v${{ steps.release.outputs.major }}"
58
+ git tag -a v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} -m "Release v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}"
59
+ git push origin v${{ steps.release.outputs.major }}
60
+ git push origin v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}
package/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
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.16](https://github.com/beauraines/bacon-ipsum-cli/compare/v0.2.15...v0.2.16) (2024-06-24)
6
+
7
+ ## [0.2.15](https://github.com/beauraines/bacon-ipsum-cli/compare/v0.2.14...v0.2.15) (2024-06-24)
8
+
9
+
10
+ ### Features
11
+
12
+ * option for output format ([2f30a3f](https://github.com/beauraines/bacon-ipsum-cli/commit/2f30a3f6fa91e7c331f9ec4dfbda9aca2fd2cd00)), closes [#6](https://github.com/beauraines/bacon-ipsum-cli/issues/6)
13
+
5
14
  ## [0.2.14](https://github.com/beauraines/bacon-ipsum-cli/compare/v0.2.13...v0.2.14) (2024-06-22)
6
15
 
7
16
  ## [0.2.13](https://github.com/beauraines/bacon-ipsum-cli/compare/v0.2.12...v0.2.13) (2024-06-22)
package/TODO.md CHANGED
@@ -8,6 +8,6 @@
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
10
  - [x] Add README
11
- - [ ] Add output format options
11
+ - [x] Add output format options
12
12
  - [x] Add clipboard bypass option
13
- - [ ] change getBacon to async/await and separate data processing
13
+ - [xs] change getBacon to async/await and separate data processing
package/cli.js CHANGED
@@ -32,12 +32,12 @@ const argv = yargs(process.argv.slice(2))
32
32
  describe: 'Starts the first paragraph with ‘Bacon ipsum dolor sit amet’',
33
33
  type: 'boolean'
34
34
  })
35
- // .option('format',{
36
- // alias: 'f',
37
- // describe:'Output format. Defaults to `text`',
38
- // default: 'text',
39
- // choices: ['text','json','html']
40
- // })
35
+ .option('format',{
36
+ alias: 'f',
37
+ describe:'Output format. Defaults to `text`',
38
+ default: 'text',
39
+ choices: ['text','json','html']
40
+ })
41
41
  .option('nc',{
42
42
  alias: 'nc',
43
43
  describe:'Only outputs to console, bypassing the clipboard.',
@@ -53,11 +53,12 @@ debug(apiUrlWithParams)
53
53
 
54
54
  // Fetch data from the Bacon Ipsum API
55
55
  let noClip = argv.nc
56
+ let format = argv.format
56
57
 
57
- let bacon = await getBacon(apiUrlWithParams)
58
+ let bacon = await getBacon(apiUrlWithParams,format)
58
59
  debug(bacon)
59
60
  let outputOptions = {
60
- noClip: noClip
61
+ noClip
61
62
  }
62
63
  debug(outputOptions)
63
- processOutput(bacon, outputOptions);
64
+ await processOutput(bacon, outputOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beauraines/bacon-ipsum-cli",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "CLI for Bacon Ipsum text",
5
5
  "exports": "./cli.js",
6
6
  "type": "module",
package/utils.js CHANGED
@@ -23,11 +23,14 @@ export const buildQueryString = (argv) => {
23
23
  * @param {String} apiUrlWithParams The bacon ipsum endpoint including any parameters
24
24
  * @returns {Array}
25
25
  */
26
- export const getBacon = async (apiUrlWithParams) => {
26
+ export const getBacon = async (apiUrlWithParams,format) => {
27
+ debug(apiUrlWithParams+`&format=${format}`)
27
28
  try {
28
- let response = await fetch(apiUrlWithParams)
29
- if (response.ok) {
29
+ let response = await fetch(apiUrlWithParams+`&format=${format}`)
30
+ if (response.ok && format == 'json') {
30
31
  return await response.json()
32
+ } else if (response.ok && (format == 'text' || format == 'html')) {
33
+ return await response.text()
31
34
  } else {
32
35
  throw new Error(response.statusText);
33
36
  }
@@ -36,13 +39,13 @@ export const buildQueryString = (argv) => {
36
39
  }
37
40
  }
38
41
 
39
- export const processOutput = (data, options) => {
42
+ export const processOutput = async (data, options) => {
40
43
  if (options.noClip) { // noClip is alias for no-clip
41
44
  // Display the fetched text in the console
42
- console.log(data.join('\n'));
45
+ console.log(data);
43
46
  } else {
44
47
  // Copy the text to the clipboard
45
- copyPaste.copy(data.join('\n'), () => {
48
+ await copyPaste.copy(data, () => {
46
49
  console.log('Bacon ipsum text copied to the clipboard!');
47
50
  });
48
51
  }
package/utils.test.js CHANGED
@@ -9,6 +9,7 @@ const debug = debugClient('utils-tests');
9
9
 
10
10
  describe('utilities', () => {
11
11
 
12
+ //? What exactly is this testing? I don't think this is good for anything.
12
13
  test('should return multiple paragraphs', () => {
13
14
  const paragraphs = 2;
14
15
  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.
@@ -27,30 +28,44 @@ Tongue venison ham tri-tip. Pig porchetta bacon, kielbasa pork chop spare ribs
27
28
  expect(buildQueryString(argv)).toBe('paras=5&type=all-meat')
28
29
  argv['start-with-lorem'] = true
29
30
  expect(buildQueryString(argv)).toBe('paras=5&start-with-lorem=1&type=all-meat')
31
+ // Format should not be added to the query string, it is passed as an argument to the API call
32
+ argv['format'] = 'html'
33
+ expect(buildQueryString(argv)).toBe('paras=5&start-with-lorem=1&type=all-meat')
30
34
  });
31
35
 
32
36
  });
33
37
 
34
38
  // Skipped because GitHub runner doesn't include xclip
35
- describe.skip("skip copy to clipboard", () => {
36
- test('skip copying to the clipboard',async () => {
39
+ describe("skip copy to clipboard", () => {
40
+ test.skip('skip copying to the clipboard',async () => {
37
41
  let bacon = ["bacon ipsum","turkey"]
38
42
  await copyPaste.copy("foo")
39
- processOutput(bacon, {noClip: true});
43
+ await processOutput(bacon, {noClip: true});
40
44
  const newClipboardContents = await copyPaste.paste()
41
45
  expect(newClipboardContents).not.toBe("foo")
42
46
  });
43
47
  });
44
48
 
45
49
  // 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
+ describe("copy JSON to clipboard", () => {
51
+ test.skip('processes JSON output to clipboard',async () => {
52
+ let bacon = ['bacon ipsum','turkey']
53
+ const noClip = false;
54
+ await copyPaste.copy("foo")
55
+ await processOutput(bacon, {noClip});
56
+ const newClipboardContents = await copyPaste.paste()
57
+ expect(newClipboardContents).toBe(bacon)
58
+ });
59
+ });
60
+
61
+ // Skipped because GitHub runner doesn't include xclip
62
+ describe("copy text to clipboard", () => {
63
+ test.skip('processes text output to clipboard',async () => {
64
+ let bacon = "bacon ipsum\nturkey";
49
65
  const noClip = undefined;
50
- await copyPaste.copy("")
51
- processOutput(bacon, {noClip});
66
+ await copyPaste.copy("foo")
67
+ await processOutput(bacon, {noClip});
52
68
  const newClipboardContents = await copyPaste.paste()
53
69
  expect(newClipboardContents).toBe("bacon ipsum\nturkey")
54
70
  });
55
-
56
71
  });