bump-cli 2.9.2 → 2.9.4

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/README.md CHANGED
@@ -5,16 +5,17 @@
5
5
  </p>
6
6
 
7
7
  <p align="center">
8
- <a href="https://help.bump.sh/">Help</a> |
8
+ <a href="https://docs.bump.sh/help">Help</a> |
9
9
  <a href="https://bump.sh/users/sign_up">Sign up</a>
10
10
  </p>
11
11
 
12
- The Bump.sh CLI is used to interact with your API documentation or hubs hosted on Bump.sh. With any API definition of your choice (from Swagger, OpenAPI or AsyncAPI), it can help you to:
12
+ The Bump.sh CLI is used to interact with API documentation and hubs hosted on Bump.sh from your choice of popular API description formats: OpenAPI, Swagger, or AsyncAPI.
13
13
 
14
- - Validate an API document before publishing it to your documentation
15
- - Publish an API document to your Bump.sh documentation or hubs
16
- - Compare two API documents to generate a human-readable diff from your API definitions
14
+ Using [OpenAPI](https://github.com/OAI/OpenAPI-Specification) (v3.x and v2.0) or [AsyncAPI](https://www.asyncapi.com/docs/reference/specification/latest) (2.x), you can do any of the following:
17
15
 
16
+ - Validate an API document before publishing to your documentation.
17
+ - Publish an API document to your Bump.sh documentation or hubs.
18
+ - Compare two API documents to generate a human-readable diff from your API definition.
18
19
  Under the hood, it uses the API of [developers.bump.sh](https://developers.bump.sh). And is built with the [`oclif`](https://oclif.io) framework in Typescript.
19
20
 
20
21
  [![Version](https://img.shields.io/npm/v/bump-cli.svg)](https://npmjs.org/package/bump-cli)
@@ -34,43 +35,43 @@ Under the hood, it uses the API of [developers.bump.sh](https://developers.bump.
34
35
 
35
36
  The Bump.sh CLI is a node package currently distributed via NPM. This means you must have the Node v20+ interpreter installed on your computer or CI servers.
36
37
 
37
- _If you are looking to use Bump.sh in a continuous integration environment you might be interested by [our Github Action](https://github.com/marketplace/actions/api-documentation-on-bump)._
38
+ _If you are looking to use Bump.sh in a continuous integration environment you might be interested by [our Github Action](https://github.com/marketplace/actions/bump-sh-api-documentation-changelog)._
38
39
 
39
40
  > You can download a standalone package directly from the latest
40
- > GitHub release assets if you don’t use Node.
41
+ > Github release assets if you don’t use Node.
41
42
  {: .info}
42
43
 
43
44
  ### Global installation
44
45
 
45
- To install it globally, run the following command with NPM
46
+ To install it globally, run the following command with NPM:
46
47
 
47
- ```sh-session
48
+ ```shell
48
49
  npm install -g bump-cli
49
50
  ```
50
51
 
51
- Or, with Yarn via
52
+ Or, with Yarn via:
52
53
 
53
- ```sh-session
54
+ ```shell
54
55
  yarn global add bump-cli
55
56
  ```
56
57
 
57
58
  ### Add Bump.sh to your Node project
58
59
 
59
- As our CLI is a node package, you can easily embed it into your project by adding the package to your `package.json` file, either with NPM
60
+ As our CLI is a node package, you can easily embed it to your project by adding the package to your `package.json` file, either with NPM:
60
61
 
61
- ```sh-session
62
+ ```shell
62
63
  npm install --save-dev bump-cli
63
64
  ```
64
65
 
65
- Or with Yarn via
66
+ Or with Yarn via:
66
67
 
67
- ```sh-session
68
+ ```shell
68
69
  yarn add --dev bump-cli
69
70
  ```
70
71
 
71
- You can then use any Bump.sh commands with `npx` (same as `npm exec`)
72
+ You can then use any Bump.sh commands with `npx` (same as `npm exec`):
72
73
 
73
- ```sh-session
74
+ ```shell
74
75
  npx bump --help
75
76
  ```
76
77
 
@@ -82,12 +83,12 @@ Unfortunately, at the moment we only support the Node environment. However, you
82
83
 
83
84
  To list all the available commands, just type `bump` in your command line environment.
84
85
 
85
- ```sh-session
86
+ ```shell
86
87
  $ bump --help
87
88
  The Bump.sh CLI is used to interact with your API documentation hosted on Bump.sh by using the API of developers.bump.sh
88
89
 
89
90
  VERSION
90
- bump-cli/2.9.1 linux-x64 node-v20.18.1
91
+ bump-cli/2.9.3 linux-x64 node-v20.18.1
91
92
 
92
93
  USAGE
93
94
  $ bump [COMMAND]
@@ -110,16 +111,16 @@ Head over to your Documentation settings in the “CI deployment” section or y
110
111
 
111
112
  ## Commands
112
113
 
113
- * [`bump deploy [FILE]`](#bump-deploy-file)
114
- * [`bump diff [FILE]`](#bump-diff-file)
115
- * [`bump preview [FILE]`](#bump-preview-file)
116
- * [`bump overlay [DEFINITION_FILE] [OVERLAY_FILE]`](#bump-overlay-definition_file-overlay_file)
114
+ * [`bump deploy [FILE]`](#the-deploy-command)
115
+ * [`bump diff [FILE]`](#the-diff-command)
116
+ * [`bump preview [FILE]`](#the-preview-command)
117
+ * [`bump overlay [DEFINITION_FILE] [OVERLAY_FILE]`](#the-overlay-command)
117
118
 
118
- ### `bump deploy [FILE]`
119
+ ### The `deploy` command
119
120
 
120
- When you update your API, you also want its documentation to be up to date for your API users. This is what the deploy command is for.
121
+ When an API is updated, the documentation should be updated at the same time. This is what the deploy command is for.
121
122
 
122
- ```sh-session
123
+ ```shell
123
124
  bump deploy path/to/api-document.yml --doc my-documentation --token $DOC_TOKEN
124
125
  ```
125
126
 
@@ -128,7 +129,7 @@ bump deploy path/to/api-document.yml --doc my-documentation --token $DOC_TOKEN
128
129
 
129
130
  You can also deploy a given API document to a different branch of your documentation with the `--branch <branch-name>` parameter. Please note the branch will be created if it doesn’t exist. More details about the branching feature are available on [this dedicated help page](https://docs.bump.sh/help/branching). E.g. deploy the API document to the `staging` branch of the documentation:
130
131
 
131
- ```sh-session
132
+ ```shell
132
133
  bump deploy path/to/api-document.yml --doc my-documentation --token $DOC_TOKEN --branch staging
133
134
  ```
134
135
 
@@ -136,7 +137,7 @@ bump deploy path/to/api-document.yml --doc my-documentation --token $DOC_TOKEN -
136
137
 
137
138
  If you already have a hub in your [Bump.sh](https://bump.sh) account, you can automatically create documentation and deploy it into that hub by publishing a whole directory containing multiple API documents in a single command:
138
139
 
139
- ```sh-session
140
+ ```shell
140
141
  bump deploy dir/path/to/apis/ --auto-create --hub my-hub --token $HUB_TOKEN
141
142
  ```
142
143
 
@@ -168,69 +169,81 @@ bump deploy path/to/apis/ --hub my-hub --filename-pattern '*-api-{slug}-service'
168
169
 
169
170
  Simulate your API document's deployment to ensure it is valid by adding the `--dry-run` flag to the `deploy` command. It is handy in a Continuous Integration environment running a test deployment outside your main branch:
170
171
 
171
- ```sh-session
172
+ ```shell
172
173
  bump deploy path/to/api-document.yml --dry-run --doc my-documentation --token $DOC_TOKEN
173
174
  ```
174
175
 
175
176
  Please check `bump deploy --help` for more usage details.
176
177
 
177
- ### `bump diff [FILE]`
178
-
179
- _If you want to receive automatic `bump diff` results on your Github Pull Requests you might be interested by [our Github Action](https://github.com/marketplace/actions/bump-sh-api-documentation-changelog) which also has a diff command._
178
+ ### The `diff` command
180
179
 
181
- Please note that by default the command will always exit with a
182
- successful return code. If you want to use this command in a CI
183
- environment and want the command to fail **in case of a breaking
184
- change**, you will need to add the `--fail-on-breaking` flag to your
185
- diff command. By default if the environment variable `CI=1` is present
186
- (in most continuous integration environment), the flag will be
187
- enabled. In that case you can disable the failures with
188
- `--no-fail-on-breaking` flag.
180
+ Using the `diff` command can help to spot differences between the local API
181
+ document and the latest deployed version.
189
182
 
190
183
  #### Public API diffs
191
184
 
192
- From any two API documents or URLs, you can retrieve a comprehensive changelog of what has changed between them.
185
+ From any two API documents or URLs, you can retrieve a comprehensive changelog
186
+ of what has changed between them.
193
187
 
194
- ```sh-session
188
+ ```shell
195
189
  $ bump diff path/to/your/file.yml path/to/your/second_file.yml
196
190
  * Comparing the two given definition files... done
197
191
  Modified: GET /consommations
198
192
  Response modified: 200
199
193
  [Breaking] Body attribute modified: energie
200
194
  ```
201
- > You can create as many diffs as you like without being authenticated. This is a **free and unlimited service** provided as long as you use the service fairly.
202
- {: .info}
203
195
 
204
- _**Note:** You can also test this feature in our dedicated web application at <https://api-diff.io/>._
196
+ By default the command will always exit with a successful return code. If you
197
+ want to use this command in a CI environment and want the command to fail **in
198
+ case of a breaking change**, you will need to add the `--fail-on-breaking` flag
199
+ to your diff command.
200
+
201
+ By default if the environment variable `CI=1` is present (in most continuous
202
+ integration environment), the flag will be enabled. In that case you can disable
203
+ the failures with `--no-fail-on-breaking` flag.
204
+
205
+ You can also test this feature in our dedicated web application at
206
+ <https://api-diff.io/>.
207
+
208
+ #### GitHub Integration
209
+
210
+ If you want to receive automatic `bump diff` results on Github Pull Requests you
211
+ might be interested by [our Github
212
+ Action](https://github.com/marketplace/actions/bump-sh-api-documentation-changelog#deploy-documentation--diff-on-pull-requests)
213
+ which has support for the diff command.
205
214
 
206
215
  #### Authenticated diffs related to your Bump.sh documentation
207
216
 
208
- From an existing Bump.sh documentation, the `diff` command will retrieve a comparison changelog between your latest published documentation and the given file or URL:
217
+ From an existing Bump.sh documentation, the `diff` command will retrieve a
218
+ comparison changelog between your latest published documentation and the given
219
+ file or URL:
209
220
 
210
- ```sh-session
221
+ ```shell
211
222
  bump diff path/to/your/file.yml --doc my-documentation --token $DOC_TOKEN
212
223
  ```
213
224
 
214
225
  If you want to compare two unpublished versions of your API document, the `diff` command can retrieve a comparison changelog between two given file or URL, “as simple as `git diff`”:
215
226
 
216
- ```sh-session
227
+ ```shell
217
228
  bump diff path/to/your/file.yml path/to/your/next-file.yml --doc my-documentation --token $DOC_TOKEN
218
229
  ```
219
230
 
220
231
  Please check `bump diff --help` for full usage details.
221
232
 
222
- ### `bump preview [FILE]`
223
-
233
+ ### The `preview` command
224
234
 
225
- When writing documentation, you might want to preview how it renders on Bump.sh. This is precisely the goal of the `preview` command: it will create temporary documentation with a unique URL, which will be available for a short period (30 minutes).
235
+ When writing documentation, you might want to preview how it renders on Bump.sh.
236
+ This is precisely the goal of the `preview` command: it will create temporary
237
+ documentation with a unique URL, which will be available for a short period (30
238
+ minutes).
226
239
 
227
- Usage from a local OpenAPI or AsyncAPI file
240
+ Usage from a local OpenAPI or AsyncAPI document:
228
241
 
229
242
  ```shell
230
243
  bump preview path/to/file.json
231
244
  ```
232
245
 
233
- You can also preview a file available from a URL
246
+ You can also preview a document available via a URL:
234
247
 
235
248
  ```shell
236
249
  bump preview https://developers.bump.sh/source.yaml
@@ -243,37 +256,48 @@ By using the `--live` flag you can stay focused on API design (OpenAPI or AsyncA
243
256
  - Launch the live preview command in your terminal
244
257
 
245
258
  ```shell
246
- bump preview --live --open openapi-definition.json
259
+ bump preview --live --open api-document.yaml
247
260
  ```
248
261
 
249
- - Edit your `openapi-definition.json` file in your favorite text editor
262
+ - Edit your `api-document.yaml` file in your favorite text editor.
250
263
  - Watch the live preview being updated each time you save your file.
264
+ - The additional `--open` flag helps to automatically open the preview URL in your browser.
251
265
 
252
266
  > You can create as many previews as you like without being authenticated. This is a **free and unlimited service**.
253
267
  {: .info}
254
268
 
255
- _**Note:** the additional `--open` flag helps to automatically open the preview URL in your browser._
256
-
257
269
  Please check `bump preview --help` for more usage details
258
270
 
259
- ### `bump overlay [DEFINITION_FILE] [OVERLAY_FILE]`
271
+ ### The `overlay` command
260
272
 
261
- > This feature implements the [OpenAPI Overlay specification](https://github.com/OAI/Overlay-Specification). It is possible to apply an Overlay to any kind of document, be it an OpenAPI or AsyncAPI definition file.
273
+ The [Overlay Specification](https://spec.openapis.org/overlay/v1.0.0.html) from the OpenAPI Initiative makes it possible to modify the content of an API definition by adding a layer on top of it. That layer helps adding, removing or changing some or all of the content of the original definition.
262
274
 
263
- The Overlay specification of OpenAPI makes it possible to modify the content of an API definition file by adding a layer on top of it. That layer helps add, remove, or change some or all of the content of the original definition.
275
+ The `bump overlay` command takes an original API document, applies the changes from the overlay document, and outputs a modified version. No changes are made directly to the original document.
264
276
 
265
- Technically, the `bump overlay` command will output a modified version of the `[DEFINITION_FILE]` (an OpenAPI or AsyncAPI document) by applying the operations described in the `[OVERLAY_FILE]` Overlay file to the original API document.
277
+ ```shell
278
+ bump overlay api-document.yaml overlay.yaml
279
+ ```
280
+
281
+ To redirect the output of the command to a new file you can run:
282
+
283
+ ```shell
284
+ bump overlay api-document.yaml overlay.yaml > modified-api-document.yaml
285
+ ```
266
286
 
267
- To redirect the output of the command to a new file you can run the following:
287
+ You can also apply the overlay using the [`deploy` command](#the-deploy-command) with the `--overlay` flag:
268
288
 
269
289
  ```shell
270
- bump overlay api-document.yaml overlay-file.yaml > api-overlayed-document.yaml
290
+ bump deploy api-document.yaml --doc my-doc --token my-token --overlay overlay.yaml
271
291
  ```
272
292
 
273
- _Note: you can also apply overlays during the [`bump deploy` command]((#bump-deploy-file)) with the `--overlay` flag (which can be used multiples times):_
293
+ If there are multiple overlays which need to be applied, the `--overlay` can be passed multiple times.
274
294
 
275
295
  ```shell
276
- bump deploy api-document.yaml --doc my-doc --token my-token --overlay overlay-file.yaml
296
+ bump deploy api-document.yaml \
297
+ --doc my-doc \
298
+ --token my-token \
299
+ --overlay overlay1.yaml \
300
+ --overlay overlay2.yaml
277
301
  ```
278
302
 
279
303
  ## Development
@@ -282,55 +306,69 @@ Make sure to have Node.js (At least v20) installed on your machine.
282
306
 
283
307
  - Install node dependencies with
284
308
 
285
- ```sh-session
309
+ ```shell
286
310
  npm install
287
311
  ```
288
312
 
289
313
  - Compile the Typescript code
290
314
 
291
- ```sh-session
315
+
316
+ ```shell
292
317
  npm run build
293
- npm run clean # to remove build artifacts
318
+ npm run clean # Remove build artifacts
294
319
  ```
295
320
 
296
321
  - Format the codebase to comply with the linter rules
297
322
 
298
- ```sh-session
323
+ ```shell
299
324
  npm run fmt
300
325
  ```
301
326
 
302
327
  - Run the test suites
303
328
 
304
- ```sh-session
329
+ ```shell
305
330
  npm run test
306
331
  npm run test-coverage # Run tests with coverage
307
332
  ```
308
333
 
309
- ## Compatible specification types
334
+ ### Use package in local environment
310
335
 
311
- We currently support [OpenAPI](https://github.com/OAI/OpenAPI-Specification) from 2.0 (called Swagger) to 3.1 and [AsyncAPI 2.x](https://www.asyncapi.com/docs/reference/specification/latest) specification file types. Both YAML and JSON file formats are accepted file inputs to the CLI.
336
+ You can run the package by executing the file `bin/run.js` locally:
312
337
 
313
- ## Contributing
338
+ ```shell
339
+ bin/run.js
340
+ ```
314
341
 
315
- Bug reports and pull requests are welcome on GitHub at <https://github.com/bump-sh/cli>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
342
+ For example to generate a preview:
316
343
 
317
- ## Thanks
344
+ ```shell
345
+ ./bin/run.js preview path/to/file.json
346
+ > Your preview is visible at: https://bump.sh/preview/42
347
+ ```
318
348
 
319
- - [Lorna Mitchel](https://github.com/lornajane/) for [openapi-overlay-js](https://github.com/lornajane/openapi-overlays-js)
349
+ Please note that even if CLI is running locally, by default requests are sent to [Bump.sh API](https://developers.bump.sh/).
350
+
351
+ If you have a local version of the Bump.sh API, you can run CLI 100% in local environment
352
+ by setting the environment variable `BUMP_HOST`:
353
+
354
+ ```shell
355
+ BUMP_HOST="http://localhost:3000" ./bin/run.js preview path/to/file.json
356
+ > Your preview is visible at: http://localhost:3000/preview/42
357
+ ```
320
358
 
321
359
  ## License
322
360
 
323
361
  The Bump CLI project is released under the [MIT License](http://opensource.org/licenses/MIT).
324
362
 
325
- ## Code of Conduct
363
+ ## Contributing
326
364
 
327
- Everyone interacting in the Bump-CLI project codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/bump-sh/.github/blob/main/CODE_OF_CONDUCT.md).
365
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/bump-sh/cli>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
328
366
 
329
- ## Versioning
367
+ ## Code of Conduct
330
368
 
331
- This npm package starts at v2.0.0 for two main reasons:
369
+ Everyone interacting in the Bump-CLI project codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/bump-sh/.github/blob/main/CODE_OF_CONDUCT.md).
332
370
 
333
- - Our [first version](https://github.com/bump-sh/bump-cli) of the Bump CLI was written in Ruby, starting at v2.0.0, which makes it clear we are working on our second version of the Bump CLI
371
+ ## Thanks
334
372
 
335
- - The `bump-cli` package used to be [owned by Rico](https://github.com/rstacruz) which already published v1.x packages. If you are looking for the old npm package please head to [`@rstacruz/bump-cli` package](https://www.npmjs.com/package/@rstacruz/bump-cli). _A big thanks to Rico for transferring the ownership of the `bump-cli` package name!_
336
- w
373
+ - [Lorna Mitchel](https://github.com/lornajane/) for [openapi-overlay-js](https://github.com/lornajane/openapi-overlays-js).
374
+ - [Rico](https://github.com/rstacruz) for transferring the ownership of the `bump-cli` package name.
package/dist/core/diff.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Config } from '@oclif/core';
2
2
  import { CLIError } from '@oclif/core/errors';
3
3
  import debug from 'debug';
4
+ import { resolve } from 'node:path';
4
5
  import { BumpApi } from '../api/index.js';
5
6
  import { API } from '../definition.js';
6
7
  export class Diff {
@@ -99,7 +100,7 @@ export class Diff {
99
100
  }
100
101
  async run(file1, file2, documentation, hub, branch, token, format, expires) {
101
102
  if (!this._config)
102
- this._config = await Config.load('../../');
103
+ this._config = await Config.load(resolve(import.meta.dirname, './../../'));
103
104
  let diffVersion;
104
105
  if (file2 && (!documentation || !token)) {
105
106
  diffVersion = await this.createDiff(file1, file2, expires);
@@ -2,4 +2,8 @@ import { APIDefinition, OpenAPIOverlay } from '../definition.js';
2
2
  export declare class Overlay {
3
3
  d(formatter: any, ...args: any[]): void;
4
4
  run(spec: APIDefinition, overlay: OpenAPIOverlay): APIDefinition;
5
+ private executeAction;
6
+ private humanName;
7
+ private remove;
8
+ private update;
5
9
  }
@@ -1,6 +1,5 @@
1
1
  import debug from 'debug';
2
- /* eslint-disable-next-line import/default */
3
- import jsonpath from 'jsonpath';
2
+ import * as jsonpath from 'jsonpathly';
4
3
  import { mergician } from 'mergician';
5
4
  export class Overlay {
6
5
  // WIP @github.com/lornajane/openapi-overlays-js
@@ -19,63 +18,106 @@ export class Overlay {
19
18
  // If you make any changes here, PLEASE ALSO MAKE THEM UPSTREAM.
20
19
  run(spec, overlay) {
21
20
  // Use jsonpath.apply to do the changes
22
- if (overlay.actions && overlay.actions.length > 0)
21
+ if (overlay.actions && overlay.actions.length > 0) {
23
22
  for (const a of overlay.actions) {
24
23
  const action = a;
25
24
  if (!action.target) {
26
- process.stderr.write('Action with a missing target\n');
25
+ process.stderr.write(`WARNING: ${this.humanName(action)} has an empty target\n`);
27
26
  continue;
28
27
  }
29
28
  const target = action.target;
30
- // Is it a remove?
31
- if (Object.hasOwn(action, 'remove')) {
32
- /* eslint-disable-next-line no-constant-condition */
33
- while (true) {
34
- const path = jsonpath.paths(spec, target);
35
- if (path.length === 0) {
36
- break;
37
- }
38
- const parent = jsonpath.parent(spec, target);
39
- const thingToRemove = path[0].at(-1);
40
- if (thingToRemove !== undefined) {
41
- if (Array.isArray(parent)) {
42
- parent.splice(thingToRemove, 1);
43
- }
44
- else {
45
- delete parent[thingToRemove];
46
- }
47
- }
48
- }
29
+ // jsonpathly's paths are strings. They represent a “Path
30
+ // expression” which represents the absolute path in the objet
31
+ // tree reached by our `target`.
32
+ //
33
+ // E.g. '$["store"]["book"][0]["price"]'
34
+ const paths = jsonpath.paths(spec, target);
35
+ if (paths.length === 0) {
36
+ process.stderr.write(`WARNING: Action target '${target}' has no matching elements\n`);
37
+ continue;
38
+ }
39
+ for (const path of paths) {
40
+ // The 'executeAction' will mutate the passed spec object in
41
+ // place.
42
+ spec = this.executeAction(spec, action, path);
43
+ }
44
+ }
45
+ }
46
+ else {
47
+ process.stderr.write('WARNING: No actions found in your overlay\n');
48
+ }
49
+ return spec;
50
+ }
51
+ /* Mutates the given 'spec' object with the 'action' given and
52
+ * targeting a unique 'pat ' within the spec object. We don't check
53
+ * if the path is valid in the object as this is the role of the
54
+ * jsonpathly lib which we used previously to extract the target
55
+ * paths. */
56
+ executeAction(spec, action, path) {
57
+ const explodedPath = path.split(/(?:]\[|\$\[)+/);
58
+ // Remove root
59
+ explodedPath.shift();
60
+ // Take last element from path (which is the thing to act
61
+ // upon)
62
+ let thingToActUpon = explodedPath.pop();
63
+ // The last element (e.g. '"price"]' or '0]') contains a final ']'
64
+ // so we need to remove it AND we need to parse the element to
65
+ // transform the string in either a string or a number
66
+ thingToActUpon =
67
+ thingToActUpon === undefined ? '$' : (thingToActUpon = JSON.parse(thingToActUpon.slice(0, -1)));
68
+ // Reconstruct the stringified path expression targeting the parent
69
+ const parentPath = explodedPath.join('][');
70
+ const parent = parentPath.length > 0 ? jsonpath.query(spec, `$[${parentPath}]`) : spec;
71
+ // Do the overlay action
72
+ // Is it a remove?
73
+ if (Object.hasOwn(action, 'remove')) {
74
+ this.remove(parent, thingToActUpon);
75
+ }
76
+ else if (Object.hasOwn(action, 'update')) {
77
+ spec = this.update(spec, parent, action.update, thingToActUpon);
78
+ }
79
+ else {
80
+ process.stderr.write(`WARNING: ${this.humanName(action)} needs either a 'remove' or an 'update' property\n`);
81
+ }
82
+ return spec;
83
+ }
84
+ humanName(action) {
85
+ return action.description ? `Action '${action.description}'` : 'Action';
86
+ }
87
+ remove(parent, property_or_index) {
88
+ if (Array.isArray(parent)) {
89
+ parent.splice(property_or_index, 1);
90
+ }
91
+ else {
92
+ delete parent[property_or_index];
93
+ }
94
+ }
95
+ update(spec, parent, update, property_or_index) {
96
+ try {
97
+ // Deep merge objects using a module (built-in spread operator is only shallow)
98
+ const merger = mergician({ appendArrays: true });
99
+ if (property_or_index === '$') {
100
+ // You can't actually merge an update on a root object
101
+ // target with the jsonpathly lib, this is just us merging
102
+ // the given update with the whole spec.
103
+ spec = merger(spec, update);
104
+ }
105
+ else if (property_or_index !== undefined) {
106
+ const targetObject = parent[property_or_index];
107
+ if (typeof targetObject === 'object' && typeof update === 'object') {
108
+ parent[property_or_index] =
109
+ Array.isArray(targetObject) && Array.isArray(update)
110
+ ? [...targetObject, ...update]
111
+ : merger(targetObject, update);
49
112
  }
50
113
  else {
51
- try {
52
- // It must be an update
53
- // Deep merge objects using a module (built-in spread operator is only shallow)
54
- const merger = mergician({ appendArrays: true });
55
- if (target === '$') {
56
- // You can't actually merge an update on a root object
57
- // target with the jsonpath lib, this is just us merging
58
- // the given update with the whole spec.
59
- spec = merger(spec, action.update);
60
- }
61
- else {
62
- jsonpath.apply(spec, target, (chunk) => {
63
- if (typeof chunk === 'object' && typeof action.update === 'object') {
64
- if (Array.isArray(chunk) && Array.isArray(action.update)) {
65
- return [...chunk, ...action.update];
66
- }
67
- return merger(chunk, action.update);
68
- }
69
- return action.update;
70
- });
71
- }
72
- }
73
- catch (error) {
74
- process.stderr.write(`Error applying overlay: ${error.message}\n`);
75
- // return chunk
76
- }
114
+ parent[property_or_index] = update;
77
115
  }
78
116
  }
117
+ }
118
+ catch (error) {
119
+ process.stderr.write(`Error applying overlay: ${error.message}\n`);
120
+ }
79
121
  return spec;
80
122
  }
81
123
  }
@@ -3,7 +3,7 @@ type FileDescription = {
3
3
  label: string;
4
4
  value: string;
5
5
  };
6
- export declare const isDir: (path: string) => boolean;
6
+ export declare const isDir: (path_or_url: string) => boolean;
7
7
  export declare class File {
8
8
  protected static readonly supportedFormats: string[];
9
9
  static listInvalidConventionFiles(path: string, regex: RegExp): FileDescription[];
@@ -1,8 +1,24 @@
1
+ import { CLIError } from '@oclif/core/errors';
1
2
  import { readdirSync, statSync } from 'node:fs';
2
3
  import { basename, extname } from 'node:path';
3
- export const isDir = (path) => {
4
+ export const isDir = (path_or_url) => {
5
+ if (isHttpUrl(path_or_url)) {
6
+ return false;
7
+ }
8
+ try {
9
+ return statSync(path_or_url).isDirectory();
10
+ }
11
+ catch (error) {
12
+ if (error instanceof Error) {
13
+ throw new CLIError(error);
14
+ }
15
+ return false;
16
+ }
17
+ };
18
+ const isHttpUrl = (path) => {
4
19
  try {
5
- return statSync(path).isDirectory();
20
+ const url = new URL(path);
21
+ return ['http:', 'https:'].includes(url.protocol);
6
22
  }
7
23
  catch {
8
24
  return false;
@@ -97,6 +97,7 @@
97
97
  "description": "Documentation or Hub token. Can be provided via BUMP_TOKEN environment variable",
98
98
  "name": "token",
99
99
  "required": true,
100
+ "default": "99f52837852249b328c0a00249f846a3",
100
101
  "hasDynamicHelp": false,
101
102
  "multiple": false,
102
103
  "type": "option"
@@ -190,6 +191,7 @@
190
191
  "description": "Documentation or Hub token. Can be provided via BUMP_TOKEN environment variable",
191
192
  "name": "token",
192
193
  "required": false,
194
+ "default": "99f52837852249b328c0a00249f846a3",
193
195
  "hasDynamicHelp": false,
194
196
  "multiple": false,
195
197
  "type": "option"
@@ -277,5 +279,5 @@
277
279
  "strict": true
278
280
  }
279
281
  },
280
- "version": "2.9.2"
282
+ "version": "2.9.4"
281
283
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bump-cli",
3
3
  "description": "The Bump CLI is used to interact with your API documentation hosted on Bump.sh by using the API of developers.bump.sh",
4
- "version": "2.9.2",
4
+ "version": "2.9.4",
5
5
  "author": "Paul Bonaud <paulr@bump.sh>",
6
6
  "bin": {
7
7
  "bump": "./bin/run.js"
@@ -73,7 +73,6 @@
73
73
  },
74
74
  "repository": "bump-sh/cli",
75
75
  "scripts": {
76
- "prepare": "npm run build",
77
76
  "build": "shx rm -rf dist && tsc -b",
78
77
  "clean": "rm -rf dist/ oclif.manifest.json",
79
78
  "lint": "eslint . --ext .ts",
@@ -93,7 +92,7 @@
93
92
  "dependencies": {
94
93
  "@apidevtools/json-schema-ref-parser": "^11.7.2",
95
94
  "@asyncapi/specs": "^6.8.0",
96
- "@clack/prompts": "^0.7.0",
95
+ "@clack/prompts": "^0.10.0",
97
96
  "@oclif/core": "^4",
98
97
  "@oclif/plugin-help": "^6",
99
98
  "@oclif/plugin-warn-if-update-available": "^3.1.20",
@@ -102,7 +101,7 @@
102
101
  "axios": "^1.7.7",
103
102
  "chalk": "^5.3.0",
104
103
  "debug": "^4.3.7",
105
- "jsonpath": "^1.1.1",
104
+ "jsonpathly": "^2.0.2",
106
105
  "mergician": "^2.0.2",
107
106
  "oas-schemas": "git+https://git@github.com/OAI/OpenAPI-Specification.git#882d1caedb0bff825a1fd10728e7e3dc43912d37",
108
107
  "open": "^10.1.0"