Skip to content

Commit e4815e0

Browse files
fix: update @asyncapi/bundler to 0.5.0 version (#1415)
Co-authored-by: asyncapi-bot <bot+chan@asyncapi.io>
1 parent f2c0980 commit e4815e0

File tree

10 files changed

+37
-99
lines changed

10 files changed

+37
-99
lines changed

package-lock.json

Lines changed: 6 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"bugs": "https://github.com/asyncapi/cli/issues",
1010
"dependencies": {
1111
"@asyncapi/avro-schema-parser": "^3.0.22",
12-
"@asyncapi/bundler": "^0.4.0",
12+
"@asyncapi/bundler": "^0.5.0",
1313
"@asyncapi/converter": "^1.4.19",
1414
"@asyncapi/diff": "^0.4.1",
1515
"@asyncapi/generator": "^1.17.25",

src/commands/bundle.ts

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,44 @@ import Command from '../base';
44
import bundle from '@asyncapi/bundler';
55
import { promises } from 'fs';
66
import path from 'path';
7-
import { Specification, load } from '../models/SpecificationFile';
8-
import { Parser } from '@asyncapi/parser';
7+
import { Specification } from '../models/SpecificationFile';
98
import { Document } from '@asyncapi/bundler/lib/document';
109

1110
const { writeFile } = promises;
1211

1312
export default class Bundle extends Command {
14-
static description = 'bundle one or multiple asyncapi documents and their references together.';
13+
static readonly description = 'Bundle one or multiple AsyncAPI Documents and their references together.';
1514
static strict = false;
1615

1716
static examples: Example[] = [
18-
'asyncapi bundle ./asyncapi.yaml > final-asyncapi.yaml',
1917
'asyncapi bundle ./asyncapi.yaml --output final-asyncapi.yaml',
20-
'asyncapi bundle ./asyncapi.yaml ./features.yaml --reference-into-components',
21-
'asyncapi bundle ./asyncapi.yaml ./features.yaml --base ./asyncapi.yaml --reference-into-components'
18+
'asyncapi bundle ./asyncapi.yaml ./features.yaml',
19+
'asyncapi bundle ./asyncapi.yaml ./features.yaml --base ./main.yaml',
20+
'asyncapi bundle ./asyncapi.yaml ./features.yaml --base ./main.yaml --xOrigin',
21+
'asyncapi bundle ./asyncapi.yaml -o final-asyncapi.yaml --base ../public-api/main.yaml --baseDir ./social-media/comments-service',
2222
];
2323

2424
static flags = {
2525
help: Flags.help({ char: 'h' }),
2626
output: Flags.string({ char: 'o', description: 'The output file name. Omitting this flag the result will be printed in the console.' }),
27-
'reference-into-components': Flags.boolean({ char: 'r', description: 'Bundle the message $refs into components object.' }),
28-
base: Flags.string({ char: 'b', description: 'Path to the file which will act as a base. This is required when some properties are to needed to be overwritten.' }),
27+
base: Flags.string({ char: 'b', description: 'Path to the file which will act as a base. This is required when some properties need to be overwritten.' }),
28+
baseDir: Flags.string({ char: 'd', description: 'One relative/absolute path to directory relative to which paths to AsyncAPI Documents that should be bundled will be resolved.' }),
29+
xOrigin: Flags.boolean({ char: 'x', description: 'Pass this switch to generate properties "x-origin" that will contain historical values of dereferenced "$ref"s.' }),
2930
};
3031

31-
parser = new Parser();
32-
3332
async run() {
3433
const { argv, flags } = await this.parse(Bundle);
3534
const output = flags.output;
36-
let baseFile;
3735
const outputFormat = path.extname(argv[0]);
38-
const AsyncAPIFiles = await this.loadFiles(argv);
39-
40-
this.metricsMetadata.files = AsyncAPIFiles.length;
41-
42-
if (flags.base) {baseFile = (await load(flags.base)).text();}
36+
const AsyncAPIFiles = argv;
4337

44-
const fileContents = AsyncAPIFiles.map((file) => file.text());
38+
this.metricsMetadata.files = AsyncAPIFiles.length;
4539

46-
const document = await bundle(fileContents,
40+
const document = await bundle(AsyncAPIFiles,
4741
{
48-
referenceIntoComponents: flags['reference-into-components'],
49-
base: baseFile
42+
base: flags.base,
43+
baseDir: flags.baseDir,
44+
xOrigin: flags.xOrigin,
5045
}
5146
);
5247

@@ -86,13 +81,4 @@ export default class Bundle extends Command {
8681
}
8782
}
8883
}
89-
90-
async loadFiles(filepaths: string[]): Promise<Specification[]> {
91-
const files = [];
92-
for (const filepath of filepaths) {
93-
const file = await load(filepath);
94-
files.push(file);
95-
}
96-
return files;
97-
}
9884
}

src/models/SpecificationFile.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,3 @@ async function detectSpecFile(): Promise<string | undefined> {
222222
}));
223223
return existingFileNames.find(filename => filename !== undefined);
224224
}
225-

