@asyncapi/cli 3.4.2 → 3.5.1
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/apps/cli/commands/generate/client.d.ts +30 -0
- package/lib/apps/cli/commands/generate/client.js +94 -0
- package/lib/apps/cli/commands/generate/fromTemplate.d.ts +28 -16
- package/lib/apps/cli/commands/generate/fromTemplate.js +29 -296
- package/lib/apps/cli/commands/start/preview.d.ts +1 -0
- package/lib/apps/cli/commands/start/preview.js +1 -1
- package/lib/apps/cli/commands/start/studio.d.ts +1 -0
- package/lib/apps/cli/commands/start/studio.js +1 -1
- package/lib/apps/cli/internal/args/generate.args.d.ts +3 -0
- package/lib/apps/cli/internal/args/generate.args.js +10 -0
- package/lib/apps/cli/internal/base/BaseGeneratorCommand.d.ts +42 -0
- package/lib/apps/cli/internal/base/BaseGeneratorCommand.js +119 -0
- package/lib/apps/cli/internal/flags/generate/clients.flags.d.ts +16 -0
- package/lib/apps/cli/internal/flags/generate/clients.flags.js +8 -0
- package/lib/apps/cli/internal/flags/generate/fromTemplate.flags.d.ts +25 -1
- package/lib/apps/cli/internal/flags/generate/fromTemplate.flags.js +2 -58
- package/lib/apps/cli/internal/flags/generate/sharedFlags.d.ts +16 -0
- package/lib/apps/cli/internal/flags/generate/sharedFlags.js +57 -0
- package/lib/apps/cli/internal/flags/start/preview.flags.d.ts +1 -0
- package/lib/apps/cli/internal/flags/start/preview.flags.js +1 -0
- package/lib/apps/cli/internal/flags/start/studio.flags.d.ts +1 -0
- package/lib/apps/cli/internal/flags/start/studio.flags.js +1 -0
- package/lib/domains/models/Preview.d.ts +1 -1
- package/lib/domains/models/Preview.js +145 -132
- package/lib/domains/models/Studio.d.ts +1 -1
- package/lib/domains/models/Studio.js +115 -100
- package/lib/domains/models/generate/ClientLanguages.d.ts +12 -0
- package/lib/domains/models/generate/ClientLanguages.js +17 -0
- package/lib/domains/models/generate/Flags.d.ts +9 -0
- package/lib/domains/models/generate/Flags.js +2 -0
- package/lib/domains/services/generator.service.d.ts +1 -0
- package/lib/domains/services/generator.service.js +5 -2
- package/lib/utils/generate/flags.d.ts +2 -0
- package/lib/utils/generate/flags.js +14 -0
- package/lib/utils/generate/mapBaseUrl.d.ts +6 -0
- package/lib/utils/generate/mapBaseUrl.js +34 -0
- package/lib/utils/generate/parseParams.d.ts +3 -0
- package/lib/utils/generate/parseParams.js +58 -0
- package/lib/utils/generate/prompts.d.ts +4 -0
- package/lib/utils/generate/prompts.js +77 -0
- package/lib/utils/generate/registry.d.ts +2 -0
- package/lib/utils/generate/registry.js +30 -0
- package/lib/utils/{fileWatcher.d.ts → generate/watcher.d.ts} +3 -0
- package/lib/utils/{fileWatcher.js → generate/watcher.js} +75 -8
- package/oclif.manifest.json +167 -3
- package/package.json +7 -5
- package/scripts/generateTypesForGenerateCommand.js +40 -0
|
@@ -25,149 +25,162 @@ function isValidFilePath(filePath) {
|
|
|
25
25
|
return (0, fs_1.existsSync)(filePath);
|
|
26
26
|
}
|
|
27
27
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
28
|
-
function startPreview(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
function startPreview(filePath, base, baseDirectory, xOrigin, suppressLogs, port = exports.DEFAULT_PORT, noBrowser) {
|
|
29
|
+
if (filePath && !isValidFilePath(filePath)) {
|
|
30
|
+
throw new specification_file_1.SpecificationFileNotFound(filePath);
|
|
31
|
+
}
|
|
32
|
+
const baseDir = path_1.default.dirname(path_1.default.resolve(filePath));
|
|
33
|
+
(0, bundler_1.default)(filePath).then((doc) => {
|
|
34
|
+
if (doc) {
|
|
35
|
+
bundleError = false;
|
|
32
36
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
37
|
+
}).catch((err) => {
|
|
38
|
+
if (suppressLogs) {
|
|
39
|
+
console.log(defaultErrorMessage);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.log(err);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const studioPath = path_1.default.dirname(require.resolve('@asyncapi/studio/package.json'));
|
|
46
|
+
const app = (0, next_1.default)({
|
|
47
|
+
dev: false,
|
|
48
|
+
dir: studioPath,
|
|
49
|
+
conf: {
|
|
50
|
+
distDir: 'build',
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
const handle = app.getRequestHandler();
|
|
54
|
+
const wsServer = new ws_1.WebSocketServer({ noServer: true });
|
|
55
|
+
wsServer.on('connection', (socket) => {
|
|
56
|
+
sockets.push(socket);
|
|
57
|
+
sendQueuedMessages();
|
|
58
|
+
});
|
|
59
|
+
wsServer.on('close', (socket) => {
|
|
60
|
+
sockets.splice(sockets.findIndex(s => s === socket));
|
|
61
|
+
});
|
|
62
|
+
app.prepare().then(() => {
|
|
63
|
+
if (filePath && !bundleError) {
|
|
64
|
+
messageQueue.push(JSON.stringify({
|
|
65
|
+
type: 'preview:connected',
|
|
66
|
+
code: 'Preview server connected'
|
|
67
|
+
}));
|
|
58
68
|
sendQueuedMessages();
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
sendQueuedMessages();
|
|
70
|
-
findPathsToWatchFromSchemaRef(filePath, baseDir);
|
|
71
|
-
filePathsToWatch.add(path_1.default.resolve(baseDir, filePath));
|
|
72
|
-
chokidar_1.default.watch([...filePathsToWatch]).on('all', (event) => {
|
|
73
|
-
switch (event) {
|
|
74
|
-
case 'add':
|
|
75
|
-
(0, bundler_1.default)([filePath], {
|
|
76
|
-
base,
|
|
77
|
-
baseDir: baseDirectory,
|
|
78
|
-
xOrigin,
|
|
79
|
-
}).then((intitalDocument) => {
|
|
80
|
-
messageQueue.push(JSON.stringify({
|
|
81
|
-
type: 'preview:file:added',
|
|
82
|
-
code: (path_1.default.extname(filePath) === '.yaml' || path_1.default.extname(filePath) === '.yml') ?
|
|
83
|
-
intitalDocument.yml() : intitalDocument.string()
|
|
84
|
-
}));
|
|
85
|
-
sendQueuedMessages();
|
|
86
|
-
}).catch((e) => {
|
|
87
|
-
if (suppressLogs) {
|
|
88
|
-
console.log(defaultErrorMessage);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
console.log(e);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
break;
|
|
95
|
-
case 'change':
|
|
96
|
-
(0, bundler_1.default)([filePath], {
|
|
97
|
-
base,
|
|
98
|
-
baseDir: baseDirectory,
|
|
99
|
-
xOrigin,
|
|
100
|
-
}).then((modifiedDocument) => {
|
|
101
|
-
messageQueue.push(JSON.stringify({
|
|
102
|
-
type: 'preview:file:changed',
|
|
103
|
-
code: (path_1.default.extname(filePath) === '.yaml' || path_1.default.extname(filePath) === '.yml') ?
|
|
104
|
-
modifiedDocument.yml() : modifiedDocument.string()
|
|
105
|
-
}));
|
|
106
|
-
sendQueuedMessages();
|
|
107
|
-
}).catch((error) => {
|
|
108
|
-
if (suppressLogs) {
|
|
109
|
-
console.log(defaultErrorMessage);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
console.log(error);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
break;
|
|
116
|
-
case 'unlink':
|
|
69
|
+
findPathsToWatchFromSchemaRef(filePath, baseDir);
|
|
70
|
+
filePathsToWatch.add(path_1.default.resolve(baseDir, filePath));
|
|
71
|
+
chokidar_1.default.watch([...filePathsToWatch]).on('all', (event) => {
|
|
72
|
+
switch (event) {
|
|
73
|
+
case 'add':
|
|
74
|
+
(0, bundler_1.default)([filePath], {
|
|
75
|
+
base,
|
|
76
|
+
baseDir: baseDirectory,
|
|
77
|
+
xOrigin,
|
|
78
|
+
}).then((intitalDocument) => {
|
|
117
79
|
messageQueue.push(JSON.stringify({
|
|
118
|
-
type: 'preview:file:
|
|
119
|
-
filePath
|
|
80
|
+
type: 'preview:file:added',
|
|
81
|
+
code: (path_1.default.extname(filePath) === '.yaml' || path_1.default.extname(filePath) === '.yml') ?
|
|
82
|
+
intitalDocument.yml() : intitalDocument.string()
|
|
120
83
|
}));
|
|
121
84
|
sendQueuedMessages();
|
|
122
|
-
|
|
123
|
-
|
|
85
|
+
}).catch((e) => {
|
|
86
|
+
if (suppressLogs) {
|
|
87
|
+
console.log(defaultErrorMessage);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
console.log(e);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
break;
|
|
94
|
+
case 'change':
|
|
95
|
+
(0, bundler_1.default)([filePath], {
|
|
96
|
+
base,
|
|
97
|
+
baseDir: baseDirectory,
|
|
98
|
+
xOrigin,
|
|
99
|
+
}).then((modifiedDocument) => {
|
|
100
|
+
messageQueue.push(JSON.stringify({
|
|
101
|
+
type: 'preview:file:changed',
|
|
102
|
+
code: (path_1.default.extname(filePath) === '.yaml' || path_1.default.extname(filePath) === '.yml') ?
|
|
103
|
+
modifiedDocument.yml() : modifiedDocument.string()
|
|
104
|
+
}));
|
|
105
|
+
sendQueuedMessages();
|
|
106
|
+
}).catch((error) => {
|
|
107
|
+
if (suppressLogs) {
|
|
108
|
+
console.log(defaultErrorMessage);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
console.log(error);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
break;
|
|
115
|
+
case 'unlink':
|
|
116
|
+
messageQueue.push(JSON.stringify({
|
|
117
|
+
type: 'preview:file:deleted',
|
|
118
|
+
filePath,
|
|
119
|
+
}));
|
|
120
|
+
sendQueuedMessages();
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
const server = (0, http_1.createServer)((req, res) => {
|
|
126
|
+
if (req.url === '/close') {
|
|
127
|
+
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
128
|
+
res.end('Shutting down server');
|
|
129
|
+
for (const socket of wsServer.clients) {
|
|
130
|
+
socket.close();
|
|
131
|
+
}
|
|
132
|
+
// Close the server
|
|
133
|
+
server.close(() => {
|
|
134
|
+
// eslint-disable-next-line no-process-exit
|
|
135
|
+
process.exit(0);
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
handle(req, res);
|
|
140
|
+
});
|
|
141
|
+
server.on('upgrade', (request, socket, head) => {
|
|
142
|
+
if (request.url === '/preview-server' && request.headers['origin'] === `http://localhost:${port}`) {
|
|
143
|
+
console.log('🔗 WebSocket connection established for the preview.');
|
|
144
|
+
wsServer.handleUpgrade(request, socket, head, (sock) => {
|
|
145
|
+
wsServer.emit('connection', sock, request);
|
|
124
146
|
});
|
|
125
147
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
148
|
+
else {
|
|
149
|
+
console.log('🔗 WebSocket connection not established.');
|
|
150
|
+
socket.destroy();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (!bundleError) {
|
|
154
|
+
server.listen(port, () => {
|
|
155
|
+
const previewServerAddr = server.address();
|
|
156
|
+
const currentPort = (previewServerAddr && typeof previewServerAddr === 'object' && 'port' in previewServerAddr) ? previewServerAddr.port : port;
|
|
157
|
+
const url = `http://localhost:${currentPort}?previewServer=${currentPort}&studio-version=${package_json_1.version}`;
|
|
158
|
+
console.log(`🎉 Connected to Preview Server running at ${(0, picocolors_1.blueBright)(url)}.`);
|
|
159
|
+
console.log(`🌐 Open this URL in your web browser: ${(0, picocolors_1.blueBright)(url)}`);
|
|
160
|
+
console.log(`🛑 If needed, press ${(0, picocolors_1.redBright)('Ctrl + C')} to stop the server.`);
|
|
161
|
+
if (filePath) {
|
|
162
|
+
for (const entry of filePathsToWatch) {
|
|
163
|
+
console.log(`👁️ Watching changes on file ${(0, picocolors_1.blueBright)(entry)}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
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.');
|
|
168
|
+
}
|
|
169
|
+
if (!bundleError && !noBrowser) {
|
|
170
|
+
(0, open_1.default)(url);
|
|
171
|
+
}
|
|
172
|
+
}).on('error', (error) => {
|
|
173
|
+
if (error.message.includes('EADDRINUSE')) {
|
|
174
|
+
console.log(error);
|
|
175
|
+
console.error((0, picocolors_1.redBright)(`Error: Port ${port} is already in use.`));
|
|
176
|
+
// eslint-disable-next-line no-process-exit
|
|
177
|
+
process.exit(1);
|
|
133
178
|
}
|
|
134
179
|
else {
|
|
135
|
-
console.
|
|
136
|
-
socket.destroy();
|
|
180
|
+
console.error(`Failed to start server on port ${port}:`, 'cause', error.cause, '\n', 'name', error.name, '\n', 'stack', error.stack, '\n', 'message', error.message);
|
|
137
181
|
}
|
|
138
182
|
});
|
|
139
|
-
|
|
140
|
-
server.listen(port, () => {
|
|
141
|
-
const previewServerAddr = server.address();
|
|
142
|
-
const currentPort = (previewServerAddr && typeof previewServerAddr === 'object' && 'port' in previewServerAddr) ? previewServerAddr.port : port;
|
|
143
|
-
const url = `http://localhost:${currentPort}?previewServer=${currentPort}&studio-version=${package_json_1.version}`;
|
|
144
|
-
console.log(`🎉 Connected to Preview Server running at ${(0, picocolors_1.blueBright)(url)}.`);
|
|
145
|
-
console.log(`🌐 Open this URL in your web browser: ${(0, picocolors_1.blueBright)(url)}`);
|
|
146
|
-
console.log(`🛑 If needed, press ${(0, picocolors_1.redBright)('Ctrl + C')} to stop the server.`);
|
|
147
|
-
if (filePath) {
|
|
148
|
-
for (const entry of filePathsToWatch) {
|
|
149
|
-
console.log(`👁️ Watching changes on file ${(0, picocolors_1.blueBright)(entry)}`);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
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.');
|
|
154
|
-
}
|
|
155
|
-
if (!bundleError) {
|
|
156
|
-
(0, open_1.default)(url);
|
|
157
|
-
}
|
|
158
|
-
}).on('error', (error) => {
|
|
159
|
-
if (error.message.includes('EADDRINUSE')) {
|
|
160
|
-
console.log(error);
|
|
161
|
-
console.error((0, picocolors_1.redBright)(`Error: Port ${port} is already in use.`));
|
|
162
|
-
// eslint-disable-next-line no-process-exit
|
|
163
|
-
process.exit(1);
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
console.error(`Failed to start server on port ${port}:`, 'cause', error.cause, '\n', 'name', error.name, '\n', 'stack', error.stack, '\n', 'message', error.message);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
});
|
|
183
|
+
}
|
|
171
184
|
});
|
|
172
185
|
}
|
|
173
186
|
function sendQueuedMessages() {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const DEFAULT_PORT = 0;
|
|
2
|
-
export declare function start(filePath: string, port?: number):
|
|
2
|
+
export declare function start(filePath: string, port?: number, noBrowser?: boolean): void;
|
|
@@ -21,120 +21,135 @@ function isValidFilePath(filePath) {
|
|
|
21
21
|
return (0, fs_1.existsSync)(filePath);
|
|
22
22
|
}
|
|
23
23
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
24
|
-
function start(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
getFileContent(filePath).then((code) => {
|
|
44
|
-
messageQueue.push(JSON.stringify({
|
|
45
|
-
type: 'file:loaded',
|
|
46
|
-
code,
|
|
47
|
-
}));
|
|
48
|
-
sendQueuedMessages();
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
24
|
+
function start(filePath, port = exports.DEFAULT_PORT, noBrowser) {
|
|
25
|
+
if (filePath && !isValidFilePath(filePath)) {
|
|
26
|
+
throw new specification_file_1.SpecificationFileNotFound(filePath);
|
|
27
|
+
}
|
|
28
|
+
// Locate @asyncapi/studio package
|
|
29
|
+
const studioPath = path_1.default.dirname(require.resolve('@asyncapi/studio/package.json'));
|
|
30
|
+
const app = (0, next_1.default)({
|
|
31
|
+
dev: false,
|
|
32
|
+
dir: studioPath,
|
|
33
|
+
conf: {
|
|
34
|
+
distDir: 'build',
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const handle = app.getRequestHandler();
|
|
38
|
+
const wsServer = new ws_1.WebSocketServer({ noServer: true });
|
|
39
|
+
wsServer.on('connection', (socket) => {
|
|
40
|
+
sockets.push(socket);
|
|
41
|
+
if (filePath) {
|
|
42
|
+
getFileContent(filePath).then((code) => {
|
|
52
43
|
messageQueue.push(JSON.stringify({
|
|
53
44
|
type: 'file:loaded',
|
|
54
|
-
code
|
|
45
|
+
code,
|
|
55
46
|
}));
|
|
56
47
|
sendQueuedMessages();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
messageQueue.push(JSON.stringify({
|
|
52
|
+
type: 'file:loaded',
|
|
53
|
+
code: '',
|
|
54
|
+
}));
|
|
55
|
+
sendQueuedMessages();
|
|
56
|
+
}
|
|
57
|
+
socket.on('message', (event) => {
|
|
58
|
+
try {
|
|
59
|
+
const json = JSON.parse(event);
|
|
60
|
+
if (filePath && json.type === 'file:update') {
|
|
61
|
+
saveFileContent(filePath, json.code);
|
|
68
62
|
}
|
|
69
|
-
|
|
70
|
-
console.
|
|
63
|
+
else {
|
|
64
|
+
console.warn('Live Server: An unknown event has been received. See details:');
|
|
65
|
+
console.log(json);
|
|
71
66
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
console.error(`Live Server: An invalid event has been received. See details:\n${event}`);
|
|
70
|
+
}
|
|
76
71
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
sendQueuedMessages();
|
|
89
|
-
});
|
|
90
|
-
break;
|
|
91
|
-
case 'unlink':
|
|
72
|
+
});
|
|
73
|
+
wsServer.on('close', (socket) => {
|
|
74
|
+
sockets.splice(sockets.findIndex((s) => s === socket));
|
|
75
|
+
});
|
|
76
|
+
app.prepare().then(() => {
|
|
77
|
+
if (filePath) {
|
|
78
|
+
chokidar_1.default.watch(filePath).on('all', (event, path) => {
|
|
79
|
+
switch (event) {
|
|
80
|
+
case 'add':
|
|
81
|
+
case 'change':
|
|
82
|
+
getFileContent(path).then((code) => {
|
|
92
83
|
messageQueue.push(JSON.stringify({
|
|
93
|
-
type: 'file:
|
|
94
|
-
|
|
84
|
+
type: 'file:changed',
|
|
85
|
+
code,
|
|
95
86
|
}));
|
|
96
87
|
sendQueuedMessages();
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
wsServer.emit('connection', sock, request);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
socket.destroy();
|
|
88
|
+
});
|
|
89
|
+
break;
|
|
90
|
+
case 'unlink':
|
|
91
|
+
messageQueue.push(JSON.stringify({
|
|
92
|
+
type: 'file:deleted',
|
|
93
|
+
filePath,
|
|
94
|
+
}));
|
|
95
|
+
sendQueuedMessages();
|
|
96
|
+
break;
|
|
111
97
|
}
|
|
112
98
|
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
console.log(`🌐 Open this URL in your web browser: ${(0, picocolors_1.blueBright)(url)}`);
|
|
119
|
-
console.log(`🛑 If needed, press ${(0, picocolors_1.redBright)('Ctrl + C')} to stop the process.`);
|
|
120
|
-
if (filePath) {
|
|
121
|
-
console.log(`👁️ Watching changes on file ${(0, picocolors_1.blueBright)(filePath)}`);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
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.');
|
|
99
|
+
}
|
|
100
|
+
const server = (0, http_1.createServer)((req, res) => {
|
|
101
|
+
if (req.url === '/close') {
|
|
102
|
+
for (const socket of wsServer.clients) {
|
|
103
|
+
socket.close();
|
|
125
104
|
}
|
|
126
|
-
(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
console.error((0, picocolors_1.redBright)(`Error: Port ${port} is already in use.`));
|
|
105
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
106
|
+
res.end(JSON.stringify({ message: 'Server is shutting down' }));
|
|
107
|
+
// Close the server
|
|
108
|
+
server.close(() => {
|
|
131
109
|
// eslint-disable-next-line no-process-exit
|
|
132
|
-
process.exit(
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
110
|
+
process.exit(0);
|
|
111
|
+
});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
handle(req, res);
|
|
115
|
+
});
|
|
116
|
+
server.on('upgrade', (request, socket, head) => {
|
|
117
|
+
if (request.url === '/live-server') {
|
|
118
|
+
console.log('🔗 WebSocket connection established.');
|
|
119
|
+
wsServer.handleUpgrade(request, socket, head, (sock) => {
|
|
120
|
+
wsServer.emit('connection', sock, request);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
socket.destroy();
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
server.listen(port, () => {
|
|
128
|
+
const addr = server.address();
|
|
129
|
+
const listenPort = (addr && typeof addr === 'object' && 'port' in addr) ? addr.port : port;
|
|
130
|
+
const url = `http://localhost:${listenPort}?liveServer=${listenPort}&studio-version=${package_json_1.version}`;
|
|
131
|
+
console.log(`🎉 Connected to Live Server running at ${(0, picocolors_1.blueBright)(url)}.`);
|
|
132
|
+
console.log(`🌐 Open this URL in your web browser: ${(0, picocolors_1.blueBright)(url)}`);
|
|
133
|
+
console.log(`🛑 If needed, press ${(0, picocolors_1.redBright)('Ctrl + C')} to stop the process.`);
|
|
134
|
+
if (filePath) {
|
|
135
|
+
console.log(`👁️ Watching changes on file ${(0, picocolors_1.blueBright)(filePath)}`);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
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.');
|
|
139
|
+
}
|
|
140
|
+
if (!noBrowser) {
|
|
141
|
+
(0, open_1.default)(url);
|
|
142
|
+
}
|
|
143
|
+
}).on('error', (error) => {
|
|
144
|
+
if (error.message.includes('EADDRINUSE')) {
|
|
145
|
+
console.log(error);
|
|
146
|
+
console.error((0, picocolors_1.redBright)(`Error: Port ${port} is already in use.`));
|
|
147
|
+
// eslint-disable-next-line no-process-exit
|
|
148
|
+
process.exit(2);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
console.error(`Failed to start server on port ${port}`);
|
|
152
|
+
}
|
|
138
153
|
});
|
|
139
154
|
});
|
|
140
155
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum AvailableLanguage {
|
|
2
|
+
Dart = "dart",
|
|
3
|
+
Java = "java",
|
|
4
|
+
Javascript = "javascript",
|
|
5
|
+
Python = "python"
|
|
6
|
+
}
|
|
7
|
+
export declare const availableLanguages: readonly ["dart", "java", "javascript", "python"];
|
|
8
|
+
export type AvailableLanguageType = typeof availableLanguages[number];
|
|
9
|
+
/**
|
|
10
|
+
* Returns the first available language as the default option.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getDefaultLanguage: () => AvailableLanguageType;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultLanguage = exports.availableLanguages = exports.AvailableLanguage = void 0;
|
|
4
|
+
// Auto-generated. Do not edit manually.
|
|
5
|
+
var AvailableLanguage;
|
|
6
|
+
(function (AvailableLanguage) {
|
|
7
|
+
AvailableLanguage["Dart"] = "dart";
|
|
8
|
+
AvailableLanguage["Java"] = "java";
|
|
9
|
+
AvailableLanguage["Javascript"] = "javascript";
|
|
10
|
+
AvailableLanguage["Python"] = "python";
|
|
11
|
+
})(AvailableLanguage || (exports.AvailableLanguage = AvailableLanguage = {}));
|
|
12
|
+
exports.availableLanguages = ['dart', 'java', 'javascript', 'python'];
|
|
13
|
+
/**
|
|
14
|
+
* Returns the first available language as the default option.
|
|
15
|
+
*/
|
|
16
|
+
const getDefaultLanguage = () => exports.availableLanguages[0];
|
|
17
|
+
exports.getDefaultLanguage = getDefaultLanguage;
|
|
@@ -9,6 +9,7 @@ export declare class GeneratorService extends BaseService {
|
|
|
9
9
|
* Verify that a given template support v3, if not, return the link to the issue that needs to be solved.
|
|
10
10
|
*/
|
|
11
11
|
private verifyTemplateSupportForV3;
|
|
12
|
+
private getGenerationSuccessMessage;
|
|
12
13
|
private checkV3NotSupported;
|
|
13
14
|
generate(asyncapi: Specification, template: string, output: string, options: GenerationOptions, genOption: any, interactive?: boolean): Promise<ServiceResult<GenerationResult>>;
|
|
14
15
|
generateUsingNewGenerator(asyncapi: Specification, template: string, output: string, options: any, genOption: any): Promise<ServiceResult<GenerationResult>>;
|
|
@@ -34,6 +34,9 @@ class GeneratorService extends base_service_1.BaseService {
|
|
|
34
34
|
}
|
|
35
35
|
return undefined;
|
|
36
36
|
}
|
|
37
|
+
getGenerationSuccessMessage(output) {
|
|
38
|
+
return `${(0, picocolors_1.yellow)('Check out your shiny new generated files at ') + (0, picocolors_1.magenta)(output) + (0, picocolors_1.yellow)('.')}\n\n`;
|
|
39
|
+
}
|
|
37
40
|
checkV3NotSupported(asyncapi, template) {
|
|
38
41
|
if (asyncapi.isAsyncAPI3()) {
|
|
39
42
|
const v3IssueLink = this.verifyTemplateSupportForV3(template);
|
|
@@ -61,7 +64,7 @@ class GeneratorService extends base_service_1.BaseService {
|
|
|
61
64
|
s.stop('Generation failed');
|
|
62
65
|
return this.createErrorResult(err.message, err.diagnostics);
|
|
63
66
|
}
|
|
64
|
-
s.stop(
|
|
67
|
+
s.stop(this.getGenerationSuccessMessage(output));
|
|
65
68
|
return this.createSuccessResult({
|
|
66
69
|
success: true,
|
|
67
70
|
outputPath: output,
|
|
@@ -83,7 +86,7 @@ class GeneratorService extends base_service_1.BaseService {
|
|
|
83
86
|
logs.push('Generation failed');
|
|
84
87
|
return this.createErrorResult(err.message, err.diagnostics);
|
|
85
88
|
}
|
|
86
|
-
logs.push(
|
|
89
|
+
logs.push(this.getGenerationSuccessMessage(output));
|
|
87
90
|
return this.createSuccessResult({
|
|
88
91
|
success: true,
|
|
89
92
|
outputPath: output,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseGeneratorFlags = parseGeneratorFlags;
|
|
4
|
+
const parseParams_1 = require("./parseParams");
|
|
5
|
+
const registry_1 = require("./registry");
|
|
6
|
+
function parseGeneratorFlags(disableHooks, params, mapBaseUrl, registryUrl, registryAuth, registryToken) {
|
|
7
|
+
return {
|
|
8
|
+
params: (0, parseParams_1.paramParser)(params),
|
|
9
|
+
disableHooks: (0, parseParams_1.disableHooksParser)(disableHooks),
|
|
10
|
+
mapBaseUrlToFolder: (0, parseParams_1.mapBaseURLParser)(mapBaseUrl),
|
|
11
|
+
registryURLValidation: (0, registry_1.registryURLParser)(registryUrl),
|
|
12
|
+
registryAuthentication: (0, registry_1.registryValidation)(registryUrl, registryAuth, registryToken)
|
|
13
|
+
};
|
|
14
|
+
}
|