From 551e9318789c1d5d9d7e97191a27cf714c473d16 Mon Sep 17 00:00:00 2001 From: alceil Date: Thu, 10 Mar 2022 21:21:38 +0530 Subject: [PATCH 1/2] init optimize using asyncapi/optimizer --- package.json | 9 +++++---- src/commands/optimize.ts | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 src/commands/optimize.ts diff --git a/package.json b/package.json index f1f85352cde..c1150d19cd0 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" diff --git a/src/commands/optimize.ts b/src/commands/optimize.ts new file mode 100644 index 00000000000..2d7581e0223 --- /dev/null +++ b/src/commands/optimize.ts @@ -0,0 +1,19 @@ +import {Flags} from '@oclif/core'; +import Command from '../base'; +import * as optimizer from '@asyncapi/optimizer'; + +import { load } from '../models/SpecificationFile'; + +export default class Optimize extends Command { + static description = 'starts a new local instance of Studio'; + + static flags = { + help: Flags.help({ char: 'h' }), + } + + static args = [] + + async run() { + const { args,flags } = await this.parse(Optimize); + } +} From c5178e65cf716588fb1527194b8816ee61f2b9f9 Mon Sep 17 00:00:00 2001 From: alceil Date: Fri, 11 Mar 2022 10:21:37 +0530 Subject: [PATCH 2/2] added flags for optimize commands --- src/commands/optimize.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/commands/optimize.ts b/src/commands/optimize.ts index 2d7581e0223..4af46103421 100644 --- a/src/commands/optimize.ts +++ b/src/commands/optimize.ts @@ -1,19 +1,31 @@ import {Flags} from '@oclif/core'; import Command from '../base'; -import * as optimizer from '@asyncapi/optimizer'; +import { Optimizer } from '@asyncapi/optimizer'; import { load } from '../models/SpecificationFile'; export default class Optimize extends Command { - static description = 'starts a new local instance of Studio'; + 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 = [] + 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)); + } } }