test/integration/bundle/bundle.test.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,14 @@ describe('bundle', () => {
4545
'bundle', './test/integration/bundle/asyncapi.yml'
4646
])
4747
.it('should throw error message if the file path is wrong', (ctx, done) => {
48-
expect(ctx.stderr).to.contain('error loading AsyncAPI document from file: ./test/integration/bundle/asyncapi.yml file does not exist.\n');
48+
expect(ctx.stderr).to.contain('Error: ENOENT: no such file or directory');
4949
done();
5050
});
5151

5252
test
5353
.stdout()
5454
.command([
55-
'bundle', './test/integration/bundle/first-asyncapi.yaml', '--reference-into-components', '--output=./test/integration/bundle/final.yaml'
56-
])
57-
.it('should be able to refence messages into components', (ctx, done) => {
58-
expect(ctx.stdout).to.contain('Check out your shiny new bundled files at ./test/integration/bundle/final.yaml\n');
59-
fileCleanup('./test/integration/bundle/final.yaml');
60-
done();
61-
});
62-
63-
test
64-
.stdout()
65-
.command([
66-
'bundle', './test/integration/bundle/first-asyncapi.yaml', './test/integration/bundle/feature.yaml', '--reference-into-components', '--output=test/integration/bundle/final.yaml'
55+
'bundle', './test/integration/bundle/first-asyncapi.yaml', './test/integration/bundle/feature.yaml', '--output=test/integration/bundle/final.yaml'
6756
])
6857
.it('should be able to bundle multiple specs along with custom reference', (ctx, done) => {
6958
expect(ctx.stdout).to.contain('Check out your shiny new bundled files at test/integration/bundle/final.yaml\n');
@@ -75,7 +64,7 @@ describe('bundle', () => {
7564
test
7665
.stdout()
7766
.command([
78-
'bundle', './test/integration/bundle/first-asyncapi.yaml', './test/integration/bundle/feature.yaml', '--reference-into-components', '--output=test/integration/bundle/final.yaml', '--base=./test/integration/bundle/first-asyncapi.yaml'
67+
'bundle', './test/integration/bundle/first-asyncapi.yaml', './test/integration/bundle/feature.yaml', '--output=test/integration/bundle/final.yaml', '--base=./test/integration/bundle/first-asyncapi.yaml'
7968
])
8069
.it('should be able to bundle correctly with overwriting base file', (ctx, done) => {
8170
expect(ctx.stdout).to.contain('Check out your shiny new bundled files at test/integration/bundle/final.yaml\n');

test/integration/bundle/channels.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
channels:
2+
commentLikedChannel:
3+
address: comment/liked

test/integration/bundle/feature.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
asyncapi: "2.5.0"
1+
asyncapi: "2.6.0"
22
info:
33
title: Account Service
44
version: 1.0.0
55
description: This service is in charge of processing user logouts
66
channels:
77
user/loggedOut:
8-
subcribe:
8+
unsubcribe:
99
message:
1010
$ref: 'test/integration/bundle/messages.yaml#/messages/UserLoggedOut'
11-

test/integration/bundle/final-asyncapi.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
asyncapi: 2.5.0
1+
asyncapi: 2.6.0
22
info:
33
title: Account Service
44
version: 1.0.0
@@ -9,7 +9,7 @@ channels:
99
message:
1010
$ref: '#/components/messages/UserSignedUp'
1111
user/loggedOut:
12-
subcribe:
12+
unsubcribe:
1313
message:
1414
$ref: '#/components/messages/UserLoggedOut'
1515
components:
@@ -38,4 +38,3 @@ components:
3838
timestamp:
3939
type: number
4040
descriptio: Time stamp when the user logged out
41-

test/integration/bundle/first-asyncapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
asyncapi: "2.5.0"
1+
asyncapi: "2.6.0"
22
info:
33
title: Account Service
44
version: 1.0.0
Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,8 @@
11
asyncapi: 3.0.0
22
info:
3-
title: Account Service
3+
title: Example Service
44
version: 1.0.0
5-
description: This service is in charge of processing user signupsA
5+
description: Example Service.
66
channels:
7-
userSignedup:
8-
address: 'user/signedup'
9-
messages:
10-
userSignedUpMessage:
11-
$ref: './test/integration/bundle/messages.yaml#/messages/UserSignedUp'
12-
test:
13-
address: '/test'
14-
messages:
15-
testMessage:
16-
$ref: '#/components/messages/TestMessage'
17-
operations:
18-
UserSignedUp:
19-
action: send
20-
channel:
21-
$ref: '#/channels/userSignedup'
22-
messages:
23-
- $ref: './test/integration/bundle/messages.yaml#/messages/UserSignedUp'
24-
TestOpp:
25-
action: send
26-
channel:
27-
$ref: '#/channels/test'
28-
messages:
29-
- $ref: '#/components/messages/TestMessage'
30-
components:
31-
messages:
32-
TestMessage:
33-
payload:
34-
type: string
7+
commentLikedChannel:
8+
$ref: './test/integration/bundle/channels.yaml#/channels/commentLikedChannel'

0 commit comments

Comments
 (0)