Skip to content

Commit

Permalink
update requried changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushRedHat committed Jan 10, 2024
1 parent 2af3c99 commit 7d7be4e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#we need to explicitly exclude them as some are commit to the repo
sonar.exclusions=test/**/*, test/test-project/**
sonar.exclusions=test/**/*
30 changes: 15 additions & 15 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const DEFAULT_TEMPLATES_DIR = path.resolve(ROOT_DIR, 'node_modules');

const TRANSPILED_TEMPLATE_LOCATION = '__transpiled';
const TEMPLATE_CONTENT_DIRNAME = 'template';
const GENERATOR_OPTIONS = ['debug', 'disabledHooks', 'entrypoint', 'forceWrite', 'install', 'noOverwriteGlobs', 'output', 'templateParams', 'mapBaseUrlToFolder','url','username','password','token','registry'];
const GENERATOR_OPTIONS = ['debug', 'disabledHooks', 'entrypoint', 'forceWrite', 'install', 'noOverwriteGlobs', 'output', 'templateParams', 'mapBaseUrlToFolder', 'url', 'username', 'password', 'token', 'registry'];
const logMessage = require('./logMessages');

const shouldIgnoreFile = filePath =>
Expand Down Expand Up @@ -90,15 +90,15 @@ class Generator {
* @param {String} [options.registry.password] Optional parameter to pass npm registry base64 encoded password
* @param {String} [options.registry.token] Optional parameter to pass npm registry auth token
*/

constructor(templateName, targetDir, { templateParams = {}, entrypoint, noOverwriteGlobs, disabledHooks, output = 'fs', forceWrite = false, install = false, debug = false, mapBaseUrlToFolder = {}, registry = {}} = {}) {
const options = arguments[arguments.length - 1];
this.verifyoptions(options);
if (!templateName) throw new Error('No template name has been specified.');
if (!entrypoint && !targetDir) throw new Error('No target directory has been specified.');
if (!['fs', 'string'].includes(output)) throw new Error(`Invalid output type ${output}. Valid values are 'fs' and 'string'.`);
/** @type {RegistryOptions} Npm registry information. */

/** @type {Object} Npm registry information. */
this.registry = registry;
/** @type {String} Name of the template to generate. */
this.templateName = templateName;
Expand Down Expand Up @@ -144,17 +144,17 @@ class Generator {

/**
* Check if the Registry Options are valid or not.
*
*
* @private
* @param {Object} invalidRegOptions Invalid Registry Options.
*
*
*/

verifyoptions(Options) {
if (typeof Options !== 'object') return [];
const invalidOptions = Object.keys(Options).filter(param => !GENERATOR_OPTIONS.includes(param));
if (invalidOptions.length > 0) {
if (typeof Options !== 'object') return [];
const invalidOptions = Object.keys(Options).filter(param => !GENERATOR_OPTIONS.includes(param));

if (invalidOptions.length > 0) {
throw new Error(`These options are not supported by the generator: ${invalidOptions.join(', ')}`);
}
}
Expand All @@ -166,7 +166,7 @@ class Generator {
* @example
* await generator.generate(myAsyncAPIdocument);
* console.log('Done!');
*
*
* @example
* generator
* .generate(myAsyncAPIdocument)
Expand Down Expand Up @@ -224,9 +224,9 @@ class Generator {
* @example
* const generator = new Generator();
* await generator.setupOutput();
*
*
* @async
*
*
* @throws {Error} If 'output' is set to 'string' without providing 'entrypoint'.
*/
async setupOutput() {
Expand Down Expand Up @@ -523,7 +523,7 @@ class Generator {

/**
* @private
* @param {Object} arbOptions ArbOptions to intialise the Registry details.
* @param {Object} arbOptions ArbOptions to intialise the Registry details.
*/
initialiseArbOptions(arbOptions) {
if (this.registry.url) arbOptions.registry = this.registry.url;
Expand Down Expand Up @@ -568,7 +568,7 @@ class Generator {
const arbOptions = {
path: ROOT_DIR,
};

if (this.registry) {
this.initialiseArbOptions(arbOptions);
}
Expand Down
2 changes: 1 addition & 1 deletion test/test-project/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:

test:
privileged: true
image: "node:18"
image: "node:${NODE_IMAGE_TAG}"
volumes:
- ../../:/app
command: bash /app/test/test-project/test.sh
7 changes: 3 additions & 4 deletions test/test-project/test-registry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const Generator = require('../lib/generator');
const dummySpecPath = path.resolve(__dirname, './docs/dummy.yml');
const crypto = require('crypto');
const mainTestResultPath = 'test/temp/integrationTestResult';
//we do not want to download chromium for html-template if it is not needed
process.env['PUPPETEER_SKIP_CHROMIUM_DOWNLOAD'] = true;

describe('Integration testing generateFromFile() to make sure the template can be download from the private repository.', () => {
const generateFolderName = () => {
Expand All @@ -21,11 +19,12 @@ describe('Integration testing generateFromFile() to make sure the template can b

it('generated using private registory', async () => {
const outputDir = generateFolderName();
const generator = new Generator('@asyncapi/html-template', outputDir,
const generator = new Generator('@asyncapi/html-template@0.16.0', outputDir,
{ forceWrite: true, templateParams: { singleFile: true },
registry: {url: 'http://localhost:4873/', username: 'admin', password: 'nimbda'}});
await generator.generateFromFile(dummySpecPath);
const file = await readFile(path.join(outputDir, 'index.html'), 'utf8');
expect(file).toMatchSnapshot();
expect(file).toBeDefined();
expect(file.length).toBeGreaterThan(0);
});
});

0 comments on commit 7d7be4e

Please sign in to comment.