jaune-tasks

1.0.1 • Public • Published

Build Status Coverage Status

jaune-tasks

Use gulp tasks only through configuration -- don't code.

Install

npm i -save jaune-tasks

Configuration

Two steps are required to set up gulp tasks

  • Add a configuration file (for example env.json) with the following attributes:
{
  "jaune" : {
    "build_tasks" : {
      "task-name-1" : [
        {
          "name" : "step1"
        },
        {
          "name" : "step2",
        }
      ]
    }
  }
}
  • Add a gulp.js file with the following content in the root of your project
'use strict';
 
require('jaune-tasks')('[r(/env)]');
 

Running a task

gulp <task-name>

You can also specify -d to print debugging information.

Supported tasks

Uglify

Adds support for gulp-uglify

Required packages in your package.json

  • gulp-uglify

Configuration

  1. name: Must be uglify
  2. destFunction: Function used to convert output path for script (more ahead)
  3. args: Same configuration that explained in original package.
  4. sources: Array of paths to be processed
  5. flatten: True to use gulp-flatten
{
  "name" : "uglify",
  "destFunction" : "[r(/tasks/app-funcs)].destFuncName",
  "sources" : ["modules/**/pages/**/*.js"],
  "flatten" : true
}

Stylus

Adds support for gulp-stylus

Required packages in your package.json

  • gulp-stylus
  • nib

Configuration

  1. name: Must be stylus
  2. destFunction: Function used to convert output path for script (more ahead)
  3. args: Same configuration that explained in original package.
  4. sources: Array of paths to be processed
  5. flatten: True to use gulp-flatten
{
  "name" : "stylus",
  "destFunction" : "[r(/tasks/app-funcs)].destFuncName",
  "sources" : ["modules/**/pages/**/*.styl"],
  "flatten" : true
}

Webpack

Adds support for gulp-webpack

Required packages in your package.json

  • gulp-webpack
  • webpack
  • Any other webpack plugin you wish to use.

Configuration

  1. name: Must be webpack
  2. destFunction: Function used to convert output path for script (more ahead)
  3. args: Same configuration that explained in original package except for some case:
  4. entry should always be used to sepecify entry points, even there is only one.
  5. test property for loaders must be a regular expression.
  6. plugins names must be a jaune-util reflection reference.

The following is an example that outputs two scripts 'page_1_script_name' and 'page_2_script_name'. Those scripts require handlebars files as template plus we want to minify them:

"jaune" : {
    "build_tasks" : {
      "assets" : [
        {
          "name" : "webpack",
          "destFunction" : "[r(/tasks/app-funcs)].destFuncName",
          "args" : {
            "plugins": [
              "[r(webpack)].optimize.UglifyJsPlugin.[i()]"
            ],
            "entry" : {
              "page_1_script_name" : "output/path/page1_script",
              "page_2_script_name" : "output/path/page2_script",
            },
            "module" : {
              "loaders" : [
                { "test":  "\\.hbs", "loader": "handlebars-template-loader" }
              ]
            },
            "output": {
              "filename": "[name].js"
            },
            "node": {
              "fs": "empty"
            }
          }
        }
      ]
    },

Destination function

Destination function is used to generate path of output files with a major flexibility; you can transform output paths using any tool available out there.

In order to set up a destination function we need another function that receives the task as parameter and returns the transforming function. Destination function is specified in the following way inside the task. Please note that destFunction is resolved using jaune-util reflection.

{
  "destFunction" : "[r(/tasks/app-funcs)].webpackDest"
}

The destination function must accept a file argument which is the same argument passed to gulp.dest. In this example we will transform the path to end with '/public/'

PUBLIC_MODULE_PATH = '/public/'
 
{parsejoin} = require 'path'
 
module.exports =
 
  webpackDest: (config) ->
 
    (file) ->
 
      [path] = file.history
      parsed = parse path
 
      unless (originalPath = config.args.entry[parsed.name])
        throw new Error "File not found in entry point #{originalPath}"
 
      join originalPathPUBLIC_MODULE_PATH

Readme

Keywords

none

Package Sidebar

Install

npm i jaune-tasks

Weekly Downloads

0

Version

1.0.1

License

ISC

Last publish

Collaborators

  • ajuste