Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new CLI architecture (part 1) #1200

Merged
merged 9 commits into from
Jun 6, 2024

Conversation

Amzani
Copy link
Collaborator

@Amzani Amzani commented Feb 23, 2024

Resolves asyncapi/server-api#485
Resolves #781

This PR introduces changes discussed in asyncapi/server-api#485 (comment) and #781 (comment)

New features

New architecture/flags extractions

.
├── adapters
│   ├── api
│   │   ├── controllers
│   │   │   ├── generator.controller.ts
│   │   │   └── ping.controller.ts
│   │   └── core
│   │       ├── app.ts
│   │       ├── constants.ts
│   │       ├── exceptions
│   │       ├── interfaces.ts
│   │       ├── logs
│   │       ├── middlewares
│   │       └── server-api.d.ts
│   └── cli
│       ├── commands
│       │   ├── bundle.ts
│       │   ├── config
│       │   ├── convert.ts
│       │   ├── diff.ts
│       │   ├── generate
│       │   ├── new
│       │   ├── optimize.ts
│       │   ├── start
│       │   └── validate.ts
│       └── core
│           ├── base.ts
│           ├── flags
│           ├── global.d.ts
│           ├── globals.ts
│           ├── hooks
│           ├── models
│           └── parser.ts
├── api.ts
├── core
│   └── services
│       ├── archiver.service.ts
│       └── generator.service.ts
├── errors
│   ├── context-error.ts
│   ├── diff-error.ts
│   ├── generator-error.ts
│   ├── specification-file.ts
│   └── validation-error.ts
├── index.ts
├── logs
├── ports
│   └── generator.interface.ts
└── utils
    ├── ajv.ts
    ├── generator.ts
    ├── logger.ts
    └── temp-dir.ts

This architecture will enable CODE Maintainers split discussed in #781

API foundations

To test the API

./bin/run start api -p 3001
curl --location 'http://localhost:3001/v1/generate' \
--data-raw '{
    "asyncapi": "asyncapi: 3.0.0\ninfo:\n  title: Account Service\n  version: 1.0.0\n  description: This service is in charge of processing user signups\nchannels:\n  userSignedup:\n    address: user/signedup\n    messages:\n      UserSignedUp:\n        $ref: '\''#/components/messages/UserSignedUp'\''\noperations:\n  sendUserSignedup:\n    action: send\n    channel:\n      $ref: '\''#/channels/userSignedup'\''\n    messages:\n      - $ref: '\''#/channels/userSignedup/messages/UserSignedUp'\''\ncomponents:\n  messages:\n    UserSignedUp:\n      payload:\n        type: object\n        properties:\n          displayName:\n            type: string\n            description: Name of the user\n          email:\n            type: string\n            format: email\n            description: Email of the user",
    "template": "@asyncapi/html-template",
    "parameters": {
        "pdf": "true"
    }
}'

http://localhost:3001/v1/ping is also available

./bin/run new file
(When Asked to open Studio - the local API will start as well

Scope

  • Migrate /generate API endpoint
  • Create Generator service
  • Split core / commands directory
  • Extract Flags

Copy link

sonarcloud bot commented Mar 15, 2024

Quality Gate Passed Quality Gate passed

Issues
78 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@Amzani
Copy link
Collaborator Author

Amzani commented Mar 15, 2024

As this PR is quite big, I'll create additional issues for

@Amzani Amzani marked this pull request as ready for review March 15, 2024 12:47
@derberg
Copy link
Member

derberg commented Mar 18, 2024

regarding this new architecture, where current package.json lands? probably each adapter will have its own, but will we use npm workspaces and keep generic package.json in root? it is needed for release pipelines so we do not have to customize them just for this repo.

also, looking at new architecture proposal. Let's imagine that I want to propose that some repos for libraries that are used in CLI and Studio should be merged here. Let's say (not consulted with anyone, just in my head for a while) we decide to merge https://github.com/asyncapi/optimizer/ in, still released as independent package, but source code developed under CLI repo. Would that be another adapter?

@Amzani
Copy link
Collaborator Author

Amzani commented Mar 19, 2024

All commands + API share the same package.json, didn't complicate things for now.

The input adapters that we have for now are CLI and API, in the example you provided it feels more like a business logic that needs to be merged and used by the optimize command. Then we might have 2 ways to do it

  1. Add it as a core service under src/core/services - especially if this logic will be shared by multiple adapters (cmd+cli)
  2. This logic is local to optimize command then it should go to adapters/cli/services

@derberg
Copy link
Member

derberg commented Mar 19, 2024

All commands + API share the same package.json, didn't complicate things for now.

one in the root?

@Amzani
Copy link
Collaborator Author

Amzani commented Mar 20, 2024

All commands + API share the same package.json, didn't complicate things for now.

one in the root?

Yes

@derberg
Copy link
Member

derberg commented Mar 21, 2024

@Amzani ok, than in theory release process should not be affected. Just keep in mind that package.json keeps the project name and version and it should eventually reflect what is published to npm. But yeah, I agree that can be done later, as in the end server-api doesn't have to go to npm, same even with CLI GitHub Action

@Shurtu-gal
Copy link
Collaborator

@Amzani I suppose we can try to merge this PR as conflicts will keep piling up.

import { Help } from '@oclif/core';

export default class Start extends Command {
static description = 'Start asyncapi studio';
static description = 'Start asyncapi studio, or asyncapi server';
Copy link
Member

@peter-rr peter-rr May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to use the start command also for running asyncapi servers? In that case, this PR might resolve #1090

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peter-rr when we have already command to start sudio, I guess we can remove this also "Start asyncapi studio" from the description : ) @Amzani

@Amzani Amzani force-pushed the samz/add-api-adapter branch 2 times, most recently from 40d7d9f to d916581 Compare June 4, 2024 12:41
@Amzani Amzani changed the title feat: new CLI architecture feat: new CLI architecture (Part 1) Jun 5, 2024
Copy link

sonarcloud bot commented Jun 5, 2024

Quality Gate Passed Quality Gate passed

Issues
12 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@Amzani Amzani changed the title feat: new CLI architecture (Part 1) feat: new CLI architecture (part 1) Jun 5, 2024
@Amzani
Copy link
Collaborator Author

Amzani commented Jun 5, 2024

As this is a big change I'll merge the changes in different PRs, for now I'm delivering part 1) which includes:

  • Split core/commands
  • Extract flags

Having API as part of CLI is not yet clear as per my comment here - If the only studio is the API consumer, and api-server package is not used why increase the complexity of CLI.
cc @smoya

Copy link
Collaborator

@Shurtu-gal Shurtu-gal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀 @Amzani.

@Amzani
Copy link
Collaborator Author

Amzani commented Jun 6, 2024

/rtm

@asyncapi-bot asyncapi-bot merged commit 26853d7 into asyncapi:master Jun 6, 2024
20 checks passed
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 1.18.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link
Member

@peter-rr peter-rr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Adding codeowners for each command Use @asyncapi/cli under the hood
6 participants