0.0.20 • Published 8 years ago

gulp-context v0.0.20

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

gulp-context

Context tasks for gulp

Description

Organize the structure of gulp tasks by context. Provides sorting tasks, separation of files and folders, and fully configurable.

Dependencies

This package use gulp and require global installation.

$ npm install gulp -g

Installation

$ npm install gulp gulp-context --save-dev

Configuration

Contexts

A context is the build configuration with specific tasks. Context must have a name, tasks and can be configured to be dependent on other context.

Supported configurations:

NameDefinition
default: booleanIf the context is default
clean: booleanIf the target-dir context must be cleaned before performing other tasks
watch: booleanEnable/Disable watch files
from-target-context: stringName of context dependent
task-dir: stringPath to the folder the task files
task: objectTasks configuration

Tasks

A task must be parameterized in the context and can be dependent on other tasks.

Configuration

The name of the task must match the file name.

...
"task-dir": "tasks/development"
"task": {
	"copy/html"
}

In this example, the context will search for the file tasks in: tasks/development/copy/html.js

Dependencies

Dependent tasks only start after the dependent task is completed.

...
"task-dir": "tasks/production"
"task": {
	"copy/html": true,
    "minify/html": 'copy/html'
}

To declare a list of dependencies, use string array. example: 'copy/html', 'minify/html'

File

It must be exposed by module.exports.

The scope of the task (this) receives the parsed scope configuration.

// tasks/production/minify/html.js
var gulp = require('gulp');
    , minifyHtml = require('gulp-minify-html');

module.exports = function () {

    var input = this.input(this.sourceDir, ['**/*.html']);

    return gulp.src(input)
        .pipe(minifyHtml())
        .pipe(gulp.dest(this.targetDir));
}
Scope

Each context, before performing the tasks, will parse the scope object values. When the tasks are performed, the parsed object will be used as scope (this).

A parser (defaultparser) solves the value of target-dir fields, source-dir and paths.

You can add other parsers:

var conf = require('./conf.json')
    , gulpc = require('gulp-context');

function parser(scope) {
	// this is the context
	if(this.getName() == 'development')  scope.targetDir = 'app/dist';
	
	return scope;
}

gulpc.addParser(parser).build(conf);

Usage

Set in gulpfile.js

var conf = require('./conf.json')
    , gulpc = require('gulp-context');

gulpc.build(conf);

Create a conf.json like this

{
    "scope": {
        "source-dir": "app/source/",
        "target-dir": "app/build/",
    },
    "context": {
        "development": {
            "default": true,
            "clean": true,
            "watch": true,
            "task-dir": "tasks/development",
            "task": {
                "copy/html": true
            }
        },
        "production": {
        	"clean": true,
            "from-target-context": "development",
            "task-dir": "tasks/production",
            "task": {
                "minify/html": true
            }
        }
    }
}

Create tasks files

// tasks/development/copy/html.js
module.exports = function () {
	...
    return gulp.src(input)
        .pipe(gulp.dest(this.targetDir));
}

// tasks/production/minify/html.js
module.exports = function () {
	...
	return gulp.src(input)
        .pipe(minifyHtml())
        .pipe(gulp.dest(this.targetDir));
}

Building

Run by the terminal:

  • Default context:
$ gulp
  • Specific context:
$ gulp development

API

..

0.0.20

8 years ago

0.0.19

8 years ago

0.0.18

8 years ago

0.0.17

8 years ago

0.0.16

8 years ago

0.0.15

9 years ago

0.0.14

9 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago