@asyncapi/cli 2.16.7 → 2.16.8
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/lib/core/models/Studio.js +57 -53
- package/oclif.manifest.json +1 -1
- package/package.json +4 -2
|
@@ -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.8",
|
|
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.0",
|
|
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",
|