zkflow-angular

Gulp tasks for AngularJS projects powered by ZKflow
Homepage:
0 people use it
Submitted by: 2339629?v=3 bolczyslaw

ZKflow for AngularJS

Gulp tasks for AngularJS projects powered by ZKflow

Made by Zaklinacze Kodu

Shields

npm npm npm Travis Code Climate David David GitHub forks GitHub stars GitHub followers

Features

  • Sass + sassdoc + css globbing + autoprefixer
  • Browserify + ngannotate
  • Assets management
  • Bower
  • AngularJS templates embedded in js
  • E2E tests with protractor and cucumber
  • Development environment

    • Webserver with livereload
    • Watching files for changes and full, fast, incremental rebuilds
    • Unit tests with karma
    • jshint
    • jsbeautifier
  • Production environment

    • js, css, jpg, png and svg minification
    • cache busting
  • Continous integration

    • build + jshint + jsbeautifier + tests + e2e with guaranteed non-zero exit status on error

Why not just write tasks yourself?

Usually simple gulp tasks have a lot of problems, which are resolved in ZKflow

  • tasks immune to errors resulting crashed watchers
  • tasks parametrized with tasks modes
  • tasks cannot run few times simultaneously after few quick changes
  • in develop mode if task detect some errors it will hold execution until all errors will be corrected and then it will let the rest of dependent tasks run
  • tasks in prod mode always returns non-zero exit status on error

Requirements

You need:

nodejs

If you've never used Node or npm before, you'll need to install Node. If you use homebrew, do:

Otherwise, you can download and install it manually.

updated npm

Update npm by running

node-gyp dependencies

Node-gyp is used to compile native extensions to node. Zkflow does not require node-gyp directly, but it is installed by its dependencies. To install this dependencies properly you need to satisfy node-gyp requirements. Go to node-gyp github page and follow instructions in "You will also need to install" paragraph in README file (python etc.)

Installation

ZKflow for AngularJS is available through npm

Put this line in your gulpfile.js

This will create a set of tasks in gulp, which you will be able to use from console

Development flow

How you can use ZKflow gulp tasks to work with Your AngularJS project

write code and test

Run in project root directory

or

This task will

  • clean whole output dir (dev/)
  • bundle all your js with browserify and watch file changes with watchify
  • bundle all your styles with sass, css globbing and autoprefix
  • generate documentation with sassdoc if enabled
  • run jshint and rerun on any js file change
  • run tests with karma and browserify and watch file changes with watchify
  • run bower install
  • bundle your angular templates into angular module (.tmp/templates.js) and rebundle on any template file change
  • copy your assets and copy any newly created asset since then
  • copy Your index.html and inject styles, scripts, angular main module name into it. Redo on index.html change.
  • start gulp-webserver with livereload
  • open Your default web browser with proper address.

Write some code, enjoy the results

write e2e tests

Run in project root directory

This task will

  • clean whole output dir (test/)
  • same as in default task, but will try to start from test module (where you can put Your e2e mocks)
  • run protractor and rerun every time you press 'r'

Write some tests

beautify your code

Run in project root directory

all your code will be automatically beatified with jsbeautifier

check everything

Run in project root directory

This task will fail if

  • code isn't beautified
  • code isn't jshinted
  • any of karma tests will fail
  • any of protractor e2e tests will fail
  • build fail (sass, browserify)

You definitly should add this task to your CI server. This task can be splitted into stages. ./node_modules/.bin/gulp ci is an equivalent for

commit :D

Production flow

installing

building

This task will

  • clean whole output dir (dist/)
  • bundle all your js with browserify and minify with uglifyjs
  • bundle all your styles with sass, css globbing, autoprefix and minify with csso
  • generate documentation with sassdoc if enabled
  • run bower install
  • bundle your angular templates into angular module (.tmp/templates.js) and minify with htmlminify
  • copy your assets and minify all .png/.jpg/.gif/.svg
  • copy Your index.html, htmlminify and inject styles, scripts, angular main module name into it.
  • Do cache busting

Apache/Nginx

Point it to ./dist directory, and configure your server to fallback to index.html if file not found (to work with router html5 mode)

Directory structure

  • dist/ - build output
  • dev/ - dev output
  • test/ - e2e output

Files

.gitignore

You should probably add this entries in .gitignore file

src/index.html

src/index.js

API

If you get 'task not found' error from gulp, you probably should pass gulp to init

options

You can pass options object to init function

For every task options are merged only 1 level deep. Deeper they will be overwritten.

For example if you have default options JavaScript { someTask: { option1: 1 option2: 2 option3: { subOption1: 3 subOption2: 4 } } }

and you pass to init JavaScript { someTask: { option1: 11 option3: { subOption1: 5 } } }

actual task options are JavaScript { someTask: { option1: 11 option2: 2 option3: { subOption1: 5 } } }

Default options

We recommend using as much default options as possible. They are based on our experience with AngularJS and they set up some solid structure for your project.

output dirs map

You can pass output dirs map object to init function. This object maps current environment to output dir.

Default output dirs map

mode

You can retrieve mode object from zkflow

This object is shared across all tasks and it define mode of operation.

Default mode

Some of the mode properties can be changed on run by environment variables

which is equivalent to

Some tasks overwrites mode

comments powered by Disqus
This page was last updated almost 2 years ago.