Giter Club home page Giter Club logo

create-react-styleguide's Introduction

create-react-styleguide

npm version Build Status

create-react-styleguide (a la create-react-app) is a tool for quickly generating styleguides and component libraries.

Quickstart

Generate your first project with the following command:

npx create-react-styleguide new my-new-styleguide

Projects are generated and configured with working styleguide documentation. To start your styleguide server run the following:

cd my-new-styleguide && npm start

Finally visit http://localhost:6060 to view your living styleguide!

Options

You can see all options for project generation with the following command:

npx create-react-styleguide --help

--stable

By default, the project will be built with the latest caret (^) version of all dependencies. If this configuration fails, use the --stable flag to generate with a known working configuration.

npx create-react-styleguide new my-new-styleguide --stable

NPM Scripts

Generated projects include the following npm scripts out of the box:

Script Description
npm start Start the styleguide server on http://localhost:6060
npm run build Build the component library to the dist folder
npm run build:styleguide Build the styleguide to the styleguide folder
npm run build:watch Watch the src folder for changes and run the build script
npm run clean Clean generated folders
npm run eslint Run eslint on all .js and .jsx files in the src folder
npm run eslint:fix Run eslint with the --fix option
npm test Run unit tests
npm run test:coverage Run unit tests with code coverage
npm run test:update Update unit test snapshots
npm run test:watch Run unit tests while watching for changes

Document Styleguide

By default, we expose some meta data from your package.json file at the top of your styleguide -- at the very least, make sure you set the "version", "homepage", and "author" properties. You can further document your library with markdown files using the sections configuration from React Styleguidist. By convention, additional markdown documentation should go in the docs folder so that they get properly packaged when linking multiple styleguides.

Customized style guide

Modify Rollup Config

You can customize Rollup configuration to your requirements. In example, you can update rollup.config.js with a sample plugin and a banner for each output file.

const { rollupConfig } = require('create-react-styleguide');
+const sampleRollupPlugin = require('sample-rollup-plugin');

module.exports = {
    ...rollupConfig,

+    output: {
+        ...rollupConfig.output,
+        banner: '/* (c) My Company Inc. */',
+    },

+    plugins: [
+        ...rollupConfig.plugins,
+        sampleRollupPlugin(),
+    ],
};

Modify Babel Config

You can customize Babel configuration to your requirements. In example, you can add SVG support with the inline-react-svg babel plugin. npm i --save-dev babel-plugin-inline-react-svg and then update babel.config.js file as follows:

const { babelConfig } = require('create-react-styleguide');

module.exports = {
    ...babelConfig,
+    plugins: [
+        ...babelConfig.plugins,
+        'inline-react-svg',
+    ],
};

You should now be able to import and use SVGs as if they were react components!

Modify Jest Config

You can customize Jest configuration to your requirements. In example, you can update jest.config.js with new threshold values.

const { jestConfig } = require('create-react-styleguide');

module.exports = {
    ...jestConfig,
+    coverageThreshold: {
+        global: {
+            branches: 80,
+            functions: 80,
+            lines: 80,
+            statements: 80,
+        },
+    },
};

Styleguide Config

Require the module:

// styleguide.config.js
const { createStyleguideConfig } = require('create-react-styleguide');

createStyleguideConfig(config, options)

Creates a React Styleguidist configuration object with some default configuration.

  • config [object] - A configuration object to be shallowly merged with the rest of the configuration
  • options.styleguides [array] - An array of CRS npm modules (the module must be installed as a dependency to your project)
  • options.packageSection [boolean] - Include package.json details as a top level section (default: true)
  • options.packageSectionComponents [boolean] - Include components configuration in the top-level package section (default: false)
  • options.componentsSection [boolean] - Include components configuration as its own separate section (default: true)

Linking Styleguides

A useful feature of create-react-styleguide is the ability to link multiple CRS component libraries into a single project. This means that separate teams can manage and own their own individual CRS libraries, and then bring them all together into a master project for broader visibility.

For a styleguide to be linked, it must first be published to npm. Running npm publish will build and publish your component library so that it can be consumed by the master project.

From the master project, first install the published CRS module. Second, you will want to add a styleguides property to the options of your createStyleguideConfig function in styleguide.config.js.

 const { createStyleguideConfig } = require('create-react-styleguide');

 module.exports = createStyleguideConfig({
     /* your own config shallowly merged here */
+}, {
+    styleguides: [
+        '@zillow/my-first-component-library',
+        '@zillow/my-second-component-library'
+    ]
 });

That's it! Running npm start will now show components from all linked libraries.

Linked style guide

