bump-cli 2.7.3-beta.1 → 2.8.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/README.md +4 -0
- package/lib/args.d.ts +1 -0
- package/lib/args.js +1 -0
- package/lib/commands/deploy.d.ts +1 -0
- package/lib/commands/deploy.js +6 -4
- package/lib/commands/overlay.d.ts +3 -1
- package/lib/commands/overlay.js +30 -22
- package/lib/core/deploy.d.ts +1 -1
- package/lib/core/deploy.js +4 -1
- package/lib/core/overlay.d.ts +4 -1
- package/lib/core/overlay.js +66 -57
- package/lib/definition.d.ts +13 -4
- package/lib/definition.js +30 -2
- package/lib/flags.d.ts +3 -1
- package/lib/flags.js +11 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -283,6 +283,10 @@ We currently support [OpenAPI](https://github.com/OAI/OpenAPI-Specification) fro
|
|
|
283
283
|
|
|
284
284
|
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.
|
|
285
285
|
|
|
286
|
+
## Thanks
|
|
287
|
+
|
|
288
|
+
- [Lorna Mitchel](https://github.com/lornajane/) for [openapi-overlay-js](https://github.com/lornajane/openapi-overlays-js)
|
|
289
|
+
|
|
286
290
|
## License
|
|
287
291
|
|
|
288
292
|
The Bump CLI project is released under the [MIT License](http://opensource.org/licenses/MIT).
|
package/lib/args.d.ts
CHANGED
package/lib/args.js
CHANGED
package/lib/commands/deploy.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export default class Deploy extends Command {
|
|
|
14
14
|
interactive: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
15
15
|
'filename-pattern': flagsBuilder.IOptionFlag<string | undefined>;
|
|
16
16
|
'dry-run': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
17
|
+
overlay: flagsBuilder.IOptionFlag<string | undefined>;
|
|
17
18
|
};
|
|
18
19
|
static args: {
|
|
19
20
|
name: string;
|
package/lib/commands/deploy.js
CHANGED
|
@@ -22,7 +22,7 @@ class Deploy extends command_1.default {
|
|
|
22
22
|
*/
|
|
23
23
|
async run() {
|
|
24
24
|
const { args, flags } = this.parse(Deploy);
|
|
25
|
-
const [dryRun, documentation, token, hub, autoCreate, interactive, filenamePattern, documentationName, branch,] = [
|
|
25
|
+
const [dryRun, documentation, token, hub, autoCreate, interactive, filenamePattern, documentationName, branch, overlay,] = [
|
|
26
26
|
flags['dry-run'],
|
|
27
27
|
flags.doc,
|
|
28
28
|
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
|
|
@@ -36,6 +36,7 @@ class Deploy extends command_1.default {
|
|
|
36
36
|
flags['filename-pattern'],
|
|
37
37
|
flags['doc-name'],
|
|
38
38
|
flags.branch,
|
|
39
|
+
flags.overlay,
|
|
39
40
|
];
|
|
40
41
|
if ((0, file_1.isDir)(args.FILE)) {
|
|
41
42
|
if (hub) {
|
|
@@ -49,7 +50,7 @@ class Deploy extends command_1.default {
|
|
|
49
50
|
if (documentation) {
|
|
50
51
|
const api = await definition_1.API.load(args.FILE);
|
|
51
52
|
this.d(`${args.FILE} looks like an ${api.specName} spec version ${api.version}`);
|
|
52
|
-
await this.deploySingleFile(api, dryRun, documentation, token, hub, autoCreate, documentationName, branch);
|
|
53
|
+
await this.deploySingleFile(api, dryRun, documentation, token, hub, autoCreate, documentationName, branch, overlay);
|
|
53
54
|
}
|
|
54
55
|
else {
|
|
55
56
|
throw new errors_1.RequiredFlagError({ flag: Deploy.flags.doc, parse: {} });
|
|
@@ -90,10 +91,10 @@ class Deploy extends command_1.default {
|
|
|
90
91
|
}
|
|
91
92
|
return;
|
|
92
93
|
}
|
|
93
|
-
async deploySingleFile(api, dryRun, documentation, token, hub, autoCreate, documentationName, branch) {
|
|
94
|
+
async deploySingleFile(api, dryRun, documentation, token, hub, autoCreate, documentationName, branch, overlay) {
|
|
94
95
|
const action = dryRun ? 'validate' : 'deploy';
|
|
95
96
|
cli_1.cli.action.start(`Let's ${action} a new version to your ${documentation} documentation on Bump.sh`);
|
|
96
|
-
const response = await new deploy_1.Deploy(this.config).run(api, dryRun, documentation, token, hub, autoCreate, documentationName, branch);
|
|
97
|
+
const response = await new deploy_1.Deploy(this.config).run(api, dryRun, documentation, token, hub, autoCreate, documentationName, branch, overlay);
|
|
97
98
|
if (dryRun) {
|
|
98
99
|
await cli_1.cli.styledSuccess('Definition is valid');
|
|
99
100
|
}
|
|
@@ -158,5 +159,6 @@ Deploy.flags = {
|
|
|
158
159
|
interactive: flagsBuilder.interactive(),
|
|
159
160
|
'filename-pattern': flagsBuilder.filenamePattern(),
|
|
160
161
|
'dry-run': flagsBuilder.dryRun(),
|
|
162
|
+
overlay: flagsBuilder.overlay(),
|
|
161
163
|
};
|
|
162
164
|
Deploy.args = [args_1.fileArg];
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import Command from '../command';
|
|
2
|
+
import * as flagsBuilder from '../flags';
|
|
2
3
|
export default class Overlay extends Command {
|
|
3
4
|
static description: string;
|
|
4
5
|
static examples: string[];
|
|
5
6
|
static flags: {
|
|
6
7
|
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
8
|
+
out: flagsBuilder.IOptionFlag<string | undefined>;
|
|
7
9
|
};
|
|
8
10
|
static args: {
|
|
9
11
|
name: string;
|
|
12
|
+
required: boolean;
|
|
10
13
|
description: string;
|
|
11
14
|
}[];
|
|
12
15
|
run(): Promise<void>;
|
|
13
|
-
applyOverlay(file: string, overlayFile: string): Promise<string>;
|
|
14
16
|
}
|
package/lib/commands/overlay.js
CHANGED
|
@@ -1,48 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
5
|
+
const promises_1 = require("node:fs/promises");
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
7
|
+
const path_1 = require("path");
|
|
6
8
|
const definition_1 = require("../definition");
|
|
9
|
+
const prompts_1 = require("../core/utils/prompts");
|
|
7
10
|
const command_1 = (0, tslib_1.__importDefault)(require("../command"));
|
|
8
11
|
const flagsBuilder = (0, tslib_1.__importStar)(require("../flags"));
|
|
9
12
|
const args_1 = require("../args");
|
|
10
13
|
const cli_1 = require("../cli");
|
|
11
|
-
const overlay_1 = require("../core/overlay");
|
|
12
14
|
class Overlay extends command_1.default {
|
|
13
15
|
async run() {
|
|
14
|
-
const { args } = this.parse(Overlay);
|
|
15
|
-
const
|
|
16
|
-
cli_1.cli.log(newDefinition);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
async applyOverlay(file, overlayFile) {
|
|
20
|
-
const api = await definition_1.API.load(file);
|
|
21
|
-
const definition = api.definition;
|
|
22
|
-
this.d(`${file} looks like an ${api.specName} spec version ${api.version}`);
|
|
23
|
-
const overlay = await definition_1.API.load(overlayFile);
|
|
24
|
-
const overlayDefinition = overlay.definition;
|
|
25
|
-
if (!definition_1.API.isOpenAPIOverlay(overlayDefinition)) {
|
|
26
|
-
throw new errors_1.CLIError(`${overlayFile} does not look like an OpenAPI overlay`);
|
|
27
|
-
}
|
|
16
|
+
const { args, flags } = this.parse(Overlay);
|
|
17
|
+
const outputPath = flags.out;
|
|
28
18
|
cli_1.cli.action.start("* Let's apply the overlay to the main definition");
|
|
29
|
-
const
|
|
19
|
+
const api = await definition_1.API.load(args.FILE);
|
|
20
|
+
await api.applyOverlay(args.OVERLAY_FILE);
|
|
21
|
+
const [overlayedDefinition] = api.extractDefinition(outputPath);
|
|
30
22
|
cli_1.cli.action.stop();
|
|
31
|
-
if (
|
|
32
|
-
|
|
23
|
+
if (outputPath) {
|
|
24
|
+
await (0, promises_1.mkdir)((0, path_1.dirname)(outputPath), { recursive: true });
|
|
25
|
+
let confirm = true;
|
|
26
|
+
if ((0, node_fs_1.existsSync)(outputPath)) {
|
|
27
|
+
await (0, prompts_1.confirm)(`Do you want to override the existing destination file? (${outputPath})`).catch(() => {
|
|
28
|
+
confirm = false;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (confirm) {
|
|
32
|
+
await (0, promises_1.writeFile)(outputPath, overlayedDefinition);
|
|
33
|
+
}
|
|
33
34
|
}
|
|
34
35
|
else {
|
|
35
|
-
|
|
36
|
+
cli_1.cli.log(overlayedDefinition);
|
|
36
37
|
}
|
|
38
|
+
return;
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
exports.default = Overlay;
|
|
40
42
|
Overlay.description = 'Apply an OpenAPI specified overlay to your API definition.';
|
|
41
43
|
Overlay.examples = [
|
|
42
|
-
|
|
44
|
+
`Apply the OVERLAY_FILE to the existing DEFINITION_FILE. The resulting
|
|
45
|
+
definition is output on stdout meaning you can redirect it to a new
|
|
46
|
+
file.
|
|
47
|
+
|
|
48
|
+
${chalk_1.default.dim('$ bump overlay DEFINITION_FILE OVERLAY_FILE > destination/file.json')}
|
|
49
|
+
* Let's apply the overlay to the main definition... done
|
|
43
50
|
`,
|
|
44
51
|
];
|
|
45
52
|
Overlay.flags = {
|
|
46
53
|
help: flagsBuilder.help({ char: 'h' }),
|
|
54
|
+
out: flagsBuilder.out(),
|
|
47
55
|
};
|
|
48
56
|
Overlay.args = [args_1.fileArg, args_1.overlayFileArg];
|
package/lib/core/deploy.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare class Deploy {
|
|
|
6
6
|
_bump: BumpApi;
|
|
7
7
|
_config: Config.IConfig;
|
|
8
8
|
constructor(config: Config.IConfig);
|
|
9
|
-
run(api: API, dryRun: boolean, documentation: string, token: string, hub: string | undefined, autoCreate: boolean, documentationName: string | undefined, branch: string | undefined): Promise<VersionResponse | undefined>;
|
|
9
|
+
run(api: API, dryRun: boolean, documentation: string, token: string, hub: string | undefined, autoCreate: boolean, documentationName: string | undefined, branch: string | undefined, overlay?: string | undefined): Promise<VersionResponse | undefined>;
|
|
10
10
|
get bumpClient(): BumpApi;
|
|
11
11
|
createVersion(request: VersionRequest, token: string): Promise<VersionResponse | undefined>;
|
|
12
12
|
validateVersion(version: VersionRequest, token: string): Promise<undefined>;
|
package/lib/core/deploy.js
CHANGED
|
@@ -8,8 +8,11 @@ class Deploy {
|
|
|
8
8
|
constructor(config) {
|
|
9
9
|
this._config = config;
|
|
10
10
|
}
|
|
11
|
-
async run(api, dryRun, documentation, token, hub, autoCreate, documentationName, branch) {
|
|
11
|
+
async run(api, dryRun, documentation, token, hub, autoCreate, documentationName, branch, overlay) {
|
|
12
12
|
let version = undefined;
|
|
13
|
+
if (overlay) {
|
|
14
|
+
await api.applyOverlay(overlay);
|
|
15
|
+
}
|
|
13
16
|
const [definition, references] = api.extractDefinition();
|
|
14
17
|
const request = {
|
|
15
18
|
documentation,
|
package/lib/core/overlay.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { APIDefinition, OpenAPIOverlay } from '../definition';
|
|
2
|
-
export declare
|
|
2
|
+
export declare class Overlay {
|
|
3
|
+
run(spec: APIDefinition, overlay: OpenAPIOverlay): APIDefinition;
|
|
4
|
+
d(formatter: any, ...args: any[]): void;
|
|
5
|
+
}
|
package/lib/core/overlay.js
CHANGED
|
@@ -1,69 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Overlay = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
// I couldn't get the upstream lib to be imported properly due to some
|
|
8
|
-
// issues with ESM module imports so this is file was copied from
|
|
9
|
-
// github.com/lornajane/openapi-overlays-js and has been adapted to
|
|
10
|
-
// make our Typescript build happy.
|
|
11
|
-
//
|
|
12
|
-
// If you make any changes here, please also make them upstream.
|
|
5
|
+
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
13
6
|
const jsonpath_1 = (0, tslib_1.__importDefault)(require("jsonpath"));
|
|
14
7
|
const mergician_1 = (0, tslib_1.__importDefault)(require("mergician"));
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const parent = jsonpath_1.default.parent(spec, target);
|
|
33
|
-
const thingToRemove = path[0][path[0].length - 1];
|
|
34
|
-
if (Array.isArray(parent)) {
|
|
35
|
-
parent.splice(thingToRemove, 1);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
delete parent[thingToRemove];
|
|
39
|
-
}
|
|
8
|
+
class Overlay {
|
|
9
|
+
// WIP @github.com/lornajane/openapi-overlays-js
|
|
10
|
+
//
|
|
11
|
+
// I couldn't get the upstream lib to be imported properly due to
|
|
12
|
+
// some issues with ESM module imports so this is method was copied
|
|
13
|
+
// from github.com/lornajane/openapi-overlays-js and has been
|
|
14
|
+
// adapted to make our Typescript build happy.
|
|
15
|
+
//
|
|
16
|
+
// If you make any changes here, PLEASE ALSO MAKE THEM UPSTREAM.
|
|
17
|
+
run(spec, overlay) {
|
|
18
|
+
// Use jsonpath.apply to do the changes
|
|
19
|
+
if (overlay.actions && overlay.actions.length >= 1)
|
|
20
|
+
overlay.actions.forEach((a) => {
|
|
21
|
+
const action = a;
|
|
22
|
+
if (!action.target) {
|
|
23
|
+
process.stderr.write('Action with a missing target\n');
|
|
24
|
+
return;
|
|
40
25
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return merger(chunk, action.update);
|
|
54
|
-
}
|
|
26
|
+
const target = action.target;
|
|
27
|
+
// Is it a remove?
|
|
28
|
+
if (action.hasOwnProperty('remove')) {
|
|
29
|
+
while (true) {
|
|
30
|
+
const path = jsonpath_1.default.paths(spec, target, 1);
|
|
31
|
+
if (path.length == 0) {
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
const parent = jsonpath_1.default.parent(spec, target);
|
|
35
|
+
const thingToRemove = path[0][path[0].length - 1];
|
|
36
|
+
if (Array.isArray(parent)) {
|
|
37
|
+
parent.splice(thingToRemove, 1);
|
|
55
38
|
}
|
|
56
39
|
else {
|
|
57
|
-
|
|
40
|
+
delete parent[thingToRemove];
|
|
58
41
|
}
|
|
59
|
-
}
|
|
42
|
+
}
|
|
60
43
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
44
|
+
else {
|
|
45
|
+
try {
|
|
46
|
+
// It must be an update
|
|
47
|
+
jsonpath_1.default.apply(spec, target, (chunk) => {
|
|
48
|
+
if (typeof chunk === 'object' && typeof action.update === 'object') {
|
|
49
|
+
if (Array.isArray(chunk) && Array.isArray(action.update)) {
|
|
50
|
+
return chunk.concat(action.update);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// Deep merge objects using a module (built-in spread operator is only shallow)
|
|
54
|
+
const merger = (0, mergician_1.default)({ appendArrays: true });
|
|
55
|
+
return merger(chunk, action.update);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return action.update;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch (ex) {
|
|
64
|
+
process.stderr.write(`Error applying overlay: ${ex.message}\n`);
|
|
65
|
+
//return chunk
|
|
66
|
+
}
|
|
64
67
|
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
});
|
|
69
|
+
return spec;
|
|
70
|
+
}
|
|
71
|
+
// Function signature type taken from @types/debug
|
|
72
|
+
// Debugger(formatter: any, ...args: any[]): void;
|
|
73
|
+
/* eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any */
|
|
74
|
+
d(formatter, ...args) {
|
|
75
|
+
return (0, debug_1.default)(`bump-cli:core:overlay`)(formatter, ...args);
|
|
76
|
+
}
|
|
68
77
|
}
|
|
69
|
-
exports.
|
|
78
|
+
exports.Overlay = Overlay;
|
package/lib/definition.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ declare class API {
|
|
|
9
9
|
readonly location: string;
|
|
10
10
|
readonly rawDefinition: string;
|
|
11
11
|
readonly definition: APIDefinition;
|
|
12
|
+
overlayedDefinition: APIDefinition | undefined;
|
|
12
13
|
readonly references: APIReference[];
|
|
13
14
|
readonly version: string;
|
|
14
15
|
readonly specName: string;
|
|
@@ -17,13 +18,16 @@ declare class API {
|
|
|
17
18
|
getSpec(definition: APIDefinition): SpecSchema;
|
|
18
19
|
getSpecName(definition: APIDefinition): string;
|
|
19
20
|
getVersion(definition: APIDefinition): string;
|
|
21
|
+
guessFormat(output?: string): string;
|
|
20
22
|
versionWithoutPatch(): string;
|
|
21
23
|
resolveRelativeLocation(absPath: string): string;
|
|
22
24
|
resolveContent($refs: $RefParser.$Refs): [string, APIDefinition];
|
|
25
|
+
serializeDefinition(outputPath?: string): string;
|
|
23
26
|
static isOpenAPI(definition: JSONSchema4Object | JSONSchema6Object): definition is OpenAPI;
|
|
24
27
|
static isAsyncAPI(definition: JSONSchema4Object | JSONSchema6Object): definition is AsyncAPI;
|
|
25
28
|
static isOpenAPIOverlay(definition: JSONSchema4Object | JSONSchema6Object): definition is OpenAPIOverlay;
|
|
26
|
-
extractDefinition(): [string, APIReference[]];
|
|
29
|
+
extractDefinition(outputPath?: string): [string, APIReference[]];
|
|
30
|
+
applyOverlay(overlayPath: string): Promise<void>;
|
|
27
31
|
static load(path: string): Promise<API>;
|
|
28
32
|
}
|
|
29
33
|
declare type APIReference = {
|
|
@@ -31,18 +35,23 @@ declare type APIReference = {
|
|
|
31
35
|
content: string;
|
|
32
36
|
};
|
|
33
37
|
declare type APIDefinition = OpenAPI | AsyncAPI | OpenAPIOverlay;
|
|
38
|
+
declare type InfoObject = {
|
|
39
|
+
readonly title: string;
|
|
40
|
+
readonly version: string;
|
|
41
|
+
readonly description?: string;
|
|
42
|
+
};
|
|
34
43
|
declare type OpenAPI = JSONSchema4Object & {
|
|
35
44
|
readonly openapi?: string;
|
|
36
45
|
readonly swagger?: string;
|
|
37
|
-
readonly info:
|
|
46
|
+
readonly info: InfoObject;
|
|
38
47
|
};
|
|
39
48
|
declare type OpenAPIOverlay = JSONSchema4Object & {
|
|
40
49
|
readonly overlay: string;
|
|
41
|
-
readonly info:
|
|
50
|
+
readonly info: InfoObject;
|
|
42
51
|
readonly actions: JSONSchema4Array;
|
|
43
52
|
};
|
|
44
53
|
declare type AsyncAPI = JSONSchema4Object & {
|
|
45
54
|
readonly asyncapi: string;
|
|
46
|
-
readonly info:
|
|
55
|
+
readonly info: InfoObject;
|
|
47
56
|
};
|
|
48
57
|
export { API, APIDefinition, OpenAPIOverlay, SupportedFormat };
|
package/lib/definition.js
CHANGED
|
@@ -7,6 +7,8 @@ const json_schema_ref_parser_1 = (0, tslib_1.__importDefault)(require("@apidevto
|
|
|
7
7
|
const options_1 = require("@apidevtools/json-schema-ref-parser/lib/options");
|
|
8
8
|
const specs_1 = (0, tslib_1.__importDefault)(require("@asyncapi/specs"));
|
|
9
9
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
10
|
+
const yaml_1 = require("@stoplight/yaml");
|
|
11
|
+
const overlay_1 = require("./core/overlay");
|
|
10
12
|
class SupportedFormat {
|
|
11
13
|
}
|
|
12
14
|
exports.SupportedFormat = SupportedFormat;
|
|
@@ -76,6 +78,9 @@ class API {
|
|
|
76
78
|
return (definition.openapi || definition.swagger);
|
|
77
79
|
}
|
|
78
80
|
}
|
|
81
|
+
guessFormat(output) {
|
|
82
|
+
return (output || this.location).endsWith('.json') ? 'json' : 'yaml';
|
|
83
|
+
}
|
|
79
84
|
versionWithoutPatch() {
|
|
80
85
|
const [major, minor] = this.version.split('.', 3);
|
|
81
86
|
return `${major}.${minor}`;
|
|
@@ -135,6 +140,21 @@ class API {
|
|
|
135
140
|
}
|
|
136
141
|
return [raw, parsed];
|
|
137
142
|
}
|
|
143
|
+
serializeDefinition(outputPath) {
|
|
144
|
+
if (this.overlayedDefinition) {
|
|
145
|
+
let serializedDefinition;
|
|
146
|
+
if (this.guessFormat(outputPath) == 'json') {
|
|
147
|
+
serializedDefinition = JSON.stringify(this.overlayedDefinition);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
serializedDefinition = (0, yaml_1.safeStringify)(this.overlayedDefinition);
|
|
151
|
+
}
|
|
152
|
+
return serializedDefinition;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
return this.rawDefinition;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
138
158
|
static isOpenAPI(definition) {
|
|
139
159
|
return (typeof definition.openapi === 'string' || typeof definition.swagger === 'string');
|
|
140
160
|
}
|
|
@@ -144,7 +164,7 @@ class API {
|
|
|
144
164
|
static isOpenAPIOverlay(definition) {
|
|
145
165
|
return 'overlay' in definition;
|
|
146
166
|
}
|
|
147
|
-
extractDefinition() {
|
|
167
|
+
extractDefinition(outputPath) {
|
|
148
168
|
const references = [];
|
|
149
169
|
for (let i = 0; i < this.references.length; i++) {
|
|
150
170
|
const reference = this.references[i];
|
|
@@ -153,7 +173,15 @@ class API {
|
|
|
153
173
|
content: reference.content,
|
|
154
174
|
});
|
|
155
175
|
}
|
|
156
|
-
return [this.
|
|
176
|
+
return [this.serializeDefinition(outputPath), references];
|
|
177
|
+
}
|
|
178
|
+
async applyOverlay(overlayPath) {
|
|
179
|
+
const overlay = await API.load(overlayPath);
|
|
180
|
+
const overlayDefinition = overlay.definition;
|
|
181
|
+
if (!API.isOpenAPIOverlay(overlayDefinition)) {
|
|
182
|
+
throw new Error(`${overlayPath} does not look like an OpenAPI overlay`);
|
|
183
|
+
}
|
|
184
|
+
this.overlayedDefinition = await new overlay_1.Overlay().run(this.definition, overlayDefinition);
|
|
157
185
|
}
|
|
158
186
|
static async load(path) {
|
|
159
187
|
const JSONParser = options_1.defaults.parse.json;
|
package/lib/flags.d.ts
CHANGED
|
@@ -15,4 +15,6 @@ declare const failOnBreaking: (options?: {}) => Parser.flags.IBooleanFlag<boolea
|
|
|
15
15
|
declare const live: (options?: {}) => Parser.flags.IBooleanFlag<boolean>;
|
|
16
16
|
declare const format: flags.Definition<string>;
|
|
17
17
|
declare const expires: flags.Definition<string>;
|
|
18
|
-
|
|
18
|
+
declare const out: flags.Definition<string>;
|
|
19
|
+
declare const overlay: flags.Definition<string>;
|
|
20
|
+
export { doc, docName, hub, branch, token, autoCreate, interactive, filenamePattern, dryRun, open, failOnBreaking, live, format, expires, out, overlay, };
|
package/lib/flags.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.expires = exports.format = exports.live = exports.failOnBreaking = exports.open = exports.dryRun = exports.filenamePattern = exports.interactive = exports.autoCreate = exports.token = exports.branch = exports.hub = exports.docName = exports.doc = void 0;
|
|
3
|
+
exports.overlay = exports.out = exports.expires = exports.format = exports.live = exports.failOnBreaking = exports.open = exports.dryRun = exports.filenamePattern = exports.interactive = exports.autoCreate = exports.token = exports.branch = exports.hub = exports.docName = exports.doc = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const command_1 = require("@oclif/command");
|
|
6
6
|
// Re-export oclif flags https://oclif.io/docs/flags
|
|
@@ -104,3 +104,13 @@ const expires = command_1.flags.build({
|
|
|
104
104
|
description: "Specify a longer expiration date for public diffs (defaults to 1 day). Use iso8601 format to provide a date, or you can use `--expires 'never'` to keep the result live indefinitely.",
|
|
105
105
|
});
|
|
106
106
|
exports.expires = expires;
|
|
107
|
+
const out = command_1.flags.build({
|
|
108
|
+
char: 'o',
|
|
109
|
+
description: 'Output file path',
|
|
110
|
+
});
|
|
111
|
+
exports.out = out;
|
|
112
|
+
const overlay = command_1.flags.build({
|
|
113
|
+
char: 'o',
|
|
114
|
+
description: 'Path or URL of an overlay file to apply before deploying',
|
|
115
|
+
});
|
|
116
|
+
exports.overlay = overlay;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { run } from '@oclif/command';
|
|
2
2
|
import { Diff } from './core/diff';
|
|
3
|
+
import { Overlay } from './core/overlay';
|
|
3
4
|
import Deploy from './commands/deploy';
|
|
4
5
|
import Preview from './commands/preview';
|
|
5
|
-
import Overlay from './commands/overlay';
|
|
6
6
|
export { VersionResponse, PreviewResponse, DiffResponse, WithDiff } from './api/models';
|
|
7
7
|
export { run, Deploy, Diff, Preview, Overlay };
|
package/lib/index.js
CHANGED
|
@@ -6,9 +6,9 @@ const command_1 = require("@oclif/command");
|
|
|
6
6
|
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return command_1.run; } });
|
|
7
7
|
const diff_1 = require("./core/diff");
|
|
8
8
|
Object.defineProperty(exports, "Diff", { enumerable: true, get: function () { return diff_1.Diff; } });
|
|
9
|
+
const overlay_1 = require("./core/overlay");
|
|
10
|
+
Object.defineProperty(exports, "Overlay", { enumerable: true, get: function () { return overlay_1.Overlay; } });
|
|
9
11
|
const deploy_1 = (0, tslib_1.__importDefault)(require("./commands/deploy"));
|
|
10
12
|
exports.Deploy = deploy_1.default;
|
|
11
13
|
const preview_1 = (0, tslib_1.__importDefault)(require("./commands/preview"));
|
|
12
14
|
exports.Preview = preview_1.default;
|
|
13
|
-
const overlay_1 = (0, tslib_1.__importDefault)(require("./commands/overlay"));
|
|
14
|
-
exports.Overlay = overlay_1.default;
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.
|
|
1
|
+
{"version":"2.8.0","commands":{"deploy":{"id":"deploy","description":"Create a new version of your documentation from the given file or URL.","pluginName":"bump-cli","pluginType":"core","aliases":[],"examples":["Deploy a new version of an existing documentation\n\n$ bump deploy FILE --doc <your_doc_id_or_slug> --token <your_doc_token>\n* Let's deploy a new documentation version on Bump... done\n* Your new documentation version will soon be ready\n","Deploy a new version of an existing documentation attached to a hub\n\n$ bump deploy FILE --doc <doc_slug> --hub <your_hub_id_or_slug> --token <your_doc_token>\n* Let's deploy a new documentation version on Bump... done\n* Your new documentation version will soon be ready\n","Deploy a whole directory of API definitions files to a hub\n\n$ bump deploy DIR --filename-pattern *-{slug}-api --hub <hub_slug> --token <hub_token>\nWe've found 2 valid API definitions to deploy\n└─ DIR\n └─ source-my-service-api.yml (OpenAPI spec version 3.1.0)\n └─ source-my-jobs-service-api.yml (AsyncAPI spec version 2.6.0)\n\nLet's deploy those documentations to your <hub_slug> hub on Bump.sh\n\n* Your new documentation version will soon be ready\nLet's deploy a new version to your my-service documentation on Bump.sh... done\n\n* Your new documentation version will soon be ready\nLet's deploy a new version to your my-jobs-service documentation on Bump.sh... done\n","Validate a new documentation version before deploying it\n\n$ bump deploy FILE --dry-run --doc <doc_slug> --token <your_doc_token>\n* Let's validate a new documentation version on Bump... done\n* Definition is valid\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"doc":{"name":"doc","type":"option","char":"d","description":"Documentation public id or slug. Can be provided via BUMP_ID environment variable"},"doc-name":{"name":"doc-name","type":"option","char":"n","description":"Documentation name. Used with --auto-create flag."},"hub":{"name":"hub","type":"option","char":"b","description":"Hub id or slug. Can be provided via BUMP_HUB_ID environment variable"},"branch":{"name":"branch","type":"option","char":"B","description":"Branch name. Can be provided via BUMP_BRANCH_NAME environment variable"},"token":{"name":"token","type":"option","char":"t","description":"Documentation or Hub token. Can be provided via BUMP_TOKEN environment variable","required":true},"auto-create":{"name":"auto-create","type":"boolean","description":"Automatically create the documentation if needed (only available with a --hub flag). Documentation name can be provided with --doc-name flag. Default: false","allowNo":false},"interactive":{"name":"interactive","type":"boolean","description":"Interactively create a configuration file to deploy a Hub (only available with a --hub flag). This will start an interactive process if you don't have a CLI configuration file. Default: false","allowNo":false},"filename-pattern":{"name":"filename-pattern","type":"option","description":"Pattern to extract the documentation slug from filenames when deploying a DIRECTORY. Pattern uses only '*' and '{slug}' as special characters to extract the slug from a filename without extension. Used with --hub flag only.","default":"{slug}-api"},"dry-run":{"name":"dry-run","type":"boolean","description":"Validate a new documentation version. Does everything a normal deploy would do except publishing the new version. Useful in automated environments such as test platforms or continuous integration. Default: false","allowNo":false},"overlay":{"name":"overlay","type":"option","char":"o","description":"Path or URL of an overlay file to apply before deploying"}},"args":[{"name":"FILE","description":"Path or URL to your API documentation file. OpenAPI (2.0 to 3.1.0) and AsyncAPI (2.x) specifications are currently supported.\nPath can also be a directory when deploying to a Hub.","required":true}]},"diff":{"id":"diff","description":"Get a comparison diff with your documentation from the given file or URL.","pluginName":"bump-cli","pluginType":"core","aliases":[],"examples":["Compare a potential new version with the currently published one:\n\n $ bump diff FILE --doc <your_doc_id_or_slug> --token <your_doc_token>\n * Comparing the given definition file with the currently deployed one... done\n Removed: GET /compare\n Added: GET /versions/{versionId}\n","Store the diff in a dedicated file:\n\n $ bump diff FILE --doc <doc_slug> --token <doc_token> > /tmp/my-saved-diff\n * Comparing the given definition file with the currently deployed one... done\n\n $ cat /tmp/my-saved-diff\n Removed: GET /compare\n Added: GET /versions/{versionId}\n","In case of a non modified definition FILE compared to your existing documentation, no changes are output:\n\n $ bump diff FILE --doc <doc_slug> --token <your_doc_token>\n * Comparing the given definition file with the currently deployed one... done\n › Warning: Your documentation has not changed\n","Compare two different input files or URL independently to the one published on bump.sh\n\n $ bump diff FILE FILE2 --doc <doc_slug> --token <your_doc_token>\n * Comparing the two given definition files... done\n Updated: POST /versions\n Body attribute added: previous_version_id\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"doc":{"name":"doc","type":"option","char":"d","description":"Documentation public id or slug. Can be provided via BUMP_ID environment variable"},"hub":{"name":"hub","type":"option","char":"b","description":"Hub id or slug. Can be provided via BUMP_HUB_ID environment variable"},"branch":{"name":"branch","type":"option","char":"B","description":"Branch name. Can be provided via BUMP_BRANCH_NAME environment variable"},"token":{"name":"token","type":"option","char":"t","description":"Documentation or Hub token. Can be provided via BUMP_TOKEN environment variable","required":false},"open":{"name":"open","type":"boolean","char":"o","description":"Open the visual diff in your browser","allowNo":false},"fail-on-breaking":{"name":"fail-on-breaking","type":"boolean","char":"F","description":"Fail when diff contains a breaking change","allowNo":false},"format":{"name":"format","type":"option","char":"f","description":"Format in which to provide the diff result","options":["text","markdown","json","html"],"default":"text"},"expires":{"name":"expires","type":"option","char":"e","description":"Specify a longer expiration date for public diffs (defaults to 1 day). Use iso8601 format to provide a date, or you can use `--expires 'never'` to keep the result live indefinitely."}},"args":[{"name":"FILE","description":"Path or URL to your API documentation file. OpenAPI (2.0 to 3.1.0) and AsyncAPI (2.x) specifications are currently supported.\nPath can also be a directory when deploying to a Hub.","required":true},{"name":"FILE2","description":"Path or URL to a second API documentation file to compute its diff"}]},"overlay":{"id":"overlay","description":"Apply an OpenAPI specified overlay to your API definition.","pluginName":"bump-cli","pluginType":"core","aliases":[],"examples":["Apply the OVERLAY_FILE to the existing DEFINITION_FILE. The resulting\ndefinition is output on stdout meaning you can redirect it to a new\nfile.\n\n$ bump overlay DEFINITION_FILE OVERLAY_FILE > destination/file.json\n* Let's apply the overlay to the main definition... done\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"out":{"name":"out","type":"option","char":"o","description":"Output file path"}},"args":[{"name":"FILE","description":"Path or URL to your API documentation file. OpenAPI (2.0 to 3.1.0) and AsyncAPI (2.x) specifications are currently supported.\nPath can also be a directory when deploying to a Hub.","required":true},{"name":"OVERLAY_FILE","description":"Path or URL to an overlay file","required":true}]},"preview":{"id":"preview","description":"Create a documentation preview from the given file or URL.","pluginName":"bump-cli","pluginType":"core","aliases":[],"examples":["$ bump preview FILE\n* Your preview is visible at: https://bump.sh/preview/45807371-9a32-48a7-b6e4-1cb7088b5b9b\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"live":{"name":"live","type":"boolean","char":"l","description":"Generate a preview each time you save the given file","allowNo":false},"open":{"name":"open","type":"boolean","char":"o","description":"Open the generated preview URL in your browser","allowNo":false}},"args":[{"name":"FILE","description":"Path or URL to your API documentation file. OpenAPI (2.0 to 3.1.0) and AsyncAPI (2.x) specifications are currently supported.\nPath can also be a directory when deploying to a Hub.","required":true}]}}}
|
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 by using the API of developers.bump.sh",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.8.0",
|
|
5
5
|
"author": "Paul Bonaud <paulr@bump.sh>",
|
|
6
6
|
"bin": {
|
|
7
7
|
"bump": "./bin/run"
|