Giter Club home page Giter Club logo

rangle-starter's Introduction

rangle-starter

Stories in Ready Join the chat at https://gitter.im/rangle/rangle-starter

A command-line utility to create a repo based on one of Rangle.io's standard tech stacks.

These stacks are designed to play nice with Rangle.io's dev ops tools and internal workflow. However they are open source and available to the community on an unsupported basis as well.

Looking for a tech stack that used to be here?

Installation

Install it like this:

npm install -g rangle-starter

Usage

First, create a repository for your new project on github. Leave it empty for now.

Next, run rangle-starter and answer the questions in order to setup your new project.

This will create a new repo locally based on the appropriate tech stack. npm install; npm start will build and run the sample app for that stack.

Push up your new repo with:

git push upstream master -u

Finally, go back to GitHub and fork your new repo to allow you to work using Rangle-Flow (see note below).

About the Stacks

JavaScript is evolving rapidly, with new approaches to application development appearing almost on a monthly basis. As a training firm, one of the services we provide is staying on top of these changes and advising our clients on contemporary thinking.

On the other hand, as a consultancy, we also need to start up new projects frequently and quickly, balancing up-to-date technology with production-level expertise.

These stacks are what we use on our projects to get teams up and running quickly, with our latest thinking on tools, technologies, and best practices. However they are also provided, free of warranty, for community usage under the terms of the MIT license.

Currently, we maintain starters for the following tech stacks:

React Starter

We transitioned to Facebook's Create-React-App project for building our react app starters.

To build a react starter project use the following commands:

// Install
$ npm install create-react-app -g

// Use our @rangle/scripts with create-react-app to generate react/redux app
$ create-react-app my-starter-app --scripts-version @rangle/react-scripts

Code Architecture

Regardless of framework, we favour an architectural approach based on 'atomic' components for presentation and Redux for state management. The code layout and CSS toolchain have been carefully chosen to accomodate this.

Component-Oriented Architecture (COA)

Component-oriented architecture is a way of thinking of apps as render trees of simple, presentational components. In this line of thinking, we:

  • build out a visual, domain-specific language of reusable UI components
  • separate state management and business logic from these UI components as much as we can.

Good presentational components have the following characteristics:

  • They are very granular (even as little as a few lines of HTML)
  • They encapsulate any CSS, HTML, and JS need to render themselves
  • They are isolated and composable into larger page elements
  • They are essentially pure functions that accept some attributes and produce some DOM.

You can learn more about COA here:

Presentational Components in React

For React, we use 'functional stateless components' to enforce these concepts. Most of your components will be pure functions of their props which return snippets of JSX.

Each component gets its own scoped CSS using the postss-local-by-default transformation.

Presentational Components in Angular 2

In Angular 2, we use very granular @Component classes whose rendered DOM is strictly a function of any @Input properties.

Each component gets its own scoped CSS using Angular 2's ViewEncapsulation feature.

CSS Toolchain

An important aspect of COA is that components are responsible for their own CSS. To means that we have to overcome the four classic problems associated with CSS:

  1. its global nature
  2. its tendency to repeat large sets of rules across different classes
  3. its inability to support dynamic features such as variables
  4. enormously variable browser support.

We have chosen to address these using a toolchain based on OOCSS utility classes and 'transpilation'.

OOCSS Utility Classes

Utility class libraries in CSS provide a large set of composable, single-purpose classes that can be reference directly in your component templates. There are a few good ones, such as tachyons and basscss; our current favourite is basscss.

Basscss utilities end up taking care of the lion's share of styling for our components.

CSS Transpilation

The other issues listed above are addressed using postcss, a 'transpiler' for CSS. Postcss allows you to list a set of transformation plugins for your CSS which can:

This lets us write component-level CSS files that are properly scoped and prefixed in the small number of cases where basscss is insufficient.

You can learn more about our CSS strategy from our Modular CSS training slides.

Developer Experience

We take developer experience very seriously. The starters are set up with the following tools:

Running any starter in dev mode will turn on these tools. Simply type npm run dev and point your browser at http://localhost:8080.

Building for Production

