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

Spike on rearranging the build and server methods. #878

Conversation

roblevintennis
Copy link
Contributor

@roblevintennis roblevintennis commented Mar 19, 2018

WIP for rearranging the print build and server methods with hopes to expose as overridable styleguide.config methods. this is for #876

I wasn't sure how this should be verified so I essentially copied examples/basic to examples/custom-message with the idea I'd get it to print the custom console message.

@roblevintennis
Copy link
Contributor Author

roblevintennis commented Mar 19, 2018

@sapegin I'm a bit stuck on what to do for configuring the schema to add the two new config options (the functions printBuildInstructions and printServerInstructions), and just even getting the sanitizeConfig to work at all:

image

That's when I try to run my new custom message example. I tried to log or throw error in scripts/utils/sanitizeConfig.js but it's not showing up in my console so I'm obviously totally misunderstanding something there, so any guidance there would be appreciated.

Update: I sort of see what's happening, it's actually using the node module version of styleguidist:
image

It's end of day for me, I'll hopefully figure out how to do this tomorrow

Copy link
Member

@sapegin sapegin left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@@ -0,0 +1,9 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

Please use one of the existing examples (like customised), creating a new one would be an overkill ;-)

That will probably fix the issue with unknown config option too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha ah ok, gotcha, I'm headed to work now...will give it a whirl thanks for help @sapegin :)

@roblevintennis
Copy link
Contributor Author

roblevintennis commented Mar 20, 2018

So the issue I was having was that I intuitively ran the examples from examples dir like: examples/foo$ npm run styleguide which of course meant it'd use the node modules styleguidist. But having a look at package.json we have these covered and locally pointing to correct styleguidist.js e.g. yarn start:customised in my case. Fixed the issue.

image

@sapegin I think this is reviewable

P.S. I'm going to see if there's a place to add a note about using the top level package.json scripts when developing / contributing in the examples on another small documentation PR :)

