@asyncapi/cli 3.3.0 → 3.4.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/assets/create-glee-app/templates/default/package-lock.json +24 -18
- package/lib/apps/cli/commands/generate/fromTemplate.js +1 -0
- package/lib/apps/cli/commands/generate/models.js +1 -0
- package/lib/apps/cli/commands/start/preview.d.ts +1 -1
- package/lib/apps/cli/commands/start/preview.js +3 -3
- package/lib/apps/cli/commands/start/studio.d.ts +1 -1
- package/lib/apps/cli/commands/start/studio.js +3 -3
- package/lib/apps/cli/internal/flags/start/preview.flags.d.ts +1 -1
- package/lib/apps/cli/internal/flags/start/preview.flags.js +1 -1
- package/lib/apps/cli/internal/flags/start/studio.flags.d.ts +1 -1
- package/lib/apps/cli/internal/flags/start/studio.flags.js +1 -1
- package/lib/domains/models/Preview.d.ts +2 -2
- package/lib/domains/models/Preview.js +136 -140
- package/lib/domains/models/Studio.d.ts +2 -2
- package/lib/domains/models/Studio.js +103 -89
- package/lib/utils/temp-dir.js +1 -0
- package/oclif.manifest.json +1 -1
- package/package.json +2 -1
- package/scripts/releasePackagesRename.js +16 -8
|
@@ -3154,9 +3154,10 @@
|
|
|
3154
3154
|
}
|
|
3155
3155
|
},
|
|
3156
3156
|
"node_modules/@npmcli/arborist/node_modules/brace-expansion": {
|
|
3157
|
-
"version": "2.0.
|
|
3158
|
-
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.
|
|
3159
|
-
"integrity": "sha512-
|
|
3157
|
+
"version": "2.0.2",
|
|
3158
|
+
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz",
|
|
3159
|
+
"integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==",
|
|
3160
|
+
"license": "MIT",
|
|
3160
3161
|
"dependencies": {
|
|
3161
3162
|
"balanced-match": "^1.0.0"
|
|
3162
3163
|
}
|
|
@@ -3241,9 +3242,10 @@
|
|
|
3241
3242
|
}
|
|
3242
3243
|
},
|
|
3243
3244
|
"node_modules/@npmcli/map-workspaces/node_modules/brace-expansion": {
|
|
3244
|
-
"version": "2.0.
|
|
3245
|
-
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.
|
|
3246
|
-
"integrity": "sha512-
|
|
3245
|
+
"version": "2.0.2",
|
|
3246
|
+
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz",
|
|
3247
|
+
"integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==",
|
|
3248
|
+
"license": "MIT",
|
|
3247
3249
|
"dependencies": {
|
|
3248
3250
|
"balanced-match": "^1.0.0"
|
|
3249
3251
|
}
|
|
@@ -4335,9 +4337,10 @@
|
|
|
4335
4337
|
}
|
|
4336
4338
|
},
|
|
4337
4339
|
"node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": {
|
|
4338
|
-
"version": "2.0.
|
|
4339
|
-
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.
|
|
4340
|
-
"integrity": "sha512-
|
|
4340
|
+
"version": "2.0.2",
|
|
4341
|
+
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz",
|
|
4342
|
+
"integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==",
|
|
4343
|
+
"license": "MIT",
|
|
4341
4344
|
"dependencies": {
|
|
4342
4345
|
"balanced-match": "^1.0.0"
|
|
4343
4346
|
}
|
|
@@ -5162,9 +5165,10 @@
|
|
|
5162
5165
|
"integrity": "sha512-vHdS19CnY3hwiNdkaqk93DvjVLfbEcI8mys4UjuWrlX1haDmroo8o4xCzh4wD6DGV6HxRCyauwhHRqMTfERtjw=="
|
|
5163
5166
|
},
|
|
5164
5167
|
"node_modules/brace-expansion": {
|
|
5165
|
-
"version": "1.1.
|
|
5166
|
-
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.
|
|
5167
|
-
"integrity": "sha512-
|
|
5168
|
+
"version": "1.1.12",
|
|
5169
|
+
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz",
|
|
5170
|
+
"integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==",
|
|
5171
|
+
"license": "MIT",
|
|
5168
5172
|
"dependencies": {
|
|
5169
5173
|
"balanced-match": "^1.0.0",
|
|
5170
5174
|
"concat-map": "0.0.1"
|
|
@@ -7533,9 +7537,10 @@
|
|
|
7533
7537
|
}
|
|
7534
7538
|
},
|
|
7535
7539
|
"node_modules/glob/node_modules/brace-expansion": {
|
|
7536
|
-
"version": "2.0.
|
|
7537
|
-
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.
|
|
7538
|
-
"integrity": "sha512-
|
|
7540
|
+
"version": "2.0.2",
|
|
7541
|
+
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz",
|
|
7542
|
+
"integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==",
|
|
7543
|
+
"license": "MIT",
|
|
7539
7544
|
"dependencies": {
|
|
7540
7545
|
"balanced-match": "^1.0.0"
|
|
7541
7546
|
}
|
|
@@ -7931,9 +7936,10 @@
|
|
|
7931
7936
|
}
|
|
7932
7937
|
},
|
|
7933
7938
|
"node_modules/ignore-walk/node_modules/brace-expansion": {
|
|
7934
|
-
"version": "2.0.
|
|
7935
|
-
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.
|
|
7936
|
-
"integrity": "sha512-
|
|
7939
|
+
"version": "2.0.2",
|
|
7940
|
+
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz",
|
|
7941
|
+
"integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==",
|
|
7942
|
+
"license": "MIT",
|
|
7937
7943
|
"dependencies": {
|
|
7938
7944
|
"balanced-match": "^1.0.0"
|
|
7939
7945
|
}
|
|
@@ -14,6 +14,7 @@ class Models extends base_1.default {
|
|
|
14
14
|
super(...arguments);
|
|
15
15
|
this.validationService = new validation_service_1.ValidationService();
|
|
16
16
|
}
|
|
17
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
17
18
|
run() {
|
|
18
19
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
19
20
|
const { args, flags } = yield this.parse(Models);
|
|
@@ -3,7 +3,7 @@ export default class PreviewStudio extends Command {
|
|
|
3
3
|
static readonly description = "starts a new local instance of Studio in minimal state bundling all the refs of the schema file and with no editing allowed.";
|
|
4
4
|
static readonly flags: {
|
|
5
5
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
6
|
-
port: import("@oclif/core/lib/interfaces").OptionFlag<
|
|
6
|
+
port: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
7
7
|
base: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
8
|
baseDir: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
9
|
xOrigin: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
@@ -9,10 +9,10 @@ const Preview_1 = require("../../../../domains/models/Preview");
|
|
|
9
9
|
class PreviewStudio extends base_1.default {
|
|
10
10
|
run() {
|
|
11
11
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
-
var _a;
|
|
12
|
+
var _a, _b;
|
|
13
13
|
const { args, flags } = yield this.parse(PreviewStudio);
|
|
14
14
|
let filePath = (_a = args['spec-file']) !== null && _a !== void 0 ? _a : flags.file;
|
|
15
|
-
const previewPort = flags.port;
|
|
15
|
+
const previewPort = parseInt((_b = flags.port) !== null && _b !== void 0 ? _b : '0', 10);
|
|
16
16
|
if (!filePath) {
|
|
17
17
|
filePath = (yield (0, SpecificationFile_1.load)()).getFilePath();
|
|
18
18
|
this.log(`Loaded the specification from: ${filePath}`);
|
|
@@ -26,7 +26,7 @@ class PreviewStudio extends base_1.default {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
this.metricsMetadata.port = previewPort;
|
|
29
|
-
(0, Preview_1.startPreview)(filePath, flags.base, flags.baseDir, flags.xOrigin, flags.suppressLogs, previewPort);
|
|
29
|
+
yield (0, Preview_1.startPreview)(filePath, flags.base, flags.baseDir, flags.xOrigin, flags.suppressLogs, previewPort);
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -4,7 +4,7 @@ export default class StartStudio extends Command {
|
|
|
4
4
|
static flags: {
|
|
5
5
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
6
6
|
file: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
7
|
-
port: import("@oclif/core/lib/interfaces").OptionFlag<
|
|
7
|
+
port: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
8
|
'no-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
9
|
};
|
|
10
10
|
static readonly args: {
|
|
@@ -10,10 +10,10 @@ const prompts_1 = require("@clack/prompts");
|
|
|
10
10
|
class StartStudio extends base_1.default {
|
|
11
11
|
run() {
|
|
12
12
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
var _a;
|
|
13
|
+
var _a, _b;
|
|
14
14
|
const { args, flags } = yield this.parse(StartStudio);
|
|
15
15
|
let filePath = (_a = args['spec-file']) !== null && _a !== void 0 ? _a : flags.file;
|
|
16
|
-
let port = flags.port;
|
|
16
|
+
let port = parseInt((_b = flags.port) !== null && _b !== void 0 ? _b : '0', 10);
|
|
17
17
|
if (flags.file) {
|
|
18
18
|
this.warn('The file flag has been removed and is being replaced by the argument spec-file. Please pass the filename directly like `asyncapi start studio asyncapi.yml`');
|
|
19
19
|
}
|
|
@@ -42,7 +42,7 @@ class StartStudio extends base_1.default {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
this.metricsMetadata.port = port;
|
|
45
|
-
(0, Studio_1.start)(filePath, port);
|
|
45
|
+
yield (0, Studio_1.start)(filePath, port);
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
parseArgs(args, port) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const previewFlags: () => {
|
|
2
2
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
3
|
-
port: import("@oclif/core/lib/interfaces").OptionFlag<
|
|
3
|
+
port: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
4
4
|
base: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
5
5
|
baseDir: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
6
6
|
xOrigin: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
@@ -5,7 +5,7 @@ const core_1 = require("@oclif/core");
|
|
|
5
5
|
const previewFlags = () => {
|
|
6
6
|
return {
|
|
7
7
|
help: core_1.Flags.help({ char: 'h' }),
|
|
8
|
-
port: core_1.Flags.
|
|
8
|
+
port: core_1.Flags.string({
|
|
9
9
|
char: 'p',
|
|
10
10
|
description: 'port in which to start Studio in the preview mode',
|
|
11
11
|
}),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const studioFlags: () => {
|
|
2
2
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
3
3
|
file: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
4
|
-
port: import("@oclif/core/lib/interfaces").OptionFlag<
|
|
4
|
+
port: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
5
5
|
'no-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
6
6
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const DEFAULT_PORT =
|
|
2
|
-
export declare function startPreview(filePath: string, base: string | undefined, baseDirectory: string | undefined, xOrigin: boolean | undefined, suppressLogs: boolean | undefined, port?: number): void
|
|
1
|
+
export declare const DEFAULT_PORT = 0;
|
|
2
|
+
export declare function startPreview(filePath: string, base: string | undefined, baseDirectory: string | undefined, xOrigin: boolean | undefined, suppressLogs: boolean | undefined, port?: number): Promise<void>;
|
|
@@ -20,155 +20,154 @@ const messageQueue = [];
|
|
|
20
20
|
const filePathsToWatch = new Set();
|
|
21
21
|
const defaultErrorMessage = 'error occured while bundling files. use --detailedLog or -l flag to get more details.';
|
|
22
22
|
let bundleError = true;
|
|
23
|
-
exports.DEFAULT_PORT =
|
|
23
|
+
exports.DEFAULT_PORT = 0;
|
|
24
24
|
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
|
-
|
|
32
|
-
const baseDir = path_1.default.dirname(path_1.default.resolve(filePath));
|
|
33
|
-
(0, bundler_1.default)(filePath)
|
|
34
|
-
.then((doc) => {
|
|
35
|
-
if (doc) {
|
|
36
|
-
bundleError = false;
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
.catch((err) => {
|
|
40
|
-
if (suppressLogs) {
|
|
41
|
-
console.log(defaultErrorMessage);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
console.log(err);
|
|
28
|
+
function startPreview(filePath_1, base_1, baseDirectory_1, xOrigin_1, suppressLogs_1) {
|
|
29
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (filePath, base, baseDirectory, xOrigin, suppressLogs, port = exports.DEFAULT_PORT) {
|
|
30
|
+
if (filePath && !isValidFilePath(filePath)) {
|
|
31
|
+
throw new specification_file_1.SpecificationFileNotFound(filePath);
|
|
45
32
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
33
|
+
const baseDir = path_1.default.dirname(path_1.default.resolve(filePath));
|
|
34
|
+
(0, bundler_1.default)(filePath).then((doc) => {
|
|
35
|
+
if (doc) {
|
|
36
|
+
bundleError = false;
|
|
37
|
+
}
|
|
38
|
+
}).catch((err) => {
|
|
39
|
+
if (suppressLogs) {
|
|
40
|
+
console.log(defaultErrorMessage);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.log(err);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const studioPath = path_1.default.dirname(require.resolve('@asyncapi/studio/package.json'));
|
|
47
|
+
const app = (0, next_1.default)({
|
|
48
|
+
dev: false,
|
|
49
|
+
dir: studioPath,
|
|
50
|
+
conf: {
|
|
51
|
+
distDir: 'build',
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
const handle = app.getRequestHandler();
|
|
55
|
+
const wsServer = new ws_1.WebSocketServer({ noServer: true });
|
|
56
|
+
wsServer.on('connection', (socket) => {
|
|
57
|
+
sockets.push(socket);
|
|
70
58
|
sendQueuedMessages();
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
59
|
+
});
|
|
60
|
+
wsServer.on('close', (socket) => {
|
|
61
|
+
sockets.splice(sockets.findIndex(s => s === socket));
|
|
62
|
+
});
|
|
63
|
+
app.prepare().then(() => {
|
|
64
|
+
if (filePath && !bundleError) {
|
|
65
|
+
messageQueue.push(JSON.stringify({
|
|
66
|
+
type: 'preview:connected',
|
|
67
|
+
code: 'Preview server connected'
|
|
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':
|
|
107
117
|
messageQueue.push(JSON.stringify({
|
|
108
|
-
type: 'preview:file:
|
|
109
|
-
|
|
110
|
-
path_1.default.extname(filePath) === '.yml'
|
|
111
|
-
? modifiedDocument.yml()
|
|
112
|
-
: modifiedDocument.string(),
|
|
118
|
+
type: 'preview:file:deleted',
|
|
119
|
+
filePath,
|
|
113
120
|
}));
|
|
114
121
|
sendQueuedMessages();
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (suppressLogs) {
|
|
118
|
-
console.log(defaultErrorMessage);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
console.log(error);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
break;
|
|
125
|
-
case 'unlink':
|
|
126
|
-
messageQueue.push(JSON.stringify({
|
|
127
|
-
type: 'preview:file:deleted',
|
|
128
|
-
filePath,
|
|
129
|
-
}));
|
|
130
|
-
sendQueuedMessages();
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
const server = (0, http_1.createServer)((req, res) => handle(req, res));
|
|
136
|
-
server.on('upgrade', (request, socket, head) => {
|
|
137
|
-
if (request.url === '/preview-server' &&
|
|
138
|
-
request.headers['origin'] === `http://localhost:${port}`) {
|
|
139
|
-
console.log('🔗 WebSocket connection established for the preview.');
|
|
140
|
-
wsServer.handleUpgrade(request, socket, head, (sock) => {
|
|
141
|
-
wsServer.emit('connection', sock, request);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
142
124
|
});
|
|
143
125
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
.listen(port, () => {
|
|
152
|
-
const url = `http://localhost:${port}?previewServer=${port}&studio-version=${package_json_1.version}`;
|
|
153
|
-
console.log(`🎉 Connected to Preview Server running at ${(0, picocolors_1.blueBright)(url)}.`);
|
|
154
|
-
console.log(`🌐 Open this URL in your web browser: ${(0, picocolors_1.blueBright)(url)}`);
|
|
155
|
-
console.log(`🛑 If needed, press ${(0, picocolors_1.redBright)('Ctrl + C')} to stop the server.`);
|
|
156
|
-
if (filePath) {
|
|
157
|
-
for (const entry of filePathsToWatch) {
|
|
158
|
-
console.log(`👁️ Watching changes on file ${(0, picocolors_1.blueBright)(entry)}`);
|
|
159
|
-
}
|
|
126
|
+
const server = (0, http_1.createServer)((req, res) => handle(req, res));
|
|
127
|
+
server.on('upgrade', (request, socket, head) => {
|
|
128
|
+
if (request.url === '/preview-server' && request.headers['origin'] === `http://localhost:${port}`) {
|
|
129
|
+
console.log('🔗 WebSocket connection established for the preview.');
|
|
130
|
+
wsServer.handleUpgrade(request, socket, head, (sock) => {
|
|
131
|
+
wsServer.emit('connection', sock, request);
|
|
132
|
+
});
|
|
160
133
|
}
|
|
161
134
|
else {
|
|
162
|
-
console.
|
|
163
|
-
|
|
164
|
-
if (!bundleError) {
|
|
165
|
-
(0, open_1.default)(url);
|
|
135
|
+
console.log('🔗 WebSocket connection not established.');
|
|
136
|
+
socket.destroy();
|
|
166
137
|
}
|
|
167
|
-
})
|
|
168
|
-
.on('error', (error) => {
|
|
169
|
-
console.error(`Failed to start server on port ${port}:`, error.message);
|
|
170
138
|
});
|
|
171
|
-
|
|
139
|
+
if (!bundleError) {
|
|
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
|
+
});
|
|
172
171
|
});
|
|
173
172
|
}
|
|
174
173
|
function sendQueuedMessages() {
|
|
@@ -180,12 +179,9 @@ function sendQueuedMessages() {
|
|
|
180
179
|
}
|
|
181
180
|
}
|
|
182
181
|
function isLocalRefAPath(key, value) {
|
|
183
|
-
return (typeof value === 'string' &&
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
value.startsWith('./') ||
|
|
187
|
-
value.startsWith('../') ||
|
|
188
|
-
!value.startsWith('#')));
|
|
182
|
+
return (typeof value === 'string' && key === '$ref' &&
|
|
183
|
+
(value.startsWith('.') || value.startsWith('./') ||
|
|
184
|
+
value.startsWith('../') || !value.startsWith('#')));
|
|
189
185
|
}
|
|
190
186
|
function findPathsToWatchFromSchemaRef(filePath, baseDir) {
|
|
191
187
|
if (filePath && !isValidFilePath(filePath)) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const DEFAULT_PORT =
|
|
2
|
-
export declare function start(filePath: string, port?: number): void
|
|
1
|
+
export declare const DEFAULT_PORT = 0;
|
|
2
|
+
export declare function start(filePath: string, port?: number): Promise<void>;
|
|
@@ -16,111 +16,125 @@ const picocolors_1 = require("picocolors");
|
|
|
16
16
|
const { readFile, writeFile } = fs_1.promises;
|
|
17
17
|
const sockets = [];
|
|
18
18
|
const messageQueue = [];
|
|
19
|
-
exports.DEFAULT_PORT =
|
|
19
|
+
exports.DEFAULT_PORT = 0;
|
|
20
20
|
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
|
-
|
|
24
|
+
function start(filePath_1) {
|
|
25
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (filePath, port = exports.DEFAULT_PORT) {
|
|
26
|
+
if (filePath && !isValidFilePath(filePath)) {
|
|
27
|
+
throw new specification_file_1.SpecificationFileNotFound(filePath);
|
|
28
|
+
}
|
|
29
|
+
// Locate @asyncapi/studio package
|
|
30
|
+
const studioPath = path_1.default.dirname(require.resolve('@asyncapi/studio/package.json'));
|
|
31
|
+
const app = (0, next_1.default)({
|
|
32
|
+
dev: false,
|
|
33
|
+
dir: studioPath,
|
|
34
|
+
conf: {
|
|
35
|
+
distDir: 'build',
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
const handle = app.getRequestHandler();
|
|
39
|
+
const wsServer = new ws_1.WebSocketServer({ noServer: true });
|
|
40
|
+
wsServer.on('connection', (socket) => {
|
|
41
|
+
sockets.push(socket);
|
|
42
|
+
if (filePath) {
|
|
43
|
+
getFileContent(filePath).then((code) => {
|
|
44
|
+
messageQueue.push(JSON.stringify({
|
|
45
|
+
type: 'file:loaded',
|
|
46
|
+
code,
|
|
47
|
+
}));
|
|
48
|
+
sendQueuedMessages();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
43
52
|
messageQueue.push(JSON.stringify({
|
|
44
53
|
type: 'file:loaded',
|
|
45
|
-
code,
|
|
54
|
+
code: '',
|
|
46
55
|
}));
|
|
47
56
|
sendQueuedMessages();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const json = JSON.parse(event);
|
|
60
|
-
if (filePath && json.type === 'file:update') {
|
|
61
|
-
saveFileContent(filePath, json.code);
|
|
57
|
+
}
|
|
58
|
+
socket.on('message', (event) => {
|
|
59
|
+
try {
|
|
60
|
+
const json = JSON.parse(event);
|
|
61
|
+
if (filePath && json.type === 'file:update') {
|
|
62
|
+
saveFileContent(filePath, json.code);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
console.warn('Live Server: An unknown event has been received. See details:');
|
|
66
|
+
console.log(json);
|
|
67
|
+
}
|
|
62
68
|
}
|
|
63
|
-
|
|
64
|
-
console.
|
|
65
|
-
console.log(json);
|
|
69
|
+
catch (e) {
|
|
70
|
+
console.error(`Live Server: An invalid event has been received. See details:\n${event}`);
|
|
66
71
|
}
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
console.error(`Live Server: An invalid event has been received. See details:\n${event}`);
|
|
70
|
-
}
|
|
72
|
+
});
|
|
71
73
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
wsServer.on('close', (socket) => {
|
|
75
|
+
sockets.splice(sockets.findIndex((s) => s === socket));
|
|
76
|
+
});
|
|
77
|
+
app.prepare().then(() => {
|
|
78
|
+
if (filePath) {
|
|
79
|
+
chokidar_1.default.watch(filePath).on('all', (event, path) => {
|
|
80
|
+
switch (event) {
|
|
81
|
+
case 'add':
|
|
82
|
+
case 'change':
|
|
83
|
+
getFileContent(path).then((code) => {
|
|
84
|
+
messageQueue.push(JSON.stringify({
|
|
85
|
+
type: 'file:changed',
|
|
86
|
+
code,
|
|
87
|
+
}));
|
|
88
|
+
sendQueuedMessages();
|
|
89
|
+
});
|
|
90
|
+
break;
|
|
91
|
+
case 'unlink':
|
|
83
92
|
messageQueue.push(JSON.stringify({
|
|
84
|
-
type: 'file:
|
|
85
|
-
|
|
93
|
+
type: 'file:deleted',
|
|
94
|
+
filePath,
|
|
86
95
|
}));
|
|
87
96
|
sendQueuedMessages();
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
case 'unlink':
|
|
91
|
-
messageQueue.push(JSON.stringify({
|
|
92
|
-
type: 'file:deleted',
|
|
93
|
-
filePath,
|
|
94
|
-
}));
|
|
95
|
-
sendQueuedMessages();
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
const server = (0, http_1.createServer)((req, res) => handle(req, res));
|
|
101
|
-
server.on('upgrade', (request, socket, head) => {
|
|
102
|
-
if (request.url === '/live-server') {
|
|
103
|
-
console.log('🔗 WebSocket connection established.');
|
|
104
|
-
wsServer.handleUpgrade(request, socket, head, (sock) => {
|
|
105
|
-
wsServer.emit('connection', sock, request);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
106
99
|
});
|
|
107
100
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
101
|
+
const server = (0, http_1.createServer)((req, res) => handle(req, res));
|
|
102
|
+
server.on('upgrade', (request, socket, head) => {
|
|
103
|
+
if (request.url === '/live-server') {
|
|
104
|
+
console.log('🔗 WebSocket connection established.');
|
|
105
|
+
wsServer.handleUpgrade(request, socket, head, (sock) => {
|
|
106
|
+
wsServer.emit('connection', sock, request);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
socket.destroy();
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
server.listen(port, () => {
|
|
114
|
+
const addr = server.address();
|
|
115
|
+
const listenPort = (addr && typeof addr === 'object' && 'port' in addr) ? addr.port : port;
|
|
116
|
+
const url = `http://localhost:${listenPort}?liveServer=${listenPort}&studio-version=${package_json_1.version}`;
|
|
117
|
+
console.log(`🎉 Connected to Live Server running at ${(0, picocolors_1.blueBright)(url)}.`);
|
|
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.');
|
|
125
|
+
}
|
|
126
|
+
(0, open_1.default)(url);
|
|
127
|
+
}).on('error', (error) => {
|
|
128
|
+
if (error.message.includes('EADDRINUSE')) {
|
|
129
|
+
console.log(error);
|
|
130
|
+
console.error((0, picocolors_1.redBright)(`Error: Port ${port} is already in use.`));
|
|
131
|
+
// eslint-disable-next-line no-process-exit
|
|
132
|
+
process.exit(2);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
console.error(`Failed to start server on port ${port}`);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
124
138
|
});
|
|
125
139
|
});
|
|
126
140
|
}
|
package/lib/utils/temp-dir.js
CHANGED
|
@@ -14,6 +14,7 @@ function createTempDirectory() {
|
|
|
14
14
|
function removeTempDirectory(tmpDir) {
|
|
15
15
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
try {
|
|
17
|
+
// eslint-disable-next-line no-unused-expressions
|
|
17
18
|
tmpDir &&
|
|
18
19
|
fs_1.default.existsSync(tmpDir) &&
|
|
19
20
|
(yield fs_1.promises.rm(tmpDir, { recursive: true }));
|
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": "3.
|
|
4
|
+
"version": "3.4.1",
|
|
5
5
|
"author": "@asyncapi",
|
|
6
6
|
"bin": {
|
|
7
7
|
"asyncapi": "./bin/run_bin"
|
|
@@ -173,6 +173,7 @@
|
|
|
173
173
|
"pack:macos": "oclif pack macos && npm run pack:rename",
|
|
174
174
|
"pack:linux": "oclif pack deb && npm run pack:rename",
|
|
175
175
|
"pack:tarballs": "oclif pack tarballs -t linux-x64 && npm run pack:rename",
|
|
176
|
+
"pack:tarballs:alpine": "oclif pack tarballs -t linux-x64 && npm run pack:rename alpine",
|
|
176
177
|
"pack:windows": "oclif pack win && npm run pack:rename",
|
|
177
178
|
"pack:rename": "node scripts/releasePackagesRename.js",
|
|
178
179
|
"prepublishOnly": "npm run build",
|
|
@@ -37,7 +37,7 @@ async function renameDeb({version, name, sha}) {
|
|
|
37
37
|
await checkAndRenameFile(generatedPath, newPath);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
async function renameTar({version, name, sha}) {
|
|
40
|
+
async function renameTar({version, name, sha, isAlpine}) {
|
|
41
41
|
const dist = 'dist';
|
|
42
42
|
|
|
43
43
|
const generatedPath = path.resolve(dist, `${name}-v${version}-${sha}-linux-x64.tar.gz`);
|
|
@@ -45,7 +45,9 @@ async function renameTar({version, name, sha}) {
|
|
|
45
45
|
// Creates a new `tar` directory(`dist/tar`), and moves the generated tarball inside that directory.
|
|
46
46
|
const tarDirectory = path.resolve(dist, 'tar');
|
|
47
47
|
await createDirectory(tarDirectory);
|
|
48
|
-
|
|
48
|
+
|
|
49
|
+
const fileName = isAlpine ? 'asyncapi-alpine.tar.gz' : 'asyncapi.tar.gz';
|
|
50
|
+
const newPath = path.resolve(tarDirectory, fileName);
|
|
49
51
|
await checkAndRenameFile(generatedPath, newPath);
|
|
50
52
|
}
|
|
51
53
|
|
|
@@ -69,12 +71,18 @@ async function renamePackages() {
|
|
|
69
71
|
const version = packageJson.version;
|
|
70
72
|
const name = 'asyncapi';
|
|
71
73
|
const sha = await git.revparse(['--short', 'HEAD']);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
const isAlpine = process.argv.includes('alpine');
|
|
75
|
+
|
|
76
|
+
if (isAlpine) {
|
|
77
|
+
await renameTar({version, name, sha, isAlpine: true});
|
|
78
|
+
} else {
|
|
79
|
+
await renameDeb({version: version.split('-')[0], name, sha});
|
|
80
|
+
await renamePkg({version, name, sha, arch: 'x64'});
|
|
81
|
+
await renamePkg({version, name, sha, arch: 'arm64'});
|
|
82
|
+
await renameWindows({version, name, sha, arch: 'x64'});
|
|
83
|
+
await renameWindows({version, name, sha, arch: 'x86'});
|
|
84
|
+
await renameTar({version, name, sha, isAlpine: false});
|
|
85
|
+
}
|
|
78
86
|
}
|
|
79
87
|
|
|
80
88
|
renamePackages();
|