Of course, one of the main motivations of these starters is to have production bundling set up and easy to go.

Typing npm run build will produce bundled, minified, JS and CSS for optimal loading speed in most browsers.

Typing npm start will fire up a simple NodeJS server you can use to serve your app; alternately you can deploy the contents of the dist folder behind the HTTP server of your choice.

Browser Support

We aim to support the same minimum browsers as the frameworks we use. Currently that means Internet Explorer 9+ and the last two versions of Chrome and Firefox.

Quality Tools

Code quality is important to us. All our starters ship with unit testing toolchains up and running.

We also use tslint and eslint for static code linting; and finally there is a selenium-based E2E setup based on the Robot framework.

A note on Rangle-flow

At Rangle.io we use a fork-and-branch strategy for pull requests, with some modifications for our internal tooling. Repos set up using this script assume that your have a central repo for the team and developers work on personal forks.

Therefore the script sets up two remotes:

origin, which points to your personal fork, and upstream, which points to a team repo which typically belongs your github organization.

If you want to change this, just fiddle with git remote after running the script.

More Info

For more in-depth discussion of these starters, see our

rangle-starter's People

Contributors

brendanfdmoore avatar codebyuma avatar gitter-badger avatar greenkeeperio-bot avatar jakxz avatar kosz avatar sethdavenport avatar smithad15 avatar sumitarora avatar waffle-iron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rangle-starter's Issues

Starter gives the incorrect remote link on newly started repo when using https link

I successfully start a new react redux project using rangle-starter.

ericjimenez@rngl ~/W/Rangle> rangle-starter react-redux-starter ericjim https://github.com/ericjim/react-playground.git
org: //github.com/ericjim folder: react-playground
Cloning into 'react-playground'...
Saving password to keychain failed
Identity added: /Users/ericjimenez/.ssh/id_rsa ((null))
remote: Counting objects: 87, done.
remote: Compressing objects: 100% (71/71), done.
remote: Total 87 (delta 5), reused 59 (delta 4), pack-reused 0
Receiving objects: 100% (87/87), 23.75 KiB | 0 bytes/s, done.
Resolving deltas: 100% (5/5), done.
Checking connectivity... done.
Initialized empty Git repository in /Users/ericjimenez/Workspace/Rangle/react-playground/.git/
[master (root-commit) 2be5f50] Initial commit from source:
 64 files changed, 1898 insertions(+)
 ....

However, my origin remote has an invalid link.

ericjimenez@rngl ~/W/R/react-playground> git push origin master
ssh: Could not resolve hostname https: nodename nor servname provided, or not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Upon further inspection, I see that my origin is missing the //github.com

ericjimenez@rngl ~/W/R/react-playground> git remote --verbose
origin  https:ericjim/react-playground.git (fetch)
origin  https:ericjim/react-playground.git (push)
upstream    https://github.com/ericjim/react-playground.git (fetch)
upstream    https://github.com/ericjim/react-playground.git (push)

With that said, since I am using two-step auth, I need to use an ssh key to push to my repo using the starter. So I change the remote to...

ericjimenez@rngl ~/W/R/react-playground> git remote rm origin
ericjimenez@rngl ~/W/R/react-playground> git remote add origin [email protected]:ericjim/react-playground.git
ericjimenez@rngl ~/W/R/react-playground> git push origin master
Counting objects: 87, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (75/75), done.
Writing objects: 100% (87/87), 23.54 KiB | 0 bytes/s, done.
Total 87 (delta 5), reused 0 (delta 0)
To [email protected]:ericjim/react-playground.git
 * [new branch]      master -> master

And that's how I circumvent the malformed origin link when using the starter.

Add contribution guidelines

Getting some PRs from the community now which is great.

We should post some contribution guidelines. Tips on rangle-flow, CI, etc.

Might be able to recycle from other open Rangle projects?

set up css linting

Should run as part of npm test (for CI) and optionally as a webpack preloader.

Support redux-devtools

There are dependencies for redux-devtools, but that they are not used.
Are you guys manually adding and removing redux-devtools?
I was thinking that it would be good if we could get them included via a specific npm run * command. Do you guys have a plan for this already in the works?