@@ -94,8 +94,10 @@ function commandBuild() {
if (err) {
console.error(err);
process.exit(1);
} else if (typeof config.printBuildInstructions === 'function') {
Copy link
Member

Choose a reason for hiding this comment

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

We can be sure that if a config option has a value, then it's a function (it'd fail before otherwise), so if (config.printBuildInstructions) would be enough.

Copy link
Contributor Author

@roblevintennis roblevintennis Mar 20, 2018

Choose a reason for hiding this comment

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

Addressed in 0eda93b

printInstructions(isHttps, config.serverHost, config.serverPort);
const configuration = Object.assign({ isHttps }, config);
if (typeof config.printServerInstructions === 'function') {
config.printServerInstructions(configuration);
Copy link
Member

Choose a reason for hiding this comment

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

I'd do config.printServerInstructions(config, { isHttps });, so config would be always a styleguide config, and extra options would be separated — less cognitive load ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. Fixed in 0eda93b


Type: `Function`, optional

Function that allows you to override the printing of build messages to console.log. Takes the `config` object with `isHttps` merged in.
Copy link
Member

Choose a reason for hiding this comment

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

I’d show an example instead of Takes the configobject withisHttps merged in..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great point. I removed and added example for both methods in 0eda93b

@@ -19,6 +19,8 @@ const CLIENT_CONFIG_OPTIONS = [
'showCode',
'showUsage',
'showSidebar',
'printBuildInstructions',
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need this, we use this array to pass config options to React.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed and ran locally and nothing bad happened. Thanks for heads up

…rintServerInstructions from CLIENT_CONFIG_OPTIONS array. Cleanup calls to new methods.
@roblevintennis
Copy link
Contributor Author

@sapegin thanks for your guidance. I think this is ready for another gander

@sapegin sapegin added this to the 6.3.0 milestone Mar 21, 2018
@sapegin
Copy link
Member

sapegin commented Mar 21, 2018

Thanks! Will include in the next release ;-)

@sapegin sapegin merged commit a2c9c3f into styleguidist:master Mar 21, 2018
@roblevintennis
Copy link
Contributor Author

awesome thanks!

@roblevintennis roblevintennis deleted the expose-print-to-console-for-build-and-server branch March 21, 2018 17:01
sapegin pushed a commit that referenced this pull request Mar 22, 2018
👋 **[Support Styleguidist](https://opencollective.com/styleguidist) on Open Collective** 👋

## New features

### Page per section 🚧

This is a huge improvement for large style guides: now you can show only one component at a page instead of all components.

![](https://d3vv6lp55qjaqc.cloudfront.net/items/0W2q2K2s3n2k311O1J0y/Screen%20Recording%202018-03-22%20at%2010.06%20AM.gif)

To enable:

```js
module.exports = {
  pagePerSection: true
};
```

This is an experimental feature and we need your feedback to make it better and really useful. For example, right now there’s no isolated mode. So feel free to share your ideas [in issues](https://github.com/styleguidist/react-styleguidist/issues).

(#835 by @bitionaire and @stepancar, closes #494 and #768)

### “Fork me” ribbon

One more step to make Styleguidist usable for documenting open source projects:

![](https://d3vv6lp55qjaqc.cloudfront.net/items/1t331n2a3v0F2i290K0Z/Image%202018-03-22%20at%209.13.11%20AM.png)

New config option to enable the ribbon, define the URL and change the label:

```js
module.exports = {
  ribbon: {
    url: 'http://example.com/',
    text: 'Fork me on GitHub'
  }
};
```

And two new [theme variables](https://github.com/styleguidist/react-styleguidist/blob/master/src/styles/theme.js) to change colors: `color.ribbonBackground` and `color.ribbonText`.

(#861 by @glebez and @wkwiatek, part of #195, closes #647)

### Options to change CLI output on server start and build

Two new options, `printServerInstructions` and `printBuildInstructions`:

```js
module.exports = {
  printBuildInstructions(config) {
    console.log(
      `Style guide published to ${
        config.styleguideDir
      }. Something else interesting.`
    );
  }
};
```

(#878 by @roblevintennis, closes #876)

### Option to modify props

A new option, `updateDocs` to modify props before rendering. For example, you can load a component version number from a JSON file:

```js
module.exports = {
  updateDocs(docs) {
    if (docs.doclets.version) {
      const versionFilePath = path.resolve(
        path.dirname(file),
        docs.doclets.version
      );
      const version = require(versionFilePath).version;

      docs.doclets.version = version;
      docs.tags.version[0].description = version;
    }

    return docs;
  }
};
```

(#868 by @ryanoglesby08)

### Limited support for named exports

Styleguidist used to require default exports for components. Now you can use named exports too, though Styleguidist still supports only one component per file. I hope this change will make some users happier, see more details [in the docs](https://react-styleguidist.js.org/docs/components.html#loading-and-exposing-components).

(#825 by @marcdavi-es, closes #820 and #633)

### Allow arrays of component paths in sections

More flexibility in structuring your style guide:

```js
module.exports = {
  sections: [
    {
      name: 'Forms',
      components: [
        'lib/components/ui/Button.js',
        'lib/components/ui/Input.js'
      ]
    }
  ]
};
```

(#794 by @glebez, closes #774)

### Sort properties by `required` and `name` attributes

This change should make props tables more predictable for the users. Instead of relying on developers to sort props in a meaningful way, Styleguidist will show required props first, and sort props in each group alphabetically.

To disable sorting, use the identity function:

```javascript
module.exports = {
  sortProps: props => props
};
```

(#784 by @dotcs)

## Bug fixes

* Allow `Immutable` state in examples (#870 by @nicoffee, closes #864)
* Change template container ID to prevent clashes (#859 by @glebez, closes #753)
* Better props definitions with Flow types (#781 by @nanot1m)
@sapegin
Copy link
Member

sapegin commented Mar 22, 2018

🎉 This PR is included in version 6.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

2 participants