@wok-cli/core
This package includes core functionalities and utilities to setup a flexible and reusable build tool chain with gulp.
@wok-cli/core
is built on top of gulp and features project configuration files, CLI arguments, sharable tasks and more.
Installation
This modules requires node.js v10.0.0 or newer and gulp 4+.
npm i gulp @wok-cli/core
Usage example
Here is a simple copy task with CLI parameters support:
// gulpfile.js
const $ = require('@wok-cli/core');
const { env, api } = $;
const srcPattern = 'src/**';
exports.copy = function copy() {
return api.src(srcPattern).pipe(api.dest(env.argv.dest));
};
The above copy
task will read every file in srcPattern
and copy it to a folder provided with the --dest
cli parameter.
You may run the task like this:
gulp copy --dest=public
Reusable tasks
Where @wok-cli/core
shines is the ability to let you create sharable and configurable tasks with ease. For example, let's extract the previous copy
task to its own module.
We need to expose and higher-order function that receives some parameters and returns the configured task.
// tasks/copy.js
module.exports = function copyTask(gulp, params, env) {
// this is the actual gulp task function
return function copy() {
return gulp.src(params.src).pipe(gulp.dest(env.argv.dest));
};
};
Then in the gulpfile.js
we leverage the $.task
function to parse and configure the task:
// gulpfile.js
const $ = require('@wok-cli/core');
const copyTask = require('./tasks/copy.js');
const srcPattern = 'src/**';
exports.copy = $.task(copyTask, {
src: srcPattern,
});
Learn More
The package comes with many more features like:
- environment specific configuration
- hookable tasks
- chainable presets
Learn more about those features in the documentation.