Closed razzeee closed 7 years ago
@Razzeee you can get it from the generated package.json
license
field.
this.fs.readJSON(this.destinationPath('package.json')).license;
Unfortunatly I need it before I write the files, as I need to write it to one of the files I'm writing it too. Not sure how to do it. My code is here: https://github.com/Razzeee/generator-kodi/blob/master/generators/app/index.js
@Razzeee you use this.props.license
after the prompt has been answered it will be populated with value
from licenses
(so it will be MIT
or Apache-2.0
or GPL-3.0
etc.).
You can see how filename is generated by appending .txt
to what you chose on https://github.com/jozefizso/generator-license/blob/master/app/index.js#L100
Hope this helps.
@ek9 the variable doesn't seem to be filed, probably due to the scope being a different one
Yeoman generators run in isolation. They don't return values.
The only way to get the selected license is from reading the value from the package.json.
You should read about the run loop here http://yeoman.io/authoring/running-context.html and order your tasks in a way where you'll be able to grab the license value from package.json to add it elsewhere.
@SBoudrias so your saying that I need a package.json to solve this? I'm creating python code, so I'm not creating a package.json
@Razzeee so you want the license to include in setup.py
?
Maybe we could add support for adding the license inside setup.py directly in this generator.
nope, I want to add it to a addon.xml as it's a generator for a kodi addon :/
Well adding things to addon.xml
isn't part of this package's scope. What I believe you should be doing:
However, this is likely to require some updates to this package too, as even when provided with some options, it still asks you to confirm things or would provide the questions multiple times. To avoid this, there needs to be some updating on when certain prompts are shown.
I plan to play around with some generators later this week, and wanted to use this one as sub-generator. Perhaps I can answer in more detail later or provide a PR which would make it possible to implement it with this.
Well could I just have my own license list and just add a matching license to options when running composeWith? If the generator does the rest of work needed, I'm fine. Will try and update later.
You can find an example on how generator-node
uses this module when asking which license to pick
https://github.com/yeoman/generator-node/blob/master/generators/app/index.js#L277
This also happens if you run yo generator
(need generator-generator
installed for that) as it calls generator-node::app
which in turn calls generator-license::app
)
The PR that is needed for you need is ability to provide "license" as an option (same way you can do with name etc.), so the license can be skipped. That way, you can have prompt in your own generator and only supply a license value to this generator. Otherwise, it will ask you for license 2nd time.
Also useful documentation on composability of Yeoman Generators: http://yeoman.io/authoring/composability.html
require('generator-license').licenses
is the list of license this generator supports. So you can use that.
I believe this one can be closed now. It might not be too bad idea to add the above comment by @SBoudrias to README.md
as it's useful information when composing generators with this one.
Is it somehow possible to get the selected license/licenseId as a return parameter?