Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow generator to pull from private npm repo #1061

Merged
merged 69 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
c0f91f2
File added
aayushRedHat Jan 9, 2024
ff9df8e
File added
aayushRedHat Jan 9, 2024
119de94
File added
aayushRedHat Jan 9, 2024
e38a8a5
Fix: testCases
aayushRedHat Dec 19, 2023
3ff3233
fix: Fix Typo
aayushRedHat Dec 19, 2023
d46cc2f
Fix lint issue and refractor code
aayushRedHat Dec 19, 2023
a12c7be
fix sonar issue
aayushRedHat Dec 19, 2023
30064a4
Fix failed test case
aayushRedHat Dec 19, 2023
54800a9
Add installation guide doc
aayushRedHat Dec 19, 2023
db03f21
Add private template doc
aayushRedHat Dec 20, 2023
49f07a3
Add doc for private registory
aayushRedHat Dec 20, 2023
ed8016e
update doc
aayushRedHat Dec 20, 2023
b7c6ec7
remove extra space
aayushRedHat Dec 20, 2023
381ea5a
Refractor options handling method
aayushRedHat Jan 4, 2024
d5c468e
Fix changes
aayushRedHat Jan 4, 2024
ffcebc0
Add veradicco config
aayushRedHat Jan 4, 2024
9162bb7
Remove unused function
aayushRedHat Jan 4, 2024
672e437
Removed getInvalidOptions
aayushRedHat Jan 4, 2024
b182d0f
update setup
derberg Jan 4, 2024
beacf2d
Added test cases
aayushRedHat Jan 5, 2024
514b64e
update sonar properties
aayushRedHat Jan 5, 2024
4c5e29d
update sonar config
aayushRedHat Jan 5, 2024
4d7f3ea
Removed unused files
aayushRedHat Jan 8, 2024
3982e9a
fix testing and removed unused files
aayushRedHat Jan 9, 2024
4ac440c
update gitignore file
aayushRedHat Jan 9, 2024
39d992d
Removed storage file
aayushRedHat Jan 9, 2024
907a30f
Update the description
aayushRedHat Jan 9, 2024
3ae1bf2
Add html-template
aayushRedHat Jan 10, 2024
2af3c99
Removed
aayushRedHat Jan 10, 2024
7d7be4e
update requried changes
aayushRedHat Jan 10, 2024
845d07e
Update the config
aayushRedHat Jan 10, 2024
785543a
update env location
aayushRedHat Jan 10, 2024
facd255
update test message
aayushRedHat Jan 10, 2024
d5dcacc
Remove extra check
aayushRedHat Jan 10, 2024
9817c55
fix lint
aayushRedHat Jan 10, 2024
34f0c47
refactor
derberg Jan 11, 2024
66c6e83
Merge pull request #2 from derberg/werwewe
AayushSaini101 Jan 12, 2024
e639bee
update the host name
aayushRedHat Jan 12, 2024
dd10d03
add extra param
aayushRedHat Jan 12, 2024
6200924
update generator unit test
aayushRedHat Jan 13, 2024
763154d
Remove extra param
aayushRedHat Jan 13, 2024
696f616
update comments
aayushRedHat Jan 13, 2024
9d24af6
Add env to avoid docker failure
aayushRedHat Jan 14, 2024
4f2715e
update env naming
aayushRedHat Jan 15, 2024
af86002
Remove space in docker env
aayushRedHat Jan 15, 2024
cee324c
Remove lint issue
aayushRedHat Jan 15, 2024
02351e4
Remove used files
aayushRedHat Jan 15, 2024
3701e4e
Changed
aayushRedHat Jan 15, 2024
cf92947
Remove unwanted files
aayushRedHat Jan 15, 2024
d2c5cc2
Update testing
aayushRedHat Jan 15, 2024
9eeba74
Remove test cases
aayushRedHat Jan 15, 2024
cde77d8
Update suggested changes
aayushRedHat Jan 15, 2024
4a2146b
Update testing
aayushRedHat Jan 15, 2024
652754e
Update testing
aayushRedHat Jan 17, 2024
0d2e51f
changed testing
aayushRedHat Jan 17, 2024
1d3e9e6
refactor of int tests
derberg Jan 17, 2024
59e7be7
Merge branch 'issue-538' into asdadsfljkadsflkjadlk
derberg Jan 17, 2024
ab6b78a
cleanup
derberg Jan 17, 2024
709a228
unit test fix
derberg Jan 17, 2024
9aea5f9
jest and lint
derberg Jan 17, 2024
73750c5
Merge pull request #3 from derberg/asdadsfljkadsflkjadlk
AayushSaini101 Jan 17, 2024
618f64b
Fix testing
aayushRedHat Jan 17, 2024
4fe6585
Remove sonar issues
aayushRedHat Jan 17, 2024
f32478e
Fix Sonar issues
aayushRedHat Jan 17, 2024
2d4de58
Fix sonar issues
aayushRedHat Jan 17, 2024
169157e
update the doc for private template
aayushRedHat Jan 17, 2024
522f863
update private doc
aayushRedHat Jan 17, 2024
111966d
update doc
aayushRedHat Jan 17, 2024
c60dff9
update doc
aayushRedHat Jan 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr-testing-with-test-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
- name: Run test
run: NODE_IMAGE_TAG=${{ matrix.node }} docker-compose up --abort-on-container-exit --remove-orphans
run: NODE_IMAGE_TAG=${{ matrix.node }} docker-compose up --abort-on-container-exit --remove-orphans --force-recreate
working-directory: ./test/test-project
11 changes: 3 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ output
out/
coverage
test/temp/integrationTestResult
#we must commit this single package to the repo as integration tests depend on it and we do not want our auto bump workflows to affect package version
#yes, below looks strange but this is how it is done with git. Read more https://stackoverflow.com/questions/5533050/gitignore-exclude-folder-but-include-specific-subfolder
!test/test-project/node_modules/
test/test-project/node_modules/*
!test/test-project/node_modules/@asyncapi/
test/test-project/node_modules/@asyncapi/*
!test/test-project/node_modules/@asyncapi/html-template/
test/test-project/package-lock.json
test/test-project/package-lock.json
test/test-project/verdaccio/storage/
test/test-project/storage/
2 changes: 1 addition & 1 deletion docs/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Examples outputs:

A template is an independent Node.js project unrelated to the `generator` repository. AsyncAPI templates are managed, released, and published separately. You can also create templates and manage templates on your own.

The generator uses the official [Arborist](https://www.npmjs.com/package/@npmcli/arborist) NPM library. (This means templates do not have to be published to package managers to use them.) Arborist helps the generator fetch the template's source code and use it for the generation process.
The generator uses the official [Arborist](https://www.npmjs.com/package/@npmcli/arborist) NPM library. (This means templates do not have to be published to package managers to use them.) Arborist helps the generator fetch the template's source code and use it for the generation process. By default, this library pulls data from the default NPM registry, which is https://registry.npmjs.org. You can also configure the generator to fetch templates that are private or hosted in different NPM registry

You can store template projects on a local drive or as a `git` repository during the development process.

Expand Down
29 changes: 29 additions & 0 deletions docs/using-private-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: "Using private templates"
weight: 180
---
Generator allows fetching the template from private repositories like Verdaccio, Nexus, npm, etc.


## Private registry options:

* **registry.url**: The URL of the registry where the private template is located. Defaults to `registry.npmjs.org`.
* **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=`.
**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.

## Pulling private template using library:

```javascript
const generator = new Generator('@asyncapi/html-template', 'output',
{
debug: true,
registry: {
url: 'http://verdaccio:4873',
auth: 'YWRtaW46bmltZGE='
// base64 encoded username and password
// represented as admin:nimda

}
});
```
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`.
3 changes: 0 additions & 3 deletions lib/__mocks__/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
const utils = jest.genMockFromModule('../utils');
const { getInvalidOptions } = require.requireActual('../utils');

utils.getInvalidOptions = getInvalidOptions;

utils.__files = {};
utils.readFile = jest.fn(async (filePath) => {
Expand Down
25 changes: 20 additions & 5 deletions lib/filtersRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { isAsyncFunction } = require('./utils');
*/
module.exports.registerFilters = async (nunjucks, templateConfig, templateDir, filtersDir) => {
await registerLocalFilters(nunjucks, templateDir, filtersDir);
await registerConfigFilters(nunjucks, templateDir, templateConfig);
registerConfigFilters(nunjucks, templateDir, templateConfig);
};

