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

Add object enum #36

Merged
merged 5 commits into from
Apr 12, 2020
Merged

Conversation

felipeplets
Copy link
Collaborator

export type ${iconTypeName} = ${svgDefinitions
.map(({ typeName }, index) => `'${typeName}'${index === svgDefinitions.length - 1 ? '' : ' | '}`)
.join('')};`;
const typeObject = `
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that currently, we would always generate both, an object for iteration and also a type and there's no option to disable it. I am just thinking of the best way to do this.

I personally would prefer to generate types by default. Then I would also offer the possibility to generate only the const or const and type. Some options like this

generateTypes: boolean (default: true);
generateTypeObject:boolean (default: false);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felipeplets what do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea. Will push the change later today.

@felipeplets
Copy link
Collaborator Author

@kreuzerk the options are created and work as we aligned.

The only point is that reading about commander I understood that to work as a boolean you can set --no-optionName and it will set the option as false, so as the default is true I've documented this way on the readme.

Also if --generateTypeObject is defined it will always generate the type as the object need it.

@@ -10,6 +10,8 @@ export const setupCommander = () => {
commander
.version(packgeJSON.version)
.option('-t --typeName <string>', 'name of the generated enumeration type', DEFAULT_OPTIONS.typeName)
.option('--no-generateType', 'prevent generating enumeration type', DEFAULT_OPTIONS.generateType)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--generateType instead of --no-generateType

README.md Outdated
@@ -201,6 +201,8 @@ Available configurations:
| --version | type | default | output the version number |
| ------------------------- | ----------------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| typeName | string | myIcons | name of the generated type |
| no-generateType | boolean | false | prevent generating enumeration type |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generateTypeinstead of no-generateTypeand it defaults to true

);
return typeHeader + types.join('');

if (convertionOptions.generateType || convertionOptions.generateTypeObject) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the or check - I would say that the user should be able to generate either a type or an object or both.

@nivekcode
Copy link
Owner

nivekcode commented Apr 6, 2020

Sorry, I just saw your comment now. All my comments in the PR correspond to your comment. 😅

I would still prefer to have the public flags like discussed. Users could still set the --generateType=false.

Why are the types needed if you generate the options?

@felipeplets
Copy link
Collaborator Author

Actually we can generate the object with the type, it's just less strict but can be done. I will change the code accordingly.

@felipeplets
Copy link
Collaborator Author

felipeplets commented Apr 6, 2020

Regarding the config parameters, I've read the guide from commander before implementing and had a couple of findings that I would address in another PR, but I can list them bellow because I believe they can be beneficial to this topic.

The commander way of setting boolean parameters is:

  • syntax --paramName
  • if --paramName is not set the value will be the default value
  • if --paramName is set the value will be true
  • if --no-paramName is set the value will be false (the no- is automatically converted to false on the parameter paramName)

I understand this is different from Angular CLI syntax, which uses it's own parser: https://github.com/angular/angular-cli/blob/master/packages/angular/cli/models/parser.ts

If we want to implement following the same Angular syntax --paramName=true|false we can but we need to add a parser for the boolean values to make sure they are behaving as expected (I can address it in a next PR if you agree).

Also --paramName <paramValue> the paramValue is always a string if we don't parse it so --compileSources and --optimizeForLazyLoading only work now because the default is false but when we set them --optimizeForLazyLoading true they actually become 'true' which is truthy. So --compileSources false and --optimizeForLazyLoading false actually make them truthy which I consider to be a bug if they are meant to be boolean.

If you agree I can change this implementation to parse the same way Angular parses, have them both as --generateType <boolean> and --generateTypeObject <boolean> and in a later PR we can apply it to the existing boolean params.

@nivekcode
Copy link
Owner

@felipeplets Wow! Thanks a lot for that detailed explanation. 👍 Didn't know about this commander conventions.

I would prefer to parse them in the way Angular parses them. I think most developers are familiar with the Angular way and less with the commander way.

@nivekcode
Copy link
Owner

nivekcode commented Apr 6, 2020

So, this means that once we change the parsing to the way Angular parses we have to do a breaking change? Are there still changes open for this branch or are we good to merge?

@felipeplets
Copy link
Collaborator Author

I don't see any breaking change.
I would say from the 3 implementations I did or am doing it all would result in a minor update.

  • Add --generateType and --generateTypeObject options to better control the auto-generated type
  • Enhance performance by adding parallel processing the icons
  • Fix --optimizeForLazyLoading and --compileSources to respect a false parameter

@nivekcode
Copy link
Owner

👍 So in order to merge this PR I would still adjust the following points:

  • Remove the or check for the type generation
  • Rename the no-generateType to generateType. I think it is cool if we keep all of our options sync - means all the argument configurations are the same as the configurations in package.json or .svg-to-tsrc

@felipeplets
Copy link
Collaborator Author

That is right @kreuzerk , this week is a bit busy for me so I will only be able to implement the changes over the weekend.

@nivekcode
Copy link
Owner

@felipeplets no stress - I can also help if you want - just let me know

@felipeplets
Copy link
Collaborator Author

@kreuzerk I've implemented the changes we agreed.

@nivekcode
Copy link
Owner

@felipeplets Awesome will go through them today and release the version today. Thanks a lot for the great work 👍

@nivekcode nivekcode merged commit 7b86b3c into nivekcode:master Apr 12, 2020
@nivekcode
Copy link
Owner

🎉 This PR is included in version 4.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nivekcode nivekcode linked an issue Apr 12, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable the type to be an enumerator instead of a type.
2 participants