undertaker-config-registry

0.1.0 • Public • Published

Undertaker Config Registry

A registry for Gulp 4 (Undertaker)

Build Status NPM Dependencies License

How to work

commonConf |> taskConfFn => taskConf |> taskDefFn => task

Gulp Structure

gulpfile.babel.js/
config/
  copy.js
tasks/
  copy.js
index.js

** filename should be prefer the task name **

// config/copy.js
export default (conf) => {
  return {
    src: `${conf.src}/**`,
    output: `${conf.dist}`
  }
}
// tasks/copy.js
import gulp from 'gulp';
 
function copy(taskConf) {
  return gulp.src(taskConf.src)
    .pipe(gulp.dest(taskConf.output));
}
 
copy.watch = function copyWatch(taskConf, taskFn) {
  gulp.watch(taskConf.src, taskFn);
};
 
export default copy;
// index.js
import gulp from 'gulp';
import requireDir from 'require-dir';
import ConfigRegistry from 'undertaker-config-registry';
 
const baseConfig = {
  src: './src',
  dist: './public'
};
 
const configRegistry = new ConfigRegistry(
  baseConfig,
  requireDir('./config', {
    recurse: true
  }),
  requireDir('./tasks')
);

Run gulp copy will be work well or defined custom task queues by gulp.series or gulp.parallel

Dev mode

taskDefFn.watch will be called only in dev model

configRegistry.enableDevMode(() => {
  // other configuration for dev model
  // ex.
  // process.env.BABEL_ENV = 'development';
})
Mutli configure

For taskConfFn, a special hook be provided. files will help to create sub task and will merge common options which exists, without changing TaskDefFn

ex.

export default (conf) => {
  return {
    files: [{
      src: `${conf.src}/target1/**`,
      output: `${conf.dist}/target1`,
      options: {
        a: 2,
        b: 1
      }
    }, {
      src: `${conf.src}/target2/**`,
      output: `${conf.dist}/target2`
    }],
    options: {
      a: 1
    }
  }
}

will be

// taskConf_0
{
  src: `${conf.src}/target1/**`,
  output: `${conf.dist}/target1`,
  options: {
    a: 2,
    b: 1
  }
}
 
// taskConf_1
{
  src: `${conf.src}/target1/**`,
  output: `${conf.dist}/target1`,
  options: {
    a: 1
  }
}

Package Sidebar

Install

npm i undertaker-config-registry

Weekly Downloads

1

Version

0.1.0

License

WTFPL

Last publish

Collaborators

  • morlay_null