Skip to content

Commit

Permalink
Merge pull request #16 from cap-js/plugin-to-package
Browse files Browse the repository at this point in the history
Plugin to reuse library
  • Loading branch information
jeevitha011 authored Apr 24, 2024
2 parents feaaa4e + 683d878 commit 4357131
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 122 deletions.
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,15 @@

# AsyncAPI Plugin

The `@cap-js/asyncapi` package is a [CDS plugin](https://cap.cloud.sap/docs/node.js/cds-plugins#cds-plugin-packages) that provides support for AsyncAPI document compilation.
The `@cap-js/asyncapi` is a package that provides support for AsyncAPI document compilation.

### Table of Contents

- [Setup](#setup)
- [Generate AsyncAPI document](#generate-asyncapi-document)
- [Contributing](#contributing)
- [Code of Conduct](#code-of-conduct)
- [Licensing](#licensing)

## Setup

To use `cds compile --to asyncapi` functionality, simply add this self-configuring plugin package to your project:

```sh
npm add @cap-js/asyncapi
```

In this guide, we use the [Incidents Management reference sample app](https://github.com/cap-js/incidents-app) as the base, to generate the AsyncAPI document for the `services.cds` file.

## Generate AsyncAPI document

### 1. Usage of programatic API
Expand Down
1 change: 0 additions & 1 deletion cds-plugin.js

This file was deleted.

17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const cds = require('@sap/cds')

function _lazyRegisterCompileTarget() {
const value = require('./lib/compile/index')
Object.defineProperty(this, "asyncapi", { value })
return value
}

const registerAsyncapiCompileTarget = () => {
Object.defineProperty(cds.compile.to, "asyncapi", {
get: _lazyRegisterCompileTarget,
configurable: true
})
}


module.exports = { registerAsyncapiCompileTarget }
17 changes: 0 additions & 17 deletions lib/compile/api.js

This file was deleted.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@cap-js/asyncapi",
"version": "1.0.0",
"description": "CAP Plugin for AsyncAPI",
"description": "CAP tool for AsyncAPI",
"repository": {
"type": "git",
"url": "git+https://github.com/cap-js/asyncapi.git"
Expand All @@ -15,9 +15,8 @@
],
"author": "SAP SE (https://www.sap.com)",
"license": "SEE LICENSE IN LICENSE",
"main": "cds-plugin.js",
"main": "index.js",
"files": [
"cds-plugin.js",
"lib/"
],
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/lib/compile/asyncapiOptions.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const toAsyncAPI = require('../../../lib/compile');
require('../../../cds-plugin')
require('../../../').registerAsyncapiCompileTarget();
const cds = require('@sap/cds');
const { readdir, read, path: { resolve } } = cds.utils;
const { join } = require('path');
Expand Down
10 changes: 0 additions & 10 deletions xmpl/.cdsrc.json

This file was deleted.

3 changes: 0 additions & 3 deletions xmpl/.gitignore

This file was deleted.

Empty file removed xmpl/README.md
Empty file.
13 changes: 0 additions & 13 deletions xmpl/package.json

This file was deleted.

14 changes: 0 additions & 14 deletions xmpl/srv/server.js

This file was deleted.

48 changes: 0 additions & 48 deletions xmpl/srv/services.cds

This file was deleted.

0 comments on commit 4357131

Please sign in to comment.