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

Feature/api docs #79

Merged
merged 29 commits into from
Feb 27, 2018
Merged

Feature/api docs #79

merged 29 commits into from
Feb 27, 2018

Conversation

penx
Copy link
Member

@penx penx commented Feb 26, 2018

Generate API.md by calling npm run docs.

This uses react-docgen.

Due to the default resolver of react-docgen not picking up Glamorous components, I've had to wrap some Glamorous only components with a JSX wrapper. I'd rather not have to do this but not sure of any alternative solution.

reactjs/react-docgen#256

I'm also not sure the format of the current API.md is useful but opening PR for consideration.

@penx penx requested a review from marksy February 26, 2018 15:53
@penx penx requested a review from stevesims February 26, 2018 15:58
@codecov
Copy link

codecov bot commented Feb 26, 2018

Codecov Report

Merging #79 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #79   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          31     32    +1     
  Lines         187    199   +12     
  Branches        6      6           
=====================================
+ Hits          187    199   +12
Impacted Files Coverage Δ
src/components/Breadcrumb/index.js 100% <ø> (ø) ⬆️
src/components/Button/index.js 100% <100%> (ø) ⬆️
src/components/Header/index.js 100% <100%> (ø) ⬆️
src/components/PhaseBadge/index.js 100% <100%> (ø) ⬆️
src/components/Label/index.js 100% <100%> (ø) ⬆️
src/components/ErrorText/index.js 100% <100%> (ø) ⬆️
src/components/Header/presets.js 100% <100%> (ø)
src/components/LabelText/index.js 100% <100%> (ø) ⬆️
src/components/BackLink/index.js 100% <100%> (ø) ⬆️
src/components/HintText/index.js 100% <100%> (ø) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 142df41...1ae9339. Read the comment docs.

}
}
return md;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

could possibly use for of?

for (const file of files) { 
  if (shouldDocumentComponent(file)) {
    md += await generateApiForFile(file);
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I did originally but got this from eslint:

iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations. (no-restricted-syntax)

discussion airbnb/javascript#1271

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok fair play

if (!Component) {
console.log(chalk.red("Error loading component:"), file);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

is it necessary to have two if (!Component)?

Copy link
Member Author

Choose a reason for hiding this comment

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

second is "if there still isn't a component after loading the default", so yes

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. try load example.js
  2. if this didn't load, index.js
  3. if this isn't a component, look for default export
  4. if still no component then log

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah true cool

if (!props) {
return "";
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe picky, but perhaps move the if !props, return to the top to avoid the const title = "Props"; from being defined

Copy link
Collaborator

Choose a reason for hiding this comment

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

unless need the title there anyway

let newString = "";
for (let i = 0; i < length; i += 1) {
newString += string;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

could maybe use for of here too?

Copy link
Member Author

Choose a reason for hiding this comment

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

same as #79 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok

import {
BUTTON_COLOUR,
BUTTON_COLOUR_DARKEN_15,
WHITE,
YELLOW
} from "govuk-colours";

const Button = glamorous.button(
const GButton = glamorous.button(
Copy link
Collaborator

Choose a reason for hiding this comment

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

was this supposed to be renamed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah looks like it, although the naming is confusing. Maybe GlamorousButton? 👨‍💻

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, react-docgen doesn't pick up glamorous components so I'm having to wrap them with a JSX component. I renamed the inner components to start with a G for Glamorous

Copy link
Collaborator

Choose a reason for hiding this comment

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

okay might be good to document that either inline comments or in the readme

Copy link
Member Author

Choose a reason for hiding this comment

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

it's in the PR description and I've created an issue here #81

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree it's not great, I just didn't want to spend too much time on documentation at this point, will hopefully revisit soon, maybe there will be progress on glamorous + react-docgen compatibility in the meantime and we can just undo this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok sounds good

Copy link
Collaborator

@marksy marksy left a comment

Choose a reason for hiding this comment

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

LGTM, although just the comment about documenting the reason why you changed the glamorous components to have a JSX wrapper around them and also named GWhataeverComponent.

@penx penx merged commit f66de1f into master Feb 27, 2018
@penx penx deleted the feature/api-docs branch February 27, 2018 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants