@asyncapi/converter 0.8.0 → 0.9.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.
Files changed (3) hide show
  1. package/README.md +7 -1
  2. package/cli.js +17 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -34,12 +34,18 @@ id: 'urn:com.asynapi.streetlights'
34
34
  ...
35
35
  ```
36
36
 
37
- Save the result in a file:
37
+ Save the result in a file by stream:
38
38
 
39
39
  ```sh
40
40
  asyncapi-converter streetlights.yml > streetlights2.yml
41
41
  ```
42
42
 
43
+ Save the result in a file by `-o, --output` flag:
44
+
45
+ ```sh
46
+ asyncapi-converter streetlights.yml -o streetlights2.yml
47
+ ```
48
+
43
49
  ### As a package
44
50
 
45
51
  ```js
package/cli.js CHANGED
@@ -10,6 +10,16 @@ const red = text => `\x1b[31m${text}\x1b[0m`;
10
10
 
11
11
  let asyncapiFile;
12
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
+ }
13
23
 
14
24
  const showErrorAndExit = err => {
15
25
  console.error(red('Something went wrong:'));
@@ -20,11 +30,9 @@ const showErrorAndExit = err => {
20
30
  program
21
31
  .version(packageInfo.version)
22
32
  .arguments('<document> [version]')
23
- .action((asyncAPIPath, v) => {
24
- asyncapiFile = path.resolve(asyncAPIPath);
25
- version = v;
26
- })
33
+ .action(parseArguments)
27
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)
28
36
  .parse(process.argv);
29
37
 
30
38
  if (!asyncapiFile) {
@@ -46,7 +54,11 @@ try {
46
54
  converted = JSON.stringify(converted, undefined, 2);
47
55
  }
48
56
 
49
- console.log(converted);
57
+ if (output) {
58
+ fs.writeFileSync(output, converted, 'utf-8');
59
+ } else {
60
+ console.log(converted);
61
+ }
50
62
  } catch (e) {
51
63
  showErrorAndExit(e);
52
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asyncapi/converter",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Convert AsyncAPI documents from older to newer versions.",
5
5
  "bin": {
6
6
  "asyncapi-converter": "cli.js"