-
-
Notifications
You must be signed in to change notification settings - Fork 186
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: load modelina configuration options from a config file #1367
Conversation
✅ Deploy Preview for modelina canceled.
|
Pull Request Test Coverage Report for Build 5161878796
💛 - Coveralls |
@jonaslagoni I've used the Why is it that way ? 🤔 Or, do you want me to import the module like this ? function readJSFile(filePath) {
try {
const fileContent = fs.readFileSync(filePath, 'utf8');
const moduleExports = {};
const moduleWrapper = eval('(function(exports) {' + fileContent + '})');
moduleWrapper(moduleExports);
return moduleExports;
} catch (error) {
console.error('Error reading JS file:', error);
return null;
}
} |
Which build command did you run? Line 78 in c0e0268
|
On running Thanks. 😄 Do you think we should add more documentation on setting up the repository for development ? |
@jonaslagoni After i add a function, and build the project ( Edit: |
@jonaslagoni I'm kind of stuck / plateaued here. 🙂 I'm talking feature wise, i haven't written the tests yet. |
SonarCloud Quality Gate failed. 0 Bugs No Coverage information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, you need to add documentation as well, probably something like the following:
- Add a section here: https://github.com/asyncapi/modelina/blob/master/docs/advanced.md
- Add your example to the list of examples: https://github.com/asyncapi/modelina/blob/master/examples/README.md
Hope this gives you a direction, otherwise let me know if you want anything clarified 🙂
@@ -64,4 +64,18 @@ export class FileHelpers { | |||
} | |||
}); | |||
} | |||
|
|||
static async getConfigFromFile(configPath: string): Promise<any> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to write some unit tests here 🙂
Make sure you test error states as well:
- What if the file exist but is not valid JS?
- What if the file exist but is TypeScript?
- What if the file exist and is correct JS, but does not expose the right config?
- What if the file exist and is correct JS, but does not expose the config file the right way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure you document this function as well i.e. what it does 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonaslagoni
I'll make sure to document and write the unit tests.
What if the file exist and is correct JS, but does not expose the right config?
and
What if the file exist and is correct JS, but does not expose the config file the right way?
Should be the same thing right ? I mean we wouldn't know if the file is exposing the config the right way, unless we know what it's exposing ? 🤔
The way i put it here might be confusing, feel free to ignore this, i will let you know later more context on this. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try fixing things one after other and contact you back 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way i put it here might be confusing, feel free to ignore this, i will let you know later more context on this. 🙂
The first one is a bit hard to pull off, which is they expose the configuration correctly, but the configuration is incorrect (not sure we actually can do this)
The second one is if they expose it like export { config2: config };
when we expected export config;
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first one is a bit hard to pull off, which is they expose the configuration correctly, but the configuration is incorrect (not sure we actually can do this)
I'll try to see if we can do the first one
The second one is if they expose it like export { config2: config }; when we expected export config;.
I'll look into this as well 🙂
Seems like a good learning oppurtunity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can restrict the users to only allow them to use js file for config right ? i hardly saw places where people used ts files for config.
What do you say ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree 👍
It can also be an improvement down the line if ever requested 🙂
const config: { config: TypeScriptOptions } = | ||
await FileHelpers.getConfigFromFile('./modelina.config.alternate.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should simplify this.
const config = await FileHelpers.getConfigFromFile('./modelina.config.alternate.js');
Instead of having to do something like config.config
, what do you think? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah definitely, it looks absurd.
We can directly export the config. 🙂
Would that work ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep 👍
The config file can be placed anywhere on the users machine, which is probably not a node package and doensn't have modelina installed. Out |
I will pause working on this PR for 2-3 days, busy with some other things |
Looks like you are nearly there @kaushik-rishi 🤔 |
SonarCloud Quality Gate failed. 0 Bugs No Coverage information Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
Hey @kaushik-rishi, want to continue or can someone else take over the progress? |
Closing as no response for over a month |
Description
Related issue(s)