diff --git a/asyncapi.yaml b/asyncapi.yaml index 0da52aa07ad..560f49a91cc 100644 --- a/asyncapi.yaml +++ b/asyncapi.yaml @@ -1,206 +1,50 @@ -asyncapi: 3.0.0 +asyncapi: 2.0.0 info: - title: Streetlights Kafka API - version: 1.0.0 - description: > - The Smartylighting Streetlights API allows you to remotely manage the city - lights. - ### Check out its awesome features: - - * Turn a specific streetlight on/off 🌃 - * Dim a specific streetlight 😎 - * Receive real-time information about environmental lighting conditions 📈 + title: Account Service + version: "1.0.0" + description: | + Manages user accounts in the system. license: name: Apache 2.0 url: https://www.apache.org/licenses/LICENSE-2.0 -defaultContentType: application/json + servers: - scram-connections: - host: test.mykafkacluster.org:18092 - protocol: kafka-secure - description: Test broker secured with scramSha256 - security: - - $ref: "#/components/securitySchemes/saslScram" - tags: - - name: env:test-scram - description: >- - This environment is meant for running internal tests through - scramSha256 - - name: kind:remote - description: This server is a remote server. Not exposed by the application - - name: visibility:private - description: This resource is private and only available to certain users - mtls-connections: - host: test.mykafkacluster.org:28092 - protocol: kafka-secure - description: Test broker secured with X509 - security: - - $ref: "#/components/securitySchemes/certs" - tags: - - name: env:test-mtls - description: This environment is meant for running internal tests through mtls - - name: kind:remote - description: This server is a remote server. Not exposed by the application - - name: visibility:private - description: This resource is private and only available to certain users + production: + url: mqtt://test.mosquitto.org + protocol: mqtt + description: Test MQTT broker + channels: - lightingMeasured: - address: smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured - messages: - lightMeasured: - $ref: "#/components/messages/lightMeasured" - description: The topic on which measured values may be produced and consumed. - parameters: - streetlightId: - $ref: "#/components/parameters/streetlightId" - lightTurnOn: - address: smartylighting.streetlights.1.0.action.{streetlightId}.turn.on - messages: - turnOn: - $ref: "#/components/messages/turnOnOff" - parameters: - streetlightId: - $ref: "#/components/parameters/streetlightId" - lightTurnOff: - address: smartylighting.streetlights.1.0.action.{streetlightId}.turn.off - messages: - turnOff: - $ref: "#/components/messages/turnOnOff" - parameters: - streetlightId: - $ref: "#/components/parameters/streetlightId" - lightsDim: - address: smartylighting.streetlights.1.0.action.{streetlightId}.dim - messages: - dimLight: - $ref: "#/components/messages/dimLight" - parameters: - streetlightId: - $ref: "#/components/parameters/streetlightId" -operations: - receiveLightMeasurement: - action: receive - channel: - $ref: "#/channels/lightingMeasured" - summary: >- - Inform about environmental lighting conditions of a particular - streetlight. - traits: - - $ref: "#/components/operationTraits/kafka" - messages: - - $ref: "#/channels/lightingMeasured/messages/lightMeasured" - turnOn: - action: send - channel: - $ref: "#/channels/lightTurnOn" - traits: - - $ref: "#/components/operationTraits/kafka" - messages: - - $ref: "#/channels/lightTurnOn/messages/turnOn" - turnOff: - action: send - channel: - $ref: "#/channels/lightTurnOff" - traits: - - $ref: "#/components/operationTraits/kafka" - messages: - - $ref: "#/channels/lightTurnOff/messages/turnOff" - dimLight: - action: send - channel: - $ref: "#/channels/lightsDim" - traits: - - $ref: "#/components/operationTraits/kafka" - messages: - - $ref: "#/channels/lightsDim/messages/dimLight" + user/signedup: + subscribe: + operationId: emitUserSignUpEvent + message: + $ref: "#/components/messages/UserSignedUp" + components: messages: - lightMeasured: - name: lightMeasured - title: Light measured - summary: >- - Inform about environmental lighting conditions of a particular - streetlight. + UserSignedUp: + name: userSignedUp + title: User signed up event + summary: Inform about a new user registration in the system contentType: application/json - traits: - - $ref: "#/components/messageTraits/commonHeaders" payload: - $ref: "#/components/schemas/lightMeasuredPayload" - turnOnOff: - name: turnOnOff - title: Turn on/off - summary: Command a particular streetlight to turn the lights on or off. - traits: - - $ref: "#/components/messageTraits/commonHeaders" - payload: - $ref: "#/components/schemas/turnOnOffPayload" - dimLight: - name: dimLight - title: Dim light - summary: Command a particular streetlight to dim the lights. - traits: - - $ref: "#/components/messageTraits/commonHeaders" - payload: - $ref: "#/components/schemas/dimLightPayload" + $ref: "#/components/schemas/userSignedUpPayload" + schemas: - lightMeasuredPayload: + userSignedUpPayload: type: object properties: - lumens: - type: integer - minimum: 0 - description: Light intensity measured in lumens. - sentAt: - $ref: "#/components/schemas/sentAt" - turnOnOffPayload: - type: object - properties: - command: + firstName: type: string - enum: - - "on" - - "off" - description: Whether to turn on or off the light. - sentAt: - $ref: "#/components/schemas/sentAt" - dimLightPayload: - type: object - properties: - percentage: - type: integer - description: Percentage to which the light should be dimmed to. - minimum: 0 - maximum: 100 - sentAt: - $ref: "#/components/schemas/sentAt" - sentAt: - type: string - format: date-time - description: Date and time when the message was sent. - securitySchemes: - saslScram: - type: scramSha256 - description: Provide your username and password for SASL/SCRAM authentication - certs: - type: X509 - description: Download the certificate files from service provider - parameters: - streetlightId: - description: The ID of the streetlight. - messageTraits: - commonHeaders: - headers: - type: object - properties: - my-app-header: - type: integer - minimum: 0 - maximum: 100 - operationTraits: - kafka: - bindings: - kafka: - clientId: - type: string - enum: - - my-app-id + description: "foo" + lastName: + type: string + description: "bar" + email: + type: string + format: email + description: "baz" + createdAt: + type: string + format: date-time diff --git a/src/commands/new/glee.ts b/src/commands/new/glee.ts index 4aa1a6d678e..6275d5e3e92 100644 --- a/src/commands/new/glee.ts +++ b/src/commands/new/glee.ts @@ -1,8 +1,12 @@ import { Flags } from "@oclif/core"; +import { promises as fPromises } from "fs"; import Command from "../../base"; +import { resolve, join } from "path"; +import fs from "fs-extra"; export default class NewGlee extends Command { static description = "Creates a new Glee project"; + protected commandName = "glee"; static flags = { @@ -12,28 +16,89 @@ export default class NewGlee extends Command { description: "name of the project", default: "project", }), + template: Flags.string({ + char: "t", + description: "template for the project", + }), + file: Flags.string({ + char: "f", + description: "path of the file", + default: "asyncapi.yaml", + }), }; - static args = [ - { - name: "file", - description: "spec path, URL or context-name", - required: true, - }, - ]; async run() { - const { args, flags } = await this.parse(NewGlee); // NOSONAR - const { file } = args; - - const gitrepo = "https://github.com/KhudaDad414/glee-generator-template"; - try { - await this.config.runCommand("generate:fromTemplate", [ - file, - gitrepo, - `--output=${flags.name}`, - ]); - } catch (error) { - console.log(error); + const { flags } = await this.parse(NewGlee); // NOSONAR + + const { name: projectName, template, file } = flags; + + const PROJECT_DIRECTORY = join(process.cwd(), projectName); + const GLEE_TEMPLATES_DIRECTORY = resolve( + __dirname, + "../../../assets/create-glee-app/templates/default", + ); + + console.log({ GLEE_TEMPLATES_DIRECTORY }); + console.log({ file }, { template }); + if (template) { + try { + await this.config.runCommand("generate:fromTemplate", [ + file, + template, + `--output=${flags.name}`, + ]); + } catch (error) { + console.log(error); + } + } else { + try { + await fPromises.mkdir(PROJECT_DIRECTORY); + } catch (err: any) { + switch (err.code) { + case "EEXIST": + this.error( + `Unable to create the project. We tried to use "${projectName}" as the directory of your new project but it already exists (${PROJECT_DIRECTORY}). Please specify a different name for the new project. For example, run the following command instead:\n\n asyncapi new ${this.commandName} --name ${projectName}-1\n`, + ); + break; + case "EACCES": + 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()}").`, + ); + break; + case "EPERM": + 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.`, + ); + break; + default: + this.error( + `Unable to create the project. Please check the following message for further info about the error:\n\n${err}`, + ); + } + } + + try { + await fs.copy(GLEE_TEMPLATES_DIRECTORY, PROJECT_DIRECTORY); + await fPromises.rename( + `${PROJECT_DIRECTORY}/env`, + `${PROJECT_DIRECTORY}/.env`, + ); + await fPromises.rename( + `${PROJECT_DIRECTORY}/gitignore`, + `${PROJECT_DIRECTORY}/.gitignore`, + ); + await fPromises.rename( + `${PROJECT_DIRECTORY}/README-template.md`, + `${PROJECT_DIRECTORY}/README.md`, + ); + this.log( + `Your project "${projectName}" has been created successfully!\n\nNext steps:\n\n cd ${projectName}\n npm install\n npm run dev\n\nAlso, you can already open the project in your favorite editor and start tweaking it.`, + ); + } catch (err) { + this.error( + `Unable to create the project. Please check the following message for further info about the error:\n\n${err}`, + ); + } } } } diff --git a/src/commands/new/template.ts b/src/commands/new/template.ts deleted file mode 100644 index 0c4df9b351c..00000000000 --- a/src/commands/new/template.ts +++ /dev/null @@ -1,4 +0,0 @@ -const template = - 'import { GleeFunction, GleeFunctionEvent } from "@asyncapi/glee"; type PayloadType = {{payload}}; type GleeFunctionEventWithCustomPayload = GleeFunctionEvent & { payload?: PayloadType;}; const {{functionName}}: GleeFunction = async ( event: GleeFunctionEventWithCustomPayload,) => { return { reply: [{payload:`Hello from Glee! You said: "${event.payload}".`,},],};};export default {{functionName}}; '; - -export default template;