Deploying Styleguide to GitHub Pages

Install the gh-pages module:

npm i --save-dev gh-pages

Add the following scripts to your package.json:

 "scripts": {
+  "predeploy": "npm run build:styleguide",
+  "deploy": "gh-pages -d styleguide"
 }

Running npm run deploy will now deploy your styleguide to Github Pages!

Environment Variables

DEBUG

All config files will log their results to the console when the DEBUG environment variable is set to any non-empty value (such as true or 1). A quick way to see the configuration these functions are creating is to run the following:

DEBUG=true node styleguide.config.js

or

DEBUG=true node jest.config.js

PORT

By default, npm start will run the react-styleguidist server on its default port, 6060. To change this, set the PORT environment variable to your custom value:

PORT=12345 npm start

Under the covers

create-react-styleguide leverages react-styleguidist under the covers for its living style guide.

Builds are created by running the src directory through Rollup and Babel. The build will create 4 bundles, dev and prod for CJS and ESM formats. An application, which imports your package, will select a correct bundle, based on node environment and bundler capabilities. In example, ESM for Vite or CJS for Webpack 4.

Migration Guide from 7x to 8x

Please read our migration guide to streamline your update efforts.

create-react-styleguide's People

Contributors

begerter avatar beryle-zillow avatar evocateur avatar kris-ellery avatar stonebk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

create-react-styleguide's Issues

Terminal error when trying to use create-react-styleguide

▶ npx create-react-styleguide new @zillow/zrs-foundation
? author:
? homepage:
create .gitignore
create CONTRIBUTING.md
create README.md
create babel.config.js
create docs/introduction.md
create jest.config.js
create package.json
create styleguide.config.js
create jest.config.js
create src/tests/index.test.js
create src/components/Button/Button.jsx
create src/components/Button/Button.md
create src/components/Button/index.js
create src/index.js
create src/styleguidist/ThemeWrapper.jsx
create src/themes/Bootstrap/index.js
create src/themes/index.js
create styleguide.config.js
create .eslintignore
create .eslintrc
✔ Initing Git repo
✔ Installing react@^16.7.0, react-dom@^16.7.0, create-react-styleguide, babel-preset-zillow@^4.0.3, husky@^1.3.1, react-test-renderer@^16.7.0, eslint-plugin-zillow@^3.1.0, eslint-plugin-jest@^22.2.1, babel-plugin-styled-components@^1.10.0 and jest-styled-components@^6.3.1
✔ Installing prop-types@^15.6.2 and styled-components@^4.1.3
✖ Adding initial commit in Git repo
Command failed: git commit -m "Initial commit from create-react-styleguide v4.0.6"
husky > pre-commit (node v10.15.3)

@zillow/[email protected] eslint path/to/my/crs-project
create-react-styleguide script eslint

path/to/my/crs-project/src/tests/index.test.js
3:38 error Unable to resolve path to module '../components/Button/Button' zillow/import/no-unresolved

path/to/my/crs-project/src/components/Button/index.js
1:25 error Unable to resolve path to module './Button' zillow/import/no-unresolved

✖ 2 problems (2 errors, 0 warnings)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @zillow/[email protected] eslint: create-react-styleguide script eslint
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @zillow/[email protected] eslint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! path/to/my/crs-project/.npm/_logs/2019-07-01T23_45_43_583Z-debug.log
husky > pre-commit hook failed (add --no-verify to bypass)

Should examples include theming?

I think theming is super important for component libraries, but it may be unnecessary complexity for getting started. We can add documentation about how you can extend the basic examples to include a theme.

Webpack config for importing external CSS/Images/Fonts

Currently when building my own style-guide, generated as described in the readme, I am unable to import assets other than javascript.

_
I would like to be able to import css
-- Locally sourced CSS (regular)
-- Locally sourced CSS file for generated font-face stacks (url sourcing issue?)
-- CSS files that are required by NPM-installed React components (rc-slider for example)
-- Stylesheets resets that are installed via NPM (like sanitize.css) --^ same issue I believe

I would like to be able to import images
-- to source as src of an img tag
-- to use as a background-image for inline CSS (styled-jsx / styled-components)

I would like to be able to import font faces(?)
-- to be referenced by a CSS stylesheet I have generated from a font-face generator(!)
-- to be required inside of the CSS file in the url param(??? - maybe not)
-- [OTHER USE?]

Cannot create a class based component

Only stateless components seem to render

const Button = props => <button {...props} />;

import React from 'react';
export default class Test {
    render() {
        return (
            <div>Hello</div>
        );
    }
}

does not work. compiles but fails silently.
@stonebk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.