@asyncapi/cli 3.6.0 → 4.0.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/oclif.manifest.json +1 -64
- package/package.json +1 -1
- package/assets/create-glee-app/templates/default/LICENSE +0 -199
- package/assets/create-glee-app/templates/default/README-template.md +0 -31
- package/assets/create-glee-app/templates/default/asyncapi.yaml +0 -28
- package/assets/create-glee-app/templates/default/env +0 -1
- package/assets/create-glee-app/templates/default/functions/onHello.ts +0 -11
- package/assets/create-glee-app/templates/default/gitignore +0 -103
- package/assets/create-glee-app/templates/default/lifecycle/onConnect.js +0 -6
- package/assets/create-glee-app/templates/default/package-lock.json +0 -13753
- package/assets/create-glee-app/templates/default/package.json +0 -32
- package/assets/create-glee-app/templates/default/tsconfig.json +0 -10
- package/assets/create-glee-app/templates/tutorial/LICENSE +0 -199
- package/assets/create-glee-app/templates/tutorial/README-template.md +0 -17
- package/assets/create-glee-app/templates/tutorial/asyncapi.yaml +0 -41
- package/assets/create-glee-app/templates/tutorial/docs/asyncapi.md +0 -24
- package/assets/create-glee-app/templates/tutorial/env +0 -1
- package/assets/create-glee-app/templates/tutorial/functions/onLightMeasured.js +0 -4
- package/assets/create-glee-app/templates/tutorial/gitignore +0 -103
- package/assets/create-glee-app/templates/tutorial/package-lock.json +0 -13751
- package/assets/create-glee-app/templates/tutorial/package.json +0 -21
- package/assets/create-glee-app/templates/tutorial/tsconfig.json +0 -9
- package/lib/apps/cli/commands/new/glee.d.ts +0 -26
- package/lib/apps/cli/commands/new/glee.js +0 -177
- package/lib/apps/cli/internal/flags/new/glee.flags.d.ts +0 -7
- package/lib/apps/cli/internal/flags/new/glee.flags.js +0 -28
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "glee-tutorial",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"description": "Tutorial from the AsyncAPI website.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"engines": {
|
|
7
|
-
"node": ">=14.15.1"
|
|
8
|
-
},
|
|
9
|
-
"scripts": {
|
|
10
|
-
"dev": "glee dev",
|
|
11
|
-
"start": "glee start"
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"glee"
|
|
15
|
-
],
|
|
16
|
-
"author": "Fran Mendez",
|
|
17
|
-
"license": "Apache-2.0",
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"@asyncapi/glee": "^0.37.9"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import Command from '../../internal/base';
|
|
2
|
-
import { Specification } from '../../../../domains/models/SpecificationFile';
|
|
3
|
-
export declare const successMessage: (projectName: string) => string;
|
|
4
|
-
export default class NewGlee extends Command {
|
|
5
|
-
static description: string;
|
|
6
|
-
protected commandName: string;
|
|
7
|
-
static readonly successMessage: (projectName: string) => string;
|
|
8
|
-
static readonly errorMessages: {
|
|
9
|
-
alreadyExists: (projectName: string) => string;
|
|
10
|
-
};
|
|
11
|
-
static flags: {
|
|
12
|
-
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
13
|
-
name: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
14
|
-
template: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
15
|
-
file: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
16
|
-
'force-write': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
17
|
-
};
|
|
18
|
-
getFilteredServers(serversObject: any): Promise<string[]>;
|
|
19
|
-
createTemporaryFile(asyncapiInput: Specification, filteredRemoteServers: string[], file: any): Promise<{
|
|
20
|
-
currentFileDirectory: string;
|
|
21
|
-
updatedAsyncApiContent: string;
|
|
22
|
-
}>;
|
|
23
|
-
validateFile(file: any, projectName: any, PROJECT_DIRECTORY: any): Promise<void>;
|
|
24
|
-
handleGenerateProjectWithFile(file: any, CURRENT_GLEE_TEMPLATE: any, projectName: string, forceWrite: boolean): Promise<void>;
|
|
25
|
-
run(): Promise<void>;
|
|
26
|
-
}
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.successMessage = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
7
|
-
const path_1 = tslib_1.__importStar(require("path"));
|
|
8
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
9
|
-
const SpecificationFile_1 = require("../../../../domains/models/SpecificationFile");
|
|
10
|
-
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
11
|
-
const inquirer_1 = require("inquirer");
|
|
12
|
-
// eslint-disable-next-line
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
const generator_1 = tslib_1.__importDefault(require("@asyncapi/generator"));
|
|
15
|
-
const picocolors_1 = require("picocolors");
|
|
16
|
-
const glee_flags_1 = require("../../internal/flags/new/glee.flags");
|
|
17
|
-
const successMessage = (projectName) => `🎉 Your Glee project has been successfully created!
|
|
18
|
-
⏩ Next steps: follow the instructions ${(0, picocolors_1.cyan)('below')} to manage your project:
|
|
19
|
-
|
|
20
|
-
cd ${projectName}\t\t ${(0, picocolors_1.gray)('# Navigate to the project directory')}
|
|
21
|
-
npm install\t\t ${(0, picocolors_1.gray)('# Install the project dependencies')}
|
|
22
|
-
npm run dev\t\t ${(0, picocolors_1.gray)('# Start the project in development mode')}
|
|
23
|
-
|
|
24
|
-
You can also open the project in your favourite editor and start tweaking it.
|
|
25
|
-
`;
|
|
26
|
-
exports.successMessage = successMessage;
|
|
27
|
-
const errorMessages = {
|
|
28
|
-
alreadyExists: (projectName) => `Unable to create the project because the directory "${(0, picocolors_1.cyan)(projectName)}" already exists at "${process.cwd()}/${projectName}".
|
|
29
|
-
To specify a different name for the new project, please run the command below with a unique project name:
|
|
30
|
-
|
|
31
|
-
${(0, picocolors_1.gray)('asyncapi new glee --name ') + (0, picocolors_1.gray)(projectName) + (0, picocolors_1.gray)('-1')}`,
|
|
32
|
-
};
|
|
33
|
-
class NewGlee extends base_1.default {
|
|
34
|
-
constructor() {
|
|
35
|
-
super(...arguments);
|
|
36
|
-
this.commandName = 'glee';
|
|
37
|
-
}
|
|
38
|
-
getFilteredServers(serversObject) {
|
|
39
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
console.log({ serversObject });
|
|
41
|
-
const servers = Object.keys(serversObject);
|
|
42
|
-
const localServers = yield (0, inquirer_1.prompt)([
|
|
43
|
-
{
|
|
44
|
-
name: 'LOCAL_SERVERS',
|
|
45
|
-
message: 'Select all of the servers that you want glee to set up and run a server for (local servers):',
|
|
46
|
-
type: 'checkbox',
|
|
47
|
-
choices() {
|
|
48
|
-
return servers;
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
]);
|
|
52
|
-
return servers.filter((server) => !localServers.LOCAL_SERVERS.includes(server));
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
createTemporaryFile(asyncapiInput, filteredRemoteServers, file) {
|
|
56
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
const asyncapiObject = asyncapiInput.toJson();
|
|
58
|
-
asyncapiObject['x-remoteServers'] = filteredRemoteServers;
|
|
59
|
-
delete asyncapiObject.filePath;
|
|
60
|
-
delete asyncapiObject.kind;
|
|
61
|
-
const updatedAsyncApiContent = js_yaml_1.default.dump(asyncapiObject, {
|
|
62
|
-
lineWidth: -1,
|
|
63
|
-
});
|
|
64
|
-
const currentFileDirectory = path_1.default.join(__dirname, file);
|
|
65
|
-
fs_extra_1.default.writeFileSync(currentFileDirectory, updatedAsyncApiContent);
|
|
66
|
-
return { currentFileDirectory, updatedAsyncApiContent };
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
validateFile(file, projectName, PROJECT_DIRECTORY) {
|
|
70
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
try {
|
|
72
|
-
const validExtensions = ['.yaml', '.yml', '.json'];
|
|
73
|
-
const fileExtension = path_1.default.extname(file);
|
|
74
|
-
if (!validExtensions.includes(fileExtension)) {
|
|
75
|
-
throw new Error('CLI Support only yml, yaml, and json extension for file');
|
|
76
|
-
}
|
|
77
|
-
if (fs_extra_1.default.existsSync(PROJECT_DIRECTORY) &&
|
|
78
|
-
fs_extra_1.default.readdirSync(PROJECT_DIRECTORY).length > 0) {
|
|
79
|
-
throw new Error(errorMessages.alreadyExists(projectName));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
this.log(error.message);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
handleGenerateProjectWithFile(file, CURRENT_GLEE_TEMPLATE, projectName, forceWrite) {
|
|
88
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
89
|
-
var _a;
|
|
90
|
-
const PROJECT_DIRECTORY = path_1.default.join(process.cwd(), projectName);
|
|
91
|
-
yield this.validateFile(file, projectName, PROJECT_DIRECTORY);
|
|
92
|
-
try {
|
|
93
|
-
console.log(file);
|
|
94
|
-
const asyncapiInput = (yield (0, SpecificationFile_1.load)(file)) || (yield (0, SpecificationFile_1.load)());
|
|
95
|
-
console.log(asyncapiInput);
|
|
96
|
-
const serversObject = (_a = asyncapiInput.toJson()) === null || _a === void 0 ? void 0 : _a.servers;
|
|
97
|
-
let filteredRemoteServers = [];
|
|
98
|
-
if (serversObject) {
|
|
99
|
-
filteredRemoteServers = yield this.getFilteredServers(serversObject);
|
|
100
|
-
}
|
|
101
|
-
const temporaryFileDirectory = 'asyncapi.yaml';
|
|
102
|
-
const { currentFileDirectory, updatedAsyncApiContent } = yield this.createTemporaryFile(asyncapiInput, filteredRemoteServers, temporaryFileDirectory);
|
|
103
|
-
const generator = new generator_1.default(CURRENT_GLEE_TEMPLATE, PROJECT_DIRECTORY, { forceWrite });
|
|
104
|
-
yield generator.generateFromString(updatedAsyncApiContent);
|
|
105
|
-
fs_extra_1.default.unlinkSync(currentFileDirectory);
|
|
106
|
-
this.log(`Success! Created ${projectName} at ${PROJECT_DIRECTORY}\n\nNext steps:\n\n cd ${projectName}\n npm install --ignore-scripts\n\nImplement the function in functions and auth folder and run the project with:\n npm run dev`);
|
|
107
|
-
}
|
|
108
|
-
catch (err) {
|
|
109
|
-
switch (err.code) {
|
|
110
|
-
case 'EACCES':
|
|
111
|
-
this.error(`Unable to create the project. We tried to access the "${PROJECT_DIRECTORY}" directory but it was not possible due to file access permissions. Please check the write permissions of your current working directory ("${process.cwd()}").`);
|
|
112
|
-
break;
|
|
113
|
-
case 'EPERM':
|
|
114
|
-
this.error(`Unable to create the project. We tried to create the "${PROJECT_DIRECTORY}" directory but the operation requires elevated privileges. Please check the privileges for your current user.`);
|
|
115
|
-
break;
|
|
116
|
-
default:
|
|
117
|
-
this.error(`Unable to create the project. Please check the following message for further info about the error:\n\n${err}`);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
run() {
|
|
123
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
const { flags } = yield this.parse(NewGlee); // NOSONAR
|
|
125
|
-
const { name: projectName, template: templateName, file, 'force-write': forceWrite, } = flags;
|
|
126
|
-
const PROJECT_DIRECTORY = (0, path_1.join)(process.cwd(), projectName);
|
|
127
|
-
const GLEE_TEMPLATES_DIRECTORY = (0, path_1.resolve)(__dirname, '../../../../../assets/create-glee-app/templates/', templateName);
|
|
128
|
-
const CURRENT_GLEE_TEMPLATE = 'https://github.com/KhudaDad414/glee-generator-template';
|
|
129
|
-
if (file && templateName && templateName !== 'default') {
|
|
130
|
-
this.error('You cannot use both --t and --f in the same command.');
|
|
131
|
-
}
|
|
132
|
-
if (file) {
|
|
133
|
-
console.log('file running');
|
|
134
|
-
yield this.handleGenerateProjectWithFile(file, CURRENT_GLEE_TEMPLATE, projectName, forceWrite);
|
|
135
|
-
this.specFile = yield (0, SpecificationFile_1.load)(flags.file);
|
|
136
|
-
this.metricsMetadata.template = flags.template;
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
try {
|
|
140
|
-
yield fs_1.promises.mkdir(PROJECT_DIRECTORY);
|
|
141
|
-
}
|
|
142
|
-
catch (err) {
|
|
143
|
-
switch (err.code) {
|
|
144
|
-
case 'EEXIST':
|
|
145
|
-
this.error(errorMessages.alreadyExists(projectName));
|
|
146
|
-
break;
|
|
147
|
-
case 'EACCES':
|
|
148
|
-
this.error(`Unable to create the project. We tried to access the "${PROJECT_DIRECTORY}" directory but it was not possible due to file access permissions. Please check the write permissions of your current working directory ("${process.cwd()}").`);
|
|
149
|
-
break;
|
|
150
|
-
case 'EPERM':
|
|
151
|
-
this.error(`Unable to create the project. We tried to create the "${PROJECT_DIRECTORY}" directory but the operation requires elevated privileges. Please check the privileges for your current user.`);
|
|
152
|
-
break;
|
|
153
|
-
default:
|
|
154
|
-
this.error(`Unable to create the project. Please check the following message for further info about the error:\n\n${err}`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
try {
|
|
158
|
-
yield fs_extra_1.default.copy(GLEE_TEMPLATES_DIRECTORY, PROJECT_DIRECTORY);
|
|
159
|
-
yield fs_1.promises.rename(`${PROJECT_DIRECTORY}/env`, `${PROJECT_DIRECTORY}/.env`);
|
|
160
|
-
yield fs_1.promises.rename(`${PROJECT_DIRECTORY}/gitignore`, `${PROJECT_DIRECTORY}/.gitignore`);
|
|
161
|
-
yield fs_1.promises.rename(`${PROJECT_DIRECTORY}/README-template.md`, `${PROJECT_DIRECTORY}/README.md`);
|
|
162
|
-
this.log((0, exports.successMessage)(projectName));
|
|
163
|
-
}
|
|
164
|
-
catch (err) {
|
|
165
|
-
this.error(`Unable to create the project. Please check the following message for further info about the error:\n\n${err}`);
|
|
166
|
-
}
|
|
167
|
-
this.specFile = yield (0, SpecificationFile_1.load)(`${GLEE_TEMPLATES_DIRECTORY}/asyncapi.yaml`);
|
|
168
|
-
this.metricsMetadata.template = flags.template;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
NewGlee.description = 'Creates a new Glee project';
|
|
174
|
-
NewGlee.successMessage = exports.successMessage;
|
|
175
|
-
NewGlee.errorMessages = errorMessages;
|
|
176
|
-
NewGlee.flags = (0, glee_flags_1.gleeFlags)();
|
|
177
|
-
exports.default = NewGlee;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const gleeFlags: () => {
|
|
2
|
-
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
3
|
-
name: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
4
|
-
template: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
5
|
-
file: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
6
|
-
'force-write': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
7
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gleeFlags = void 0;
|
|
4
|
-
const core_1 = require("@oclif/core");
|
|
5
|
-
const gleeFlags = () => {
|
|
6
|
-
return {
|
|
7
|
-
help: core_1.Flags.help({ char: 'h' }),
|
|
8
|
-
name: core_1.Flags.string({
|
|
9
|
-
char: 'n',
|
|
10
|
-
description: 'Name of the Project',
|
|
11
|
-
default: 'project',
|
|
12
|
-
}),
|
|
13
|
-
template: core_1.Flags.string({
|
|
14
|
-
char: 't',
|
|
15
|
-
description: 'Name of the Template',
|
|
16
|
-
default: 'default',
|
|
17
|
-
}),
|
|
18
|
-
file: core_1.Flags.string({
|
|
19
|
-
char: 'f',
|
|
20
|
-
description: 'The path to the AsyncAPI file for generating a Glee project.',
|
|
21
|
-
}),
|
|
22
|
-
'force-write': core_1.Flags.boolean({
|
|
23
|
-
default: false,
|
|
24
|
-
description: 'Force writing of the generated files to given directory even if it is a git repo with unstaged files or not empty dir (defaults to false)',
|
|
25
|
-
}),
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
exports.gleeFlags = gleeFlags;
|