/**
Expand Down Expand Up @@ -71,16 +71,31 @@ async function registerConfigFilters(nunjucks, templateDir, templateConfig) {

const promises = confFilters.map(async filtersModule => {
let mod;
let filterName = filtersModule;
try {
//first we try to grab module with filters by the module name
//this is when generation is used on production using remote templates
mod = require(filtersModule);
mod = require(filterName);
} catch (error) {
//in case template is local but was not installed in node_modules of the generator then we need to explicitly provide modules location
mod = require(path.resolve(templateDir, DEFAULT_MODULES_DIR, filtersModule));
try {
filterName = path.resolve(templateDir, DEFAULT_MODULES_DIR, filtersModule);
mod = require(filterName);
} catch (e) {
//sometimes it may happen that template is located in node_modules with other templates and its filter package is on the same level as template, as it is shared with other templates
try {
filterName = path.resolve(templateDir, '../..', filtersModule);
mod = require(filterName);
} catch (error) {
//in rare cases, especially in isolated tests, it may happen that installation
//ends but is not yet fully completed, so initial require of the same path do not work
//but in next attempt it works
//we need to keep this workaround until we find a solution
mod = require(filterName);
}
}
}

addFilters(nunjucks, mod);
return addFilters(nunjucks, mod);
});

await Promise.all(promises);
Expand Down
Loading
Loading