Skip to content

Commit

Permalink
Merge pull request #21 from cap-js/remove-compile-target
Browse files Browse the repository at this point in the history
remove registering compile target
  • Loading branch information
jeevitha011 authored May 14, 2024
2 parents 8a1106b + ce91110 commit 5aa5b18
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 44 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Version 1.0.0 - 14.05.2024

### Changed

- Removed registering compile target

## Version 1.0.0 - 02.05.2024

### Added
Expand Down
31 changes: 6 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ The `@cap-js/asyncapi` is a package that provides support for AsyncAPI document
### Table of Contents

- [Requirements and Setup](#requirements-and-setup)
- [Generate AsyncAPI document](#generate-asyncapi-document)
- [Contributing](#contributing)
- [Code of Conduct](#code-of-conduct)
- [Licensing](#licensing)
Expand All @@ -24,34 +23,16 @@ $ npm install @cap-js/asyncapi

### Usage

```sh
require("@cap-js/asyncapi").register()
```

## Generate AsyncAPI document

### 1. Usage of programatic API

To invoke `cds compile --to asyncapi` programatically:

```sh
await cds.compile(<filename>).to.asyncapi()
```js
const cds = require('@sap/cds')
const { compile } = require('@cap-js/asyncapi')
```

For more information, visit [capire](https://cap.cloud.sap/docs/node.js/cds-compile#asyncapi)


### 2. Usage from CLI

Run the following command in the CLI to generate the AsyncAPI document.

```sh
$ cds compile <filename> --to asyncapi
```js
const csn = await cds.load(cds.env.folders.srv)
const asyncapiDocument = compile(csn)
```


For more information, visit [capire](https://cap.cloud.sap/docs/advanced/publishing-apis/asyncapi#cli)

## Contributing

This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/asyncapi/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
Expand Down
19 changes: 3 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
const cds = require('@sap/cds')

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

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


module.exports = { register }
module.exports = {
compile: require('./lib/compile')
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cap-js/asyncapi",
"version": "1.0.0",
"version": "1.0.1",
"description": "CAP tool for AsyncAPI",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions test/lib/compile/asyncapiOptions.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const toAsyncAPI = require('../../../lib/compile');
require('../../../').register();
const cds = require('@sap/cds');
const { readdir, read, path: { resolve } } = cds.utils;
const { join } = require('path');
Expand Down Expand Up @@ -65,7 +64,8 @@ describe('asyncapi export: options', () => {
});

// generates two files for services set to all
const generatedAsyncAPI = await cds.compile(fileList).to.asyncapi({ service: 'all' });
const csn = await cds.compile(fileList).to.csn();
const generatedAsyncAPI = toAsyncAPI(csn, { service: 'all' });
const filesFound = new Set();
for (const [, metadata] of generatedAsyncAPI) {
filesFound.add(metadata.file);
Expand Down

0 comments on commit 5aa5b18

Please sign in to comment.