@asyncapi/generator 1.17.24 → 2.0.0

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/docs/index.md CHANGED
@@ -23,7 +23,7 @@ The AsyncAPI generator is a tool that generates anything you want using the **[A
23
23
  2. The **Generator** sends to the **[Parser](generator/parser)** the **asyncapiString** which is a stringified version of the original **AsyncAPI Document**.
24
24
  3. The **Parser** uses additional plugins such as the OpenAPI, RAML, or Avro schemas to validate custom schemas of message payloads defined in the **AsyncAPI Document**.
25
25
  4. If the **Parser** determines that the original **AsyncAPI Document** is valid, it manipulates the document and returns a set of helper functions and properties and bundles them together into an **asyncapi** variable that is an instance of [**AsyncAPIDocument**](https://github.com/asyncapi/parser-api/blob/master/docs/api.md#asyncapidocument). The **asyncapi** helper functions make it easier to access the contents of the AsyncAPI Document.
26
- 5. At this point, the **Generator** passes the **[asyncapi](generator/asyncapi-document#method-2-asyncapi-and-template)**, the **[originalAsyncAPI](generator/asyncapi-document#method-1-originalasyncapi-and-template)**, and the **params** which collectively make up the **[Template Context](generator/asyncapi-context)** to the **Render Engine**.
26
+ 5. At this point, the **Generator** passes the **[asyncapi](generator/asyncapi-document#method-2-asyncapi-and-template)**, the **[originalAsyncAPI](generator/asyncapi-document#method-1-originalasyncapi-and-template)**, and the **params** which collectively make up the **[Template Context](generator/template-context)** to the **Render Engine**.
27
27
  6. AsyncAPI has two **Render Engines**([react](generator/react-render-engine) and [nunjucks](generator/nunjucks-render-engine). Depending on which one you've specified in your `package.json`, the **Generator** knows the right **Render Engine** to pass both the **Template Files** and the **Template Context**.
28
28
  7. Once the **Render Engine** receives the **Template Files** and the **Template Context**, it injects all the dynamic values in your react or nunjucks based **Template Files** using the **Template Context**. As a result, the **Render Engine** generates **markdown**, **pdf**, **boilerplate code**, and **anything else** you specified to be generated as output.
29
29
 
@@ -9,8 +9,8 @@ You can use the generator library to generate whatever you want in your event-dr
9
9
 
10
10
  ## Prerequisites
11
11
  Before you install and use the AsyncAPI CLI and the generator library, ensure you meet the prerequisites below, then [install the CLI](#installation).
12
- 1. Node.js v12.16 and higher
13
- 2. Npm v6.13.7 and higher
12
+ 1. Node.js v18.12.0 and higher
13
+ 2. Npm v8.19.0 and higher
14
14
 
15
15
  To verify the versions of Node and Npm you have, run the following command on your terminal:
16
16
  ```
package/docs/template.md CHANGED
@@ -5,7 +5,7 @@ weight: 50
5
5
 
6
6
  ## Template
7
7
 
8
- A template is a project that specifies the generation process output by using the AsyncAPI generator and an [AsyncAPI document](asyncapi-file.md). These files describe the generation results depending on the AsyncAPI document's content.
8
+ A template is a project that specifies the generation process output by using the AsyncAPI generator and an [AsyncAPI document](asyncapi-document.md). These files describe the generation results depending on the AsyncAPI document's content.
9
9
 
10
10
  Examples outputs:
11
11
 
@@ -2,14 +2,26 @@
2
2
  title: "Using private templates"
3
3
  weight: 180
4
4
  ---
5
- Generator allows fetching the template from private repositories like Verdaccio, Nexus, npm, etc.
5
+ Generator allows fetching the template from private repositories like Verdaccio, Nexus, npm, etc.
6
+ By default, the generator fetches the template from the public npm registry configured in the npm configuration.
7
+ To fetch the template from a private registry, you need to provide the registry URL and authentication details in the .npmrc. For more information [read the docs](https://docs.npmjs.com/cli/v9/configuring-npm/npmrc).
8
+ However, you can override the default behavior by providing the registry URL and authentication details as arguments of the commandline.
6
9
 
7
10
 
8
- ## Private registry options:
11
+ ## Private registry using .npmrc:
12
+ ```bash
13
+ npm config set registry http://verdaccio:4873
14
+ npm config set //verdaccio:4873/:_auth=$(echo -n 'username:password' | base64)
15
+ ```
16
+ * **npm config set registry** : Provide the registry URL that points to the registry URL.
17
+ * **npm config set _auth** : Provide the base64 encoded value that represents the username and password for basic auth.
18
+ * **npm config set _authToken** : Provide the access token generated by the registry.
19
+
20
+ ## Private registry overriding arguments:
9
21
 
10
22
  * **registry.url**: The URL of the registry where the private template is located. Defaults to `registry.npmjs.org`.
11
23
  * **registry.auth**: An optional parameter to pass the npm registry username and password encoded with base64, formatted as `username:password`. For example, if the username and password are `admin` and `nimda`, you need to encode them with the base64 value like `admin:nimda` which results in `YWRtaW46bmltZGE=`.
12
- **registry.token**: An optional parameter to pass to the npm registry authentication token. To get the token, you can first authenticate with the registry using `npm login` and then grab the generated token from the `.npmrc` file.
24
+ * **registry.token**: An optional parameter to pass to the npm registry authentication token. To get the token, you can first authenticate with the registry using `npm login` and then grab the generated token from the `.npmrc` file.
13
25
 
14
26
  ## Pulling private template using library:
15
27
 
@@ -26,4 +38,4 @@ const generator = new Generator('@asyncapi/html-template', 'output',
26
38
  }
27
39
  });
28
40
  ```
29
- Assuming you host `@asyncapi/html-template` in a private package registry like Verdaccio. To pull this template, you need to provide `registry.url` option that points to the registry URL and `registry.auth` as a base64 encoded value that represents the username and password. Instead of username and password, you can also pass `registry.token`.
41
+ Assuming you host `@asyncapi/html-template` in a private package registry like Verdaccio. To pull this template, you need to provide `registry.url` option that points to the registry URL and `registry.auth` as a base64 encoded value that represents the username and password. Instead of username and password, you can also pass `registry.token`.
package/lib/generator.js CHANGED
@@ -7,6 +7,10 @@ const filenamify = require('filenamify');
7
7
  const git = require('simple-git');
8
8
  const log = require('loglevel');
9
9
  const Arborist = require('@npmcli/arborist');
10
+ const Config = require('@npmcli/config');
11
+ const requireg = require('requireg');
12
+ const npmPath = requireg.resolve('npm').replace('index.js','');
13
+
10
14
  const { isAsyncAPIDocument } = require('@asyncapi/parser/cjs/document');
11
15
 
12
16
  const { configureReact, renderReact, saveRenderedReactContent } = require('./renderer/react');
@@ -31,6 +35,7 @@ const {
31
35
  const { parse, usesNewAPI, getProperApiDocument } = require('./parser');
32
36
  const { registerFilters } = require('./filtersRegistry');
33
37
  const { registerHooks } = require('./hooksRegistry');
38
+ const { definitions, flatten, shorthands } = require('@npmcli/config/lib/definitions');
34
39
 
35
40
  const FILTERS_DIRNAME = 'filters';
36
41
  const HOOKS_DIRNAME = 'hooks';
@@ -532,7 +537,7 @@ class Generator {
532
537
  arbOptions.registry = providedRegistry;
533
538
  registryUrl = providedRegistry;
534
539
  }
535
-
540
+
536
541
  const domainName = registryUrl.replace(/^https?:\/\//, '');
537
542
  //doing basic if/else so basically only one auth type is used and token as more secure is primary
538
543
  if (this.registry.token) {
@@ -541,11 +546,12 @@ class Generator {
541
546
  } else if (this.registry.auth) {
542
547
  authorizationName = `//${domainName}:_auth`;
543
548
  arbOptions[authorizationName] = this.registry.auth;
544
- }
549
+ }
545
550
 
546
551
  //not sharing in logs neither token nor auth for security reasons
547
552
  log.debug(`Using npm registry ${registryUrl} and authorization type ${authorizationName} to handle template installation.`);
548
553
  }
554
+
549
555
  /**
550
556
  * Downloads and installs a template and its dependencies
551
557
  *
@@ -556,14 +562,14 @@ class Generator {
556
562
  let pkgPath;
557
563
  let installedPkg;
558
564
  let packageVersion;
559
-
565
+
560
566
  try {
561
567
  installedPkg = getTemplateDetails(this.templateName, PACKAGE_JSON_FILENAME);
562
568
  pkgPath = installedPkg && installedPkg.pkgPath;
563
569
  packageVersion = installedPkg && installedPkg.version;
564
570
  log.debug(logMessage.templateSource(pkgPath));
565
571
  if (packageVersion) log.debug(logMessage.templateVersion(packageVersion));
566
-
572
+
567
573
  return {
568
574
  name: installedPkg.name,
569
575
  path: pkgPath
@@ -573,38 +579,45 @@ class Generator {
573
579
  // We did our best. Proceed with installation...
574
580
  }
575
581
  }
576
-
582
+
577
583
  const debugMessage = force ? logMessage.TEMPLATE_INSTALL_FLAG_MSG : logMessage.TEMPLATE_INSTALL_DISK_MSG;
578
584
  log.debug(logMessage.installationDebugMessage(debugMessage));
579
-
585
+
580
586
  if (isFileSystemPath(this.templateName)) log.debug(logMessage.NPM_INSTALL_TRIGGER);
581
-
582
- const arbOptions = {
583
- path: ROOT_DIR,
584
- };
585
- if (this.registry) {
587
+
588
+ const config = new Config({
589
+ definitions,
590
+ flatten,
591
+ shorthands,
592
+ npmPath
593
+ });
594
+
595
+ await config.load();
596
+
597
+ const arbOptions = {...{path: ROOT_DIR}, ...config.flat};
598
+
599
+ if (Object.keys(this.registry).length !== 0) {
586
600
  this.initialiseArbOptions(arbOptions);
587
601
  }
588
-
589
602
  const arb = new Arborist(arbOptions);
590
-
603
+
591
604
  try {
592
605
  const installResult = await arb.reify({
593
606
  add: [this.templateName],
594
607
  saveType: 'prod',
595
608
  save: false
596
609
  });
597
-
610
+
598
611
  const addResult = arb[Symbol.for('resolvedAdd')];
599
612
  if (!addResult) throw new Error('Unable to resolve the name of the added package. It was most probably not added to node_modules successfully');
600
-
613
+
601
614
  const packageName = addResult[0].name;
602
615
  const packageVersion = installResult.children.get(packageName).version;
603
616
  const packagePath = installResult.children.get(packageName).path;
604
-
617
+
605
618
  if (!isFileSystemPath(this.templateName)) log.debug(logMessage.templateSuccessfullyInstalled(packageName, packagePath));
606
619
  if (packageVersion) log.debug(logMessage.templateVersion(packageVersion));
607
-
620
+
608
621
  return {
609
622
  name: packageName,
610
623
  path: packagePath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asyncapi/generator",
3
- "version": "1.17.24",
3
+ "version": "2.0.0",
4
4
  "description": "The AsyncAPI generator. It can generate documentation, code, anything!",
5
5
  "main": "./lib/generator.js",
6
6
  "bin": {
@@ -8,8 +8,8 @@
8
8
  "ag": "./cli.js"
9
9
  },
10
10
  "engines": {
11
- "node": ">12.16",
12
- "npm": ">6.13.7"
11
+ "node": ">=18.12.0",
12
+ "npm": ">=8.19.0"
13
13
  },
14
14
  "scripts": {
15
15
  "test": "npm run test:unit && npm run test:integration && npm run test:cli",
@@ -51,6 +51,7 @@
51
51
  "@asyncapi/generator-react-sdk": "^1.0.18",
52
52
  "@asyncapi/parser": "^3.0.14",
53
53
  "@npmcli/arborist": "5.6.3",
54
+ "@npmcli/config": "^8.0.2",
54
55
  "@smoya/multi-parser": "^5.0.0",
55
56
  "ajv": "^8.12.0",
56
57
  "chokidar": "^3.4.0",
@@ -65,6 +66,7 @@
65
66
  "minimatch": "^3.0.4",
66
67
  "node-fetch": "^2.6.0",
67
68
  "nunjucks": "^3.2.0",
69
+ "requireg": "^0.2.2",
68
70
  "resolve-from": "^5.0.0",
69
71
  "resolve-pkg": "^2.0.0",
70
72
  "semver": "^7.3.2",