npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

generator-reactor

v1.3.3

Published

Yeoman generator for ReactJS and Webpack

Downloads

8

Readme

generator-reactor

Build Status

Yeoman generator for ReactJS - lets you quickly set up a project including karma test runner and Webpack module system. Using NPM Scripts, Karma and WebPack by default.

Example

http://willmendesneto.github.io/generator-reactor/

Usage

Install generator-reactor:

npm install -g generator-reactor

Make a new directory, and cd into it:

mkdir my-new-project && cd $_

Run yo reactor, optionally passing an app name:

yo reactor [app-name]

Run npm run build for building and npm run start-dist for preview in the browser at localhost.

Generators

Available generators:

and for Flux or Reflux :

App

Sets up a new ReactJS app, generating all the boilerplate you need to get started. The app generator also facilitates the following:

  1. Configures Webpack to modularise the app enabling loading of various file formats e.g. JSON, CSS, PNG, etc.
  2. Configures Karma to run all tests.
  3. Watches for changes and recompiles JS and refreshes the browser.

Example:

yo reactor

Component

Generates a JSX component in src/scripts/components, its corresponding test in src/spec/components and its style in src/style.

Example:

yo reactor:component foo  //or just: yo reactor:c foo

Produces src/components/Foo.js (javascript - JSX):

'use strict';

var React = require('react/addons');

require('styles/componentName.css'); //or .sass,.less etc...

var Foo = React.createClass({
  render: function () {
    return (
        <div>
          <p>Content for Foo</p>
        </div>
      )
  }
});

module.exports = Foo;

And test/spec/components/Foo.js (javascript - jasmine):

'use strict';

describe('Foo', function () {
  var Foo, component;

  beforeEach(function () {
    Foo = require('../../../src/components/Foo');
    component = Foo();
  });

  it('should create a new instance of Foo', function () {
    expect(component).toBeDefined();
  });
});

Create stylesheet of component

You can add a stylesheet file for your new component using - style flag:

yo reactor:c foo --style

And src/styles/Foo.css (or .sass, .less etc...) will be created:

.Foo{
  border: 1px dashed #f00;
}

rich flag

For all you lazy programmers out there, we've added another shortcut - rich flag:

yo reactor:c foo --rich

This will give you all of react component's most common stuff :

var React = require('react/addons');

require('styles/Foofoo.sass');

var Foofoo = React.createClass({
  mixins: [],
  getInitialState: function() { return({}) },
  getDefaultProps: function() {},
  componentWillMount: function() {},
  componentDidMount: function() {},
  shouldComponentUpdate: function() {},
  componentDidUpdate: function() {},
  componentWillUnmount: function() {},

  render: function () {
    return (
        <div>
          <p>Content for Foofoo</p>
        </div>
      );
  }
});

module.exports = Foofoo;

Just remove those you don't need, then fill and space out the rest.

Action

When using Flux or Reflux architecture, it generates an actionCreator in src/actions and it's corresponding test in src/spec/actions.

Example:

yo reactor:action bar //or just: yo reactor:a bar

Will create a file - src/actions/BarActionCreators.js

if 'architecture' is Flux, it Produces :

'use strict';

var BarActionCreators = {

}

module.exports = BarActionCreators;

And if it's Reflux:

'use strict';

var Reflux = require('reflux');

var BarActionCreators  =  Reflux.createActions([

]);


module.exports = BarActionCreators;

and same test for both architectures:

'use strict';

describe('BarActionCreators', function() {
  var action;

  beforeEach(function() {
    action = require('actions/BarActionCreators.js');
  });

  it('should be defined', function() {
    expect(action).toBeDefined();
  });
});

Store

When using Flux or Reflux architecture, it generates a store in src/stores and it's corresponding test in src/spec/stores.

Example:

yo reactor:store baz //or just: yo reactor:s baz

Will create a file - src/stores/BazStore.js

if 'architecture' is Flux, it Produces :

'use strict';

var EventEmitter = require('events').EventEmitter;
var assign = require('object-assign');
var MainAppDispatcher = require('../dispatcher/MainAppDispatcher');

var BazStore = assign({}, EventEmitter.prototype, {

});

BazStore.dispatchToken = MainAppDispatcher.register(function(action) {

  switch(action.type) {
    default:
  }

});

module.exports = BazStore;

And if it's Reflux:

'use strict';

var Reflux = require('reflux');
//var Actions = require('actions/..');


var BazStore = Reflux.createStore({
  listenables: Actions,


});

module.exports = BazStore;

and same test for both architectures:

'use strict';

describe('BazStore', function() {
  var store;

  beforeEach(function() {
    store = require('stores/BazStore.js');
  });

  it('should be defined', function() {
    expect(store).toBeDefined();
  });
});

Options

Options are available as additional installs to the initial application generation phase.

ReactRouter

A complete routing library for React. This option only adds the basic hooks to get started with react router.

styles language

css, sass, scss, less or stylus

Sets the style file's template and extension

architecture

flux or reflux

Testing

Running npm test will run the unit tests with karma. Tests are written using Jasmine by default.

Further Information

Naming Components

I have opted to follow @floydophone convention of uppercase for component file naming e.g. Component.js. I am open to suggestions if there is a general objection to this decision.

Modules

Each component is a module and can be required using the Webpack module system. Webpack uses Loaders which means you can also require CSS and a host of other file types. Read the Webpack documentation to find out more.

NPM Scripts

Out the box, the generator uses npm scripts configured with the following:

  1. webpack: uses the webpack to load all required modules and output to a single JS file src/scripts/components/main.js. This is included in the src/index.html file by default and will reload in the browser as and when it is recompiled.
  2. webpack-dev-server: uses the webpack-dev-server to watch for file changes and also serve the webpack app in development.
  3. karma: uses the karma to load the Karma configuration file karma.conf.js located in the project root. This will run all tests using PhantomJS by default but supports many other browsers.
  4. editorconfig-tools: check and validate all files application (src and test folders) based in .editorconfig params.

Stylesheet

Included in the project with options:

  • CSS;
  • SASS;
  • SCSS;
  • LESS;
  • STYLUS;

Contribute

Contributions are welcomed. When submitting a bugfix, write a test that exposes the bug and fails before applying your fix. Submit the test alongside the fix.

Running Tests

npm test