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: integrate asyncapi optimize library using the optimize command #255

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
},
"bugs": "https://github.com/asyncapi/cli/issues",
"dependencies": {
"@oclif/core": "^1.2.0",
"@asyncapi/diff": "^0.3.0",
"@asyncapi/optimizer": "^0.1.6",
"@asyncapi/parser": "^1.14.0",
"@oclif/plugin-not-found": "^2.3.1",
"@asyncapi/studio": "^0.10.0",
"@oclif/core": "^1.2.0",
"@oclif/plugin-not-found": "^2.3.1",
"@types/inquirer": "^8.1.3",
"@types/ws": "^8.2.0",
"chalk": "^4.1.0",
Expand Down Expand Up @@ -63,8 +64,8 @@
"rimraf": "^3.0.2",
"semantic-release": "^17.4.3",
"ts-node": "^10.4.0",
"typescript": "^4.4.3",
"tslib": "^2.3.1"
"tslib": "^2.3.1",
"typescript": "^4.4.3"
},
"engines": {
"node": ">12.16"
Expand Down
31 changes: 31 additions & 0 deletions src/commands/optimize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {Flags} from '@oclif/core';
import Command from '../base';
import { Optimizer } from '@asyncapi/optimizer';

import { load } from '../models/SpecificationFile';

export default class Optimize extends Command {
static description = 'It enables users to optimize single AsyncAPI file';

static flags = {
help: Flags.help({ char: 'h' }),
report: Flags.boolean({ char: 'r', description: 'generates report' }),
}

static args = [
{ name: 'file', description: 'context,filepath or url', required: true },
]

async run() {
const { args,flags } = await this.parse(Optimize);
const filePath = args['file'];
const file = await load(filePath);
const optimizer = new Optimizer(file);
const report = optimizer.getOptimizedDocument();
this.log(report);
if (flags.report) {
const report = await optimizer.getReport();
this.log(String(report));
}
}
}