build is creating .js and .js.map files from .tsx

When I run npm run build, each of the .tsx files in src are being transpiled into .js and .js.map files in the same place as the .tsx file.

I'd like a way to clean these files after the build is completed, or when npm run clean is executed.

autoprefixer warning

Warning: postcss-cssnext found a duplicate plugin ('autoprefixer') in your postcss plugins. This might be inefficient. You should remove 'autoprefixer' from your postcss plugin list since it's already included by postcss-cssnext.
Note: If, for a really specific reason, postcss-cssnext warnings are irrelevant for your use case, and you really know what you are doing, you can disable this warnings by setting 'warnForDuplicates' option of postcss-cssnext to 'false'.

npm install fails on Windows 7 64bit

There are a number of events that log errors throughout the npm install process.
All there errors seem to be around the gentlyRM and the node_modules.staging folder
I've include an excerpt. If you'd like more please let me know.

63159 silly gunzTarPerm extractEntry web/immediate.js
63160 silly gunzTarPerm extractEntry web/index.js
63161 silly gentlyRm c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\tslint-d9521495\node_modules is being purged
63162 verbose gentlyRm don't care about contents; nuking c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\tslint-d9521495\node_modules
63163 silly gunzTarPerm extractEntry web/timers.js
63164 silly gentlyRm c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\lodash-8cbee679\node_modules is being purged
63165 verbose gentlyRm don't care about contents; nuking c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\lodash-8cbee679\node_modules
63166 silly gentlyRm c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\lodash-es-b83bbc1c\node_modules is being purged
63167 verbose gentlyRm don't care about contents; nuking c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\lodash-es-b83bbc1c\node_modules
63168 silly gentlyRm c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\caniuse-db-56371315\node_modules is being purged
63169 verbose gentlyRm don't care about contents; nuking c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\caniuse-db-56371315\node_modules
63170 silly gentlyRm c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\core-js-593eb406\node_modules is being purged
63171 verbose gentlyRm don't care about contents; nuking c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\core-js-593eb406\node_modules
63172 silly gentlyRm c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\lodash-81788f91\node_modules is being purged
63173 verbose gentlyRm don't care about contents; nuking c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\lodash-81788f91\node_modules
63174 silly gentlyRm c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\lodash-20a473b4\node_modules is being purged
63175 verbose gentlyRm don't care about contents; nuking c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\lodash-20a473b4\node_modules
63176 silly gentlyRm c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\lodash-928b1699\node_modules is being purged
63177 verbose gentlyRm don't care about contents; nuking c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\lodash-928b1699\node_modules
63178 verbose unlock done using C:\Users\mdentremont\AppData\Roaming\npm-cache\_locks\staging-72a4912d4ab12fd9.lock for c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging
63179 silly rollbackFailedOptional Starting
63180 silly rollbackFailedOptional Finishing
63181 silly runTopLevelLifecycles Starting
63182 silly runTopLevelLifecycles Finishing
63183 silly install printInstalled
63184 warn optional Skipping failed optional dependency /chokidar/fsevents:
63185 warn notsup Not compatible with your operating system or architecture: [email protected]
63186 verbose stack Error: ENOENT: no such file or directory, open 'c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\basscss-radium-11304021\Icon
'
63186 verbose stack     at Error (native)
63187 verbose cwd c:\Projects\REACT\typescript-react-redux-starter
63188 error Windows_NT 6.1.7601
63189 error argv "c:\\Program Files\\nodejs\\node.exe" "c:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
63190 error node v5.6.0
63191 error npm  v3.6.0
63192 error path c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\basscss-radium-11304021\Icon
63193 error code ENOENT
63194 error errno -4058
63195 error syscall open
63196 error enoent ENOENT: no such file or directory, open 'c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\basscss-radium-11304021\Icon
'
63197 error enoent ENOENT: no such file or directory, open 'c:\Projects\REACT\typescript-react-redux-starter\node_modules\.staging\basscss-radium-11304021\Icon
'
63197 error enoent This is most likely not a problem with npm itself
63197 error enoent and is related to npm not being able to find a file.
63198 verbose exit [ -4058, true ]

