Skip to content

Commit

Permalink
move helpers as independent package
Browse files Browse the repository at this point in the history
  • Loading branch information
derberg committed Dec 16, 2024
1 parent fc3292d commit b644ab8
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 61 deletions.
20 changes: 19 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"components:test": "turbo run test --filter=@asyncapi/generator-components",
"components:build": "turbo run build --filter=@asyncapi/generator-components",
"components:lint": "turbo run lint --filter=@asyncapi/generator-components",
"helpers:test": "turbo run test --filter=@asyncapi/generator-helpers",
"helpers:lint": "turbo run lint --filter=@asyncapi/generator-helpers",
"templates:test": "turbo run test --filter=@asyncapi/template*"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "https://github.com/asyncapi/generator/apps/components"
"url": "https://github.com/asyncapi/generator/packages/components"
},
"author": "Lukasz Gornicki",
"license": "Apache-2.0",
Expand All @@ -22,6 +22,7 @@
"@asyncapi/modelina": "^4.0.0-next.62"
},
"devDependencies": {
"jest": "^27.3.1",
"@babel/cli": "^7.25.9",
"@babel/core": "^7.26.0",
"@babel/preset-env": "^7.26.0",
Expand Down
30 changes: 30 additions & 0 deletions packages/helpers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@asyncapi/generator-helpers",
"version": "1.0.0",
"description": "Package with reusable helpers that make it easier to work with AsyncAPI structures.",
"scripts": {
"test": "jest --coverage",
"lint": "eslint --max-warnings 0 --config ../../.eslintrc --ignore-path ../../.eslintignore .",
"lint:fix": "eslint --max-warnings 0 --config ../../.eslintrc --ignore-path ../../.eslintignore . --fix"
},
"main": "src/index.js",
"repository": {
"type": "git",
"url": "https://github.com/asyncapi/generator/packages/helpers"
},
"author": "Lukasz Gornicki",
"license": "Apache-2.0",
"dependencies": {
"@asyncapi/generator-react-sdk": "^1.1.2",
"@asyncapi/modelina": "^4.0.0-next.62"
},
"devDependencies": {
"jest": "^27.3.1"
},
"jest": {
"moduleNameMapper": {
"^nimma/legacy$": "<rootDir>/../../node_modules/nimma/dist/legacy/cjs/index.js",
"^nimma/(.*)": "<rootDir>/../../node_modules/nimma/dist/cjs/$1"
}
}
}
7 changes: 7 additions & 0 deletions packages/helpers/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { getServerUrl } = require('./servers');
const { getClientName } = require('./utils');

module.exports = {
getServerUrl,
getClientName
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* return {string} - The server URL.
*/
function getServerUrl(server) {
module.exports.getServerUrl = (server) => {
let url = server.host();

//might be that somebody by mistake duplicated protocol info inside the host field
Expand All @@ -19,9 +19,7 @@ function getServerUrl(server) {
}

return url;
}
};

//TODO: this separate file for helpers for servers represents approach to keep all helpers in separate files related to extractions of data from specific high level AsyncAPI objects. Here we will have more helpers for example related to variables extraction from servers, security, etc.

export { getServerUrl };

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
*
* return {string} - The client name with "Client" appended at the end.
*/
function getClientName(info) {
module.exports.getClientName = (info) => {
const title = info.title();

// Remove spaces, make the first letter uppercase, and add "Client" at the end
return `${title.replace(/\s+/g, '') // Remove all spaces
.replace(/^./, char => char.toUpperCase()) // Make the first letter uppercase
}Client`;
};

export { getClientName };

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path';
import { Parser, fromFile } from '@asyncapi/parser';
import { getServerUrl } from '../../helpers/servers';
const path = require('path');
const { Parser, fromFile } = require('@asyncapi/parser');
const { getServerUrl } = require('@asyncapi/generator-helpers');

const parser = new Parser();
const asyncapi_v3_path = path.resolve(__dirname, '../__fixtures__/asyncapi-websocket-query.yml');
const asyncapi_v3_path = path.resolve(__dirname, './__fixtures__/asyncapi-websocket-query.yml');

describe('getServerUrl integration test with AsyncAPI', () => {
let parsedAsyncAPIDocument;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path';
import { Parser, fromFile } from '@asyncapi/parser';
import { getClientName } from '../../helpers/utils';
const path = require('path');
const { Parser, fromFile } = require('@asyncapi/parser');
const { getClientName } = require('@asyncapi/generator-helpers');

const parser = new Parser();
const asyncapi_v3_path = path.resolve(__dirname, '../__fixtures__/asyncapi-websocket-query.yml');
const asyncapi_v3_path = path.resolve(__dirname, './__fixtures__/asyncapi-websocket-query.yml');

describe('getClientName integration test with AsyncAPI', () => {
let parsedAsyncAPIDocument;
Expand Down
44 changes: 4 additions & 40 deletions packages/templates/clients/js/websocket/__transpiled/client.js.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/templates/clients/js/websocket/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
"license": "Apache-2.0",
"dependencies": {
"@asyncapi/generator-react-sdk": "^1.1.2",
"@asyncapi/parser": "^3.0.14",
"@asyncapi/generator-helpers": "*",
"rimraf": "^3.0.2"
},
"devDependencies": {
"@asyncapi/parser": "^3.0.14",
"@babel/cli": "^7.25.9",
"@babel/core": "^7.26.0",
"@babel/preset-env": "^7.26.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { File, Text } from '@asyncapi/generator-react-sdk';
import { getClientName } from '../helpers/utils';
import { getServerUrl } from '../helpers/servers';
import { getClientName, getServerUrl } from '@asyncapi/generator-helpers';
import { FileHeaderInfo } from '../components/FileHeaderInfo';
import { Requires } from '../components/Requires';

Expand Down

0 comments on commit b644ab8

Please sign in to comment.