-
Notifications
You must be signed in to change notification settings - Fork 8
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(schemas): extend schema and split builders #18
Conversation
export default createBuilder<Options & JsonObject>((options: Options, context: BuilderContext) => { | ||
return new Promise<BuilderOutput>(async (resolve, reject) => { | ||
try { | ||
if (options.conversionType !== ConversionType.CONSTANTS) { |
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 remove the check for options.conversionType
because schema now requires it and it won't get to the error.
I added a check to match builder with the options.conversionType
and removed extra conditionals to simplify.
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.
Perfect - that's also how I imagined it.
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.
With the comment above I think that we can also remove this check. Basically, we would remove the conversionType
from the options in this project.
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.
Gave this a shot and it raises a question. It's trivial to remove the validation bit in the index.ts
files. The side effect is I can't remove the requirement from schema.json
because that drives the conditional logic and schema checks run before any typescript checks, otherwise I could just for the correct value on the typescript side.
Removing validation would be ok, maybe, because in an ideal world the ng-add setup the builder correctly and it should work. Other fields would also likely fail if the user mismatched them, just not sure they would know why.
Thoughts 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 see. Very good point. I didn't think about this. In this case, I would leave it as it is. Maybe it's even better because then the options are the same as in svg-to-ts
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.
@kaltepeter very very nice, well done 👍 The only thing I would still do before merging is to remove the conversionOption
from the schema
and the README
. What do you think?
After we merged this, I think we are ready to release v1.0.0. The ng-add can then be another feature that follows later, what do you think?
"generate-icons": { | ||
"builder": "@angular-extensions/svg-icons-builder:svg-icons-files-builder", | ||
"options": { | ||
"conversionType": "files", |
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.
Do we still need to specify the conversionType
? I think this is already specified with the builder.
export default createBuilder<Options & JsonObject>((options: Options, context: BuilderContext) => { | ||
return new Promise<BuilderOutput>(async (resolve, reject) => { | ||
try { | ||
if (options.conversionType !== ConversionType.CONSTANTS) { |
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.
With the comment above I think that we can also remove this check. Basically, we would remove the conversionType
from the options in this project.
}, | ||
"svgoConfig": { | ||
{ | ||
"if": { |
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.
Very cool - I didn't know that you can use if
then
statements in schema.json
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 didn't either! I was trying to re-use fields and found this. The nice tool online to test schemas does not yet support this but working in small bits worked.
@@ -0,0 +1,15 @@ | |||
import { CommonConversionOptions } from 'svg-to-ts'; | |||
import { Delimiter } from 'svg-to-ts/src/lib/generators/code-snippet-generators'; |
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 also something we should export from svg-to-ts
. I will do this and then adjust later once a new version from svg-to-ts
is deployed.
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.
Sounds good!
🎉 This PR is included in version 1.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
fixes: #9
I had originally intended to create a separate schema for each type but that introduced a few challenges. The builders are able to stay isolated easy enough.
Schema options/challenges:
$ref
to include base options for that schema. Did not work with angular cli requiring explicit uri's for refs. Tested with gist and it would work if the uri exists. (https://json-schema.org/understanding-json-schema/structuring.html#extending)conversionType
to conditionally include the properties for a builder using the$ref
technique in the same schema file. (https://json-schema.org/understanding-json-schema/reference/conditionals.html)Things to consider:
angular.json
This approach can be take further or require the builder config to provide all required fields and make it easier with #15 generating the default config. @kreuzerk I stopped here as a good point to get thoughts. Maybe issue #15 is a better place to decide.