Comparing version 0.16.0 to 0.17.0
@@ -6,2 +6,15 @@ # Change Log | ||
<a name="0.17.0"></a> | ||
# [0.17.0](https://github.com/untool/untool/compare/v0.16.0...v0.17.0) (2018-08-17) | ||
### Features | ||
* **untool:** enable option to silence log output ([e972da7](https://github.com/untool/untool/commit/e972da7)) | ||
* **untool:** introduce configurable export ([178c6cb](https://github.com/untool/untool/commit/178c6cb)) | ||
<a name="0.16.0"></a> | ||
@@ -8,0 +21,0 @@ # [0.16.0](https://github.com/untool/untool/compare/v0.15.1...v0.16.0) (2018-08-06) |
39
index.js
@@ -9,12 +9,33 @@ #!/usr/bin/env node | ||
try { | ||
const getRootDir = () => { | ||
const pkgFile = findUp('package.json'); | ||
const yargsPath = resolve(dirname(pkgFile), '@untool/yargs'); | ||
require(yargsPath) | ||
.configure({ mixins: [__dirname] }) | ||
.run(); | ||
} catch (_) { | ||
// eslint-disable-next-line no-console | ||
console.error("Error: Can't find @untool/yargs \n"); | ||
process.exit(1); | ||
if (!pkgFile) throw new Error("Can't resolve package.json"); | ||
return dirname(pkgFile); | ||
}; | ||
const configure = (config = { mixins: [__dirname] }, options) => ({ | ||
run() { | ||
try { | ||
const rootDir = getRootDir(); | ||
const yargsPath = resolve(rootDir, '@untool/yargs'); | ||
const { configure: configureYargs } = require(yargsPath); | ||
configureYargs(config, options).run(); | ||
} catch (error) { | ||
if (error.message && error.message.startsWith("Can't resolve")) { | ||
// eslint-disable-next-line no-console | ||
console.error("Error: Can't find @untool/yargs \n"); | ||
} else { | ||
// eslint-disable-next-line no-console | ||
console.error(error.stack ? error.stack.toString() : error.toString()); | ||
} | ||
process.exit(1); | ||
} | ||
}, | ||
configure, | ||
}); | ||
module.exports = configure(); | ||
if (module === require.main) { | ||
module.exports.run(); | ||
} |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const { format } = require('url'); | ||
@@ -6,19 +8,40 @@ | ||
module.exports = class CLIMixin { | ||
constructor(config) { | ||
constructor(config, options) { | ||
this.config = config; | ||
this.options = options; | ||
} | ||
registerCommands(yargs) { | ||
return yargs.option('quiet', { | ||
alias: 'q', | ||
description: 'Silence log output', | ||
type: 'boolean', | ||
}); | ||
} | ||
handleArguments(argv) { | ||
this.options = { ...this.options, ...argv }; | ||
const { quiet } = this.options; | ||
const { name } = this.config; | ||
if (!quiet) { | ||
process.stdout.write( | ||
`[${name}] started in ${process.env.NODE_ENV || 'development'} mode\n` | ||
); | ||
} | ||
} | ||
configureBuild(webpackConfig, loaderConfigs, target) { | ||
if (target === 'develop') { | ||
const { quiet } = this.options; | ||
const { name } = this.config; | ||
webpackConfig.plugins.push({ | ||
apply(compiler) { | ||
compiler.hooks.done.tap('untool-log-plugin', (stats) => { | ||
process.stdout.write( | ||
`${name} built successfully in ${prettyMS( | ||
stats.endTime - stats.startTime | ||
)}\n` | ||
); | ||
}); | ||
}, | ||
}); | ||
if (!quiet) { | ||
webpackConfig.plugins.push({ | ||
apply(compiler) { | ||
compiler.hooks.done.tap('untool-log-plugin', (stats) => { | ||
process.stdout.write( | ||
`[${name}] built successfully in ${prettyMS( | ||
stats.endTime - stats.startTime | ||
)}\n` | ||
); | ||
}); | ||
}, | ||
}); | ||
} | ||
} | ||
@@ -28,24 +51,30 @@ return webpackConfig; | ||
inspectBuild(stats) { | ||
const { quiet } = this.options; | ||
const { name } = this.config; | ||
process.stdout.write( | ||
`${name} built successfully\n\n${stats.toString({ | ||
colors: false, | ||
version: false, | ||
hash: false, | ||
modules: false, | ||
entrypoints: false, | ||
chunks: false, | ||
})}\n\n` | ||
); | ||
if (!quiet) { | ||
process.stdout.write( | ||
`[${name}] built successfully\n\n${stats.toString({ | ||
colors: false, | ||
version: false, | ||
hash: false, | ||
modules: false, | ||
entrypoints: false, | ||
chunks: false, | ||
})}\n\n` | ||
); | ||
} | ||
} | ||
inspectServer(server) { | ||
const { quiet } = this.options; | ||
const { name, https, basePath: pathname } = this.config; | ||
const { address, port } = server.address(); | ||
const hostname = ['::', '::1', '0.0.0.0', '127.0.0.1'].includes(address) | ||
? 'localhost' | ||
: address; | ||
const protocol = https ? 'https' : 'http'; | ||
const parts = { protocol, hostname, port, pathname }; | ||
process.stdout.write(`${name} listening at ${format(parts)}\n`); | ||
if (!quiet) { | ||
const { address, port } = server.address(); | ||
const hostname = ['::', '::1', '0.0.0.0', '127.0.0.1'].includes(address) | ||
? 'localhost' | ||
: address; | ||
const protocol = https ? 'https' : 'http'; | ||
const parts = { protocol, hostname, port, pathname }; | ||
process.stdout.write(`[${name}] listening at ${format(parts)}\n`); | ||
} | ||
} | ||
}; |
{ | ||
"name": "untool", | ||
"version": "0.16.0", | ||
"version": "0.17.0", | ||
"description": "untool cli", | ||
"preferGlobal": true, | ||
"bin": { | ||
@@ -27,3 +26,4 @@ "untool": "index.js", | ||
"pretty-ms": "^3.2.0" | ||
} | ||
}, | ||
"gitHead": "9d9952d8df5e891d74249232c458e262b90f5f18" | ||
} |
@@ -5,7 +5,7 @@ # `untool` | ||
`untool` is our main, global command line interface. It serves a single purposes: it can be used to to control `untool` projects. To do so, it provides the terminal command `un`. | ||
`untool` is our main command line interface. It serves a single purposes: it can be used to to control `untool` projects. To do so, it provides the terminal command `un`. Additionally, `untool` provides a bare-bones logging facility that can be disabled by providing a `-q` (or `--quiet`) CLI argument. | ||
### Installation | ||
`untool` is meant to be installed globally, not inside specific projects. If you want to add a local command line interface to your project to be used in `package.json` scripts, please just use [`@untool/yargs`](https://github.com/untool/untool/blob/master/packages/yargs/README.md) directly. | ||
`untool` is meant to be installed globally or inside specific projects. If you install it globally, you can directly call it inside any `untool` powered project. | ||
@@ -16,10 +16,17 @@ ```bash | ||
If you want to add a local command line interface to your project to be used in `package.json` [scripts](https://docs.npmjs.com/cli/run-script), simply add it to that project. | ||
```bash | ||
$ yarn add untool # OR npm install untool | ||
``` | ||
### Utilization | ||
`untools`'s mode of operation is that it will find a locally installed [`@untool/yargs`](https://github.com/untool/untool/blob/master/packages/yargs/README.md) and execute it. It will act as a very minimal wrapper around it. | ||
`untools`'s mode of operation is that it will find a locally installed [`@untool/yargs`](https://github.com/untool/untool/blob/master/packages/yargs/README.md) and control it, acting as a very minimal wrapper around it. | ||
```text | ||
$ un start -s | ||
foo info | ||
server listening at http://localhost:8080 | ||
[foo] started in development mode | ||
[foo] listening at http://localhost:8080 | ||
[foo] built successfully in 1.4s | ||
``` | ||
@@ -40,4 +47,4 @@ | ||
Options: | ||
--version Show version number [boolean] | ||
--help, -h Show help [boolean] | ||
--quiet, -q Suppress log output [boolean] | ||
--help, -h Show help [boolean] | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9314
6
109
48
2