Use node_modules/.bin links for NPM scripts

The NPM scripts currently assume we have things like webpack, cross-env, eslint, etc globally installed. This is not mentioned anywhere. Since, we already install these as local dependencies we can use node_modules/.bin links instead. For example:

"build": "node_modules/.bin/cross-env NODE_ENV=production node_modules/.binwebpack -p"

Organize npm production vs devDependencies properly

I noticed that the angular2 starter has all its dependencies listed under devDependencies. This should probably get split properly for when someone has built an app and wants to deploy it and run npm install --production [in their Dockerfile for example].

Fix sourcemaps when generating CSS into a standalone bundle

From igor-ka:

It is possible to generate css into a stand-alone bundle, and might be preferable in some situation. The steps required to generate a stand-alone css bundle can be found here.

When I tried this, the bundling worked but the source-maps became broken. I could get it to work for either .ts files or .css files, but not both, by playing with css loaders source maps parameter and devtools: source-map option of the webpack config.

Production error in console

On heroku, the following error is happening in the console:

You are currently using minified code outside of NODE_ENV === 'production'. This means that you are running a slower development build of Redux. You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify or DefinePlugin for webpack (http://stackoverflow.com/questions/30030031) to ensure you have the correct code for your production

This started happening due to a change in redux v3.0.6: https://github.com/rackt/redux/releases/tag/v3.0.6

The solution is to modify the webpack.config.js:

new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),

Decide, document, and test minimum browser support.

I'm thinking we're limited by what the main frameworks support, but that we need to decide what we're willing to worry about as well. I suggest the following:

es6-react, ts-react:

  • IE9, Android 4.1, iOS 8

angular1:

  • IE9, Android 4,1, iOS8

angular2:

  • IE9, Android 4,1, iOS8? Depends on what ng2 supports in the end.

Namespace UI Components

The starter app breaks down UI into granular UI components, consistent with our practice. However they are not namespaced to the project, which is inconsistent with our practice.

This leads to the risk of name clashes with other libraries, and in some cases with HTML itself (which is bad).

windows using rangle-starter

run: npm install
webpack

and get the following errors:¨

ERROR in multi vendor
Module not found: Error: Cannot resolve module 'angular2/bundles/angular2-polyfills' in C:\Users\Hans\Web\js\angular20-redux\angular2-redux-starter
@ multi vendor

ERROR in multi vendor
Module not found: Error: Cannot resolve module 'angular2/bootstrap' in C:\Users\Hans\Web\js\angular20-redux\angular2-redux-starter
@ multi vendor

ERROR in multi vendor
Module not found: Error: Cannot resolve module 'angular2/platform/browser' in C:\Users\Hans\Web\js\angular20-redux\angular2-redux-starter
@ multi vendor

ERROR in multi vendor
Module not found: Error: Cannot resolve module 'angular2/platform/common_dom' in C:\Users\Hans\Web\js\angular20-redux\angular2-redux-starter
@ multi vendor

ERROR in multi vendor
Module not found: Error: Cannot resolve module 'angular2/core' in C:\Users\Hans\Web\js\angular20-redux\angular2-redux-starter
@ multi vendor

ERROR in multi vendor
Module not found: Error: Cannot resolve module 'angular2/router' in C:\Users\Hans\Web\js\angular20-redux\angular2-redux-starter
@ multi vendor

ERROR in multi vendor
Module not found: Error: Cannot resolve module 'angular2/http' in C:\Users\Hans\Web\js\angular20-redux\angular2-redux-starter
@ multi vendor

ERROR in multi vendor
Module not found: Error: Cannot resolve module 'redux' in C:\Users\Hans\Web\js\angular20-redux\angular2-redux-starter
@ multi vendor

ERROR in multi vendor
Module not found: Error: Cannot resolve module 'redux-thunk' in C:\Users\Hans\Web\js\angular20-redux\angular2-redux-starter
@ multi vendor

