@asyncapi/cli 0.8.1 → 0.10.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/assets/examples/anyof.yml +31 -0
- package/assets/examples/application-headers.yml +83 -0
- package/assets/examples/correlation-id.yml +144 -0
- package/assets/examples/default-example.yaml +23 -0
- package/assets/examples/examples.json +58 -0
- package/assets/examples/gitter-streaming.yml +164 -0
- package/assets/examples/mercure.yml +49 -0
- package/assets/examples/not.yml +24 -0
- package/assets/examples/oneof.yml +46 -0
- package/assets/examples/rpc-client.yml +69 -0
- package/assets/examples/rpc-server.yml +66 -0
- package/assets/examples/simple.yml +23 -0
- package/assets/examples/slack-rtm.yml +884 -0
- package/assets/examples/streetlights-kafka.yml +163 -0
- package/assets/examples/streetlights-mqtt.yml +209 -0
- package/assets/examples/websocket-gemini.yml +213 -0
- package/lib/commands/new.d.ts +2 -1
- package/lib/commands/new.js +44 -11
- package/lib/models/Context.js +5 -5
- package/lib/models/SpecificationFile.js +5 -5
- package/oclif.manifest.json +1 -1
- package/package.json +7 -4
package/lib/commands/new.js
CHANGED
|
@@ -9,6 +9,7 @@ const Studio_1 = require("../models/Studio");
|
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const { writeFile, readFile } = fs_1.promises;
|
|
11
11
|
const DEFAULT_ASYNCAPI_FILE_NAME = 'asyncapi.yaml';
|
|
12
|
+
const DEFAULT_ASYNCAPI_TEMPLATE = 'default-example.yaml';
|
|
12
13
|
class New extends base_1.default {
|
|
13
14
|
async run() {
|
|
14
15
|
const { flags } = this.parse(New);
|
|
@@ -17,7 +18,8 @@ class New extends base_1.default {
|
|
|
17
18
|
return this.runInteractive();
|
|
18
19
|
}
|
|
19
20
|
const fileName = flags['file-name'] || DEFAULT_ASYNCAPI_FILE_NAME;
|
|
20
|
-
|
|
21
|
+
const template = flags['example'] || DEFAULT_ASYNCAPI_TEMPLATE;
|
|
22
|
+
this.createAsyncapiFile(fileName, template);
|
|
21
23
|
if (flags.studio) {
|
|
22
24
|
if (isTTY) {
|
|
23
25
|
Studio_1.start(fileName, flags.port || Studio_1.DEFAULT_PORT);
|
|
@@ -30,7 +32,9 @@ class New extends base_1.default {
|
|
|
30
32
|
async runInteractive() {
|
|
31
33
|
const { flags } = this.parse(New);
|
|
32
34
|
let fileName = flags['file-name'];
|
|
35
|
+
let selectedTemplate = flags['example'];
|
|
33
36
|
let openStudio = flags.studio;
|
|
37
|
+
let examples = [];
|
|
34
38
|
const questions = [];
|
|
35
39
|
if (!fileName) {
|
|
36
40
|
questions.push({
|
|
@@ -40,6 +44,30 @@ class New extends base_1.default {
|
|
|
40
44
|
default: DEFAULT_ASYNCAPI_FILE_NAME,
|
|
41
45
|
});
|
|
42
46
|
}
|
|
47
|
+
try {
|
|
48
|
+
const exampleFiles = await readFile(path_1.resolve(__dirname, '../../assets/examples/examples.json'), { encoding: 'utf8' });
|
|
49
|
+
examples = JSON.parse(exampleFiles);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
// no examples found
|
|
53
|
+
}
|
|
54
|
+
if (!selectedTemplate && examples.length > 0) {
|
|
55
|
+
questions.push({
|
|
56
|
+
name: 'use-example',
|
|
57
|
+
message: 'would you like to start your new file from one of our examples?',
|
|
58
|
+
type: 'confirm',
|
|
59
|
+
default: true,
|
|
60
|
+
});
|
|
61
|
+
questions.push({
|
|
62
|
+
type: 'list',
|
|
63
|
+
name: 'selectedTemplate',
|
|
64
|
+
message: 'What example would you like to use?',
|
|
65
|
+
choices: examples,
|
|
66
|
+
when: (answers) => {
|
|
67
|
+
return answers['use-example'];
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
43
71
|
if (openStudio === undefined) {
|
|
44
72
|
questions.push({
|
|
45
73
|
name: 'studio',
|
|
@@ -53,32 +81,36 @@ class New extends base_1.default {
|
|
|
53
81
|
if (!fileName) {
|
|
54
82
|
fileName = answers.filename;
|
|
55
83
|
}
|
|
84
|
+
if (!selectedTemplate) {
|
|
85
|
+
selectedTemplate = answers.selectedTemplate;
|
|
86
|
+
}
|
|
56
87
|
if (openStudio === undefined) {
|
|
57
88
|
openStudio = answers.studio;
|
|
58
89
|
}
|
|
59
90
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
await this.createAsyncapiFile(fileName);
|
|
91
|
+
fileName = fileName || DEFAULT_ASYNCAPI_FILE_NAME;
|
|
92
|
+
selectedTemplate = selectedTemplate || DEFAULT_ASYNCAPI_TEMPLATE;
|
|
93
|
+
await this.createAsyncapiFile(fileName, selectedTemplate);
|
|
64
94
|
if (openStudio) {
|
|
65
95
|
Studio_1.start(fileName, flags.port || Studio_1.DEFAULT_PORT);
|
|
66
96
|
}
|
|
67
97
|
}
|
|
68
|
-
async createAsyncapiFile(fileName) {
|
|
69
|
-
const
|
|
98
|
+
async createAsyncapiFile(fileName, selectedTemplate) {
|
|
99
|
+
const asyncApiFile = await readFile(path_1.resolve(__dirname, '../../assets/examples/', selectedTemplate), { encoding: 'utf8' });
|
|
100
|
+
const fileNameHasFileExtension = fileName.includes('.');
|
|
101
|
+
const fileNameToWriteToDisk = fileNameHasFileExtension ? fileName : `${fileName}.yaml`;
|
|
70
102
|
try {
|
|
71
|
-
const content = await readFile(
|
|
103
|
+
const content = await readFile(fileNameToWriteToDisk, { encoding: 'utf8' });
|
|
72
104
|
if (content !== '') {
|
|
73
|
-
console.log(`File ${
|
|
105
|
+
console.log(`File ${fileNameToWriteToDisk} already exists. Ignoring...`);
|
|
74
106
|
return;
|
|
75
107
|
}
|
|
76
108
|
}
|
|
77
109
|
catch (e) {
|
|
78
110
|
// File does not exist. Proceed creating it...
|
|
79
111
|
}
|
|
80
|
-
await writeFile(
|
|
81
|
-
console.log(`Created file ${
|
|
112
|
+
await writeFile(fileNameToWriteToDisk, asyncApiFile, { encoding: 'utf8' });
|
|
113
|
+
console.log(`Created file ${fileNameToWriteToDisk}...`);
|
|
82
114
|
}
|
|
83
115
|
}
|
|
84
116
|
exports.default = New;
|
|
@@ -86,6 +118,7 @@ New.description = 'creates a new asyncapi file';
|
|
|
86
118
|
New.flags = {
|
|
87
119
|
help: command_1.flags.help({ char: 'h' }),
|
|
88
120
|
'file-name': command_1.flags.string({ char: 'n', description: 'name of the file' }),
|
|
121
|
+
example: command_1.flags.string({ char: 'e', description: 'name of the example to use' }),
|
|
89
122
|
studio: command_1.flags.boolean({ char: 's', description: 'open in Studio' }),
|
|
90
123
|
port: command_1.flags.integer({ char: 'p', description: 'port in which to start Studio' }),
|
|
91
124
|
'no-tty': command_1.flags.boolean({ description: 'do not use an interactive terminal' }),
|
package/lib/models/Context.js
CHANGED
|
@@ -13,7 +13,7 @@ exports.DEFAULT_CONTEXT_FILE_PATH = path.resolve(os.homedir(), CONTEXT_FILENAME)
|
|
|
13
13
|
async function loadContext(contextName) {
|
|
14
14
|
const fileContent = await loadContextFile();
|
|
15
15
|
if (contextName) {
|
|
16
|
-
const context = fileContent.store[contextName];
|
|
16
|
+
const context = fileContent.store[String(contextName)];
|
|
17
17
|
if (!context) {
|
|
18
18
|
throw new context_error_1.ContextNotFound(contextName);
|
|
19
19
|
}
|
|
@@ -46,19 +46,19 @@ async function addContext(contextName, pathToFile) {
|
|
|
46
46
|
throw err;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
fileContent.store[contextName] = pathToFile;
|
|
49
|
+
fileContent.store[String(contextName)] = pathToFile;
|
|
50
50
|
await saveContextFile(fileContent);
|
|
51
51
|
}
|
|
52
52
|
exports.addContext = addContext;
|
|
53
53
|
async function removeContext(contextName) {
|
|
54
54
|
const fileContent = await loadContextFile();
|
|
55
|
-
if (!fileContent.store[contextName]) {
|
|
55
|
+
if (!fileContent.store[String(contextName)]) {
|
|
56
56
|
throw new context_error_1.ContextNotFound(contextName);
|
|
57
57
|
}
|
|
58
58
|
if (fileContent.current === contextName) {
|
|
59
59
|
delete fileContent.current;
|
|
60
60
|
}
|
|
61
|
-
delete fileContent.store[contextName];
|
|
61
|
+
delete fileContent.store[String(contextName)];
|
|
62
62
|
await saveContextFile(fileContent);
|
|
63
63
|
}
|
|
64
64
|
exports.removeContext = removeContext;
|
|
@@ -73,7 +73,7 @@ async function getCurrentContext() {
|
|
|
73
73
|
exports.getCurrentContext = getCurrentContext;
|
|
74
74
|
async function setCurrentContext(contextName) {
|
|
75
75
|
const fileContent = await loadContextFile();
|
|
76
|
-
if (!fileContent.store[contextName]) {
|
|
76
|
+
if (!fileContent.store[String(contextName)]) {
|
|
77
77
|
throw new context_error_1.ContextNotFound(contextName);
|
|
78
78
|
}
|
|
79
79
|
fileContent.current = contextName;
|
|
@@ -39,14 +39,14 @@ async function load(filePathOrContextName) {
|
|
|
39
39
|
return await loadFromContext();
|
|
40
40
|
}
|
|
41
41
|
catch (e) {
|
|
42
|
-
|
|
42
|
+
const autoDetectedSpecFile = await detectSpecFile();
|
|
43
|
+
if (autoDetectedSpecFile) {
|
|
44
|
+
return new SpecificationFile(autoDetectedSpecFile);
|
|
45
|
+
}
|
|
46
|
+
if (!filePathOrContextName || !autoDetectedSpecFile) {
|
|
43
47
|
throw e;
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
|
-
const autoDetectedSpecFile = await detectSpecFile();
|
|
47
|
-
if (autoDetectedSpecFile) {
|
|
48
|
-
return new SpecificationFile(autoDetectedSpecFile);
|
|
49
|
-
}
|
|
50
50
|
throw new specification_file_1.SpecificationFileNotFound();
|
|
51
51
|
}
|
|
52
52
|
exports.load = load;
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.10.0","commands":{"config":{"id":"config","description":"access configs","pluginName":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"new":{"id":"new","description":"creates a new asyncapi file","pluginName":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"file-name":{"name":"file-name","type":"option","char":"n","description":"name of the file"},"example":{"name":"example","type":"option","char":"e","description":"name of the example to use"},"studio":{"name":"studio","type":"boolean","char":"s","description":"open in Studio","allowNo":false},"port":{"name":"port","type":"option","char":"p","description":"port in which to start Studio"},"no-tty":{"name":"no-tty","type":"boolean","description":"do not use an interactive terminal","allowNo":false}},"args":[]},"validate":{"id":"validate","description":"validate asyncapi file","pluginName":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"spec-file","description":"spec path or context-name","required":false}]},"config:context":{"id":"config:context","pluginName":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"start:studio":{"id":"start:studio","description":"starts a new local instance of Studio","pluginName":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"file":{"name":"file","type":"option","char":"f","description":"path to the AsyncAPI file to link with Studio"},"port":{"name":"port","type":"option","char":"p","description":"port in which to start Studio"}},"args":[]},"config:context:add":{"id":"config:context:add","description":"Add or modify a context in the store","pluginName":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"context-name","description":"context name","required":true},{"name":"spec-file-path","description":"file path of the spec file","required":true}]},"config:context:current":{"id":"config:context:current","description":"Shows the current context that is being used","pluginName":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"config:context:list":{"id":"config:context:list","description":"List all the stored context in the store","pluginName":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"config:context:remove":{"id":"config:context:remove","description":"Delete a context from the store","pluginName":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"context-name","description":"Name of the context to delete","required":true}]},"config:context:use":{"id":"config:context:use","description":"Set a context as current","pluginName":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"context-name","description":"name of the saved context","required":true}]}}}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asyncapi/cli",
|
|
3
3
|
"description": "All in one CLI for all AsyncAPI tools",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"author": "@asyncapi",
|
|
6
6
|
"bin": {
|
|
7
7
|
"asyncapi": "./bin/run"
|
|
8
8
|
},
|
|
9
9
|
"bugs": "https://github.com/asyncapi/cli/issues",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@asyncapi/parser": "^1.
|
|
12
|
-
"@asyncapi/studio": "^0.2
|
|
11
|
+
"@asyncapi/parser": "^1.11.0",
|
|
12
|
+
"@asyncapi/studio": "^0.3.2",
|
|
13
13
|
"@fmvilas/oclif-plugin-spaced-commands": "^1.0.4",
|
|
14
14
|
"@oclif/command": "^1.8.0",
|
|
15
15
|
"@oclif/config": "^1.17.0",
|
|
@@ -20,8 +20,10 @@
|
|
|
20
20
|
"inquirer": "^8.2.0",
|
|
21
21
|
"open": "^8.4.0",
|
|
22
22
|
"reflect-metadata": "^0.1.13",
|
|
23
|
+
"request": "^2.88.2",
|
|
23
24
|
"serve-handler": "^6.1.3",
|
|
24
25
|
"tslib": "^1.14.1",
|
|
26
|
+
"unzipper": "^0.10.11",
|
|
25
27
|
"ws": "^8.2.3"
|
|
26
28
|
},
|
|
27
29
|
"devDependencies": {
|
|
@@ -63,6 +65,7 @@
|
|
|
63
65
|
"files": [
|
|
64
66
|
"/bin",
|
|
65
67
|
"/lib",
|
|
68
|
+
"/assets",
|
|
66
69
|
"/npm-shrinkwrap.json",
|
|
67
70
|
"/oclif.manifest.json"
|
|
68
71
|
],
|
|
@@ -106,7 +109,7 @@
|
|
|
106
109
|
},
|
|
107
110
|
"repository": "asyncapi/cli",
|
|
108
111
|
"scripts": {
|
|
109
|
-
"build": "tsc",
|
|
112
|
+
"build": "node scripts/fetch-asyncapi-example.js && tsc",
|
|
110
113
|
"bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION",
|
|
111
114
|
"dev": "tsc --watch",
|
|
112
115
|
"generate:assets": "npm run generate:readme:toc",
|