From cc82a70533048177525bdbb4d897ef93d4a3773f Mon Sep 17 00:00:00 2001 From: Jeevitha P Date: Tue, 14 May 2024 13:10:58 +0530 Subject: [PATCH 1/4] remove registering compile target --- CHANGELOG.md | 6 ++++++ README.md | 26 ++---------------------- index.js | 19 +++-------------- package.json | 4 ++-- test/lib/compile/asyncapiOptions.test.js | 4 ++-- 5 files changed, 15 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca201d3..9044378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index b9601b6..70c1b47 100644 --- a/README.md +++ b/README.md @@ -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) @@ -25,33 +24,12 @@ $ npm install @cap-js/asyncapi ### Usage ```sh -require("@cap-js/asyncapi").register() +const processor = require('@cap-js/asyncapi') ``` - -## Generate AsyncAPI document - -### 1. Usage of programatic API - -To invoke `cds compile --to asyncapi` programatically: - ```sh -await cds.compile().to.asyncapi() +processor(csn) ``` -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 --to asyncapi -``` - - -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). diff --git a/index.js b/index.js index 27fcc34..9eef64a 100644 --- a/index.js +++ b/index.js @@ -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') +} \ No newline at end of file diff --git a/package.json b/package.json index ea4f4ee..b6f5813 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cap-js/asyncapi", - "version": "1.0.0", + "version": "1.0.1", "description": "CAP tool for AsyncAPI", "repository": { "type": "git", @@ -15,7 +15,7 @@ ], "author": "SAP SE (https://www.sap.com)", "license": "SEE LICENSE IN LICENSE", - "main": "index.js", + "main": "lib/compile/index.js", "files": [ "lib/", "index.js", diff --git a/test/lib/compile/asyncapiOptions.test.js b/test/lib/compile/asyncapiOptions.test.js index f6f2737..63d7bb8 100644 --- a/test/lib/compile/asyncapiOptions.test.js +++ b/test/lib/compile/asyncapiOptions.test.js @@ -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'); @@ -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); From 3ebe82953dbe867a32222cf44419ca4d5b6ae5d1 Mon Sep 17 00:00:00 2001 From: Jeevitha P Date: Tue, 14 May 2024 13:29:50 +0530 Subject: [PATCH 2/4] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b6f5813..8da2de6 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ ], "author": "SAP SE (https://www.sap.com)", "license": "SEE LICENSE IN LICENSE", - "main": "lib/compile/index.js", + "main": "index.js", "files": [ "lib/", "index.js", From 44403ecbe93ba7cfb6fb4c6add468b01a6ccd395 Mon Sep 17 00:00:00 2001 From: Jeevitha P Date: Tue, 14 May 2024 13:32:13 +0530 Subject: [PATCH 3/4] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 70c1b47..258375d 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,10 @@ $ npm install @cap-js/asyncapi ### Usage ```sh -const processor = require('@cap-js/asyncapi') +const { compile } = require('@cap-js/asyncapi') ``` ```sh -processor(csn) +compile(csn) ``` ## Contributing From ce9111049313a30cf429974dd9ac9aac056e0919 Mon Sep 17 00:00:00 2001 From: Jeevitha P Date: Tue, 14 May 2024 13:38:13 +0530 Subject: [PATCH 4/4] Update README.md --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 258375d..d7166ad 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,14 @@ $ npm install @cap-js/asyncapi ### Usage -```sh +```js +const cds = require('@sap/cds') const { compile } = require('@cap-js/asyncapi') ``` -```sh -compile(csn) + +```js +const csn = await cds.load(cds.env.folders.srv) +const asyncapiDocument = compile(csn) ``` ## Contributing