-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add methods for work with yaml file #6769
Add methods for work with yaml file #6769
Conversation
code from hipster-labs/generator-jhipster-spring-cloud-stream
correct unit test on windows correct unit test for windows user
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.
What is the need for these functions? I'm not in favour of dumping these here without a solid reason. They seem to be very specific for YML handling in that case why not just publish it as a standalone open-source library and use it where needed. Atleast I dont see any need for these within the generator
* @param {string} generator - The generator | ||
* @return {string} the value of property or undefined | ||
*/ | ||
function getPropertyInArray(array, name, generator) { |
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.
Please use lodash directly. This method doesnt add any value so please remove it
* @param {string} generator - The generator | ||
* @param {string} value - (optional) value of the property | ||
*/ | ||
function updatePropertyInArray(array, name, generator, value) { |
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.
Please use lodash directly. This method doesnt add any value so please remove it
* @param {string} name - property name to search "format myProperty.level2.level3" | ||
* @param {string} generator - The generator | ||
*/ | ||
function deletePropertyInArray(array, name, generator) { |
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.
Please use lodash directly. This method doesnt add any value so please remove it
* @return {string} the value of property or undefined | ||
*/ | ||
function getYamlProperty(file, name, generator) { | ||
const treeData = jsyaml.safeLoad(generator.fs.read(file)); |
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.
This is not efficient if reading multiple props. Ideally, you should just load file once and read all required values from that. Its better to do this directly using the library. I dont see added value in having this method
* @param {array} properties - array of property to add | ||
* @param {string} generator - The generator | ||
*/ | ||
function addYamlPropertiesAtBeginin(file, properties, generator) { |
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.
method name should be addYamlPropertiesAtBeginning
* @param {string} numberSpace - number espace to start | ||
*/ | ||
function addYamlPropertiesAtLineIndex(file, properties, generator, indexLine, numberSpace) { | ||
const body = generator.fs.read(file); |
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.
pass body, dont read
spaceStr += ' '; | ||
} | ||
bodyLines.splice(indexLine, 0, newLines.map(line => spaceStr + line).join('\n')); | ||
generator.fs.write(file, bodyLines.join('\n')); |
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.
return result, dont write
|
||
/** | ||
* Add a yaml property at beginin | ||
* TODO manage value of array type |
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.
please don't add incomplete methods to public util file
} | ||
|
||
/** | ||
* Get the last property of a common hierarchical. |
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.
write a better explanation comment
} | ||
|
||
/** | ||
* Retourne l'index de la ligne d'une propriété simple et unique |
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.
please write comments in english
@antarus I don't think these should be added to the main generator. They are too specific to handle YML files. Maybe just publish them as a generic utility library |
Hello, the goal is to facilitate the integration of external module to the main generator. There is currently nothing in the generator to add, edit a spring's configuration file . For me, it's missing. There are function to add graddle or maven dependencies, for me it's the same notion. It took me a long time to manage this for the stream-cloud module. I think the main generator lacks tools to make life easier for module developers and their integration. After about the code deportation in an external library, I don't know, I'm not a node developer, I've never done it. |
I was thinking about something similar for JHipster Modules (while working on JHipster-kotlin)🤔 where we need to add few things extra to the base something similar to angular-cli, how it is generating the application |
@antarus let me think about this. May be I can create a utils project under jhipster and you can PR these there. Give me some time |
As @antarus said, it's for adding properties into spring boot yaml configuration. For that, currently, we have differents solutions:
|
@pascalgrimaud yes I understand the need but I feel that if we start adding everything into the main generator it will become like a kitchen sink. Let's do a new library called |
For me this is a valid use case. There should be an API to add properties from a module. However manipulating YAML files sucks, so I'm a bit reserved on this. @deepu105, Do we really need to create yet another repo and npm package for which we will need to manage the release cycle. I have already lost track of how many we already have ! |
@PierreBesson multiple npm repo are better than making our core a kitchen sink. Imagine the amount of code that would need to be updated each time we rewrite something, say for example like the ES6 update I did. These are too specific functions for YML handling which ideally should be done by a lib like jsyaml, but if not either PR to that or worst case create a library to do that. This lib might never need much maintenance. Given the current size of Jhipster codebase, I'm reserved on adding stuff like these here. If is is one or two methods that's fine but this is too much code that i'm not willing to maintain in core. Remember every line of code we add makes our life tougher 😉 |
Also the main problem is that these methods are never used by the generator itself its only used by one module now and if another module needs it in the future than an external lib is ideal for that |
@deepu your 2nd point convinced me. Still wished we didn't have so many repos but I guess this can't be helped. |
Agree with you @deepu105
|
@pascalgrimaud I dont understand one thing cant you load the YML using jsyaml and add new props and stuff to the parsed object and then dump the object back using jsyaml? Isnt that what we do in our Kubernetes generator and stuff? why is it required to do all these manual parsing? Sorry of its a stupid question |
@antarus already tried this, it works fine but we lost all comments, which are so important |
Hello. there are two problems with jsyaml, the first like the pascal says, we lose all the comments. the second problem, when we load the application-dev file and save it, it adds 'null' to the 'application:' property |
@pascalgrimaud @antarus ok I understand. Did we raise the issues to jsyaml guys? I'm pretty sure they might be able to fix them since its a valid usecase? |
Since no other repo uses these at the moment if jsyaml guys can fix the issue I guess that would be the best solution |
jsyaml has not been updated since September 19th, the null is report since January 24th, and the comments not manage it seems to me that it's also reported .. |
For now, I think we should not merge this into generator-jhipster as it's specific for modules and globally for Yaml. Depending if a lot of module need it or not, we can reconsider later:
So I'm closing this, I hope you agree, @antarus |
I agree that in the state this PR is too oriented yaml, but I remain convinced that it is necessary to facilitate the integration of modules in the main project. |
I'm gonna follow YAGNIY principle here, so if another module ever needs it
we can reconsider
Thanks & Regards,
Deepu
…On Mon, Dec 11, 2017 at 2:03 PM, Cédric ***@***.***> wrote:
I agree that in the state this PR is too oriented yaml, but I remain
convinced that it is necessary to facilitate the integration of modules in
the main project.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6769 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABDlF4F41h1kspt_SGqm03PwxHbB9_0tks5s_SgZgaJpZM4QvZ5f>
.
|
This code allows you to add one or more properties to a yaml file.
code update from hipster-labs/generator-jhipster-spring-cloud-stream
Please make sure the below checklist is followed for Pull Requests.
Travis tests are green
Tests are added where necessary
Documentation is added/updated where necessary
Coding Rules & Commit Guidelines as per our CONTRIBUTING.md document are followed