require-tasks
A tool to require a directory, and (optionally) inject each file in that directory with supplied arguments.
For example, given the following directory structure:
├── build
├── tasks
└── copy.js
└── webpack.js
this tool (when configured to search in build/tasks
) will load each file in tasks, and will inject each task with supplied arguments, and then return a structure like:
{} // reference to what copy.js returns {} // reference to what webpack.js returns
Install
npm i require-tasks -D
Usage
; const tasks = ; // any arguments passed will be made available to any task that exports a function
tasks
will be an object with each key representing the filename of every file in build/tasks
. Additionally, any files that export an object (or a function that returns an object) will available as a property on the filename as the key.
Multi-tasks
Additionally, if a task returns an object, that task will be treated as "multi-task" and each key in the object will be added to the parent task. For example, given the following task:
build/tasks/copy.js
{ return { // do something } { // do something else } { // do this thing } ;}
The returned object will contain a property like so:
copy: {} {} {}