mkr
target and task based build tool for Node.js
mkr is a target and task based build tool. It is split into two modules, one that provides a global command line trigger (mkr-global
), and one that provides the actual functionality (mkr
). That makes it possible to install different versions of mkr per project. The global command mkr
checks the current working directory for a local installation of module mkr
and, if successful, triggers the CLI of the local installation.
Install
mkr-global (once)
Run this command once to install the global command line trigger:
> npm install -g mkr-global
The global command mkr
should now be available:
> mkr --help
mkr-global v0.5.0
command line trigger for the mkr build tool
No local installation of "mkr"! (expected "./node_modules/mkr")
mkr (per project)
In your project folder:
> npm install mkr
Now mkr
will be available in this folder:
> mkr --help
Usage: mkr [options] <target ...>
Options:
-h, --help output usage information
-V, --version output the version number
-f, --file [mkrfile] specify mkrfile [mkrfile.js]
-t, --show-targets show targets
-T, --list-targets list targets
-D, --list-defaults list default targets
-b, --babel use babel to load mkrfile
Usage
A very basic mkrfile.js
:
module.exports = function (suite) {
suite.target('hello').task(function () {
console.log('Hi!');
});
};
Run a target from the command line:
> mkr hello
[mkr] starting: hello
[mkr] hello
Hi!
[mkr] successful in 0.002 seconds
Targets
Targets can declare dependencies via an array of target names. mkr will resolve all dependencies and run the targets in the right order. Additional comments might clarify what targets do.
module.exports = function (suite) {
suite.target('hello', [], 'Output welcome message.').task(function () {
console.log('Hi!');
});
suite.target('goodbye', ['hello'], 'Output goodbye message.').task(function () {
console.log('Bye!');
});
};
Set default targets with suite.defaults()
. The function accepts either a single target name or an array of target names. These targets are started if no targets are specified on the command line.
module.exports = function (suite) {
suite.defaults('hello');
suite.target('hello', [], 'Output welcome message.').task(function () {
console.log('Hi!');
});
suite.target('goodbye', ['hello'], 'Output goodbye message.').task(function () {
console.log('Bye!');
});
};
Tasks
There can be more than one task per target that will run in sequence.
suite.target('hello')
.task(function () {
console.log('Hi!');
})
.task(function () {
console.log('Hey!');
});
Tasks that either request an argument or return a promise are considered asynchronous.
suite.target('hello')
.task(function (done, fail) {
setTimeout(function () {
// do some work
done();
}, 1000);
})
.task(function () {
// do some work
return aPromise;
});
Command Line Args
Command line arguments starting with :
are passed through to the suite
instance. For example:
> mkr target1 target2 :flag :key=value
The above line will result in an object suite.args
of the form
suite.args = {
flag: true,
key: 'value'
}
Don't use whitespace characters in the key value pairs. :
-arguments might be in mixed order with targets. The next line has the same effect, as the line above:
> mkr :flag target1 :key=value target2