@asyncapi/converter 0.11.0 → 1.0.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 CHANGED
@@ -2,48 +2,64 @@
2
2
 
3
3
  Convert [AsyncAPI](https://asyncapi.com) documents older to newer versions.
4
4
 
5
+ <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
6
+ [![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors-)
7
+ <!-- ALL-CONTRIBUTORS-BADGE:END -->
8
+
9
+ <!-- toc is generated with GitHub Actions do not remove toc markers -->
10
+
11
+ <!-- toc -->
12
+
13
+ - [Installation](#installation)
14
+ - [Usage](#usage)
15
+ * [From CLI](#from-cli)
16
+ * [In JS](#in-js)
17
+ * [In TS](#in-ts)
18
+ - [Known missing features](#known-missing-features)
19
+ - [Development](#development)
20
+ - [Contribution](#contribution)
21
+ - [Contributors ✨](#contributors-%E2%9C%A8)
22
+
23
+ <!-- tocstop -->
24
+
5
25
  ## Installation
6
26
 
7
27
  ```sh
8
- npm i -g @asyncapi/converter
28
+ npm i @asyncapi/converter
9
29
  ```
10
30
 
11
31
  ## Usage
12
32
 
13
33
  ### From CLI
14
34
 
15
- Minimal example:
35
+ To convert an AsyncAPi document in the console needs the official [AsyncAPI CLI](https://github.com/asyncapi/cli).
16
36
 
17
- ```sh
18
- asyncapi-converter streetlights.yml
37
+ If you don't have CLI installed, run this command to install the CLI globally on your system:
19
38
 
20
- # Result:
21
- asyncapi: '2.0.0'
22
- channels:
23
- ...
39
+ ```sh
40
+ npm install -g @asyncapi/cli
24
41
  ```
25
42
 
26
- Specify the application id:
43
+ Minimal usage example with output given:
27
44
 
28
45
  ```sh
29
- asyncapi-converter --id=urn:com.asynapi.streetlights streetlights.yml
46
+ asyncapi convert streetlights.yml -o streetlights2.yml
30
47
 
31
48
  # Result:
32
49
  asyncapi: '2.0.0'
33
- id: 'urn:com.asynapi.streetlights'
50
+ channels:
34
51
  ...
35
52
  ```
36
53
 
37
- Save the result in a file by stream:
54
+ Convert to specific version:
38
55
 
39
56
  ```sh
40
- asyncapi-converter streetlights.yml > streetlights2.yml
41
- ```
42
-
43
- Save the result in a file by `-o, --output` flag:
57
+ asyncapi convert streetlights.yml -o streetlights2.yml -t 2.3.0
44
58
 
45
- ```sh
46
- asyncapi-converter streetlights.yml -o streetlights2.yml
59
+ # Result:
60
+ asyncapi: '2.3.0'
61
+ channels:
62
+ ...
47
63
  ```
48
64
 
49
65
  ### In JS
@@ -84,3 +100,42 @@ try {
84
100
  ## Known missing features
85
101
 
86
102
  * When converting from 1.x to 2.x, Streaming APIs (those using `stream` instead of `topics` or `events`) are converted correctly but information about framing type and delimiter is missing until a [protocolInfo](https://github.com/asyncapi/extensions-catalog/issues/1) for that purpose is created.
103
+
104
+ ## Development
105
+
106
+ 1. Setup project by installing dependencies `npm install`
107
+ 2. Write code and tests.
108
+ 3. Make sure all tests pass `npm test`
109
+
110
+ ## Contribution
111
+
112
+ Read [CONTRIBUTING](https://github.com/asyncapi/.github/blob/master/CONTRIBUTING.md) guide.
113
+
114
+ ## Contributors ✨
115
+
116
+ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
117
+
118
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
119
+ <!-- prettier-ignore-start -->
120
+ <!-- markdownlint-disable -->
121
+ <table>
122
+ <tr>
123
+ <td align="center"><a href="https://github.com/magicmatatjahu"><img src="https://avatars.githubusercontent.com/u/20404945?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Maciej Urbańczyk</b></sub></a><br /><a href="#maintenance-magicmatatjahu" title="Maintenance">🚧</a> <a href="https://github.com/asyncapi/converter-js/commits?author=magicmatatjahu" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/issues?q=author%3Amagicmatatjahu" title="Bug reports">🐛</a> <a href="https://github.com/asyncapi/converter-js/pulls?q=is%3Apr+reviewed-by%3Amagicmatatjahu" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/asyncapi/converter-js/commits?author=magicmatatjahu" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/converter-js/commits?author=magicmatatjahu" title="Documentation">📖</a></td>
124
+ <td align="center"><a href="http://www.fmvilas.com/"><img src="https://avatars.githubusercontent.com/u/242119?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Fran Méndez</b></sub></a><br /><a href="#maintenance-fmvilas" title="Maintenance">🚧</a> <a href="https://github.com/asyncapi/converter-js/commits?author=fmvilas" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/issues?q=author%3Afmvilas" title="Bug reports">🐛</a> <a href="https://github.com/asyncapi/converter-js/pulls?q=is%3Apr+reviewed-by%3Afmvilas" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/asyncapi/converter-js/commits?author=fmvilas" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/converter-js/commits?author=fmvilas" title="Documentation">📖</a></td>
125
+ <td align="center"><a href="https://www.brainfart.dev/"><img src="https://avatars.githubusercontent.com/u/6995927?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lukasz Gornicki</b></sub></a><br /><a href="#maintenance-derberg" title="Maintenance">🚧</a> <a href="https://github.com/asyncapi/converter-js/commits?author=derberg" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/issues?q=author%3Aderberg" title="Bug reports">🐛</a> <a href="https://github.com/asyncapi/converter-js/pulls?q=is%3Apr+reviewed-by%3Aderberg" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/asyncapi/converter-js/commits?author=derberg" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/converter-js/commits?author=derberg" title="Documentation">📖</a> <a href="#infra-derberg" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
126
+ <td align="center"><a href="https://github.com/germanschnyder"><img src="https://avatars.githubusercontent.com/u/1844525?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Germán Schnyder</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=germanschnyder" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/commits?author=germanschnyder" title="Tests">⚠️</a></td>
127
+ <td align="center"><a href="https://github.com/bszwarc"><img src="https://avatars.githubusercontent.com/u/17266942?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Barbara Czyż</b></sub></a><br /><a href="#infra-bszwarc" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
128
+ <td align="center"><a href="https://github.com/depimomo"><img src="https://avatars.githubusercontent.com/u/12368942?v=4?s=100" width="100px;" alt=""/><br /><sub><b>depimomo</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=depimomo" title="Code">💻</a></td>
129
+ <td align="center"><a href="https://github.com/crypto-cmd"><img src="https://avatars.githubusercontent.com/u/54287503?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Orville Daley</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=crypto-cmd" title="Code">💻</a></td>
130
+ </tr>
131
+ <tr>
132
+ <td align="center"><a href="https://www.arctype.co/"><img src="https://avatars.githubusercontent.com/u/549273?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ryan R Sundberg</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=sundbry" title="Code">💻</a></td>
133
+ </tr>
134
+ </table>
135
+
136
+ <!-- markdownlint-restore -->
137
+ <!-- prettier-ignore-end -->
138
+
139
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
140
+
141
+ This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
package/lib/convert.js CHANGED
@@ -68,9 +68,8 @@ function from__1_1_0__to__1_2_0(asyncapi, _) {
68
68
  asyncapi.asyncapi = '1.2.0';
69
69
  return asyncapi;
70
70
  }
71
- function from__1_2_0__to__2_0_0_rc1(asyncapi, options) {
71
+ function from__1_2_0__to__2_0_0_rc1(asyncapi, _) {
72
72
  asyncapi.asyncapi = '2.0.0-rc1';
73
- asyncapi.id = options.id || `urn:${asyncapi.info.title.toLowerCase().split(' ').join('.')}`;
74
73
  if (asyncapi.servers) {
75
74
  const security = asyncapi.security;
76
75
  asyncapi.servers = asyncapi.servers.map((server) => {
@@ -116,9 +115,8 @@ function from__1_2_0__to__2_0_0_rc1(asyncapi, options) {
116
115
  delete asyncapi.security;
117
116
  return asyncapi;
118
117
  }
119
- function from__2_0_0_rc1__to__2_0_0_rc2(asyncapi, options) {
118
+ function from__2_0_0_rc1__to__2_0_0_rc2(asyncapi, _) {
120
119
  asyncapi.asyncapi = '2.0.0-rc2';
121
- asyncapi.id = asyncapi.id || options.id;
122
120
  if (asyncapi.servers) {
123
121
  const serverMap = {};
124
122
  asyncapi.servers.forEach((server, index) => {
@@ -170,14 +168,10 @@ function from__2_0_0_rc1__to__2_0_0_rc2(asyncapi, options) {
170
168
  delete parameter.name;
171
169
  });
172
170
  }
173
- if (!options.id)
174
- delete asyncapi.id;
175
171
  return asyncapi;
176
172
  }
177
- function from__2_0_0_rc2__to__2_0_0(asyncapi, options) {
173
+ function from__2_0_0_rc2__to__2_0_0(asyncapi, _) {
178
174
  asyncapi.asyncapi = '2.0.0';
179
- if (!options.id)
180
- delete asyncapi.id;
181
175
  return asyncapi;
182
176
  }
183
177
  function from__2_0_0__to__2_1_0(asyncapi, _) {
@@ -3,5 +3,4 @@ export declare type AsyncAPIDocument = {
3
3
  } & Record<string, any>;
4
4
  export declare 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';
5
5
  export interface ConvertOptions {
6
- id?: string;
7
6
  }
package/package.json CHANGED
@@ -1,10 +1,7 @@
1
1
  {
2
2
  "name": "@asyncapi/converter",
3
- "version": "0.11.0",
3
+ "version": "1.0.0",
4
4
  "description": "Convert AsyncAPI documents from older to newer versions.",
5
- "bin": {
6
- "asyncapi-converter": "cli.js"
7
- },
8
5
  "main": "lib/index.js",
9
6
  "types": "lib/index.d.ts",
10
7
  "scripts": {
@@ -12,7 +9,8 @@
12
9
  "test": "cross-env CI=true NODE_ENV=test jest --coverage",
13
10
  "lint": "echo 'no linter configured yet'",
14
11
  "release": "semantic-release",
15
- "generate:assets": "echo 'No additional assets need to be generated at the moment'",
12
+ "generate:assets": "npm run generate:readme:toc",
13
+ "generate:readme:toc": "markdown-toc -i README.md",
16
14
  "bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION",
17
15
  "prepublishOnly": "npm run build"
18
16
  },
@@ -24,7 +22,6 @@
24
22
  ],
25
23
  "files": [
26
24
  "/lib",
27
- "cli.js",
28
25
  "./README.md",
29
26
  "./LICENSE"
30
27
  ],
@@ -42,7 +39,6 @@
42
39
  "author": "Fran Mendez <fmvilas@gmail.com> (fmvilas.com)",
43
40
  "license": "Apache-2.0",
44
41
  "dependencies": {
45
- "commander": "^8.3.0",
46
42
  "js-yaml": "^3.14.1"
47
43
  },
48
44
  "devDependencies": {
@@ -56,10 +52,11 @@
56
52
  "conventional-changelog-conventionalcommits": "^4.6.3",
57
53
  "cross-env": "^7.0.3",
58
54
  "jest": "^27.5.1",
59
- "semantic-release": "^18.0.1",
55
+ "semantic-release": "^19.0.3",
60
56
  "ts-jest": "^27.1.3",
61
57
  "ts-node": "^10.7.0",
62
- "typescript": "^4.6.2"
58
+ "typescript": "^4.6.2",
59
+ "markdown-toc": "^1.2.0"
63
60
  },
64
61
  "release": {
65
62
  "branches": [
package/cli.js DELETED
@@ -1,66 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const path = require('path');
4
- const fs = require('fs');
5
- const program = require('commander');
6
- const packageInfo = require('./package.json');
7
- const converter = require('./lib');
8
-
9
- const red = text => `\x1b[31m${text}\x1b[0m`;
10
-
11
- let asyncapiFile;
12
- let version;
13
- let output;
14
-
15
- const parseArguments = (asyncAPIPath, v) => {
16
- asyncapiFile = path.resolve(asyncAPIPath);
17
- version = v;
18
- }
19
-
20
- const parseOutput = (filePath) => {
21
- output = path.resolve(filePath);
22
- }
23
-
24
- const showErrorAndExit = err => {
25
- console.error(red('Something went wrong:'));
26
- console.error(red(err.stack || err.message));
27
- process.exit(1);
28
- };
29
-
30
- program
31
- .version(packageInfo.version)
32
- .arguments('<document> [version]')
33
- .action(parseArguments)
34
- .option('--id <id>', 'application id (defaults to a generated one)')
35
- .option('-o, --output <outputFile>', 'file where to put the converted AsyncAPI document', parseOutput)
36
- .parse(process.argv);
37
-
38
- if (!asyncapiFile) {
39
- console.error(red('> Path to AsyncAPI file not provided.'));
40
- program.help(); // This exits the process
41
- }
42
- if (!version) {
43
- version = '2.4.0';
44
- }
45
-
46
- try {
47
- const asyncapi = fs.readFileSync(asyncapiFile, 'utf-8');
48
- let converted = converter.convert(asyncapi, version, {
49
- id: program.id,
50
- });
51
-
52
- // JSON case
53
- if (typeof converted === 'object') {
54
- converted = JSON.stringify(converted, undefined, 2);
55
- }
56
-
57
- if (output) {
58
- fs.writeFileSync(output, converted, 'utf-8');
59
- } else {
60
- console.log(converted);
61
- }
62
- } catch (e) {
63
- showErrorAndExit(e);
64
- }
65
-
66
- process.on('unhandledRejection', showErrorAndExit);