Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@untool/yargs

Package Overview
Dependencies
Maintainers
2
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@untool/yargs - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

12

CHANGELOG.md

@@ -6,2 +6,14 @@ # Change Log

<a name="0.4.0"></a>
# [0.4.0](https://github.com/untool/untool/compare/v0.3.2...v0.4.0) (2018-04-16)
### Features
* **yargs:** add logDebug mixin method ([eb727b1](https://github.com/untool/untool/commit/eb727b1))
* **yargs:** make log output app specific ([6fdd813](https://github.com/untool/untool/commit/6fdd813))
<a name="0.3.0"></a>

@@ -8,0 +20,0 @@ # 0.3.0 (2018-03-22)

22

mixin.core.js

@@ -8,3 +8,3 @@ /* eslint-disable no-console */

registerCommands(yargs, chalk) {
const levels = ['info', 'warn', 'error', 'silent'];
const levels = ['debug', 'info', 'warn', 'error', 'silent'];
const index = levels.indexOf(yargs.alias('l', 'log').argv.log);

@@ -15,5 +15,13 @@ this.levels = levels.slice(Math.max(index, 0), -1);

}
logDebug(...args) {
const { namespace } = this.config;
if (this.levels && this.levels.includes('debug')) {
console.log(this.chalk.bold(`${namespace} debug`));
console.debug(...args);
}
}
logInfo(...args) {
const { namespace } = this.config;
if (this.levels && this.levels.includes('info')) {
console.log(this.chalk.bold('untool info'));
console.log(this.chalk.bold(`${namespace} info`));
console.info(...args);

@@ -23,4 +31,5 @@ }

logWarn(...args) {
const { namespace } = this.config;
if (this.levels && this.levels.includes('warn')) {
console.log(this.chalk.yellow.bold('untool warn'));
console.log(this.chalk.yellow.bold(`${namespace} warn`));
console.warn(...args);

@@ -30,4 +39,5 @@ }

logError(error) {
const { namespace } = this.config;
if (!this.levels || this.levels.includes('error')) {
console.log(this.chalk.red.bold('untool error'));
console.log(this.chalk.red.bold(`${namespace} error`));
console.error(error.stack ? error.stack.toString() : error.toString());

@@ -37,4 +47,5 @@ }

logStats(stats) {
const { namespace } = this.config;
if (this.levels && this.levels.includes('info')) {
console.log(this.chalk.bold('untool stats'));
console.log(this.chalk.bold(`${namespace} stats`));
console.info(

@@ -49,2 +60,3 @@ stats.toString({ chunks: false, modules: false, entrypoints: false })

registerCommands: pipe,
logDebug: override,
logInfo: override,

@@ -51,0 +63,0 @@ logWarn: override,

{
"name": "@untool/yargs",
"version": "0.3.0",
"version": "0.4.0",
"description": "untool yargs mixin",

@@ -28,3 +28,3 @@ "keywords": [

"dependencies": {
"@untool/core": "0.1.0",
"@untool/core": "^0.4.0",
"chalk": "^2.3.1",

@@ -31,0 +31,0 @@ "mixinable": "^1.5.0",

@@ -1,1 +0,78 @@

# Coming soon.
# `@untool/yargs`
[![npm](https://img.shields.io/npm/v/@untool%2Fyargs.svg)](https://www.npmjs.com/package/@untool%2Fyargs)
`@untool/yargs` is a [core mixin](https://github.com/untool/untool/blob/master/packages/core/README.md#mixins) providing `untool`'s actual command line interface, allowing other mixins to define their own commands. These custom commands will work exactly as those defined by `untool`'s own modules and can be called using a local or global `un` executable.
### Installation
```bash
$ yarn add @untool/yargs # OR npm install @untool/yargs
```
## CLI
`@untool/yargs` can either be used with `untool`'s global [command line interface](https://github.com/untool/untool/blob/master/packages/cli/README.md) or directly, within `package.json` [scripts](https://docs.npmjs.com/cli/run-script) of the project it is installed in: it locally installs an `un` command.
```text
$ un
Usage: un <command> [options]
Commands:
un serve Serve foo
un start Build and serve foo
un build Build foo
un develop Serve foo in watch mode
Options:
--version Show version number [boolean]
--help, -h Show help [boolean]
$ un start
foo info
server listening at http://localhost:8080
```
`@untool/yargs` does not define any commands of its own, but takes care of basically setting up [`yargs`](http://yargs.js.org) and logging to [`stdout`](<https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)>) and [`stderr`](<https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)>). You can call `un` with an optional `-l` or `--log` command line argument with one of the following values to control its output: `debug`, `info`, `warn`, `error`, `silent`
## API
`@untool/yargs` exposes a couple of mixin hooks other mixins can implement, allowing them to alter or extend its functionality. These hooks will be called either by `@untool/yargs` itself or by others.
### `registerCommands(yargs, chalk)` ([pipe](https://github.com/untool/mixinable/blob/master/README.md#definepipe))
This is the most relevant hook provided by `@untool/yargs`: it enables other mixins to register their respective commands. Implementations of this mixin method will receive two arguments: a [`yargs`](http://yargs.js.org) instance and [`chalk`](https://github.com/chalk/chalk) to help you format your console output. Implementations need to return the `yargs` instance that they were called with.
```javascript
const { Mixin } = require('@untool/core');
module.exports = class FooMixin extends Mixin {
registerCommands(yargs) {
return yargs.command({
command: 'foo',
handler: argv => {},
});
}
};
```
### `log{Debug,Info,Warn,Error}(...args)` ([override](https://github.com/untool/mixinable/blob/master/README.md#defineoverride))
These are rather unusual mixin hooks, as they are basically utility methods that you can use in other mixins. They basically simply map to [`console.debug()`](https://nodejs.org/api/console.html#console_console_debug_data_args), [`console.info()`](https://nodejs.org/api/console.html#console_console_info_data_args), [`console.warn()`](https://nodejs.org/api/console.html#console_console_warn_data_args), [`console.error()`](https://nodejs.org/api/console.html#console_console_error_data_args).
```javascript
const { Mixin } = require('@untool/core');
module.exports = class FooMixin extends Mixin {
foo() {
const { logInfo } = this.core;
logInfo('foo!');
}
};
```
You can override the default implementation of these hooks by defining the appropriate methods in a custom `@untool/core` [`core` mixin](https://github.com/untool/untool/blob/master/packages/core/README.md#mixins).
### `logStats(stats)` ([override](https://github.com/untool/mixinable/blob/master/README.md#defineoverride))
This is yet another utility, aimed specifically at printing [Webpack stats](https://webpack.js.org/configuration/stats/). It receives a [`stats`](https://github.com/webpack/docs/wiki/node.js-api#stats) object and its output to `stdout` is considered `info`. It uses [`console.info()`](https://nodejs.org/api/console.html#console_console_info_data_args) under the hood.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc