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 cupid in cli using the relation command #143

Closed
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
40,985 changes: 20,731 additions & 20,254 deletions package-lock.json

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
{
"name": "@asyncapi/cli",
"description": "All in one CLI for all AsyncAPI tools",
"version": "0.12.4",
"version": "0.15.0",
"author": "@asyncapi",
"bin": {
"asyncapi": "./bin/run"
},
"bugs": "https://github.com/asyncapi/cli/issues",
"dependencies": {
"@asyncapi/parser": "^1.12.0",
"@asyncapi/studio": "^0.5.5",
"@fmvilas/oclif-plugin-spaced-commands": "^1.0.4",
"@oclif/command": "^1.8.0",
"@oclif/config": "^1.17.0",
"@oclif/plugin-help": "^3.2.3",
"@oclif/core": "^1.2.0",
"@asyncapi/diff": "^0.3.0",
"@asyncapi/parser": "^1.14.0",
"@asyncapi/studio": "^0.10.0",
"@types/inquirer": "^8.1.3",
"@types/ws": "^8.2.0",
"chalk": "^4.1.0",
Expand All @@ -27,14 +25,12 @@
"request": "^2.88.2",
"serve-handler": "^6.1.3",
"strip-ansi": "^6.0.0",
"tslib": "^1.14.1",
"unzipper": "^0.10.11",
"wrap-ansi": "^4.0.0",
"ws": "^8.2.3"
},
"devDependencies": {
"@oclif/dev-cli": "^1.26.0",
"@oclif/test": "^1.2.8",
"@oclif/test": "^2",
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/github": "^7.2.3",
"@semantic-release/npm": "^7.1.3",
Expand All @@ -49,7 +45,7 @@
"@typescript-eslint/eslint-plugin": "^4.28.4",
"@typescript-eslint/parser": "^4.28.4",
"acorn": "^8.5.0",
"chai": "^4.3.4",
"chai": "^4",
"conventional-changelog-conventionalcommits": "^4.4.0",
"cross-env": "^7.0.3",
"eslint": "^7.31.0",
Expand All @@ -60,13 +56,14 @@
"eslint-plugin-sonarjs": "^0.10.0",
"globby": "^10.0.2",
"markdown-toc": "^1.2.0",
"mocha": "^5.2.0",
"mocha": "^9",
"nyc": "^14.1.1",
"oclif": "^1.18.1",
"oclif": "^2",
"rimraf": "^3.0.2",
"semantic-release": "^17.4.3",
"ts-node": "^8.10.2",
"typescript": "^3.9.10"
"ts-node": "^10.2.1",
"typescript": "^4.4.3",
"tslib": "^2.3.1"
},
"engines": {
"node": ">12.16"
Expand All @@ -88,9 +85,12 @@
"commands": "./lib/commands",
"bin": "asyncapi",
"plugins": [
"@fmvilas/oclif-plugin-spaced-commands"
],
"helpClass": "./lib/help"
"topicSeparator": " ",
"topics": {
"config:context": {},
"config": {}
}
},
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -121,22 +121,22 @@
},
"repository": "asyncapi/cli",
"scripts": {
"build": "node scripts/fetch-asyncapi-example.js && tsc",
"build": "rimraf lib && node scripts/fetch-asyncapi-example.js && tsc",
"bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION",
"dev": "tsc --watch",
"generate:assets": "npm run generate:readme:toc",
"generate:readme:toc": "markdown-toc -i README.md",
"lint": "eslint --max-warnings 0 --config .eslintrc .",
"lint:fix": "eslint --max-warnings 5 --config .eslintrc . --fix",
"postpack": "rimraf oclif.manifest.json",
"prepack": "rimraf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
"prepack": "rimraf lib && tsc -b && oclif manifest && oclif readme",
"prepublishOnly": "npm run build",
"pretest": "npm run build",
"pretest:coverage": "npm run build",
"release": "semantic-release",
"start": "npm run build && node dist/cli.js",
"test": "cross-env TEST=1 nyc --extension .ts mocha --require ts-node/register --reporter spec --timeout 10000 \"test/**/*.test.ts\"",
"version": "oclif-dev readme && git add README.md",
"version": "oclif readme && git add README.md",
"test": "cross-env TEST=1 CONTEXT_FILENAME=\"./test.asyncapi\" CONTEXT_FILE_PATH=\"./\" nyc --extension .ts mocha --require ts-node/register --require test/helpers/init.js --reporter spec --timeout 10000 \"test/**/*.test.ts\"",
"readme": "oclif readme"
},
"types": "lib/index.d.ts"
Expand Down
77 changes: 77 additions & 0 deletions src/commands/relation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {flags} from '@oclif/command';
import * as cupid from '@asyncapi/cupid';
import Command from '../base';
import { load } from '../models/SpecificationFile';
import { ValidationError } from '../errors/validation-error';
import { SpecificationFileNotFound } from '../errors/specification-file';

export default class Relation extends Command {
static description = 'visualize your defined event-driven architecture'

static flags = {
help: flags.help({char: 'h'}),
type: flags.string({
char: 't',
description: 'the type of output syntax, currently supporting mermaid, plantUML and reactFlow'
}),
}

static strict = false;

static args = [
{ name: 'spec-file', description: 'spec path or context-name', required: true },
];

async loadFiles(files: string[]) {
const docs: string[] = [];

await Promise.all(files.map(async (file) => {
try {
const spec = await load(file);
docs.push(await spec.read());
} catch (err) {
if (err instanceof SpecificationFileNotFound) {
this.error(
new ValidationError({
type: 'invalid-file',
filepath: file,
})
);
} else {
this.error(err as Error);
}
}
}));
return docs;
}

async run() {
const { argv, flags } = this.parse(Relation);

const outputType = flags['type'];

let docs;

if (argv.length <= 1) {
throw this.error('Please provide more than one context/filepaths.');
}

try {
docs = await this.loadFiles(argv);
} catch (err) {
this.error(err as Error);
}

let result;
try {
if (outputType) {
result = await cupid.getRelations(docs,{syntax: outputType});
} else {
result = await cupid.getRelations(docs);
}
this.log(result);
} catch (err) {
this.error(err as Error);
}
}
}
Loading