0.2.4 • Published 10 years ago

angular-app-automation v0.2.4

Weekly downloads
3
License
-
Repository
github
Last release
10 years ago

npm.io

Dependency Status

Gulp automation suite for an angular app.

It also works for an app without angular.

This package does certainly not cover all your needs.
Feel free to fork it and create pull request with your improvements.

Features

  • Compiles JavaScript modules into a single file (browserify) with source maps
  • Compiles Jade templates as javascript module if needed
  • Compiles CoffeeScript files as javascript module if needed
  • Uses ng-annotate before minification (UglifyJS2)
  • Compiles LESS into a single CSS file with source maps
  • Uses csso to minify CSS and postprocesses it with autoprefixer
  • Lint JS (jshint) and CSS (recess)
  • Runs unit tests using karma with jasmine
  • Generates coverage report with istanbul and complexity/maintainability reports (history) with plato
  • Provides a development server (express) with livereload capability
  • Fingerprints assets through lo-dash templates
  • Indicates size of distribution files
  • Provides a way to separate external libs from application (useful for huge project)

Installation

npm install --save-dev angular-app-automation

You need to have gulp:

npm install -g gulp

Usage

Take a look at angular-app-seed to see how to use this package.

// gulpfile.js

var gulp = require('gulp')
  , automation = require('angular-app-automation');

automation(gulp, /* options here */);

// no option
automation(gulp);

// inline options
automation(gulp, {jsSrc: './src/js/**/*.js', jsApp: './src/main.js'});

Fingerprinting

Simple technique (recommended by Google) to force browsers to download latest versions of assets.
Based on lo-dash templates and use the options version or create a random hash if version is not provided:

// index.html

// before
<link rel="stylesheet" type="text/css" href="/dist/app.css?<%= version %>">

// after
<link rel="stylesheet" type="text/css" href="/dist/app.css?49af3efc9ba0d83100858b883ce3001361a3244e">

Externals

Provides a list of externals will build a browserify bundle with externals and an other one for the application.

To declare an external:

//in gulpfile.js
externalsList: [
  {require: 'path/to/lib', expose: 'whatever you want to require this lib in your app'}
, {require: 'npm package', expose: '...'}
]

Configuration

Here are the available options:

optionpurpose
namename of the application, defaults to app
portport used by express, defaults to 5000
versionversion used for fingerprinting
lrportlivereload port, defaults to 5001
jsSrcJavaScript source files, defaults to ./src/**/*.js
jsAppJavaScript entry point for browserify, defaults to ./src/app.js
jsLintJavaScript lint config object, defaults in jshint.default.cfg file
jsUseLintenable/disable jshint, default true
jsJadeIndicates if browserify should use a Jade transformation, default false
jsCoffeeIndicates if browserify should use a Coffee transformation, default false
cssSrcLESS & CSS source files, defaults to ./src/**/*.less{,.css}
cssAppLESS entry point for LESS compiler, defaults to ./src/app.less
cssLintCSS lint config object, defaults in recess.default.cfg file
cssUseLintenable/disable recess, default true
externalsAppJavaScript entry point for browserify, defaults to ./src/externals.js
externalsListList of external libs, default [], expect [{require: '', expose: ''}]
htmlSrcHTML source files, default to ./src/**/*.html
testSrcJavaScript unit test source files, defaults to ./src/**/*.unit.js
testAppJavaScript unit test entry point for browserify, defaults to ./src/app.unit.js
buildDirDirectory of development builds, defaults to ./build
distDirDirectory of distribution builds, defaults to ./dist
karmaKarma config object, defaults in karma.default.cfg

Convention

The default configuration is motivated by a modular organization of the application:

  • src
    • app.js
    • app.less
    • index.html
    • module1
      • controller1.js
      • controller2.js
      • service1.js
      • view1.html
      • view2.html
      • style1.less
    • module2
      • ...

Take a look at this article for more details.

Task reference

taskspurpose
devBuilds application (browserify, less, lint) and watch source files
dev:smdev task with sourcemap (sourcemaps double size of build files)
dev:lrdev task and serve it (express, livereload), sourcemap included
dev:unitStarts the dev environment with unit testing support (karma and jasmine)
dist:buildBuilds distribution (minification)
dist:serveBuilds distribution and serve it for checking purpose
complexity:reportGenerates complexity/maintenability report (plato)
complexity:serveServes plato report
coverage:reportGenerates coverage report (istanbul)
coverage:serveServes coverage report
ciContinuous integration task used for travis & coveralls

Todo

  • Add images optimization

License

The MIT License (MIT)

Copyright (c) 2014 Nicolas Briemant

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.