Skip to content

Commit

Permalink
feat!: release 1.0.0 without CLI (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
magicmatatjahu authored Jun 27, 2022
1 parent a46a63c commit f2ee74e
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 103 deletions.
32 changes: 14 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,41 @@ Convert [AsyncAPI](https://asyncapi.com) documents older to newer versions.
## Installation

```sh
npm i -g @asyncapi/converter
npm i @asyncapi/converter
```

## Usage

### From CLI

Minimal example:
To convert an AsyncAPi document in the console needs the official [AsyncAPI CLI](https://github.com/asyncapi/cli).

```sh
asyncapi-converter streetlights.yml
If you don't have CLI installed, run this command to install the CLI globally on your system:

# Result:
asyncapi: '2.0.0'
channels:
...
```sh
npm install -g @asyncapi/cli
```

Specify the application id:
Minimal usage example with output given:

```sh
asyncapi-converter --id=urn:com.asynapi.streetlights streetlights.yml
asyncapi convert streetlights.yml -o streetlights2.yml

# Result:
asyncapi: '2.0.0'
id: 'urn:com.asynapi.streetlights'
channels:
...
```

Save the result in a file by stream:
Convert to specific version:

```sh
asyncapi-converter streetlights.yml > streetlights2.yml
```

Save the result in a file by `-o, --output` flag:
asyncapi convert streetlights.yml -o streetlights2.yml -t 2.3.0

```sh
asyncapi-converter streetlights.yml -o streetlights2.yml
# Result:
asyncapi: '2.3.0'
channels:
...
```

### In JS
Expand Down
66 changes: 0 additions & 66 deletions cli.js

This file was deleted.

5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"name": "@asyncapi/converter",
"version": "0.11.0",
"description": "Convert AsyncAPI documents from older to newer versions.",
"bin": {
"asyncapi-converter": "cli.js"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
Expand All @@ -25,7 +22,6 @@
],
"files": [
"/lib",
"cli.js",
"./README.md",
"./LICENSE"
],
Expand All @@ -43,7 +39,6 @@
"author": "Fran Mendez <[email protected]> (fmvilas.com)",
"license": "Apache-2.0",
"dependencies": {
"commander": "^8.3.0",
"js-yaml": "^3.14.1"
},
"devDependencies": {
Expand Down
10 changes: 3 additions & 7 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ function from__1_1_0__to__1_2_0(asyncapi: AsyncAPIDocument, _: ConvertOptions) {
return asyncapi;
}

function from__1_2_0__to__2_0_0_rc1(asyncapi: AsyncAPIDocument, options: ConvertOptions) { // NOSONAR
function from__1_2_0__to__2_0_0_rc1(asyncapi: AsyncAPIDocument, _: ConvertOptions) { // NOSONAR
asyncapi.asyncapi = '2.0.0-rc1';
asyncapi.id = options.id || `urn:${asyncapi.info.title.toLowerCase().split(' ').join('.')}`;

if (asyncapi.servers) {
const security = asyncapi.security;
Expand Down Expand Up @@ -131,9 +130,8 @@ function from__1_2_0__to__2_0_0_rc1(asyncapi: AsyncAPIDocument, options: Convert
return asyncapi;
}

function from__2_0_0_rc1__to__2_0_0_rc2(asyncapi: AsyncAPIDocument, options: ConvertOptions) { // NOSONAR
function from__2_0_0_rc1__to__2_0_0_rc2(asyncapi: AsyncAPIDocument, _: ConvertOptions) { // NOSONAR
asyncapi.asyncapi = '2.0.0-rc2';
asyncapi.id = asyncapi.id || options.id;

if (asyncapi.servers) {
const serverMap: Record<string, any> = {};
Expand Down Expand Up @@ -191,13 +189,11 @@ function from__2_0_0_rc1__to__2_0_0_rc2(asyncapi: AsyncAPIDocument, options: Con
});
}

if (!options.id) delete asyncapi.id;
return asyncapi;
}

function from__2_0_0_rc2__to__2_0_0(asyncapi: AsyncAPIDocument, options: ConvertOptions) {
function from__2_0_0_rc2__to__2_0_0(asyncapi: AsyncAPIDocument, _: ConvertOptions) {
asyncapi.asyncapi = '2.0.0';
if (!options.id) delete asyncapi.id;
return asyncapi;
}

Expand Down
4 changes: 1 addition & 3 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export type AsyncAPIDocument = { asyncapi: string } & Record<string, any>;
export type ConvertVersion = '1.1.0' | '1.2.0' | '2.0.0-rc1' | '2.0.0-rc2' | '2.0.0' | '2.1.0' | '2.2.0' | '2.3.0' | '2.4.0';
export interface ConvertOptions {
id?: string;
}
export interface ConvertOptions {}
1 change: 0 additions & 1 deletion test/input/2.0.0-rc1/streetlights.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ components:
description: The ID of the streetlight.
schema:
type: string
id: 'urn:streetlights.api'
channels:
'smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured':
parameters:
Expand Down
1 change: 0 additions & 1 deletion test/output/2.0.0-rc1/gitter-streaming.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ components:
enum:
- |+
id: 'urn:gitter.streaming.api'
channels:
/:
publish:
Expand Down
1 change: 0 additions & 1 deletion test/output/2.0.0-rc1/slack-rtm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,6 @@ components:
type: string
text:
type: string
id: 'urn:slack.real.time.messaging.api'
channels:
/:
publish:
Expand Down
1 change: 0 additions & 1 deletion test/output/2.0.0-rc1/streetlights.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ components:
description: The ID of the streetlight.
schema:
type: string
id: 'urn:streetlights.api'
channels:
'smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured':
parameters:
Expand Down

0 comments on commit f2ee74e

Please sign in to comment.