0.1.0-alpha6 • Published 10 years ago

gulp-distributor v0.1.0-alpha6

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

#Gulp Distributor

status: in alpha

Create multiple module distributions from your JavaScript source files.

You should clone this library to your local machine and run the default gulptask to see how the module works.

//  src/
//     - array-copy-src.js
//     - base-class-src.js
//     - sub-class-src.js



var gulp = require("gulp"),
	distribute = require("./lib/index"),
	runSequence = require("run-sequence");




gulp.task("distribute", function() {
	return gulp.src(["src/*-src.js"])
				.pipe(distribute({
					files: {
						'base-class': {
					        exports: ['BaseClass'] // class to export
					    },
					    'sub-class': {
					    	deps: ["bass-class"],  // file/module to import.
					    	exports: ["SubClass"]
					    },
					    'array-copy': {
					    	exports: ['self']      // self will set exports = arrayCopy;
					    },
					},
					namespace: "kit",
					license: "license.js",
					pattern: "$file-src"
				}));
});

gulp.task('default', function(cb) {
	runSequence("distribute");
});

// will generate files in the following

// lib/
//    - array-copy.js
//    - base-class.js
//    - sub-class.js

// dist/amd/lib
//    - array-copy.js
//    - base-class.js
//    - sub-class.js

// dist/browser/lib
//    - array-copy.js
//    - base-class.js
//    - sub-class.js

Options

dist

  • src - a variable location for the distribution files. Defaults to "/dist" and replaces the $src var.
  • amd - the location for the amd distribution files. Defaults to $src/amd/lib
  • browser - the location for the browser distribution files. Defaults to $src/browser/lib
  • commonjs - the location for the commonjs distribution files. Defaults to /lib
  • es6 - (Not Implemented) the location for the es6 distribution files. Defaults to $src/es6/lib

templates

  • src - a variable location for the template folder. Defaults to __dirname + "/templates" and replaces the $src var.
  • amd - the location for the amd distribution files. Defaults to $src/amd.tpl
  • browser - the location for the browser distribution files. Defaults to $src/browser.tpl
  • commonjs - the location for the commonjs distribution files. Defaults to $src/lib.tpl
  • es6 - (Not Implemented) the location for the es6 distribution files. Defaults to $src/es6.tpl

newLine

  • default: "\n"
  • amd: "\n\t"
  • browser: "\n\t"

distro

Instructs which distributions that will be created. The available options are:

  • all
  • amd
  • browser
  • commonjs
  • es6 (Not Implemented)

    If you wish to remove an option, set the template option to false i.e.

       return gulp.src(["src/*-src.js"])
    					.pipe(distribute({
    						templates: {
    							commonjs: false,
    							amd: false
    						},  
    						distro: "all",
    						license: "license.js",
    					}));

    If you wish to add an option for a distro, add a template

       return gulp.src(["src/*-src.js"])
    					.pipe(distribute({
    						dist: {
    							hybrid: "$src/hybrid/lib"
    						},
    						templates: {
    							hybrid: "src/templates/hybrid.tpl"
    						},  
    						distro: "all",
    						license: "license.js",
    					}));

    namespace

    This will instruct the browser distributions to append exports to a global namespace/ variable for source files.

exports

An export variable that will be present in all files.

templateEngine

Allows you to define the template engine that will create your module distributions.

The value must be a function that takes a content string and object for template variables.

 templateEngine: function() {
     return require("lodash").template;
 };

files

Configures source files and dependencies.

// src
//   router-src.js
// node_modules/ux-lexer

  return gulp.src(["src/*-src.js"])
				.pipe(distribute({
					files: {
						'router': {
					        exports: ['Router'],

					        // distributor will attempt to see if the file 
					        // has any configuration, otherwise it will assume
					        // a simple require for dependencies.  
					        deps: ['lexer', 'parser'] 
					    },
					    'lexer': {
					    	require: ['ux-lexer'],
					    	exports: ['Lexer', 'Token']
						}
					},
					namespace: "kit",  
					distro: "all",
					license: "license.js",
					pattern: "$file-src"
				}));
sample output for commonjs
   var d0 = require("ux-lexer"),
   	Lexer = d0.Lexer,
   	Token = d0.Token;

   var parser = require("parser");

   // router code
   var Router = function() {

   };

   exports.Router = Router;
	module.exports = exports;

license

The the license file that should be prepended to each distribution file.

data

Default values that will be injected into the distribution templates.