@ioka-technologies/asyncapi-rust-client-template 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ioka-technologies/asyncapi-rust-client-template",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "AsyncAPI template for generating Rust NATS clients",
5
5
  "main": "template/index.js",
6
6
  "keywords": [
@@ -14,12 +14,21 @@
14
14
  "author": "AsyncAPI Generator",
15
15
  "license": "Apache-2.0",
16
16
  "dependencies": {
17
- "@asyncapi/generator-react-sdk": "^1.0.0"
17
+ "@asyncapi/generator-react-sdk": "^1.0.20"
18
18
  },
19
19
  "scripts": {
20
+ "build": "webpack --config ../webpack.config.js --env template=rust-client",
21
+ "build:dev": "webpack --config ../webpack.config.js --env template=rust-client --mode development",
22
+ "prepublishOnly": "npm run build",
20
23
  "test": "npm run test:nats",
21
- "test:nats": "asyncapi generate fromTemplate ../examples/nats/asyncapi.yaml ./ -o test-output-nats --force-write && echo 'Generated library files:' && ls -la test-output-nats/ && cd test-output-nats && cargo build --lib"
24
+ "test:nats": "asyncapi generate fromTemplate ../examples/nats/asyncapi.yaml ./ -o test-output-nats --force-write && echo 'Generated library files:' && ls -la test-output-nats/ && cd test-output-nats && cargo build --lib",
25
+ "clean": "rm -rf dist test-output-*"
22
26
  },
27
+ "files": [
28
+ "template/**/*",
29
+ "dist/common/**/*",
30
+ "README.md"
31
+ ],
23
32
  "generator": {
24
33
  "renderer": "react",
25
34
  "apiVersion": "v3",
@@ -1,49 +1,24 @@
1
1
  /* eslint-disable no-unused-vars */
2
2
  import { File } from '@asyncapi/generator-react-sdk';
3
+ import {
4
+ toKebabCase,
5
+ toSnakeCase,
6
+ isTemplateVariable,
7
+ extractAsyncApiInfo,
8
+ resolveTemplateParameters
9
+ } from './helpers/index.js';
3
10
 
4
11
  module.exports = function ({ asyncapi, params }) {
5
- // Helper function to convert title to kebab-case
6
- function toKebabCase(str) {
7
- return str.replace(/[^a-zA-Z0-9]/g, '-')
8
- .toLowerCase()
9
- .replace(/-+/g, '-')
10
- .replace(/^-|-$/g, '');
11
- }
12
+ const asyncApiInfo = extractAsyncApiInfo(asyncapi);
13
+ const { title, version, description } = asyncApiInfo;
12
14
 
13
- // Helper function to convert title to snake_case
14
- function toSnakeCase(str) {
15
- return str.replace(/[^a-zA-Z0-9]/g, '_')
16
- .toLowerCase()
17
- .replace(/_+/g, '_')
18
- .replace(/^_|_$/g, '');
19
- }
15
+ const resolvedParams = resolveTemplateParameters(params, asyncApiInfo);
16
+ const { packageName, packageVersion, author, license } = resolvedParams;
20
17
 
21
- const info = asyncapi.info();
22
- const title = info.title();
23
- const description = (info.description() || `Generated Rust NATS client for ${title}`)
18
+ const finalDescription = (description || `Generated Rust NATS client for ${title}`)
24
19
  .replace(/"/g, '\\"')
25
20
  .replace(/\n/g, ' ')
26
21
  .trim();
27
- const version = info.version();
28
-
29
- // Helper function to check if a parameter contains unresolved template variables
30
- function isTemplateVariable(value) {
31
- return typeof value === 'string' && value.includes('{{') && value.includes('}}');
32
- }
33
-
34
- // Resolve parameters with fallbacks
35
- const packageName = (params.packageName && !isTemplateVariable(params.packageName))
36
- ? params.packageName
37
- : toKebabCase(title) + '-client';
38
- const packageVersion = (params.packageVersion && !isTemplateVariable(params.packageVersion))
39
- ? params.packageVersion
40
- : version;
41
- const author = (params.author && !isTemplateVariable(params.author))
42
- ? params.author
43
- : 'AsyncAPI Generator';
44
- const license = (params.license && !isTemplateVariable(params.license))
45
- ? params.license
46
- : 'Apache-2.0';
47
22
 
48
23
  return (
49
24
  <File name="Cargo.toml">
@@ -53,7 +28,7 @@ version = "${packageVersion}"
53
28
  edition = "2021"
54
29
  authors = ["${author}"]
55
30
  license = "${license}"
56
- description = "${description}"
31
+ description = "${finalDescription}"
57
32
  repository = "https://github.com/your-org/${packageName}"
58
33
  documentation = "https://docs.rs/${packageName}"
59
34
  keywords = ["asyncapi", "nats", "client", "messaging"]