-
Notifications
You must be signed in to change notification settings - Fork 320
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 component options (args) to YAML, add as JSON to package
#998
Conversation
1668edf
to
7fd6b03
Compare
tasks/gulp/copy-to-destination.js
Outdated
|
||
try { | ||
let json = yaml.safeLoad(fs.readFileSync(componentPath), {encoding: 'utf8', json: true}) | ||
let paramsJson = {'params': json.params} // We only want the 'params' data from component yaml |
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.
should we stop the task if the yaml file doesn't contain the params
data ?
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 in a try
block so it will throw up an error if that happens and the tests will also fail. That's probably okay? This is in the middle of the copy-files
task so if we exit here, there might already be files copied over to package
and others deleted.
a700c1f
to
4cd3f81
Compare
4cd3f81
to
dbdecba
Compare
dbdecba
to
d05f1f8
Compare
d05f1f8
to
7e0ed3f
Compare
7e0ed3f
to
5b6970a
Compare
package
package
- name: caller | ||
type: nunjucks-block | ||
required: false | ||
description: Not strictly a parameter but <a href="https://mozilla.github.io/nunjucks/templating.html#call">Nunjucks code convention</a>. Using a `call` block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire fielset component in a `call` block. See <a href="https://github.com/alphagov/govuk-frontend/blob/master/src/components/checkboxes/template.njk#L86">checkboxes component</a> for an example. |
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're using html here for the links. We're also using ` backticks for option names, which is a markdown convention. We don't have to do anything with the backticks, but it's probably best to run them through a renderer to get <code>
blocks. In which case maybe we should just use markdown for the links too?
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.
Good shout. I was avoiding markdown since I only needed to use HTML in this one place for the component options and we discovered we'll need to do some extra processing as part of the build in the Design System to render markdown from here. But since we've got the code blocks too then making it all markdown makes sense 🙂
5b6970a
to
3bad6a4
Compare
tasks/gulp/copy-to-destination.js
Outdated
let paramsJson = json.params // We only want the 'params' data from component yaml | ||
file.contents = Buffer.from(JSON.stringify(paramsJson, null, 4)) | ||
} catch (e) { | ||
console.log('ENOENT: no such file or directory: ', 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 should probably be console.error
. Also the try
section has 3 lines in it, so we don't know for sure that this is the error. I'd recommend trying to reduce the try
to just opening the 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.
I've split up the error messages more, have a look.
tasks/gulp/copy-to-destination.js
Outdated
let componentPath = path.join(configPaths.components, componentName, `${componentName}.yaml`) | ||
|
||
try { | ||
let json = yaml.safeLoad(fs.readFileSync(componentPath), {encoding: 'utf8', json: true}) |
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 readFileSync
could be pulled out into a line above to make it more readable and have fewer operations happening in a single line
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.
Changed!
Do we still have a frontend test app? Maybe we can read the macro options json and write to a page in that, so we can see it works? |
3bad6a4
to
a89abfe
Compare
a89abfe
to
d8b2b40
Compare
@joelanman Thanks a lot for the review 🙌 We test if the file contains JSON and if the JSON contains attributes ( |
f771693
to
38c8fdf
Compare
38c8fdf
to
7881ccc
Compare
7881ccc
to
cbef971
Compare
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.
All the components have been reviewed by the team and given a 👍 so I think this is good to go.
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 need to add a CHANGELOG entry
beeb64a
to
00135bf
Compare
00135bf
to
535f17d
Compare
535f17d
to
83ba92d
Compare
83ba92d
to
624c997
Compare
Call files `macro-options.json` as only that data is copied over to package.
`additionalFilesInSrc` can now accept wildcards in filenames, allowing us to add new files to `package/components`. The test checks if all components have a `macro-options.json` and whether it contains JSON with expected attributes "name", "type", "required" and "description".
624c997
to
643ae80
Compare
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 a ton of work, thanks a lot Hanna 👍
As per changes made in #998 and alphagov/govuk-design-system#518 update contributor docs on component options
We want to expose the component options (arguments) to GOV.UK Design System. To do this, they need to be generated for inclusion in
package
.This PR:
params
.isComponent
option (so that the options for that component can be linked to in the Design System).package
whengulp build:package --destination 'package'
is run.package
to allow filenames with wildcards inadditionalFilesNotInSrc
package/components
have amacro-options.json
that contains valid JSON with the expected attributesname
,type
,required
,description
Created this as one PR so that the generated JSON files can be tested against alphagov/govuk-design-system#518
More on component options:
text
andhtml
attributes, we are continuing to explain this in the description of the attributes, ie. "Ifhtml
is set, this is not required." There didn't seem to be a sensible way of trying to show this relationship in a simple table so using just text appeared to be the most accessible method.To test, run
npm run build:package
https://trello.com/c/QN0imhXt/722-define-arguments-for-components-in-the-component-yaml-file
https://trello.com/c/00iDbQOU/1323-allow-argument-yamls-to-be-transformed-into-json-and-copied-to-package