ERROR in multi vendor
Module not found: Error: Cannot resolve module 'ng2-redux' in C:\Users\Hans\Web\js\angular20-redux\angular2-redux-starter
@ multi vendor

ERROR in multi vendor
Module not found: Error: Cannot resolve module 'redux-logger' in C:\Users\Hans\Web\js\angular20-redux\angular2-redux-starter
@ multi vendor

ERROR in Entry module not found: Error: Cannot resolve module 'ts' in C:\Users\Hans\Web\js\angular20-redux\angular2-redux-starter
Child html-webpack-plugin for "index.html":
+ 1 hidden modules
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]

Hans@HP-HANS C:\Users\Hans\Web\js\angular20-redux\angular2-redux-starter

Clean up how styles are used in all starters

Currently there are a few things that could be improved about CSS for the react starters.

  1. inline styles should use Radium so we can benefit from vendor prefixing etc.
  2. we pass className around a lot when it should be part of the base styles for a component.
  3. es6 react
  4. typescript react
  5. ng1
  6. ng2

Better use of TypeScript with React and Redux

(edit: tracking items with a tasklist)

Doing typescript with react is still a bit unconventional, but I think there's a lot of promise there. However the current starter has a few outstanding questions I'd like us to resolve.

  • Drop React.PropTypes in favour of specifying a props interface for all components. Since this is checked at build time instead of runtime, it's a stronger check and makes React.PropTypes redundant for TypeScript projects. Syntax is also cleaner.
  • VSCode gives red squigglies every time a stateless functional component is used in TSX. Need to make the editor use the correct version of TS (in this case 1.8).
  • TS barfs any time we try to wrap a stateless functional component in a call to react-redux connect. Looks like react-redux needs an overload for it's connect decorator (see comment below). We should contribute a PR to the community typings.
  • Same as above, but for redux-form's decorator. We should contribute a PR to the community typings.
  • Remove the webpack config hack to suppress certain TS errors. It's no longer needed since 1.8.

Improve React stateless functional components

There are a couple of improvements we can make to the way we use stateless functional components in the two React starters.

For example, consider this component:

import React from 'react';

const Input = ({
  type,
  style,
  placeholder,
  fieldDefinition,
}) => (
  // ...
);

Input.propTypes = {
  type: React.PropTypes.string,
  style: React.PropTypes.object,
  placeholder: React.PropTypes.string,
  fieldDefinition: React.PropTypes.object.isRequired,
};

Input.defaultProps = {
  type: 'text',
  style: {},
  placeholder: '',
};

export default Input;

Now consider this version:

import React from 'react';

export default function Input({
  type = 'text',
  style = {},
  placeholder = '',
  fieldDefinition,
}) {
  return (
    // ...
  );
};

Input.propTypes = {
  type: React.PropTypes.string,
  style: React.PropTypes.object,
  placeholder: React.PropTypes.string,
  fieldDefinition: React.PropTypes.object.isRequired,
};

IMO it has several improvements:

  1. less boilerplate
  2. specifying default params inline as part of parameter destructuring is DRY-er
  3. using named functions instead of arrow functions results in better stack traces (?). Since we don't need this in a stateless component there's no point to using an arrow function anyway.
  4. we get to put the export default at the top; this reads more naturally to me.

devDependencies not being installed on heroku by default

Even though the app.json file seems to configure NPM_CONFIG_PRODUCTION=false, deployment attempts on Heroku do not work until this setting is manually added to heroku using the heroku toolbelt.

Steps to reproduce ( at least on my heroku account ):

  • clone the starter repo and setup a new github repo with it
  • setup Heroku to deploy from the new github repo
  • attempt to manually deploy will fail
    screen shot 2016-03-13 at 2 10 17 pm

Workaround :

mbuchetics/heroku-buildpack-nodejs-grunt#5 (comment)

Other notes:

  • PR Apps work out of the box.
  • I've experienced this with the angular starters as well as the typescript react starter
  • Other people, using other heroku accounts, indicated that they cannot reproduce

Use webpack dev server

The current approach. based on serve-webpack-client, makes hot reloading and live reloading harder than they should be. It's also non-standard.

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.