• Stars
    star
    178
  • Rank 214,989 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Seed project for ES6 / jspm based apps with full production workflow

vanilla-es6-jspm

Build Status Sauce Test Status devDependency Status

ES6 is here and you can't avoid it. We have great tools to make it work, one of them is jspm.

jspm is great but all-in-one yeoman generators or seed projects (with build/sass/livereload/sourcemaps/unit-tests ...) are still lacking, so I decided to make my own angular/ES6/jspm stack.

This project is the first step: a vanillaJS/ES6/jspm boilerplate (more infos on the Wiki).

Features

  • Simple ES6 app using basic ES6 features
    • so that you won't have to struggle to understand the code base
    • but advanced enough to be used as an example
  • Use ES6 Modules via SystemJS module loader (built on top of ES6 Module Loader Polyfill)
  • Manage development and production workflow with jspm, SystemJS Builder and Gulp.
  • Backend mocking / stubs / overriding of the module loader
  • Karma unit tests (using mocks and stubs)
  • e2e testing with protractor
  • Produce optimized, production ready code for deployment
  • Continuous Integration ready (tests via Travis CI with SauceLabs integration for e2e tests)
  • Automated documentation generation

TL;DR

Want to get started right now and bother about all the great features later ?

$ npm install -g jspm
$ git clone https://github.com/topheman/vanilla-es6-jspm.git
$ cd vanilla-es6-jspm
$ npm install
$ gulp serve

You're ready to develop in ES6 the project in the src folder!

Requirements

  • node/npm (tested on both node v4, v5 & v6 - see tests)
  • gulp npm install -g gulp-cli
  • jspm npm install -g jspm

Why all dependencies in local (see wiki) ?

Installation

