@asyncapi/cli 2.0.4 → 2.1.0
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-template/templates/default/asyncapi.yaml +34 -0
- package/assets/create-template/templates/default/package.json +10 -0
- package/assets/create-template/templates/default/readme.md +4 -0
- package/assets/create-template/templates/default/template/index.js +11 -0
- package/lib/commands/new/template.d.ts +19 -0
- package/lib/commands/new/template.js +103 -0
- package/lib/core/flags/new/template.flags.d.ts +8 -0
- package/lib/core/flags/new/template.flags.js +33 -0
- package/oclif.manifest.json +71 -1
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
asyncapi: 3.0.0
|
|
2
|
+
info:
|
|
3
|
+
title: Temperature Service
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
description: This service is in charge of processing all the events related to temperature.
|
|
6
|
+
|
|
7
|
+
servers:
|
|
8
|
+
dev:
|
|
9
|
+
url: test.mosquitto.org
|
|
10
|
+
protocol: mqtt
|
|
11
|
+
|
|
12
|
+
channels:
|
|
13
|
+
temperature/changed:
|
|
14
|
+
description: Updates the bedroom temperature in the database when the temperature drops or goes up.
|
|
15
|
+
publish:
|
|
16
|
+
operationId: temperatureChange
|
|
17
|
+
message:
|
|
18
|
+
description: Message that is being sent when the temperature in the bedroom changes.
|
|
19
|
+
contentType: application/json
|
|
20
|
+
payload:
|
|
21
|
+
type: object
|
|
22
|
+
additionalProperties: false
|
|
23
|
+
properties:
|
|
24
|
+
temperatureId:
|
|
25
|
+
type: string
|
|
26
|
+
|
|
27
|
+
components:
|
|
28
|
+
schemas:
|
|
29
|
+
temperatureId:
|
|
30
|
+
type: object
|
|
31
|
+
additionalProperties: false
|
|
32
|
+
properties:
|
|
33
|
+
temperatureId:
|
|
34
|
+
type: string
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { File, Text } from '@asyncapi/generator-react-sdk';
|
|
2
|
+
|
|
3
|
+
// Pass the others parameters to get the specificatin of the asyncapi document
|
|
4
|
+
export default function ({ asyncapi }) {
|
|
5
|
+
return (
|
|
6
|
+
<File name="asyncapi.md">
|
|
7
|
+
<Text>My application's markdown file.</Text>
|
|
8
|
+
<Text>App name: **{asyncapi.info().title()}**</Text>
|
|
9
|
+
</File>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Command from '../../core/base';
|
|
2
|
+
export declare const successMessage: (projectName: string) => string;
|
|
3
|
+
export default class template extends Command {
|
|
4
|
+
static description: string;
|
|
5
|
+
protected commandName: string;
|
|
6
|
+
static readonly successMessage: (projectName: string) => string;
|
|
7
|
+
static readonly errorMessages: {
|
|
8
|
+
alreadyExists: (projectName: string) => string;
|
|
9
|
+
};
|
|
10
|
+
static flags: {
|
|
11
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
12
|
+
name: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
13
|
+
template: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
14
|
+
file: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
15
|
+
'force-write': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
renderer: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
17
|
+
};
|
|
18
|
+
run(): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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("../../core/base"));
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const SpecificationFile_1 = require("../../core/models/SpecificationFile");
|
|
9
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
10
|
+
const template_flags_1 = require("../../core/flags/new/template.flags");
|
|
11
|
+
const picocolors_1 = require("picocolors");
|
|
12
|
+
const jsonfile_1 = tslib_1.__importDefault(require("jsonfile"));
|
|
13
|
+
const path_2 = tslib_1.__importDefault(require("path"));
|
|
14
|
+
const successMessage = (projectName) => `🎉 Your template is succesfully created
|
|
15
|
+
⏩ Next steps: follow the instructions ${(0, picocolors_1.cyan)('below')} to manage your project:
|
|
16
|
+
|
|
17
|
+
cd ${projectName}\t\t ${(0, picocolors_1.gray)('# Navigate to the project directory')}
|
|
18
|
+
npm install\t\t ${(0, picocolors_1.gray)('# Install the project dependencies')}
|
|
19
|
+
asyncapi generate fromTemplate <templateName> ../${projectName} \t\t ${(0, picocolors_1.gray)('# Execute the template from anasyncapi document')}
|
|
20
|
+
|
|
21
|
+
You can also open the project in your favourite editor and start tweaking it.
|
|
22
|
+
`;
|
|
23
|
+
exports.successMessage = successMessage;
|
|
24
|
+
const errorMessages = {
|
|
25
|
+
alreadyExists: (projectName) => `Unable to create the project because the directory "${(0, picocolors_1.cyan)(projectName)}" already exists at "${process.cwd()}/${projectName}".
|
|
26
|
+
To specify a different name for the new project, please run the command below with a unique project name:
|
|
27
|
+
|
|
28
|
+
${(0, picocolors_1.gray)('asyncapi new template --name ') + (0, picocolors_1.gray)(projectName) + (0, picocolors_1.gray)('-1')}`,
|
|
29
|
+
};
|
|
30
|
+
class template extends base_1.default {
|
|
31
|
+
constructor() {
|
|
32
|
+
super(...arguments);
|
|
33
|
+
this.commandName = 'template';
|
|
34
|
+
}
|
|
35
|
+
run() {
|
|
36
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const { flags } = yield this.parse(template); // NOSONAR
|
|
38
|
+
const { name: projectName, template: templateName, renderer: rendererName } = flags;
|
|
39
|
+
const PROJECT_DIRECTORY = (0, path_1.join)(process.cwd(), projectName);
|
|
40
|
+
if (rendererName !== 'nunjucks' && rendererName !== 'react') {
|
|
41
|
+
this.error('Invalid flag check the flag name of renderer');
|
|
42
|
+
}
|
|
43
|
+
const templateDirectory = (0, path_1.resolve)(__dirname, '../../../assets/create-template/templates/', templateName);
|
|
44
|
+
{
|
|
45
|
+
try {
|
|
46
|
+
yield fs_1.promises.mkdir(PROJECT_DIRECTORY);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
switch (err.code) {
|
|
50
|
+
case 'EEXIST':
|
|
51
|
+
this.error(errorMessages.alreadyExists(projectName));
|
|
52
|
+
break;
|
|
53
|
+
case 'EACCES':
|
|
54
|
+
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()}").`);
|
|
55
|
+
break;
|
|
56
|
+
case 'EPERM':
|
|
57
|
+
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.`);
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
this.error(`Unable to create the project. Please check the following message for further info about the error:\n\n${err}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
yield copyAndModify(templateDirectory, PROJECT_DIRECTORY, rendererName, projectName);
|
|
65
|
+
this.log((0, exports.successMessage)(projectName));
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
this.error(`Unable to create the project. Please check the following message for further info about the error:\n\n${err}`);
|
|
69
|
+
}
|
|
70
|
+
this.specFile = yield (0, SpecificationFile_1.load)(`${templateDirectory}/asyncapi.yaml`);
|
|
71
|
+
this.metricsMetadata.template = flags.template;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.default = template;
|
|
77
|
+
template.description = 'Creates a new template';
|
|
78
|
+
template.successMessage = exports.successMessage;
|
|
79
|
+
template.errorMessages = errorMessages;
|
|
80
|
+
template.flags = (0, template_flags_1.templateFlags)();
|
|
81
|
+
function copyAndModify(templateDirectory, PROJECT_DIRECTORY, rendererName, projectName) {
|
|
82
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const packageJsonPath = path_2.default.join(templateDirectory, 'package.json');
|
|
84
|
+
try {
|
|
85
|
+
yield fs_extra_1.default.copy(templateDirectory, PROJECT_DIRECTORY, {
|
|
86
|
+
filter: (src) => {
|
|
87
|
+
return !src.endsWith('package.json');
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const packageData = yield jsonfile_1.default.readFile(packageJsonPath);
|
|
91
|
+
if ((packageData.generator && 'renderer' in packageData.generator)) {
|
|
92
|
+
packageData.generator.renderer = rendererName;
|
|
93
|
+
}
|
|
94
|
+
if (packageData.name) {
|
|
95
|
+
packageData.name = projectName;
|
|
96
|
+
}
|
|
97
|
+
yield fs_extra_1.default.writeJSON(`${PROJECT_DIRECTORY}/package.json`, packageData, { spaces: 2 });
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
console.error('Error:', err);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const templateFlags: () => {
|
|
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
|
+
renderer: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.templateFlags = void 0;
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const templateFlags = () => {
|
|
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 template.',
|
|
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
|
+
renderer: core_1.Flags.string({
|
|
27
|
+
char: 'r',
|
|
28
|
+
default: 'react',
|
|
29
|
+
description: 'Creating a template for particular engine, Its value can be either react or nunjucks.'
|
|
30
|
+
})
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
exports.templateFlags = templateFlags;
|
package/oclif.manifest.json
CHANGED
|
@@ -1159,6 +1159,76 @@
|
|
|
1159
1159
|
"index.js"
|
|
1160
1160
|
]
|
|
1161
1161
|
},
|
|
1162
|
+
"new:template": {
|
|
1163
|
+
"aliases": [],
|
|
1164
|
+
"args": {},
|
|
1165
|
+
"description": "Creates a new template",
|
|
1166
|
+
"flags": {
|
|
1167
|
+
"help": {
|
|
1168
|
+
"char": "h",
|
|
1169
|
+
"description": "Show CLI help.",
|
|
1170
|
+
"name": "help",
|
|
1171
|
+
"allowNo": false,
|
|
1172
|
+
"type": "boolean"
|
|
1173
|
+
},
|
|
1174
|
+
"name": {
|
|
1175
|
+
"char": "n",
|
|
1176
|
+
"description": "Name of the Project",
|
|
1177
|
+
"name": "name",
|
|
1178
|
+
"default": "project",
|
|
1179
|
+
"hasDynamicHelp": false,
|
|
1180
|
+
"multiple": false,
|
|
1181
|
+
"type": "option"
|
|
1182
|
+
},
|
|
1183
|
+
"template": {
|
|
1184
|
+
"char": "t",
|
|
1185
|
+
"description": "Name of the Template",
|
|
1186
|
+
"name": "template",
|
|
1187
|
+
"default": "default",
|
|
1188
|
+
"hasDynamicHelp": false,
|
|
1189
|
+
"multiple": false,
|
|
1190
|
+
"type": "option"
|
|
1191
|
+
},
|
|
1192
|
+
"file": {
|
|
1193
|
+
"char": "f",
|
|
1194
|
+
"description": "The path to the AsyncAPI file for generating a template.",
|
|
1195
|
+
"name": "file",
|
|
1196
|
+
"hasDynamicHelp": false,
|
|
1197
|
+
"multiple": false,
|
|
1198
|
+
"type": "option"
|
|
1199
|
+
},
|
|
1200
|
+
"force-write": {
|
|
1201
|
+
"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)",
|
|
1202
|
+
"name": "force-write",
|
|
1203
|
+
"allowNo": false,
|
|
1204
|
+
"type": "boolean"
|
|
1205
|
+
},
|
|
1206
|
+
"renderer": {
|
|
1207
|
+
"char": "r",
|
|
1208
|
+
"description": "Creating a template for particular engine, Its value can be either react or nunjucks.",
|
|
1209
|
+
"name": "renderer",
|
|
1210
|
+
"default": "react",
|
|
1211
|
+
"hasDynamicHelp": false,
|
|
1212
|
+
"multiple": false,
|
|
1213
|
+
"type": "option"
|
|
1214
|
+
}
|
|
1215
|
+
},
|
|
1216
|
+
"hasDynamicHelp": false,
|
|
1217
|
+
"hiddenAliases": [],
|
|
1218
|
+
"id": "new:template",
|
|
1219
|
+
"pluginAlias": "@asyncapi/cli",
|
|
1220
|
+
"pluginName": "@asyncapi/cli",
|
|
1221
|
+
"pluginType": "core",
|
|
1222
|
+
"strict": true,
|
|
1223
|
+
"errorMessages": {},
|
|
1224
|
+
"isESM": false,
|
|
1225
|
+
"relativePath": [
|
|
1226
|
+
"lib",
|
|
1227
|
+
"commands",
|
|
1228
|
+
"new",
|
|
1229
|
+
"template.js"
|
|
1230
|
+
]
|
|
1231
|
+
},
|
|
1162
1232
|
"start": {
|
|
1163
1233
|
"aliases": [],
|
|
1164
1234
|
"args": {},
|
|
@@ -1497,5 +1567,5 @@
|
|
|
1497
1567
|
]
|
|
1498
1568
|
}
|
|
1499
1569
|
},
|
|
1500
|
-
"version": "2.0
|
|
1570
|
+
"version": "2.1.0"
|
|
1501
1571
|
}
|