@asyncapi/cli 2.16.7 → 2.16.9
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.
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"asyncapi": "3.0.0",
|
|
3
|
+
"info": {
|
|
4
|
+
"title": "Account Service",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"description": "This service is in charge of processing user signups"
|
|
7
|
+
},
|
|
8
|
+
"channels": {
|
|
9
|
+
"userSignedUp": {
|
|
10
|
+
"address": "user/signedup",
|
|
11
|
+
"messages": {
|
|
12
|
+
"UserSignedUp": {
|
|
13
|
+
"$ref": "#/components/messages/UserSignedUp"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"operations": {
|
|
19
|
+
"onUserSignUp": {
|
|
20
|
+
"action": "receive",
|
|
21
|
+
"channel": {
|
|
22
|
+
"$ref": "#/channels/userSignedUp"
|
|
23
|
+
},
|
|
24
|
+
"messages": [
|
|
25
|
+
{
|
|
26
|
+
"$ref": "#/channels/userSignedUp/messages/UserSignedUp"
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"components": {
|
|
32
|
+
"messages": {
|
|
33
|
+
"UserSignedUp": {
|
|
34
|
+
"payload": {
|
|
35
|
+
"type": "object",
|
|
36
|
+
"properties": {
|
|
37
|
+
"displayName": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"description": "Name of the user"
|
|
40
|
+
},
|
|
41
|
+
"email": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"format": "email",
|
|
44
|
+
"description": "Email of the user"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
package/lib/commands/new/file.js
CHANGED
|
@@ -11,7 +11,8 @@ const picocolors_1 = require("picocolors");
|
|
|
11
11
|
const file_flags_1 = require("../../core/flags/new/file.flags");
|
|
12
12
|
const { writeFile, readFile } = fs_1.promises;
|
|
13
13
|
const DEFAULT_ASYNCAPI_FILE_NAME = 'asyncapi.yaml';
|
|
14
|
-
const
|
|
14
|
+
const DEFAULT_ASYNCAPI_YAML_TEMPLATE = 'default-example.yaml';
|
|
15
|
+
const DEFAULT_ASYNCAPI_JSON_TEMPLATE = 'default-example.json';
|
|
15
16
|
function loadExampleFile() {
|
|
16
17
|
const exampleFiles = (0, fs_1.readFileSync)((0, path_1.resolve)(__dirname, '../../../assets/examples/examples.json'), { encoding: 'utf8' });
|
|
17
18
|
return JSON.parse(exampleFiles);
|
|
@@ -33,7 +34,15 @@ class NewFile extends base_1.default {
|
|
|
33
34
|
return this.runInteractive();
|
|
34
35
|
}
|
|
35
36
|
const fileName = flags['file-name'] || DEFAULT_ASYNCAPI_FILE_NAME;
|
|
36
|
-
|
|
37
|
+
// Determine template based on file extension
|
|
38
|
+
let default_template;
|
|
39
|
+
if (fileName.endsWith('.json')) {
|
|
40
|
+
default_template = DEFAULT_ASYNCAPI_JSON_TEMPLATE;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
default_template = DEFAULT_ASYNCAPI_YAML_TEMPLATE;
|
|
44
|
+
}
|
|
45
|
+
const template = flags['example'] || default_template;
|
|
37
46
|
yield this.createAsyncapiFile(fileName, template);
|
|
38
47
|
if (flags.studio) {
|
|
39
48
|
if (isTTY) {
|
|
@@ -107,7 +116,15 @@ class NewFile extends base_1.default {
|
|
|
107
116
|
}
|
|
108
117
|
}
|
|
109
118
|
fileName = fileName || DEFAULT_ASYNCAPI_FILE_NAME;
|
|
110
|
-
|
|
119
|
+
// Determine template based on file extension
|
|
120
|
+
let default_template;
|
|
121
|
+
if (fileName.endsWith('.json')) {
|
|
122
|
+
default_template = DEFAULT_ASYNCAPI_JSON_TEMPLATE;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
default_template = DEFAULT_ASYNCAPI_YAML_TEMPLATE;
|
|
126
|
+
}
|
|
127
|
+
selectedTemplate = selectedTemplate || default_template;
|
|
111
128
|
yield this.createAsyncapiFile(fileName, selectedTemplate);
|
|
112
129
|
fileName = fileName.includes('.') ? fileName : `${fileName}.yaml`;
|
|
113
130
|
if (openStudio) {
|
|
@@ -6,10 +6,10 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const specification_file_1 = require("../errors/specification-file");
|
|
8
8
|
const http_1 = require("http");
|
|
9
|
-
const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
|
|
10
9
|
const ws_1 = require("ws");
|
|
11
10
|
const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
|
|
12
11
|
const open_1 = tslib_1.__importDefault(require("open"));
|
|
12
|
+
const next_1 = tslib_1.__importDefault(require("next"));
|
|
13
13
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
14
|
const package_json_1 = require("@asyncapi/studio/package.json");
|
|
15
15
|
const picocolors_1 = require("picocolors");
|
|
@@ -24,49 +24,16 @@ function start(filePath, port = exports.DEFAULT_PORT) {
|
|
|
24
24
|
if (filePath && !isValidFilePath(filePath)) {
|
|
25
25
|
throw new specification_file_1.SpecificationFileNotFound(filePath);
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
code,
|
|
36
|
-
}));
|
|
37
|
-
sendQueuedMessages();
|
|
38
|
-
});
|
|
39
|
-
break;
|
|
40
|
-
case 'unlink':
|
|
41
|
-
messageQueue.push(JSON.stringify({
|
|
42
|
-
type: 'file:deleted',
|
|
43
|
-
filePath,
|
|
44
|
-
}));
|
|
45
|
-
sendQueuedMessages();
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
const server = (0, http_1.createServer)((request, response) => {
|
|
51
|
-
//not all CLI users use npm. Some package managers put dependencies in different weird places
|
|
52
|
-
//this is why we need to first figure out where exactly is the index.html located
|
|
53
|
-
//and then strip index.html from the path to point to directory with the rest of the studio
|
|
54
|
-
const indexLocation = require.resolve('@asyncapi/studio/build/index.html');
|
|
55
|
-
const hostFolder = indexLocation.substring(0, indexLocation.lastIndexOf(path_1.default.sep));
|
|
56
|
-
return (0, serve_handler_1.default)(request, response, {
|
|
57
|
-
public: hostFolder,
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
server.on('upgrade', (request, socket, head) => {
|
|
61
|
-
if (request.url === '/live-server') {
|
|
62
|
-
wsServer.handleUpgrade(request, socket, head, (sock) => {
|
|
63
|
-
wsServer.emit('connection', sock, request);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
socket.destroy();
|
|
68
|
-
}
|
|
27
|
+
// Locate @asyncapi/studio package
|
|
28
|
+
const studioPath = path_1.default.dirname(require.resolve('@asyncapi/studio/package.json'));
|
|
29
|
+
const app = (0, next_1.default)({
|
|
30
|
+
dev: false,
|
|
31
|
+
dir: studioPath,
|
|
32
|
+
conf: {
|
|
33
|
+
distDir: 'build',
|
|
34
|
+
},
|
|
69
35
|
});
|
|
36
|
+
const handle = app.getRequestHandler();
|
|
70
37
|
const wsServer = new ws_1.WebSocketServer({ noServer: true });
|
|
71
38
|
wsServer.on('connection', (socket) => {
|
|
72
39
|
sockets.push(socket);
|
|
@@ -105,18 +72,55 @@ function start(filePath, port = exports.DEFAULT_PORT) {
|
|
|
105
72
|
wsServer.on('close', (socket) => {
|
|
106
73
|
sockets.splice(sockets.findIndex(s => s === socket));
|
|
107
74
|
});
|
|
108
|
-
|
|
109
|
-
const url = `http://localhost:${port}?liveServer=${port}&studio-version=${package_json_1.version}`;
|
|
110
|
-
console.log(`🎉 Connected to Live Server running at ${(0, picocolors_1.blueBright)(url)}.`);
|
|
111
|
-
console.log(`🌐 Open this URL in your web browser: ${(0, picocolors_1.blueBright)(url)}`);
|
|
112
|
-
console.log(`🛑 If needed, press ${(0, picocolors_1.redBright)('Ctrl + C')} to stop the process.`);
|
|
75
|
+
app.prepare().then(() => {
|
|
113
76
|
if (filePath) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
77
|
+
chokidar_1.default.watch(filePath).on('all', (event, path) => {
|
|
78
|
+
switch (event) {
|
|
79
|
+
case 'add':
|
|
80
|
+
case 'change':
|
|
81
|
+
getFileContent(path).then((code) => {
|
|
82
|
+
messageQueue.push(JSON.stringify({
|
|
83
|
+
type: 'file:changed',
|
|
84
|
+
code,
|
|
85
|
+
}));
|
|
86
|
+
sendQueuedMessages();
|
|
87
|
+
});
|
|
88
|
+
break;
|
|
89
|
+
case 'unlink':
|
|
90
|
+
messageQueue.push(JSON.stringify({
|
|
91
|
+
type: 'file:deleted',
|
|
92
|
+
filePath,
|
|
93
|
+
}));
|
|
94
|
+
sendQueuedMessages();
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
118
98
|
}
|
|
119
|
-
(0,
|
|
99
|
+
const server = (0, http_1.createServer)((req, res) => handle(req, res));
|
|
100
|
+
server.on('upgrade', (request, socket, head) => {
|
|
101
|
+
if (request.url === '/live-server') {
|
|
102
|
+
console.log('🔗 WebSocket connection established.');
|
|
103
|
+
wsServer.handleUpgrade(request, socket, head, (sock) => {
|
|
104
|
+
wsServer.emit('connection', sock, request);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
socket.destroy();
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
server.listen(port, () => {
|
|
112
|
+
const url = `http://localhost:${port}?liveServer=${port}&studio-version=${package_json_1.version}`;
|
|
113
|
+
console.log(`🎉 Connected to Live Server running at ${(0, picocolors_1.blueBright)(url)}.`);
|
|
114
|
+
console.log(`🌐 Open this URL in your web browser: ${(0, picocolors_1.blueBright)(url)}`);
|
|
115
|
+
console.log(`🛑 If needed, press ${(0, picocolors_1.redBright)('Ctrl + C')} to stop the process.`);
|
|
116
|
+
if (filePath) {
|
|
117
|
+
console.log(`👁️ Watching changes on file ${(0, picocolors_1.blueBright)(filePath)}`);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
console.warn('Warning: No file was provided, and we couldn\'t find a default file (like "asyncapi.yaml" or "asyncapi.json") in the current folder. Starting Studio with a blank workspace.');
|
|
121
|
+
}
|
|
122
|
+
(0, open_1.default)(url);
|
|
123
|
+
});
|
|
120
124
|
});
|
|
121
125
|
}
|
|
122
126
|
function sendQueuedMessages() {
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asyncapi/cli",
|
|
3
3
|
"description": "All in one CLI for all AsyncAPI tools",
|
|
4
|
-
"version": "2.16.
|
|
4
|
+
"version": "2.16.9",
|
|
5
5
|
"author": "@asyncapi",
|
|
6
6
|
"bin": {
|
|
7
7
|
"asyncapi": "./bin/run_bin"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@asyncapi/parser": "^3.3.0",
|
|
20
20
|
"@asyncapi/protobuf-schema-parser": "^3.5.1",
|
|
21
21
|
"@asyncapi/raml-dt-schema-parser": "^4.0.24",
|
|
22
|
-
"@asyncapi/studio": "^0.
|
|
22
|
+
"@asyncapi/studio": "^0.23.1",
|
|
23
23
|
"@changesets/changelog-git": "^0.2.0",
|
|
24
24
|
"@clack/prompts": "^0.7.0",
|
|
25
25
|
"@oclif/core": "^4.2.9",
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
"https-proxy-agent": "^7.0.6",
|
|
34
34
|
"inquirer": "^8.2.0",
|
|
35
35
|
"js-yaml": "^4.1.0",
|
|
36
|
+
"next": "^14.2.24",
|
|
37
|
+
"node-fetch": "^2.0.0",
|
|
36
38
|
"oclif": "^4.17.34",
|
|
37
39
|
"open": "^8.4.0",
|
|
38
40
|
"picocolors": "^1.0.0",
|