https://github.com/morlay/undertaker-config-registry
https://github.com/morlay/undertaker-config-registry
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/morlay/undertaker-config-registry
- Owner: morlay
- Created: 2015-12-23T09:18:29.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-23T09:22:44.000Z (over 10 years ago)
- Last Synced: 2025-11-18T18:25:45.968Z (7 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Undertaker Config Registry
A registry for Gulp 4 ([Undertaker](https://github.com/gulpjs/undertaker))
[](https://travis-ci.org/morlay/undertaker-config-registry)
[](https://npmjs.org/package/undertaker-config-registry)
[](https://david-dm.org/morlay/undertaker-config-registry)
[](https://npmjs.org/package/undertaker-config-registry)
### 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 **
```js
// config/copy.js
export default (conf) => {
return {
src: `${conf.src}/**`,
output: `${conf.dist}`
}
}
```
```js
// 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;
```
```js
// 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
```js
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.
```js
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
```js
// 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
}
}
```