generator-wercker-component
v0.1.0
Published
Scaffold out a Wercker component in no time!
Downloads
5
Readme
wercker-component-generator
Scaffold out a Wercker component in no time!
Installation
This is a Yeoman generator so Yeoman needs to be installed globally to run it. With Yarn installed run:
yarn global add yo
Create a project directory
mkdir <name of your component> && cd "$_"
Now you're ready to install the generator. This can be done globally (with the
global
flag) or within the project.
yarn add wercker-component-generator
With the generator installed you should be able to run it:
yo wercker-component
Once completed the files are scaffolded out and the component is ready to be developed.
Requirements
The generator required Node.js 6 or later.
Developing a component
Once the component has been generated start dev mode with yarn dev
. Open up
localhost:3000 to see the result.
This sets up a webpack dev server that watches the files and rebuilds things as needed.
In order to present multiple states of a component an example
page is created
in src/example/page.js
. Update this page, passing in various props to your
component, to showcase the different ways the component can be used. When you
start dev mode this page is rendered for you to see.
Generated files
| path | what is it? |
|-------------------------|-------------------------------------------------------------------|
| .git/
| Empty git repository set up |
| node_modules/
| Dependencies from package.json |
| src/
| Component source |
| src/__snapshots__/
| Jest snapshots |
| src/example/index.js
| Setup stuff for the example page |
| src/example/page.js
| The contents of the example page (update this page) |
| src/component.js
| Component implementation |
| src/component.test.js
| Jest unit tests for component |
| src/index.js
| Component exports |
| src/styles.css
| Component CSS |
| .babelrc
| Confiugration for Babel |
| .eslintrc.js
| Configuration for ESlint |
| .flowconfig
| Configuration for Flow |
| .gitignore
| Sensible default ignores |
| .stylelintrc
| Configuration for Stylelint |
| LICENSE
| Apache 2 license |
| package.json
| Dependencies for component build |
| README.md
| Component readme |
| webpack.config.dev.js
| Webpack config for development time |
| webpack.config.js
| Webpack config for building building distributable components |
| wercker.yml
| Default Wercker build configuration |
| yarn.lock
| Lockfile for Yarn. This locks dependencies to a certain version |
Scripts in generated component
Run with yarn run <script name>
| script | purpose |
|-----------------|----------------------------------------------------------------------------|
| lint-css
| Checks CSS for stylisting errors and warnings with Stylelint |
| lint-js
| Checks Javascript for common errors and style with ESLint |
| flow
| Runs Flow type checker |
| lint
| Runs css and js linters + flow type checker |
| prettier
| Runs Prettier on all javascript and css to format the code |
| stylefmt
| Runs [Styleflmt] on all css sort declarations |
| format
| Formats javascript (prettier) and css (stylefmt) |
| test
| Runs Jest unit tests |
| test-coverage
| Runs Jest unit tests with code coverage enabled (written in coverage/
) |
| check-eslint
| Checks that there are no conflicting ESlint rules with Prettier |
CSS modules
The CSS is scoped to the component itself so the class name can be written in a
human-friendly way, rather than being worried that it will clash with other
classes. A class name such as button
, title
, background
or similar is
perfectly fine (and encouraged).
Prettier
Prettier is used to format all javascript and css source code. This removes all discussion about style (similar to gofmt).
The default configuration is modified slightly:
--single-quote
--parser flow
--trailing-comma es5
You probably want to integrate this in your editor but if not you can use yarn
prettier
to format the code. Code that is not formatted with prettier will
break the build.