bump-cli 2.2.5 → 2.3.2-beta
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 +2 -2
- package/lib/api/index.d.ts +4 -2
- package/lib/api/index.js +6 -0
- package/lib/api/models.d.ts +26 -0
- package/lib/cli/index.d.ts +3 -3
- package/lib/command.d.ts +0 -5
- package/lib/command.js +0 -23
- package/lib/commands/deploy.js +4 -1
- package/lib/commands/diff.d.ts +4 -7
- package/lib/commands/diff.js +38 -72
- package/lib/commands/preview.js +4 -1
- package/lib/core/diff.d.ts +22 -0
- package/lib/core/diff.js +150 -0
- package/lib/definition.d.ts +2 -1
- package/lib/definition.js +12 -1
- package/lib/flags.d.ts +2 -1
- package/lib/flags.js +8 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +2 -2
- package/oclif.manifest.json +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -114,7 +114,7 @@ From a Bump documentation, the `diff` command will retrieve a comparaison change
|
|
|
114
114
|
|
|
115
115
|
```sh-session
|
|
116
116
|
$ bump diff path/to/your/file.yml --doc DOC_ID_OR_SLUG --token DOC_TOKEN
|
|
117
|
-
*
|
|
117
|
+
* Comparing the given definition file with the currently deployed one... done
|
|
118
118
|
|
|
119
119
|
Updated: POST /validations
|
|
120
120
|
Body attribute modified: documentation
|
|
@@ -124,7 +124,7 @@ If you want to compare two unpublished versions of your definition file, the `di
|
|
|
124
124
|
|
|
125
125
|
```sh-session
|
|
126
126
|
$ bump diff path/to/your/file.yml path/to/your/next-file.yml --doc <doc_slug> --token <your_doc_token>
|
|
127
|
-
*
|
|
127
|
+
* Comparing the two given definition files... done
|
|
128
128
|
|
|
129
129
|
Updated: POST /versions
|
|
130
130
|
Body attribute added: previous_version_id
|
package/lib/api/index.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import * as Config from '@oclif/config';
|
|
2
2
|
import { AxiosInstance, AxiosResponse } from 'axios';
|
|
3
|
-
import { PingResponse, PreviewRequest, PreviewResponse, VersionRequest, VersionResponse } from './models';
|
|
3
|
+
import { PingResponse, PreviewRequest, PreviewResponse, VersionRequest, VersionResponse, DiffRequest, DiffResponse, WithDiff } from './models';
|
|
4
4
|
import APIError from './error';
|
|
5
5
|
declare class BumpApi {
|
|
6
6
|
protected config: Config.IConfig;
|
|
7
7
|
protected readonly client: AxiosInstance;
|
|
8
8
|
constructor(config: Config.IConfig);
|
|
9
9
|
getPing: () => Promise<AxiosResponse<PingResponse>>;
|
|
10
|
-
getVersion: (versionId: string, token: string) => Promise<AxiosResponse<VersionResponse>>;
|
|
10
|
+
getVersion: (versionId: string, token: string) => Promise<AxiosResponse<VersionResponse & WithDiff>>;
|
|
11
11
|
postPreview: (body?: PreviewRequest | undefined) => Promise<AxiosResponse<PreviewResponse>>;
|
|
12
12
|
putPreview: (versionId: string, body?: PreviewRequest | undefined) => Promise<AxiosResponse<PreviewResponse>>;
|
|
13
13
|
postVersion: (body: VersionRequest, token: string) => Promise<AxiosResponse<VersionResponse>>;
|
|
14
|
+
postDiff: (body: DiffRequest) => Promise<AxiosResponse<DiffResponse>>;
|
|
15
|
+
getDiff: (diffId: string) => Promise<AxiosResponse<DiffResponse>>;
|
|
14
16
|
postValidation: (body: VersionRequest, token: string) => Promise<AxiosResponse<void>>;
|
|
15
17
|
private initializeResponseInterceptor;
|
|
16
18
|
private handleError;
|
package/lib/api/index.js
CHANGED
|
@@ -29,6 +29,12 @@ class BumpApi {
|
|
|
29
29
|
headers: this.authorizationHeader(token),
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
|
+
this.postDiff = (body) => {
|
|
33
|
+
return this.client.post('/diffs', body);
|
|
34
|
+
};
|
|
35
|
+
this.getDiff = (diffId) => {
|
|
36
|
+
return this.client.get(`/diffs/${diffId}`);
|
|
37
|
+
};
|
|
32
38
|
this.postValidation = (body, token) => {
|
|
33
39
|
return this.client.post('/validations', body, {
|
|
34
40
|
headers: this.authorizationHeader(token),
|
package/lib/api/models.d.ts
CHANGED
|
@@ -33,7 +33,33 @@ export interface VersionRequest {
|
|
|
33
33
|
export interface VersionResponse {
|
|
34
34
|
id: string;
|
|
35
35
|
doc_public_url?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface WithDiff {
|
|
36
38
|
diff_public_url?: string;
|
|
37
39
|
diff_summary?: string;
|
|
40
|
+
diff_markdown?: string;
|
|
41
|
+
diff_details?: DiffItem[];
|
|
38
42
|
diff_breaking?: boolean;
|
|
39
43
|
}
|
|
44
|
+
export interface DiffRequest {
|
|
45
|
+
definition: string;
|
|
46
|
+
references?: Reference[];
|
|
47
|
+
previous_definition: string;
|
|
48
|
+
previous_references?: Reference[];
|
|
49
|
+
}
|
|
50
|
+
export interface DiffResponse {
|
|
51
|
+
id: string;
|
|
52
|
+
public_url?: string;
|
|
53
|
+
text?: string;
|
|
54
|
+
markdown?: string;
|
|
55
|
+
details?: DiffItem[];
|
|
56
|
+
breaking?: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface DiffItem {
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
status: string;
|
|
62
|
+
type: string;
|
|
63
|
+
breaking: boolean;
|
|
64
|
+
children: DiffItem[];
|
|
65
|
+
}
|
package/lib/cli/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import success from './styled/success';
|
|
|
2
2
|
declare const cli: {
|
|
3
3
|
styledSuccess: typeof success;
|
|
4
4
|
config: import("cli-ux").Config;
|
|
5
|
-
warn: typeof import("@oclif/errors").warn;
|
|
6
|
-
error: typeof import("@oclif/errors").error;
|
|
7
|
-
exit: typeof import("@oclif/errors").exit;
|
|
5
|
+
warn: typeof import("@oclif/core/lib/errors").warn;
|
|
6
|
+
error: typeof import("@oclif/core/lib/errors").error;
|
|
7
|
+
exit: typeof import("@oclif/core/lib/errors").exit;
|
|
8
8
|
prompt: typeof import("cli-ux/lib/prompt").prompt;
|
|
9
9
|
anykey: typeof import("cli-ux/lib/prompt").anykey;
|
|
10
10
|
confirm: typeof import("cli-ux/lib/prompt").confirm;
|
package/lib/command.d.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { Command as Base } from '@oclif/command';
|
|
2
2
|
import { BumpApi } from './api';
|
|
3
|
-
import { Reference } from './api/models';
|
|
4
3
|
export default abstract class Command extends Base {
|
|
5
4
|
private base;
|
|
6
5
|
_bump: BumpApi;
|
|
7
|
-
get pollingPeriod(): number;
|
|
8
6
|
get bump(): BumpApi;
|
|
9
7
|
catch(error?: Error): Promise<void>;
|
|
10
8
|
d(formatter: any, ...args: any[]): void;
|
|
11
|
-
pollingDelay(): Promise<void>;
|
|
12
|
-
private delay;
|
|
13
|
-
prepareDefinition(filepath: string): Promise<[string, Reference[]]>;
|
|
14
9
|
}
|
package/lib/command.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const command_1 = require("@oclif/command");
|
|
5
5
|
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
6
|
-
const definition_1 = require("./definition");
|
|
7
6
|
const api_1 = require("./api");
|
|
8
7
|
const package_json_1 = (0, tslib_1.__importDefault)(require("../package.json"));
|
|
9
8
|
class Command extends command_1.Command {
|
|
@@ -11,9 +10,6 @@ class Command extends command_1.Command {
|
|
|
11
10
|
super(...arguments);
|
|
12
11
|
this.base = `${package_json_1.default.name}@${package_json_1.default.version}`;
|
|
13
12
|
}
|
|
14
|
-
get pollingPeriod() {
|
|
15
|
-
return 1000;
|
|
16
|
-
}
|
|
17
13
|
get bump() {
|
|
18
14
|
if (!this._bump)
|
|
19
15
|
this._bump = new api_1.BumpApi(this.config);
|
|
@@ -31,24 +27,5 @@ class Command extends command_1.Command {
|
|
|
31
27
|
d(formatter, ...args) {
|
|
32
28
|
return (0, debug_1.default)(`bump-cli:command:${this.constructor.name.toLowerCase()}`)(formatter, ...args);
|
|
33
29
|
}
|
|
34
|
-
async pollingDelay() {
|
|
35
|
-
return await this.delay(this.pollingPeriod);
|
|
36
|
-
}
|
|
37
|
-
async delay(ms) {
|
|
38
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
39
|
-
}
|
|
40
|
-
async prepareDefinition(filepath) {
|
|
41
|
-
const api = await definition_1.API.loadAPI(filepath);
|
|
42
|
-
const references = [];
|
|
43
|
-
this.d(`${filepath} looks like an ${api.specName} spec version ${api.version}`);
|
|
44
|
-
for (let i = 0; i < api.references.length; i++) {
|
|
45
|
-
const reference = api.references[i];
|
|
46
|
-
references.push({
|
|
47
|
-
location: reference.location,
|
|
48
|
-
content: reference.content,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return [api.rawDefinition, references];
|
|
52
|
-
}
|
|
53
30
|
}
|
|
54
31
|
exports.default = Command;
|
package/lib/commands/deploy.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
const definition_1 = require("../definition");
|
|
4
5
|
const command_1 = (0, tslib_1.__importDefault)(require("../command"));
|
|
5
6
|
const flags = (0, tslib_1.__importStar)(require("../flags"));
|
|
6
7
|
const args_1 = require("../args");
|
|
@@ -14,10 +15,12 @@ class Deploy extends command_1.default {
|
|
|
14
15
|
*/
|
|
15
16
|
async run() {
|
|
16
17
|
const { args, flags } = this.parse(Deploy);
|
|
17
|
-
const
|
|
18
|
+
const api = await definition_1.API.load(args.FILE);
|
|
19
|
+
const [definition, references] = api.extractDefinition();
|
|
18
20
|
const action = flags['dry-run'] ? 'validate' : 'deploy';
|
|
19
21
|
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
|
|
20
22
|
const [documentation, token] = [flags.doc, flags.token];
|
|
23
|
+
this.d(`${args.FILE} looks like an ${api.specName} spec version ${api.version}`);
|
|
21
24
|
cli_1.cli.action.start(`* Let's ${action} a new documentation version on Bump`);
|
|
22
25
|
const request = {
|
|
23
26
|
documentation,
|
package/lib/commands/diff.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Command from '../command';
|
|
2
2
|
import * as flags from '../flags';
|
|
3
|
-
import {
|
|
3
|
+
import { DiffResponse } from '../api/models';
|
|
4
4
|
export default class Diff extends Command {
|
|
5
5
|
static description: string;
|
|
6
6
|
static examples: string[];
|
|
@@ -10,15 +10,12 @@ export default class Diff extends Command {
|
|
|
10
10
|
hub: flags.IOptionFlag<string | undefined>;
|
|
11
11
|
token: flags.IOptionFlag<string | undefined>;
|
|
12
12
|
open: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
13
|
+
format: flags.IOptionFlag<string | undefined>;
|
|
13
14
|
};
|
|
14
15
|
static args: {
|
|
15
16
|
name: string;
|
|
16
17
|
description: string;
|
|
17
18
|
}[];
|
|
18
|
-
run(): Promise<
|
|
19
|
-
|
|
20
|
-
displayCompareResult(result: VersionResponse, token: string, open: boolean): Promise<void>;
|
|
21
|
-
waitChangesResult(versionId: string, token: string, opts: {
|
|
22
|
-
timeout: number;
|
|
23
|
-
}): Promise<VersionResponse>;
|
|
19
|
+
run(): Promise<void>;
|
|
20
|
+
displayCompareResult(result: DiffResponse, format: string, open: boolean): Promise<void>;
|
|
24
21
|
}
|
package/lib/commands/diff.js
CHANGED
|
@@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const errors_1 = require("@oclif/errors");
|
|
5
5
|
const command_1 = (0, tslib_1.__importDefault)(require("../command"));
|
|
6
6
|
const flags = (0, tslib_1.__importStar)(require("../flags"));
|
|
7
|
+
const diff_1 = require("../core/diff");
|
|
7
8
|
const args_1 = require("../args");
|
|
8
9
|
const cli_1 = require("../cli");
|
|
9
10
|
class Diff extends command_1.default {
|
|
@@ -15,83 +16,47 @@ class Diff extends command_1.default {
|
|
|
15
16
|
*/
|
|
16
17
|
async run() {
|
|
17
18
|
const { args, flags } = this.parse(Diff);
|
|
18
|
-
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
|
|
19
19
|
const [documentation, hub, token] = [flags.doc, flags.hub, flags.token];
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let diffVersion = undefined;
|
|
28
|
-
if (args.FILE2) {
|
|
29
|
-
diffVersion = await this.createVersion(args.FILE2, documentation, token, hub, version && version.id);
|
|
20
|
+
if (flags.format == 'text') {
|
|
21
|
+
if (args.FILE2) {
|
|
22
|
+
cli_1.cli.action.start('* Comparing the two given definition files');
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
cli_1.cli.action.start('* Comparing the given definition file with the currently deployed one');
|
|
26
|
+
}
|
|
30
27
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
diffVersion = await this.waitChangesResult(diffVersion.id, token, {
|
|
34
|
-
timeout: 30,
|
|
35
|
-
});
|
|
36
|
-
await this.displayCompareResult(diffVersion, token, flags.open);
|
|
28
|
+
if (!args.FILE2 && (!documentation || !token)) {
|
|
29
|
+
throw new errors_1.CLIError('Please provide a second file argument or login with an existing token');
|
|
37
30
|
}
|
|
31
|
+
const diff = await new diff_1.Diff(this.config).run(args.FILE, args.FILE2, documentation, hub, token);
|
|
38
32
|
cli_1.cli.action.stop();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
references,
|
|
48
|
-
unpublished: true,
|
|
49
|
-
previous_version_id,
|
|
50
|
-
};
|
|
51
|
-
const response = await this.bump.postVersion(request, token);
|
|
52
|
-
switch (response.status) {
|
|
53
|
-
case 201:
|
|
54
|
-
this.d(`Unpublished version created with ID ${response.data.id}`);
|
|
55
|
-
return response.data;
|
|
56
|
-
break;
|
|
57
|
-
case 204:
|
|
58
|
-
this.warn('Your documentation has not changed');
|
|
59
|
-
break;
|
|
33
|
+
if (diff) {
|
|
34
|
+
/* Flags format has a default value, so it's always defined. But
|
|
35
|
+
* oclif types can"t detect it */
|
|
36
|
+
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
|
|
37
|
+
await this.displayCompareResult(diff, flags.format, flags.open);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
await cli_1.cli.log('No changes detected.');
|
|
60
41
|
}
|
|
61
42
|
return;
|
|
62
43
|
}
|
|
63
|
-
async displayCompareResult(result,
|
|
64
|
-
if (
|
|
65
|
-
await cli_1.cli.log(result.
|
|
66
|
-
if (open && result.diff_public_url) {
|
|
67
|
-
await cli_1.cli.open(result.diff_public_url);
|
|
68
|
-
}
|
|
44
|
+
async displayCompareResult(result, format, open) {
|
|
45
|
+
if (format == 'text' && result.text) {
|
|
46
|
+
await cli_1.cli.log(result.text);
|
|
69
47
|
}
|
|
70
|
-
else {
|
|
71
|
-
|
|
48
|
+
else if (format == 'markdown' && result.markdown) {
|
|
49
|
+
await cli_1.cli.log(result.markdown);
|
|
72
50
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
51
|
+
else if (format == 'json' && result.details) {
|
|
52
|
+
await cli_1.cli.log(JSON.stringify(result.details, null, 2));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
await cli_1.cli.log('No structural changes detected.');
|
|
78
56
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const version = diffResponse.data;
|
|
82
|
-
this.d(`Received version:`);
|
|
83
|
-
this.d(version);
|
|
84
|
-
return version;
|
|
85
|
-
break;
|
|
86
|
-
case 202:
|
|
87
|
-
this.d('Waiting 1 sec before next pool');
|
|
88
|
-
await this.pollingDelay();
|
|
89
|
-
return await this.waitChangesResult(versionId, token, {
|
|
90
|
-
timeout: opts.timeout - 1,
|
|
91
|
-
});
|
|
92
|
-
break;
|
|
57
|
+
if (open && result.public_url) {
|
|
58
|
+
await cli_1.cli.open(result.public_url);
|
|
93
59
|
}
|
|
94
|
-
return {};
|
|
95
60
|
}
|
|
96
61
|
}
|
|
97
62
|
exports.default = Diff;
|
|
@@ -100,14 +65,14 @@ Diff.examples = [
|
|
|
100
65
|
`Compare a potential new version with the currently published one:
|
|
101
66
|
|
|
102
67
|
$ bump diff FILE --doc <your_doc_id_or_slug> --token <your_doc_token>
|
|
103
|
-
*
|
|
68
|
+
* Comparing the given definition file with the currently deployed one... done
|
|
104
69
|
Removed: GET /compare
|
|
105
70
|
Added: GET /versions/{versionId}
|
|
106
71
|
`,
|
|
107
72
|
`Store the diff in a dedicated file:
|
|
108
73
|
|
|
109
74
|
$ bump diff FILE --doc <doc_slug> --token <doc_token> > /tmp/my-saved-diff
|
|
110
|
-
*
|
|
75
|
+
* Comparing the given definition file with the currently deployed one... done
|
|
111
76
|
|
|
112
77
|
$ cat /tmp/my-saved-diff
|
|
113
78
|
Removed: GET /compare
|
|
@@ -116,22 +81,23 @@ Diff.examples = [
|
|
|
116
81
|
`In case of a non modified definition FILE compared to your existing documentation, no changes are output:
|
|
117
82
|
|
|
118
83
|
$ bump diff FILE --doc <doc_slug> --token <your_doc_token>
|
|
119
|
-
*
|
|
84
|
+
* Comparing the given definition file with the currently deployed one... done
|
|
120
85
|
› Warning: Your documentation has not changed
|
|
121
86
|
`,
|
|
122
87
|
`Compare two different input files or URL independently to the one published on bump.sh
|
|
123
88
|
|
|
124
89
|
$ bump diff FILE FILE2 --doc <doc_slug> --token <your_doc_token>
|
|
125
|
-
*
|
|
90
|
+
* Comparing the two given definition files... done
|
|
126
91
|
Updated: POST /versions
|
|
127
92
|
Body attribute added: previous_version_id
|
|
128
93
|
`,
|
|
129
94
|
];
|
|
130
95
|
Diff.flags = {
|
|
131
96
|
help: flags.help({ char: 'h' }),
|
|
132
|
-
doc: flags.doc(),
|
|
97
|
+
doc: flags.doc({ required: false }),
|
|
133
98
|
hub: flags.hub(),
|
|
134
|
-
token: flags.token(),
|
|
99
|
+
token: flags.token({ required: false }),
|
|
135
100
|
open: flags.open({ description: 'Open the visual diff in your browser' }),
|
|
101
|
+
format: flags.format(),
|
|
136
102
|
};
|
|
137
103
|
Diff.args = [args_1.fileArg, args_1.otherFileArg];
|
package/lib/commands/preview.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
const definition_1 = require("../definition");
|
|
4
5
|
const command_1 = (0, tslib_1.__importDefault)(require("../command"));
|
|
5
6
|
const flags = (0, tslib_1.__importStar)(require("../flags"));
|
|
6
7
|
const args_1 = require("../args");
|
|
@@ -19,7 +20,9 @@ class Preview extends command_1.default {
|
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
22
|
async preview(file, open = false, currentPreview = undefined) {
|
|
22
|
-
const
|
|
23
|
+
const api = await definition_1.API.load(file);
|
|
24
|
+
const [definition, references] = api.extractDefinition();
|
|
25
|
+
this.d(`${file} looks like an ${api.specName} spec version ${api.version}`);
|
|
23
26
|
if (!currentPreview) {
|
|
24
27
|
cli_1.cli.action.start("* Let's render a preview on Bump");
|
|
25
28
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as Config from '@oclif/config';
|
|
2
|
+
import { BumpApi } from '../api';
|
|
3
|
+
import { VersionResponse, WithDiff, DiffResponse } from '../api/models';
|
|
4
|
+
export declare class Diff {
|
|
5
|
+
_bump: BumpApi;
|
|
6
|
+
_config: Config.IConfig;
|
|
7
|
+
constructor(config: Config.IConfig);
|
|
8
|
+
run(file1: string, file2: string | undefined, documentation: string | undefined, hub: string | undefined, token: string | undefined): Promise<DiffResponse | undefined>;
|
|
9
|
+
get bumpClient(): BumpApi;
|
|
10
|
+
get pollingPeriod(): number;
|
|
11
|
+
createDiff(file1: string, file2: string): Promise<DiffResponse | undefined>;
|
|
12
|
+
createVersion(file: string, documentation: string, token: string, hub: string | undefined, previous_version_id?: string | undefined): Promise<VersionResponse | undefined>;
|
|
13
|
+
waitResult(result: VersionResponse | DiffResponse, token: string | undefined, opts: {
|
|
14
|
+
timeout: number;
|
|
15
|
+
}): Promise<DiffResponse>;
|
|
16
|
+
pollingDelay(): Promise<void>;
|
|
17
|
+
private delay;
|
|
18
|
+
d(formatter: any, ...args: any[]): void;
|
|
19
|
+
isVersion(result: VersionResponse | DiffResponse): result is VersionResponse;
|
|
20
|
+
isVersionWithDiff(result: (VersionResponse & WithDiff) | DiffResponse): result is VersionResponse & WithDiff;
|
|
21
|
+
extractDiff(versionWithDiff: VersionResponse & WithDiff): DiffResponse;
|
|
22
|
+
}
|
package/lib/core/diff.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Diff = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const errors_1 = require("@oclif/errors");
|
|
6
|
+
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
7
|
+
const definition_1 = require("../definition");
|
|
8
|
+
const api_1 = require("../api");
|
|
9
|
+
class Diff {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this._config = config;
|
|
12
|
+
}
|
|
13
|
+
async run(file1, file2, documentation, hub, token) {
|
|
14
|
+
let diffVersion = undefined;
|
|
15
|
+
if (file2 && (!documentation || !token)) {
|
|
16
|
+
diffVersion = await this.createDiff(file1, file2);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
if (!documentation || !token) {
|
|
20
|
+
throw new Error('Please login to bump (with documentation & token) when using a single file argument');
|
|
21
|
+
}
|
|
22
|
+
diffVersion = await this.createVersion(file1, documentation, token, hub);
|
|
23
|
+
if (file2) {
|
|
24
|
+
diffVersion = await this.createVersion(file2, documentation, token, hub, diffVersion && diffVersion.id);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (diffVersion) {
|
|
28
|
+
return await this.waitResult(diffVersion, token, {
|
|
29
|
+
timeout: 30,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
get bumpClient() {
|
|
37
|
+
if (!this._bump)
|
|
38
|
+
this._bump = new api_1.BumpApi(this._config);
|
|
39
|
+
return this._bump;
|
|
40
|
+
}
|
|
41
|
+
get pollingPeriod() {
|
|
42
|
+
return 1000;
|
|
43
|
+
}
|
|
44
|
+
async createDiff(file1, file2) {
|
|
45
|
+
const api = await definition_1.API.load(file1);
|
|
46
|
+
const [previous_definition, previous_references] = api.extractDefinition();
|
|
47
|
+
const api2 = await definition_1.API.load(file2);
|
|
48
|
+
const [definition, references] = api2.extractDefinition();
|
|
49
|
+
const request = {
|
|
50
|
+
previous_definition,
|
|
51
|
+
previous_references,
|
|
52
|
+
definition,
|
|
53
|
+
references,
|
|
54
|
+
};
|
|
55
|
+
const response = await this.bumpClient.postDiff(request);
|
|
56
|
+
switch (response.status) {
|
|
57
|
+
case 201:
|
|
58
|
+
this.d(`Diff created with ID ${response.data.id}`);
|
|
59
|
+
this.d(response.data);
|
|
60
|
+
return response.data;
|
|
61
|
+
break;
|
|
62
|
+
case 204:
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
async createVersion(file, documentation, token, hub, previous_version_id = undefined) {
|
|
68
|
+
const api = await definition_1.API.load(file);
|
|
69
|
+
const [definition, references] = api.extractDefinition();
|
|
70
|
+
const request = {
|
|
71
|
+
documentation,
|
|
72
|
+
hub,
|
|
73
|
+
definition,
|
|
74
|
+
references,
|
|
75
|
+
unpublished: true,
|
|
76
|
+
previous_version_id,
|
|
77
|
+
};
|
|
78
|
+
const response = await this.bumpClient.postVersion(request, token);
|
|
79
|
+
switch (response.status) {
|
|
80
|
+
case 201:
|
|
81
|
+
this.d(`Unpublished version created with ID ${response.data.id}`);
|
|
82
|
+
return response.data;
|
|
83
|
+
break;
|
|
84
|
+
case 204:
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
async waitResult(result, token, opts) {
|
|
90
|
+
let pollingResponse = undefined;
|
|
91
|
+
if (this.isVersion(result) && token) {
|
|
92
|
+
pollingResponse = await this.bumpClient.getVersion(result.id, token);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
pollingResponse = await this.bumpClient.getDiff(result.id);
|
|
96
|
+
}
|
|
97
|
+
if (opts.timeout <= 0) {
|
|
98
|
+
throw new errors_1.CLIError('We were unable to compute your documentation diff. Sorry about that. Please try again later');
|
|
99
|
+
}
|
|
100
|
+
switch (pollingResponse.status) {
|
|
101
|
+
case 200:
|
|
102
|
+
let diff = pollingResponse.data;
|
|
103
|
+
if (this.isVersionWithDiff(diff)) {
|
|
104
|
+
diff = this.extractDiff(diff);
|
|
105
|
+
}
|
|
106
|
+
this.d('Received diff:');
|
|
107
|
+
this.d(diff);
|
|
108
|
+
return diff;
|
|
109
|
+
break;
|
|
110
|
+
case 202:
|
|
111
|
+
this.d('Waiting 1 sec before next poll');
|
|
112
|
+
await this.pollingDelay();
|
|
113
|
+
return await this.waitResult(result, token, {
|
|
114
|
+
timeout: opts.timeout - 1,
|
|
115
|
+
});
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
return {};
|
|
119
|
+
}
|
|
120
|
+
async pollingDelay() {
|
|
121
|
+
return await this.delay(this.pollingPeriod);
|
|
122
|
+
}
|
|
123
|
+
async delay(ms) {
|
|
124
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
125
|
+
}
|
|
126
|
+
// Function signature type taken from @types/debug
|
|
127
|
+
// Debugger(formatter: any, ...args: any[]): void;
|
|
128
|
+
/* eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any */
|
|
129
|
+
d(formatter, ...args) {
|
|
130
|
+
return (0, debug_1.default)(`bump-cli:core:diff`)(formatter, ...args);
|
|
131
|
+
}
|
|
132
|
+
isVersion(result) {
|
|
133
|
+
return result.doc_public_url !== undefined;
|
|
134
|
+
}
|
|
135
|
+
isVersionWithDiff(result) {
|
|
136
|
+
return result.diff_summary !== undefined;
|
|
137
|
+
}
|
|
138
|
+
extractDiff(versionWithDiff) {
|
|
139
|
+
// TODO: return a real diff_id in the GET /version API
|
|
140
|
+
return {
|
|
141
|
+
id: versionWithDiff.id,
|
|
142
|
+
public_url: versionWithDiff.diff_public_url,
|
|
143
|
+
text: versionWithDiff.diff_summary,
|
|
144
|
+
markdown: versionWithDiff.diff_markdown,
|
|
145
|
+
details: versionWithDiff.diff_details,
|
|
146
|
+
breaking: versionWithDiff.diff_breaking,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.Diff = Diff;
|
package/lib/definition.d.ts
CHANGED
|
@@ -17,7 +17,8 @@ declare class API {
|
|
|
17
17
|
resolveContent($refs: $RefParser.$Refs): [string, APIDefinition];
|
|
18
18
|
static isOpenAPI(definition: JSONSchema4Object | JSONSchema6Object): definition is OpenAPI;
|
|
19
19
|
static isAsyncAPI(definition: JSONSchema4Object | JSONSchema6Object): definition is AsyncAPI;
|
|
20
|
-
|
|
20
|
+
extractDefinition(): [string, APIReference[]];
|
|
21
|
+
static load(path: string): Promise<API>;
|
|
21
22
|
}
|
|
22
23
|
declare type APIReference = {
|
|
23
24
|
location: string;
|
package/lib/definition.js
CHANGED
|
@@ -129,7 +129,18 @@ class API {
|
|
|
129
129
|
static isAsyncAPI(definition) {
|
|
130
130
|
return 'asyncapi' in definition;
|
|
131
131
|
}
|
|
132
|
-
|
|
132
|
+
extractDefinition() {
|
|
133
|
+
const references = [];
|
|
134
|
+
for (let i = 0; i < this.references.length; i++) {
|
|
135
|
+
const reference = this.references[i];
|
|
136
|
+
references.push({
|
|
137
|
+
location: reference.location,
|
|
138
|
+
content: reference.content,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return [this.rawDefinition, references];
|
|
142
|
+
}
|
|
143
|
+
static async load(path) {
|
|
133
144
|
const JSONParser = options_1.defaults.parse.json;
|
|
134
145
|
const YAMLParser = options_1.defaults.parse.yaml;
|
|
135
146
|
const TextParser = options_1.defaults.parse.text;
|
package/lib/flags.d.ts
CHANGED
|
@@ -9,4 +9,5 @@ declare const autoCreate: (options?: {}) => Parser.flags.IBooleanFlag<boolean>;
|
|
|
9
9
|
declare const dryRun: (options?: {}) => Parser.flags.IBooleanFlag<boolean>;
|
|
10
10
|
declare const open: (options?: {}) => Parser.flags.IBooleanFlag<boolean>;
|
|
11
11
|
declare const live: (options?: {}) => Parser.flags.IBooleanFlag<boolean>;
|
|
12
|
-
|
|
12
|
+
declare const format: flags.Definition<string>;
|
|
13
|
+
export { doc, docName, hub, token, autoCreate, dryRun, open, live, format };
|
package/lib/flags.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.live = exports.open = exports.dryRun = exports.autoCreate = exports.token = exports.hub = exports.docName = exports.doc = void 0;
|
|
3
|
+
exports.format = exports.live = exports.open = exports.dryRun = exports.autoCreate = exports.token = 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
|
|
@@ -62,3 +62,10 @@ const live = (options = {}) => {
|
|
|
62
62
|
return command_1.flags.boolean(Object.assign({ char: 'l', default: false }, options));
|
|
63
63
|
};
|
|
64
64
|
exports.live = live;
|
|
65
|
+
const format = command_1.flags.build({
|
|
66
|
+
char: 'f',
|
|
67
|
+
description: 'Format in which to provide the diff result',
|
|
68
|
+
default: 'text',
|
|
69
|
+
options: ['text', 'markdown', 'json'],
|
|
70
|
+
});
|
|
71
|
+
exports.format = format;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { run } from '@oclif/command';
|
|
2
|
-
import Diff from './
|
|
2
|
+
import { Diff } from './core/diff';
|
|
3
3
|
import Deploy from './commands/deploy';
|
|
4
4
|
import Preview from './commands/preview';
|
|
5
|
-
|
|
6
|
-
export { run, Deploy, Diff, Preview
|
|
5
|
+
export { VersionResponse, PreviewResponse, DiffResponse, WithDiff } from './api/models';
|
|
6
|
+
export { run, Deploy, Diff, Preview };
|
package/lib/index.js
CHANGED
|
@@ -4,8 +4,8 @@ exports.Preview = exports.Diff = exports.Deploy = exports.run = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const command_1 = require("@oclif/command");
|
|
6
6
|
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return command_1.run; } });
|
|
7
|
-
const diff_1 =
|
|
8
|
-
exports
|
|
7
|
+
const diff_1 = require("./core/diff");
|
|
8
|
+
Object.defineProperty(exports, "Diff", { enumerable: true, get: function () { return diff_1.Diff; } });
|
|
9
9
|
const deploy_1 = (0, tslib_1.__importDefault)(require("./commands/deploy"));
|
|
10
10
|
exports.Deploy = deploy_1.default;
|
|
11
11
|
const preview_1 = (0, tslib_1.__importDefault)(require("./commands/preview"));
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.2
|
|
1
|
+
{"version":"2.3.2-beta","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","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","required":true},"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"},"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},"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}},"args":[{"name":"FILE","description":"Path or URL to your API documentation file. OpenAPI (2.0 to 3.1.0) and AsyncAPI (2.0 to 2.2) specifications are currently supported.","required":true}]},"diff":{"id":"diff","description":"Get a comparaison 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","required":false},"hub":{"name":"hub","type":"option","char":"b","description":"Hub id or slug. Can be provided via BUMP_HUB_ID 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},"format":{"name":"format","type":"option","char":"f","description":"Format in which to provide the diff result","options":["text","markdown","json"],"default":"text"}},"args":[{"name":"FILE","description":"Path or URL to your API documentation file. OpenAPI (2.0 to 3.1.0) and AsyncAPI (2.0 to 2.2) specifications are currently supported.","required":true},{"name":"FILE2","description":"Path or URL to a second API documentation file to compute its diff"}]},"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.0 to 2.2) specifications are currently supported.","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.2
|
|
4
|
+
"version": "2.3.2-beta",
|
|
5
5
|
"author": "Paul Bonaud <paulr@bump.sh>",
|
|
6
6
|
"bin": {
|
|
7
7
|
"bump": "./bin/run"
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"bugs": "https://github.com/bump-sh/cli/issues",
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@oclif/dev-cli": "^1.26.0",
|
|
12
|
-
"@oclif/test": "^
|
|
12
|
+
"@oclif/test": "^2.0.3",
|
|
13
13
|
"@types/debug": "^4.1.5",
|
|
14
14
|
"@types/mocha": "^9.0.0",
|
|
15
|
-
"@types/node": "^
|
|
15
|
+
"@types/node": "^17.0.4",
|
|
16
16
|
"@typescript-eslint/eslint-plugin": "^4.21.0",
|
|
17
17
|
"@typescript-eslint/parser": "^4.21.0",
|
|
18
18
|
"chai": "^4.3.4",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"np": "^7.5.0",
|
|
27
27
|
"nyc": "^15.1.0",
|
|
28
28
|
"prettier": "^2.2.1",
|
|
29
|
-
"sinon": "^
|
|
29
|
+
"sinon": "^12.0.1",
|
|
30
30
|
"stdout-stderr": "^0.1.13",
|
|
31
31
|
"ts-node": "^10.0.0",
|
|
32
32
|
"typescript": "^4.3.3"
|
|
@@ -80,10 +80,10 @@
|
|
|
80
80
|
"@asyncapi/specs": "^2.9.0",
|
|
81
81
|
"@oclif/command": "^1.8.0",
|
|
82
82
|
"@oclif/config": "^1.17.0",
|
|
83
|
-
"@oclif/plugin-help": "^
|
|
83
|
+
"@oclif/plugin-help": "^5.1.10",
|
|
84
84
|
"async-mutex": "^0.3.2",
|
|
85
|
-
"axios": "^0.
|
|
86
|
-
"cli-ux": "^
|
|
85
|
+
"axios": "^0.25.0",
|
|
86
|
+
"cli-ux": "^6.0.7",
|
|
87
87
|
"debug": "^4.3.1",
|
|
88
88
|
"oas-schemas": "git+https://git@github.com/OAI/OpenAPI-Specification.git#0f9d3ec7c033fef184ec54e1ffc201b2d61ce023",
|
|
89
89
|
"tslib": "^2.3.0"
|