Skip to content

Commit

Permalink
feat: Use npmcli config in asyncapi generator
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrick-boule committed Jan 25, 2024
1 parent 8256031 commit e9f8a32
Show file tree
Hide file tree
Showing 5 changed files with 509 additions and 11,711 deletions.
17 changes: 17 additions & 0 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const filenamify = require('filenamify');
const git = require('simple-git');
const log = require('loglevel');
const Arborist = require('@npmcli/arborist');
const Config = require('@npmcli/config');

const { isAsyncAPIDocument } = require('@asyncapi/parser/cjs/document');

const { configureReact, renderReact, saveRenderedReactContent } = require('./renderer/react');
Expand All @@ -31,6 +33,7 @@ const {
const { parse, usesNewAPI, getProperApiDocument } = require('./parser');
const { registerFilters } = require('./filtersRegistry');
const { registerHooks } = require('./hooksRegistry');
const { definitions, flatten, shorthands } = require('@npmcli/config/lib/definitions')

const FILTERS_DIRNAME = 'filters';
const HOOKS_DIRNAME = 'hooks';
Expand Down Expand Up @@ -546,6 +549,8 @@ class Generator {
//not sharing in logs neither token nor auth for security reasons
log.debug(`Using npm registry ${registryUrl} and authorization type ${authorizationName} to handle template installation.`);
}


/**
* Downloads and installs a template and its dependencies
*
Expand Down Expand Up @@ -584,6 +589,18 @@ class Generator {
};
if (this.registry) {
this.initialiseArbOptions(arbOptions);
} else {
const npmPath = process.execPath.replace('/bin/node','/lib/node_modules/npm/');

const config = new Config({
definitions,
flatten,
shorthands,
npmPath
})

await config.load()
arbOptions = config.flat
}

const arb = new Arborist(arbOptions);
Expand Down
Loading

0 comments on commit e9f8a32

Please sign in to comment.