0.1.0 • Published 8 years ago

generator-wercker-component v0.1.0

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
8 years ago

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

pathwhat is it?
.git/Empty git repository set up
node_modules/Dependencies from package.json
src/Component source
src/__snapshots__/Jest snapshots
src/example/index.jsSetup stuff for the example page
src/example/page.jsThe contents of the example page (update this page)
src/component.jsComponent implementation
src/component.test.jsJest unit tests for component
src/index.jsComponent exports
src/styles.cssComponent CSS
.babelrcConfiugration for Babel
.eslintrc.jsConfiguration for ESlint
.flowconfigConfiguration for Flow
.gitignoreSensible default ignores
.stylelintrcConfiguration for Stylelint
LICENSEApache 2 license
package.jsonDependencies for component build
README.mdComponent readme
webpack.config.dev.jsWebpack config for development time
webpack.config.jsWebpack config for building building distributable components
wercker.ymlDefault Wercker build configuration
yarn.lockLockfile for Yarn. This locks dependencies to a certain version

Scripts in generated component

Run with yarn run <script name>

scriptpurpose
lint-cssChecks CSS for stylisting errors and warnings with Stylelint
lint-jsChecks Javascript for common errors and style with ESLint
flowRuns Flow type checker
lintRuns css and js linters + flow type checker
prettierRuns Prettier on all javascript and css to format the code
stylefmtRuns Styleflmt on all css sort declarations
formatFormats javascript (prettier) and css (stylefmt)
testRuns Jest unit tests
test-coverageRuns Jest unit tests with code coverage enabled (written in coverage/)
check-eslintChecks 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.

Stylefmt