@untool/info
v2.1.3
Published
untool info mixin
Downloads
812
Keywords
Readme
@untool/info
@untool/info
is a core mixin providing output for untool
's command line interface. Besides that, it allows other mixins to define pre-flight checks that are run during application startup.
Installation
$ yarn add @untool/info # OR npm install @untool/info
CLI
@untool/info
does not define any commands of its own, but only adds some global CLI flags to control console output. Using the flags -v
/--verbose
and -q
/--quiet
once or multiple times, you can de- and increase the log output. Default log level is info
, passing a single -q
will reduce it to warning
while a single -v
will bump it to verbose
. Passing -qqq
will silence all output completely.
Log Levels
{
error: 0,
warning: 1,
info: 2,
verbose: 3,
}
Additionally, you can pass --color
/--no-color
flags to manually enable or disable output colors, but you can usually rely on @untool/info
to determine color support automatically.
$ un start -v --no-color
API
@untool/info
exposes a couple of utility mixin hooks other mixins can implement.
getLogger()
(callable)
This utility hook defined by @untool/info
provides other mixins with a fully configured logger instance. This logger has three standard log methods (info
, warning
and error
) that correspond to the lower three log levels described above. Additionally, it supports arbitrary log methods (e.g. request
, hint
, foo
)
const { Mixin } = require('@untool/core');
module.exports = class FooMixin extends Mixin {
bar() {
if (typeof this.getLogger === 'function') {
const logger = this.getLogger();
logger.info('this will log an info message');
logger.warning('this will log a warning message');
logger.error('this will log an error message');
logger.baz('this will log a verbose message');
logger.qux('this will log a verbose message, too');
}
}
};
diagnose(doctor)
(parallel)
By implementing this method, your core mixin can perform pre-flight checks during application startup and return an array of warnings. If you need to do something asynchronous at this point, just return a Promise
.
const { Mixin } = require('@untool/core');
module.exports = class FooMixin extends Mixin {
diagnose(doctor) {
doctor.diagnoseDuplicatePackages('bar');
if (1 + 1 !== 2) {
return ['Math is broken.'];
}
}
};
Additionally, you can use the helper methods defined on our semi-private doctor object that is being passed into this hook.