All you need is to run npm install

  • npm install: install all npm dependencies + will automatically triggers the following at postinstall (so you don't need to run those):
    • jspm install: installs front dependencies via jspm
    • npm run webdriver-manager-update installs necessary binaries for Selenium (for e2e testing)

Launch

You can launch your app in different modes (dev/dist/test):

  • gulp serve : will launch a dev server
  • gulp serve --env dist : will launch the version of the site built in build/dist folder (need to gulp build before) - usefull to check your site before deploying it.
  • gulp serve --env test : will launch a dev server with test configuration - usefull to debug / create unit tests:
    • jspm configuration overridden by the test/jspm.override.json file
    • the app will appear with "TEST" in background, thanks to test/fixtures/bs.snippet.html injected on the the fly (containing specific css)

You can pass the following flags to the gulp serve command:

  • --env: accepts dev, dist, test (dev by default)
  • --port: overrides the port of the server you'll launch
  • --disable-watch: disables watching/reloading
  • --open false: won't open the site in the browser

Build

  • gulp build : builds a production ready version of the site in build/dist folder
  • gulp build --env test : same as gulp build, but bundles a test version of your website (using test/jspm.override.json)
    • can be usefull if you want to do end-to-end testing on a built version of your website

You can also pass the following flags to gulp build:

Test

Unit

The unit tests are in test/unit/spec.

You can see exactly which commands match the following npm tasks in the package.json.

  • npm test: runs all the tests (will be triggered on git-pre-commit)
  • npm run test-unit: runs the unit tests through karma
  • npm run test-build: tests the gulp build task (will be triggered on git-pre-push)
    • if build/dist folder is under git management (see deployment section), this task will git stash/unstash before and after testing.

e2e

The e2e tests are in test/e2e/spec. It's using protractor - an end-to-end test framework for AngularJS applications, based on Selenium Webdriver. It can also be used on non-angular websites (more on wiki).

You can run the e2e tests two ways (either way, they need a server in order to run):

  • standalone (no need to have a server launched / make sure you don't) - launch : npm run test-e2e-standalone: this will:
    • start a test server
    • run the e2e tests
    • stop the test server
  • if you want to run them against your current server (this should be a server launched in test mode with gulp serve --env test), open a new terminal tab and run npm run test-e2e

Git workflow & Continuous Integration

Git hooks

To prevent you from sending broken code, some client-side git hooks are enabled:

  • pre-commit: will run npm test (checks jshint, htmlhint and karma unit tests)
  • pre-push: will run npm run test-build (checks if the build runs smoothly)
    • I decided to put this check on pre-push because: it takes time and git stash/unstash build/dist folder repo - it could be put on pre-commit ...

You can bypass those checks by adding to your git command the flag --no-verify (but know that the Travis CI build will fail).

Travis CI

On each push, Travis CI will run the following tests/builds (see complete steps in .travis.yml):

  • gulp build: runs the build routine (to make sure it works fine)
  • gulp build --env test: builds a test version of the app (to be served for e2e tests)
  • npm test: runs unit tests
  • npm run test-e2e: runs end to end tests via SauceLabs

If either one of them fails, the build will be flagged as failed.

  • Travis CI setup
  • The WITH_DOCS=true env var is exported at the beginning so that the doc generation should also be tested on the gulp build task (without changing the commands)
  • As you'll see e2e tests don't run on pull requests. See explanation on the FAQ.

SauceLabs

You can skip this if e2e testing isn't part of your Continuous Integration workflow.

SauceLabs is a cross-browser automation tool built on top of Selenium WebDriver (Protractor uses Selenium WebDriver). It lets you run e2e tests accross multiple devices and is well integrated to Travis CI.

If you want to set it up for your own project, read this post.

To avoid traffic on the Sauce Connect tunnel that could lead to timeouts, SauceLabs tests are run against a server serving the build/dist folder, containing a bundled version of the site in test mode (to benefit from the stubs and mocks) which was created thanks to gulp build --env test.

More infos on this commit: #7898239

See the SauceLabs Report (much like Travis but for e2e tests)

Generate Docs

Documentation generation is currently based on YUIDoc. A set of tasks is at your disposal:

  • npm run yuidoc: Will generate documentation in build/docs
  • gulp build --with-docs: Same as above, but will also copy the generated documentation to build/dist/docs (can be usefull if you have an opensource project and want to share docs)

The configuration of YUIDoc is specified in the package.json, in the yuidoc entry - you can override this config (the theme for example).

Here is an example of the output.

Notes:

  • I'm still looking for a replacement for yuidoc, feel free to use your own doc generator - if you have one more suited for ES6, please let me know.
  • I opened an issue here, for the moment, the doc doesn't display well when served over https.

Deployment

On github pages

You can host your project on github pages like this (source), pushing to the github pages the dist folder where the project is built.

$ gulp build
$ cd build/dist
$ git init
$ git remote add origin https://github.com/username/vanilla-es6-jspm
$ git fetch origin
$ git checkout --orphan gh-pages
$ gulp build
$ git add .
$ git commit -m "first push to production"
$ git push -u origin gh-pages

Next time, you'll only have to do the last 4 steps ...

Folder Organization

Development

src
β”œβ”€β”€ 404.html
β”œβ”€β”€ analytics.snippet.html  --> analytics snippet (only added at build)
β”œβ”€β”€ app                     --> folder containing app js files
β”‚Β Β  β”œβ”€β”€ bootstrap.js        --> js module entry point
β”‚Β Β  β”œβ”€β”€ components
β”‚Β Β  β”œβ”€β”€ main.js
β”‚Β Β  └── services
β”œβ”€β”€ favicon-128x128.png
β”œβ”€β”€ favicon-32x32.png
β”œβ”€β”€ favicon.ico
β”œβ”€β”€ images                  --> images files
β”œβ”€β”€ index.html              --> app main file
└── styles                  --> styles folder (.scss)

Production

build
β”œβ”€β”€ dist                    --> distribution source code that goes to production
β”‚Β Β  β”œβ”€β”€ 404.html
β”‚Β Β  β”œβ”€β”€ docs                --> generate doc with "gulp build --with-docs"
β”‚   β”œβ”€β”€ favicon-128x128.png
β”‚   β”œβ”€β”€ favicon-32x32.png
β”‚   β”œβ”€β”€ favicon.ico
β”‚   β”œβ”€β”€ images              --> images files
β”‚   β”œβ”€β”€ index.html          --> app main file
β”‚   β”œβ”€β”€ scripts             --> js files
β”‚   β”‚Β Β  └── app.bootstrap.build-597baeaa0a.js  --> concat, minify, reved app js files and cached templates
β”‚   └── styles              --> css files
β”‚       └── main.min-b8451af87d.css  --> concat & minify app css files
└── docs                    --> generate doc with "npm run yuidoc"

Test

test
β”œβ”€β”€ e2e
β”‚Β Β  β”œβ”€β”€ spec             --> e2e tests run by protractor with jasmine
β”‚Β Β  └── utils.js
β”œβ”€β”€ fixtures
β”‚Β Β  └── bs.snippet.html  --> html snippet added on gulp serve:test
β”œβ”€β”€ forever.gulp.serve.dist.json
β”œβ”€β”€ forever.gulp.serve.test.json
β”œβ”€β”€ jspm.override.json   --> file to override jspm.config.js in test mode
β”œβ”€β”€ stubs                --> replacements for existing modules, injected in test mode (configured in jspm.override.json)
β”‚Β Β  └── app
β”‚Β Β      └── services
└── unit
    └── spec             --> unit tests run by karma with jasmine
        β”œβ”€β”€ components
        └── services

Changelog

See releases section.

Contributing

This section is in progress, you can still take a look at the public trello board.

FAQ

See Wiki

Resources

See Wiki

More Repositories

1

react-es6-redux

A simple app to try React, ES6 and redux, using topheman-apis-proxy as data api backend
JavaScript
156
star
2

webpack-babel-starter

Webpack 2 / Babel starter kit with full development & build workflow
JavaScript
103
star
3

npm-registry-browser

Browse the npm registry with an SPA made in React, with full dev workflow.
JavaScript
101
star
4

docker-experiments

Discover docker with a simple use case in development, production (local kubernetes) and CI
JavaScript
96
star
5

topheman-datavisual

Realtime datavisualization with Angular, d3, and nodejs based on Twitter Stream API
JavaScript
77
star
6

twitter-stream-channels

Lets you manage multiple channels of keywords on the same twitter stream
JavaScript
70
star
7

d3-react-experiments

Mix d3 & react
JavaScript
51
star
8

nextjs-movie-browser

A NextJS implementation of the themoviedb.org website
TypeScript
45
star
9

react-es6-isomorphic

A simple app to try React and ES6, using topheman-apis-proxy as data api backend NOW with isomorphism
JavaScript
42
star
10

rxjs-experiments

Playing with RxJS
JavaScript
38
star
11

react-fiber-experiments

Discover the latest features of React fiber like "Suspense"
JavaScript
27
star
12

PanoramaSensorsViewer

Let Google Street View panoramas be browserable via the gyroscope+accelerometer of your mobile device
JavaScript
26
star
13

webassembly-wasi-experiments

Discover WebAssembly System Interface (WASI) with C/Rust use cases
Makefile
24
star
14

rust-wasm-experiments

Discover how to use Rust to generate WebAssembly, called by JavaScript
JavaScript
20
star
15

nextjs-github-browser

Browse github through a website made in NextJS
TypeScript
19
star
16

bevy-rust-wasm-experiments

πŸ¦€ A small video game developed in Rust with Bevy framework targeting both desktop and WebAssembly (browser)
Rust
19
star
17

angular2-sandbox

Mixing Angular2 and RxJS, using @ngrx/store for state management and Webpack for bundling
TypeScript
15
star
18

my-react-app-starter

eslint/prettier/other pre-configured and customisable create-react-app project
JavaScript
11
star
19

Ball.js

Ball.js is a Javascript class that handles physics interactions between balls (i.e. collisions) on a flat area as well as rendering.
JavaScript
10
star
20

webrtc-remote-control

Thin abstraction layer above peerjs that will let you be more productive at making WebRTC data channels based apps.
JavaScript
10
star
21

playground2

An experiment with socket.io and accelerometer (control your desktop with multiple mobile devices)
JavaScript
8
star
22

bombs

HTML5 / Javascript game that takes advantage of the canvas element and the accelerometer on your device.
JavaScript
7
star
23

gopher-ball

Video game made in golang, based on sdl2 bindings
Go
6
star
24

webrtc-experiments

An example of how you could use WebRTC on the web, based on the PeerJS library
JavaScript
5
star
25

sensorsChecker.js

Mostly all recent browsers expose an api for deviceorientation and devicemotion events. This module will let you check if there is really an accelerometer+gyroscope to rely on.
JavaScript
5
star
26

lite-router

A very light router based on history package
JavaScript
4
star
27

squares

An adaptation in HTML5/Javascript - based on the memories I have, of a game I used to play in the 90s on our IIvi (our first color computer).
JavaScript
4
star
28

topheman-apis-proxy

Access your public APIs on the same server, benefite from the existing proxies developed or create yours.
JavaScript
4
star
29

cycle-infos

AngularJS side project made up with the yeoman angular fullstack. Find out the availability of bikes and bike's stands of the JCDecaux self-service bikes
JavaScript
4
star
30

threejs-cone

A little test on threejs ...
JavaScript
3
star
31

BabylonJSFirstSteps

You will find here my first steps on BabylonJS. Those are only tests ...
JavaScript
3
star
32

rustlang-first-try

Starting out in rust
Rust
2
star
33

m102-notes

My general notes taken on the fly while watching the M102 for DBA courses
Shell
2
star
34

Array.foreachLoopBack.js

Loop from any index to any other in your array, looping back at the end of it without bothering about indexes
JavaScript
1
star
35

rust-wasm-examples

JavaScript
1
star
36

my-docker-fullstack-project

1
star
37

SoftLogger

Simple logger that overrides console.log and let's you inject it in a canvas
JavaScript
1
star
38

angular-yeoman-sass-compass

Playing with AngularJS, Yeoman, Grunt, Bower and Karma ...
JavaScript
1
star
39

delay-proxy

Delay specific requests with custom delay - perfect for development
JavaScript
1
star
40

webRtcFirstSteps

JavaScript
1
star
41

HighScoresManager.js

Simlple high scores manager with localStorage
JavaScript
1
star
42

build-free-boilerplate

Simple boilerplate, without any build pipeline, for practice and teaching purpose.
JavaScript
1
star
43

conventional-changelog-angular-loose

conventional-changelog angular config (for those who missed the colon)
JavaScript
1
star